index.vue
3.06 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
<template>
<div>
<PageWrapper
:title="t('system.password.title')"
:content="t('system.password.content')"
class="p-4"
:contentStyle="{ margin: '16px 0 ' }"
>
<div class="py-8 bg-white flex flex-col justify-center items-center">
<BasicForm @register="register" />
<div class="flex justify-center">
<a-button @click="resetFields"> {{ t('common.resetText') }} </a-button>
<a-button class="!ml-4" type="primary" @click="handleSubmit">
{{ t('common.okText') }}
</a-button>
</div>
</div>
</PageWrapper>
</div>
</template>
<script lang="ts">
import { defineComponent } from 'vue';
import { PageWrapper } from '/@/components/Page';
import { BasicForm, useForm } from '/@/components/Form';
import { USER_INFO_KEY } from '/@/enums/cacheEnum';
import { getAuthCache } from '/@/utils/auth';
import { formSchema } from './pwd.data';
import { resetPassword } from '/@/api/system/system';
import { useMultipleTabStore } from '/@/store/modules/multipleTab';
import { useUserStore } from '/@/store/modules/user';
import { useAppStore } from '/@/store/modules/app';
import { usePermissionStore } from '/@/store/modules/permission';
import { useMessage } from '/@/hooks/web/useMessage';
import { useI18n } from '/@/hooks/web/useI18n';
import { useLocaleStore } from '/@/store/modules/locale';
export default defineComponent({
name: 'ChangePassword',
components: { BasicForm, PageWrapper },
setup() {
const { t } = useI18n();
const [register, { validate, resetFields }] = useForm({
size: 'large',
labelWidth: 100,
showActionButtonGroup: false,
schemas: formSchema,
});
const tabStore = useMultipleTabStore();
const userStore = useUserStore();
const appStore = useAppStore();
const permissionStore = usePermissionStore();
const { createMessage } = useMessage();
const userInfo = getAuthCache(USER_INFO_KEY);
async function handleSubmit() {
try {
const values = await validate();
const { passwordOld, passwordNew } = values;
const params = {
userId: userInfo.userId,
password: passwordOld,
resetPassword: passwordNew,
};
await resetPassword(params).then((result) => {
if (result.data) {
createMessage.success(t('common.editOkText'));
// /dashboard/analysis
setTimeout(function () {
const localeState = useLocaleStore();
const locale = { ...localeState.localInfo };
localStorage.clear();
appStore.resetAllState();
permissionStore.resetState();
tabStore.resetState();
userStore.resetState();
location.reload();
localeState.setLocaleInfo(locale);
}, 500);
}
});
} catch (error) {}
}
return { register, resetFields, handleSubmit, t };
},
});
</script>