fix: 登录界面,增加记住密码。
This commit is contained in:
@@ -12,7 +12,7 @@
|
||||
</view>
|
||||
<view class="input-item flex align-center">
|
||||
<view class="iconfont icon-password icon"></view>
|
||||
<input v-model="loginForm.password" type="password" class="input" placeholder="请输入密码" maxlength="20" />
|
||||
<input v-model="loginForm.password" type="password" class="input" placeholder="请输入密码" maxlength="20" />
|
||||
</view>
|
||||
<view class="input-item flex align-center" style="width: 60%;margin: 0px;" v-if="captchaEnabled">
|
||||
<view class="iconfont icon-code icon"></view>
|
||||
@@ -21,6 +21,17 @@
|
||||
<image :src="codeUrl" @click="getCode" class="login-code-img"></image>
|
||||
</view>
|
||||
</view>
|
||||
<view class="flex align-center" style="margin-left: 5px;">
|
||||
<up-checkbox
|
||||
:customStyle="{marginBottom: '8px'}"
|
||||
label="记住密码"
|
||||
name="agree"
|
||||
usedAlone
|
||||
@change="rememberMeChange()"
|
||||
v-model:checked="rememberMe"
|
||||
>
|
||||
</up-checkbox>
|
||||
</view>
|
||||
<view class="action-btn">
|
||||
<button @click="handleLogin" class="login-btn cu-btn block bg-blue lg round">登录</button>
|
||||
</view>
|
||||
@@ -37,17 +48,19 @@
|
||||
<script setup>
|
||||
import modal from '@/plugins/modal'
|
||||
import { getCodeImg } from '@/api/login'
|
||||
import { ref } from "vue";
|
||||
import { ref , onMounted } from "vue";
|
||||
import config from '@/config.js'
|
||||
import useUserStore from '@/store/modules/user'
|
||||
import { getWxCode } from '@/utils/geek';
|
||||
import { wxLogin } from '@/api/oauth';
|
||||
import { setToken } from '@/utils/auth';
|
||||
import { encrypt, decrypt } from '@/utils/jsencrypt'
|
||||
const userStore = useUserStore()
|
||||
const codeUrl = ref("");
|
||||
const captchaEnabled = ref(true); // 是否开启验证码
|
||||
const useWxLogin = ref(false); // 是否使用微信登录
|
||||
const globalConfig = ref(config);
|
||||
const rememberMe = ref(false);
|
||||
const loginForm = ref({
|
||||
username: "",
|
||||
password: "",
|
||||
@@ -66,7 +79,17 @@ if (useWxLogin.value) {
|
||||
});
|
||||
})
|
||||
}
|
||||
// 页面加载时检查是否记住了密码
|
||||
onMounted(() => {
|
||||
|
||||
const username = localStorage.getItem('username');
|
||||
const password = localStorage.getItem('password');
|
||||
if (username&&password) {
|
||||
loginForm.value.username = username;
|
||||
loginForm.value.password = decrypt(password);
|
||||
rememberMe.value = true;
|
||||
}
|
||||
});
|
||||
|
||||
// 获取图形验证码
|
||||
function getCode() {
|
||||
@@ -78,7 +101,6 @@ function getCode() {
|
||||
}
|
||||
})
|
||||
};
|
||||
|
||||
function handleRegister() {
|
||||
uni.navigateTo({
|
||||
url: `/pages/register`
|
||||
@@ -109,8 +131,15 @@ async function pwdLogin() {
|
||||
}
|
||||
})
|
||||
};
|
||||
|
||||
function loginSuccess(result) {
|
||||
if (rememberMe.value) {
|
||||
localStorage.setItem('username', loginForm.value.username);
|
||||
localStorage.setItem('password', encrypt(loginForm.value.password));
|
||||
} else {
|
||||
rememberMe.value=false
|
||||
localStorage.removeItem('username');
|
||||
localStorage.removeItem('password');
|
||||
}
|
||||
// 设置用户信息
|
||||
userStore.getInfo().then(res => {
|
||||
uni.switchTab({
|
||||
@@ -119,6 +148,10 @@ function loginSuccess(result) {
|
||||
})
|
||||
}
|
||||
|
||||
function rememberMeChange(){
|
||||
rememberMe.value = !rememberMe.value;
|
||||
|
||||
}
|
||||
// 隐私协议
|
||||
function handlePrivacy() {
|
||||
let site = globalConfig.value.appInfo.agreements[0];
|
||||
@@ -133,7 +166,6 @@ function handleUserAgrement() {
|
||||
url: `/pages/common/webview/index?title=${site.title}&url=${site.url}`
|
||||
});
|
||||
};
|
||||
|
||||
getCode();
|
||||
</script>
|
||||
|
||||
|
||||
Reference in New Issue
Block a user