64 lines
2.1 KiB
Vue
64 lines
2.1 KiB
Vue
<script setup lang="ts">
|
|
import { computed, reactive, ref } from 'vue';
|
|
import { useRouter } from 'vue-router';
|
|
|
|
import { useUserStore } from '@vben/stores';
|
|
|
|
import { Alert, Button, Card, Form, FormItem, Input, message } from 'ant-design-vue';
|
|
|
|
import { changeMyPassword } from '#/api/console';
|
|
import { t } from '#/locales/t';
|
|
|
|
const router = useRouter();
|
|
const userStore = useUserStore();
|
|
// 只有后端标记「首登必须改密」时(getUserInfoApi 把落地页锁在本页)才挂警告;从下拉「个人中心」进来改密码的不挂
|
|
const mustChange = computed(() => userStore.userInfo?.homePath === '/profile/password');
|
|
const submitting = ref(false);
|
|
const form = reactive({ current_password: '', new_password: '', confirm: '' });
|
|
|
|
async function submit() {
|
|
if (form.new_password !== form.confirm) {
|
|
message.warning(t('两次输入的新密码不一致'));
|
|
return;
|
|
}
|
|
submitting.value = true;
|
|
try {
|
|
await changeMyPassword({
|
|
current_password: form.current_password,
|
|
new_password: form.new_password,
|
|
});
|
|
message.success(t('密码已修改'));
|
|
await router.push('/');
|
|
} finally {
|
|
submitting.value = false;
|
|
}
|
|
}
|
|
</script>
|
|
|
|
<template>
|
|
<div class="mx-auto max-w-xl p-5">
|
|
<Alert
|
|
v-if="mustChange"
|
|
class="mb-4"
|
|
type="warning"
|
|
show-icon
|
|
:message="t('首次登录必须修改初始密码')"
|
|
:description="t('初始密码是公开的默认值,不改等于没有密码。改完才能进入其他页面。')"
|
|
/>
|
|
<Card :title="t('修改密码')">
|
|
<Form :model="form" layout="vertical">
|
|
<FormItem :label="t('当前密码')">
|
|
<Input.Password v-model:value="form.current_password" />
|
|
</FormItem>
|
|
<FormItem :label="t('新密码(至少 10 位,需同时含字母和数字)')">
|
|
<Input.Password v-model:value="form.new_password" />
|
|
</FormItem>
|
|
<FormItem :label="t('确认新密码')">
|
|
<Input.Password v-model:value="form.confirm" />
|
|
</FormItem>
|
|
<Button type="primary" :loading="submitting" @click="submit">{{ t('提交') }}</Button>
|
|
</Form>
|
|
</Card>
|
|
</div>
|
|
</template>
|