|
|
@@ -42,18 +42,7 @@
|
|
|
<img :src="codeUrl" @click="getCode" class="login-code-img"/>
|
|
|
</div>
|
|
|
</el-form-item>
|
|
|
- <el-checkbox v-model="loginForm.rememberMe">记住密码</el-checkbox>
|
|
|
-
|
|
|
- <!-- 同意用户协议和隐私协议复选框 -->
|
|
|
- <el-form-item prop="agree" style="margin-bottom: 20px;">
|
|
|
- <el-checkbox v-model="loginForm.agree">
|
|
|
- 同意
|
|
|
- <el-link type="primary" :underline="false" href="/user-agreement" target="_blank">《用户协议》</el-link>
|
|
|
- 和
|
|
|
- <el-link type="primary" :underline="false" href="/privacy-policy" target="_blank">《隐私政策》</el-link>
|
|
|
- </el-checkbox>
|
|
|
- </el-form-item>
|
|
|
-
|
|
|
+ <el-checkbox v-model="loginForm.rememberMe" style="margin:0px 0px 25px 0px;">记住密码</el-checkbox>
|
|
|
<el-form-item style="width:100%;">
|
|
|
<el-button
|
|
|
:loading="loading"
|
|
|
@@ -71,16 +60,7 @@
|
|
|
</el-form-item>
|
|
|
</el-form>
|
|
|
</div>
|
|
|
-
|
|
|
- <!-- Cookie同意横幅(深色字体,浅色背景) -->
|
|
|
- <div v-if="showCookieBanner" class="cookie-banner">
|
|
|
- <span class="cookie-text">
|
|
|
- 我们将使用Cookie优化您的浏览体验,并通过第三方SDK实现网站功能。如果您想继续浏览本网站,请您同意使用Cookie和隐私条款。
|
|
|
- </span>
|
|
|
- <el-button type="primary" size="small" @click="acceptCookies">同意</el-button>
|
|
|
- </div>
|
|
|
-
|
|
|
- <!-- 底部版权信息 -->
|
|
|
+ <!-- 底部 -->
|
|
|
<div class="el-login-footer">
|
|
|
<span>{{ footerContent }}</span>
|
|
|
</div>
|
|
|
@@ -93,9 +73,6 @@ import Cookies from "js-cookie"
|
|
|
import { encrypt, decrypt } from "@/utils/jsencrypt"
|
|
|
import useUserStore from '@/store/modules/user'
|
|
|
import defaultSettings from '@/settings'
|
|
|
-import { ElMessage } from "element-plus"
|
|
|
-import { ref, watch, getCurrentInstance, onMounted } from 'vue'
|
|
|
-import { useRoute, useRouter } from 'vue-router'
|
|
|
|
|
|
const title = import.meta.env.VITE_APP_TITLE
|
|
|
const footerContent = defaultSettings.footerContent
|
|
|
@@ -104,59 +81,48 @@ const route = useRoute()
|
|
|
const router = useRouter()
|
|
|
const { proxy } = getCurrentInstance()
|
|
|
|
|
|
-// 登录表单数据
|
|
|
const loginForm = ref({
|
|
|
username: "",
|
|
|
password: "",
|
|
|
rememberMe: false,
|
|
|
code: "",
|
|
|
- uuid: "",
|
|
|
- agree: false
|
|
|
+ uuid: ""
|
|
|
})
|
|
|
|
|
|
-// 表单验证规则
|
|
|
const loginRules = {
|
|
|
username: [{ required: true, trigger: "blur", message: "请输入您的账号" }],
|
|
|
password: [{ required: true, trigger: "blur", message: "请输入您的密码" }],
|
|
|
- code: [{ required: true, trigger: "change", message: "请输入验证码" }],
|
|
|
- agree: [{ required: true, trigger: "change", message: "请同意用户协议和隐私政策" }]
|
|
|
+ code: [{ required: true, trigger: "change", message: "请输入验证码" }]
|
|
|
}
|
|
|
|
|
|
const codeUrl = ref("")
|
|
|
const loading = ref(false)
|
|
|
-const captchaEnabled = ref(true) // 验证码开关
|
|
|
-const register = ref(false) // 注册开关
|
|
|
+// 验证码开关
|
|
|
+const captchaEnabled = ref(true)
|
|
|
+// 注册开关
|
|
|
+const register = ref(false)
|
|
|
const redirect = ref(undefined)
|
|
|
-const showCookieBanner = ref(false) // 控制Cookie横幅显示
|
|
|
|
|
|
-// 监听重定向地址
|
|
|
watch(route, (newRoute) => {
|
|
|
- redirect.value = newRoute.query && newRoute.query.redirect
|
|
|
+ redirect.value = newRoute.query && newRoute.query.redirect
|
|
|
}, { immediate: true })
|
|
|
|
|
|
-// 登录处理
|
|
|
function handleLogin() {
|
|
|
- if (!proxy.$refs.loginRef) return
|
|
|
-
|
|
|
- proxy.$refs.loginRef.validate((valid) => {
|
|
|
- if (!loginForm.value.agree) {
|
|
|
- ElMessage.warning('请先同意用户协议和隐私协议')
|
|
|
- return
|
|
|
- }
|
|
|
-
|
|
|
+ proxy.$refs.loginRef.validate(valid => {
|
|
|
if (valid) {
|
|
|
loading.value = true
|
|
|
- // 记住密码
|
|
|
+ // 勾选了需要记住密码设置在 cookie 中设置记住用户名和密码
|
|
|
if (loginForm.value.rememberMe) {
|
|
|
Cookies.set("username", loginForm.value.username, { expires: 30 })
|
|
|
Cookies.set("password", encrypt(loginForm.value.password), { expires: 30 })
|
|
|
Cookies.set("rememberMe", loginForm.value.rememberMe, { expires: 30 })
|
|
|
} else {
|
|
|
+ // 否则移除
|
|
|
Cookies.remove("username")
|
|
|
Cookies.remove("password")
|
|
|
Cookies.remove("rememberMe")
|
|
|
}
|
|
|
-
|
|
|
+ // 调用action的登录方法
|
|
|
userStore.login(loginForm.value).then(() => {
|
|
|
const query = route.query
|
|
|
const otherQueryParams = Object.keys(query).reduce((acc, cur) => {
|
|
|
@@ -168,6 +134,7 @@ function handleLogin() {
|
|
|
router.push({ path: redirect.value || "/", query: otherQueryParams })
|
|
|
}).catch(() => {
|
|
|
loading.value = false
|
|
|
+ // 重新获取验证码
|
|
|
if (captchaEnabled.value) {
|
|
|
getCode()
|
|
|
}
|
|
|
@@ -176,7 +143,6 @@ function handleLogin() {
|
|
|
})
|
|
|
}
|
|
|
|
|
|
-// 获取验证码
|
|
|
function getCode() {
|
|
|
getCodeImg().then(res => {
|
|
|
captchaEnabled.value = res.captchaEnabled === undefined ? true : res.captchaEnabled
|
|
|
@@ -187,54 +153,19 @@ function getCode() {
|
|
|
})
|
|
|
}
|
|
|
|
|
|
-// 从Cookie读取记住的密码
|
|
|
function getCookie() {
|
|
|
- try {
|
|
|
- const username = Cookies.get("username")
|
|
|
- const password = Cookies.get("password")
|
|
|
- const rememberMe = Cookies.get("rememberMe")
|
|
|
-
|
|
|
- if (username !== undefined) loginForm.value.username = username
|
|
|
- if (password !== undefined) {
|
|
|
- try {
|
|
|
- loginForm.value.password = decrypt(password)
|
|
|
- } catch (e) {
|
|
|
- console.warn('密码解密失败', e)
|
|
|
- loginForm.value.password = ''
|
|
|
- }
|
|
|
- }
|
|
|
- if (rememberMe !== undefined) loginForm.value.rememberMe = Boolean(rememberMe)
|
|
|
- } catch (e) {
|
|
|
- console.error('读取Cookie失败', e)
|
|
|
- }
|
|
|
-}
|
|
|
-
|
|
|
-// 检查是否已经同意过Cookie(使用localStorage)
|
|
|
-function checkCookieConsent() {
|
|
|
- const consented = localStorage.getItem('cookieConsent')
|
|
|
- if (consented === 'true') {
|
|
|
- showCookieBanner.value = false
|
|
|
- // 如果之前同意过,自动勾选协议复选框
|
|
|
- loginForm.value.agree = true
|
|
|
- } else {
|
|
|
- showCookieBanner.value = true
|
|
|
+ const username = Cookies.get("username")
|
|
|
+ const password = Cookies.get("password")
|
|
|
+ const rememberMe = Cookies.get("rememberMe")
|
|
|
+ loginForm.value = {
|
|
|
+ username: username === undefined ? loginForm.value.username : username,
|
|
|
+ password: password === undefined ? loginForm.value.password : decrypt(password),
|
|
|
+ rememberMe: rememberMe === undefined ? false : Boolean(rememberMe)
|
|
|
}
|
|
|
}
|
|
|
|
|
|
-// 同意Cookie
|
|
|
-function acceptCookies() {
|
|
|
- localStorage.setItem('cookieConsent', 'true')
|
|
|
- showCookieBanner.value = false
|
|
|
- loginForm.value.agree = true // 同时勾选协议复选框
|
|
|
- ElMessage.success('感谢您的同意')
|
|
|
-}
|
|
|
-
|
|
|
-// 初始化
|
|
|
-onMounted(() => {
|
|
|
- getCode()
|
|
|
- getCookie()
|
|
|
- checkCookieConsent()
|
|
|
-})
|
|
|
+getCode()
|
|
|
+getCookie()
|
|
|
</script>
|
|
|
|
|
|
<style lang='scss' scoped>
|
|
|
@@ -254,6 +185,7 @@ onMounted(() => {
|
|
|
right: 0;
|
|
|
padding-top: 5%;
|
|
|
|
|
|
+
|
|
|
.title-logo {
|
|
|
margin: 30px auto;
|
|
|
color: #333;
|
|
|
@@ -270,6 +202,7 @@ onMounted(() => {
|
|
|
font-size: 24rpx;
|
|
|
line-height: 32rpx;
|
|
|
}
|
|
|
+
|
|
|
}
|
|
|
|
|
|
.login-form {
|
|
|
@@ -303,46 +236,6 @@ onMounted(() => {
|
|
|
vertical-align: middle;
|
|
|
}
|
|
|
}
|
|
|
-.login-code-img {
|
|
|
- height: 40px;
|
|
|
-}
|
|
|
-
|
|
|
-/* Cookie同意横幅样式:深色字体,浅色背景,固定在底部 */
|
|
|
-.cookie-banner {
|
|
|
- position: fixed;
|
|
|
- bottom: 40px; /* 位于版权信息上方 */
|
|
|
- left: 0;
|
|
|
- width: 100%;
|
|
|
- background-color: #f9f9f9; /* 浅色背景 */
|
|
|
- color: #333; /* 深色字体 */
|
|
|
- padding: 12px 20px;
|
|
|
- display: flex;
|
|
|
- justify-content: center;
|
|
|
- align-items: center;
|
|
|
- gap: 20px;
|
|
|
- box-shadow: 0 -2px 8px rgba(0,0,0,0.1);
|
|
|
- z-index: 1000;
|
|
|
- font-size: 14px;
|
|
|
- flex-wrap: wrap;
|
|
|
- text-align: center;
|
|
|
-}
|
|
|
-.cookie-text {
|
|
|
- max-width: 70%;
|
|
|
- line-height: 1.5;
|
|
|
-}
|
|
|
-.el-button--small {
|
|
|
- background-color: #409EFF;
|
|
|
- color: white;
|
|
|
- border: none;
|
|
|
- padding: 8px 16px;
|
|
|
- border-radius: 4px;
|
|
|
- cursor: pointer;
|
|
|
- font-weight: 500;
|
|
|
-}
|
|
|
-.el-button--small:hover {
|
|
|
- background-color: #66b1ff;
|
|
|
-}
|
|
|
-
|
|
|
.el-login-footer {
|
|
|
height: 40px;
|
|
|
line-height: 40px;
|
|
|
@@ -355,4 +248,7 @@ onMounted(() => {
|
|
|
font-size: 12px;
|
|
|
letter-spacing: 1px;
|
|
|
}
|
|
|
-</style>
|
|
|
+.login-code-img {
|
|
|
+ height: 40px;
|
|
|
+}
|
|
|
+</style>
|