mirror of
https://gitee.com/beijing_hongye_huicheng/lilishop-ui.git
synced 2026-11-09 02:18:55 +08:00
- buyer(95) / seller(169) / im(53) / manager(280) 共 597 个组件全部从 Options API 转换为 <script setup> - 四端 vuex 全部移除,状态管理统一迁移至 pinia 4(stores/ 目录) - util.js 等基础设施去除 vm 首参依赖;全局属性($Message/$filters 等)在 script 内改为具名导入 - 被外部 ref 访问的公共组件均已补齐 defineExpose(清单见各端 MIGRATION-VUE3.md) - 各端 eslint 启用 vue/component-api-style 防止新代码回退 Options API - 四端 yarn build 全部通过;迁移约定与注意事项已更新至各端 MIGRATION-VUE3.md
122 lines
3.7 KiB
Vue
122 lines
3.7 KiB
Vue
<template>
|
|
<div>
|
|
<el-card class="change-pass">
|
|
<template #header>修改密码</template>
|
|
<el-form
|
|
ref="editPasswordFormRef"
|
|
:model="editPasswordForm"
|
|
label-width="100px"
|
|
label-position="right"
|
|
:rules="passwordValidate"
|
|
style="width: 450px"
|
|
class="mt_10"
|
|
>
|
|
<el-form-item label="原密码" prop="oldPassword">
|
|
<el-input
|
|
v-model="editPasswordForm.oldPassword"
|
|
type="password"
|
|
show-password
|
|
placeholder="请输入现在使用的密码"
|
|
/>
|
|
</el-form-item>
|
|
<el-form-item label="新密码" prop="newPassword">
|
|
<SetPassword v-model="editPasswordForm.newPassword" @on-change="changeInputPass" />
|
|
</el-form-item>
|
|
<el-form-item label="确认新密码" prop="rePassword">
|
|
<el-input
|
|
v-model="editPasswordForm.rePassword"
|
|
type="password"
|
|
show-password
|
|
placeholder="请再次输入新密码"
|
|
/>
|
|
</el-form-item>
|
|
<el-form-item>
|
|
<el-button type="primary" :loading="savePassLoading" @click="saveEditPass">保存</el-button>
|
|
<el-button @click="cancelEditPass">取消</el-button>
|
|
</el-form-item>
|
|
</el-form>
|
|
</el-card>
|
|
</div>
|
|
</template>
|
|
|
|
<script setup>
|
|
import { reactive, ref } from "vue";
|
|
import { useRouter } from "vue-router";
|
|
import SetPassword from "@/components/lili/set-password";
|
|
import { changePass } from "@/api/index";
|
|
import { ElMessageBox } from "element-plus";
|
|
import { md5 } from "@/utils/md5.js";
|
|
import { useAppStore } from "@/stores/app";
|
|
import { useUserStore } from "@/stores/user";
|
|
|
|
defineOptions({ name: "change-password" });
|
|
|
|
const router = useRouter();
|
|
const appStore = useAppStore();
|
|
const userStore = useUserStore();
|
|
|
|
const editPasswordFormRef = ref(null);
|
|
const savePassLoading = ref(false);
|
|
const editPasswordForm = reactive({
|
|
oldPassword: "",
|
|
newPassword: "",
|
|
rePassword: "",
|
|
});
|
|
const strength = ref("");
|
|
const valideRePassword = (rule, value, callback) => {
|
|
if (value !== editPasswordForm.newPassword) {
|
|
callback(new Error("两次输入密码不一致"));
|
|
} else {
|
|
callback();
|
|
}
|
|
};
|
|
const passwordValidate = {
|
|
oldPassword: [{ required: true, message: "请输入原密码", trigger: "blur" }],
|
|
newPassword: [
|
|
{ required: true, message: "请输入新密码", trigger: "blur" },
|
|
{ min: 6, message: "请至少输入6个字符", trigger: "blur" },
|
|
{ max: 32, message: "最多输入32个字符", trigger: "blur" },
|
|
],
|
|
rePassword: [
|
|
{ required: true, message: "请再次输入新密码", trigger: "blur" },
|
|
{ validator: valideRePassword, trigger: "blur" },
|
|
],
|
|
};
|
|
|
|
function changeInputPass(v, grade, strengthVal) {
|
|
strength.value = strengthVal;
|
|
}
|
|
|
|
function saveEditPass() {
|
|
const params = {
|
|
password: md5(editPasswordForm.oldPassword),
|
|
newPassword: md5(editPasswordForm.newPassword),
|
|
passStrength: md5(strength.value),
|
|
};
|
|
editPasswordFormRef.value.validate((valid) => {
|
|
if (!valid) return;
|
|
savePassLoading.value = true;
|
|
changePass(params).then((res) => {
|
|
savePassLoading.value = false;
|
|
if (res.success) {
|
|
ElMessageBox.alert("修改密码成功,需重新登录", "修改密码成功", {
|
|
confirmButtonText: "确定",
|
|
callback: () => {
|
|
userStore.logout();
|
|
router.push({ name: "login" });
|
|
},
|
|
});
|
|
}
|
|
});
|
|
});
|
|
}
|
|
|
|
function cancelEditPass() {
|
|
appStore.removeTag("change_password");
|
|
localStorage.pageOpenedList = JSON.stringify(appStore.pageOpenedList);
|
|
const list = appStore.pageOpenedList;
|
|
const lastPageName = list.length > 1 ? list[list.length - 1].name : list[0].name;
|
|
router.push({ name: lastPageName });
|
|
}
|
|
</script>
|