fix: 登录界面,增加记住密码。
This commit is contained in:
@@ -66,6 +66,7 @@
|
||||
"@ttou/uview-typings": "^2.0.5",
|
||||
"clipboard": "^2.0.11",
|
||||
"dayjs": "^1.11.9",
|
||||
"jsencrypt": "3.3.1",
|
||||
"mqtt": "4.1.0",
|
||||
"pinia": "^2.0.36",
|
||||
"pinia-plugin-persist": "^1.0.0",
|
||||
|
||||
@@ -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>
|
||||
|
||||
|
||||
30
src/utils/jsencrypt.js
Normal file
30
src/utils/jsencrypt.js
Normal file
@@ -0,0 +1,30 @@
|
||||
import JSEncrypt from 'jsencrypt/bin/jsencrypt.min'
|
||||
|
||||
// 密钥对生成 http://web.chacuo.net/netrsakeypair
|
||||
|
||||
const publicKey = 'MFwwDQYJKoZIhvcNAQEBBQADSwAwSAJBAKoR8mX0rGKLqzcWmOzbfj64K8ZIgOdH\n' +
|
||||
'nzkXSOVOZbFu/TJhZ7rFAN+eaGkl3C4buccQd/EjEsj9ir7ijT7h96MCAwEAAQ=='
|
||||
|
||||
const privateKey = 'MIIBVAIBADANBgkqhkiG9w0BAQEFAASCAT4wggE6AgEAAkEAqhHyZfSsYourNxaY\n' +
|
||||
'7Nt+PrgrxkiA50efORdI5U5lsW79MmFnusUA355oaSXcLhu5xxB38SMSyP2KvuKN\n' +
|
||||
'PuH3owIDAQABAkAfoiLyL+Z4lf4Myxk6xUDgLaWGximj20CUf+5BKKnlrK+Ed8gA\n' +
|
||||
'kM0HqoTt2UZwA5E2MzS4EI2gjfQhz5X28uqxAiEA3wNFxfrCZlSZHb0gn2zDpWow\n' +
|
||||
'cSxQAgiCstxGUoOqlW8CIQDDOerGKH5OmCJ4Z21v+F25WaHYPxCFMvwxpcw99Ecv\n' +
|
||||
'DQIgIdhDTIqD2jfYjPTY8Jj3EDGPbH2HHuffvflECt3Ek60CIQCFRlCkHpi7hthh\n' +
|
||||
'YhovyloRYsM+IS9h/0BzlEAuO0ktMQIgSPT3aFAgJYwKpqRYKlLDVcflZFCKY7u3\n' +
|
||||
'UP8iWi1Qw0Y='
|
||||
|
||||
// 加密
|
||||
export function encrypt(txt) {
|
||||
const encryptor = new JSEncrypt()
|
||||
encryptor.setPublicKey(publicKey) // 设置公钥
|
||||
return encryptor.encrypt(txt) // 对数据进行加密
|
||||
}
|
||||
|
||||
// 解密
|
||||
export function decrypt(txt) {
|
||||
const encryptor = new JSEncrypt()
|
||||
encryptor.setPrivateKey(privateKey) // 设置私钥
|
||||
return encryptor.decrypt(txt) // 对数据进行解密
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user