|
|
@@ -1,16 +1,19 @@
|
|
|
<script setup lang="ts">
|
|
|
-import { computed, reactive, ref, watch } from 'vue';
|
|
|
+import { computed, onMounted, reactive, ref, watch } from 'vue';
|
|
|
+import { Crypto } from '@sa/utils';
|
|
|
import { useAuthStore } from '@/store/modules/auth';
|
|
|
import { useFormRules, useNaiveForm } from '@/hooks/common/form';
|
|
|
import { getUUID } from '@/utils/zt';
|
|
|
+import { localStg } from '@/utils/storage';
|
|
|
import { $t } from '@/locales';
|
|
|
-
|
|
|
defineOptions({
|
|
|
name: 'PwdLogin'
|
|
|
});
|
|
|
+const pd = new Crypto<{ data: string }>('zhongshuweilai');
|
|
|
|
|
|
const authStore = useAuthStore();
|
|
|
const { formRef, validate } = useNaiveForm();
|
|
|
+const isRememberMe = ref(false);
|
|
|
const imgPath = ref('');
|
|
|
interface FormModel {
|
|
|
userName: string;
|
|
|
@@ -19,11 +22,22 @@ interface FormModel {
|
|
|
}
|
|
|
|
|
|
const model: FormModel = reactive({
|
|
|
- userName: 'admin',
|
|
|
- password: 'root2025',
|
|
|
+ userName: '',
|
|
|
+ password: '',
|
|
|
imageCode: ''
|
|
|
});
|
|
|
|
|
|
+onMounted(() => {
|
|
|
+ const userName = localStg.get('userName');
|
|
|
+ const password = localStg.get('password');
|
|
|
+ const obj = pd.decrypt(String(password));
|
|
|
+ if (userName && password && obj) {
|
|
|
+ model.userName = userName;
|
|
|
+ model.password = obj.data;
|
|
|
+ isRememberMe.value = true;
|
|
|
+ }
|
|
|
+});
|
|
|
+
|
|
|
const rules = computed<Record<keyof FormModel, App.Global.FormRule[]>>(() => {
|
|
|
// inside computed to make locale reactive, if not apply i18n, you can define it without computed
|
|
|
const { formRules } = useFormRules();
|
|
|
@@ -37,6 +51,11 @@ const rules = computed<Record<keyof FormModel, App.Global.FormRule[]>>(() => {
|
|
|
const sessionUUID = ref('');
|
|
|
async function handleSubmit() {
|
|
|
await validate();
|
|
|
+ if (isRememberMe.value) {
|
|
|
+ const pwd = pd.encrypt({ data: model.password });
|
|
|
+ localStg.set('userName', model.userName);
|
|
|
+ localStg.set('password', pwd);
|
|
|
+ }
|
|
|
await authStore.login({ ...model, sessionUUID: sessionUUID.value });
|
|
|
}
|
|
|
async function getDataCode() {
|
|
|
@@ -77,7 +96,7 @@ watch(
|
|
|
</NFormItem>
|
|
|
<NSpace vertical :size="24">
|
|
|
<div class="flex-y-center justify-between">
|
|
|
- <NCheckbox>{{ $t('page.login.pwdLogin.rememberMe') }}</NCheckbox>
|
|
|
+ <NCheckbox v-model:checked="isRememberMe">{{ $t('page.login.pwdLogin.rememberMe') }}</NCheckbox>
|
|
|
</div>
|
|
|
<NButton type="primary" size="large" round block :loading="authStore.loginLoading" @click="handleSubmit">
|
|
|
{{ $t('common.confirm') }}
|