🎨一些提交

This commit is contained in:
comma 2024-05-20 20:09:25 +08:00
parent 6a675d0418
commit 6a37c8d902
3 changed files with 147 additions and 2 deletions

View File

@ -25,3 +25,8 @@ export const editUser = (data?: object) => {
export const deleteUser = (userId: string) => {
return http.request("delete", baseUri("/user/delete/" + userId));
};
// 修改密码
export const changePassword = (data?: object) => {
return http.request("post", baseUri("/user/change-password"), { data });
};

View File

@ -0,0 +1,95 @@
<script setup lang="ts">
import { ref } from "vue";
import { FormInstance } from "element-plus";
// props
export interface ChangePwdFormProps {
formInline: {
id: string;
originPassword: string;
newPassword: string;
confirmPassword: string;
};
}
// props
// https://cn.vuejs.org/guide/typescript/composition-api.html#typing-component-props
const props = withDefaults(defineProps<ChangePwdFormProps>(), {
formInline: () => ({
id: "",
originPassword: "",
newPassword: "",
confirmPassword: ""
})
});
// vue prop prop Vue
// reactive ref Ref value reactive
// newFormInline === props.formInline true props.formInline
// props.formInline
// https://cn.vuejs.org/guide/components/props.html#one-way-data-flow
const changePwdForm = ref(props.formInline);
const changePwdFormRef = ref<FormInstance>();
function getUserChangePwdFormRef() {
return changePwdFormRef.value;
}
//
const passConfirm = (rule: any, value: any, callback: any) => {
if (value === "") {
callback(new Error("确认密码不能为空"));
} else if (value !== changePwdForm.value.newPassword) {
callback(new Error("两次密码不一致"));
} else {
callback();
}
};
defineExpose({ getUserChangePwdFormRef });
</script>
<template>
<el-form ref="changePwdFormRef" :model="changePwdForm" label-width="20%">
<el-form-item
prop="originPassword"
label="原密码"
:rules="[{ required: true, message: '原密码不能为空', trigger: 'blur' }]"
>
<el-input
v-model="changePwdForm.originPassword"
show-password
class="!w-[220px]"
placeholder="原密码"
/>
</el-form-item>
<el-form-item
prop="newPassword"
label="新密码"
:rules="[
{ required: true, message: '新密码不能为空', trigger: 'blur' },
{ min: 6, message: '密码最低6位', trigger: 'blur' },
{ max: 32, message: '密码最长32位', trigger: 'blur' }
]"
>
<el-input
v-model="changePwdForm.newPassword"
show-password
class="!w-[220px]"
placeholder="新密码"
/>
</el-form-item>
<el-form-item
prop="confirmPassword"
label="确认密码"
:rules="[{ validator: passConfirm, trigger: 'blur' }]"
>
<el-input
v-model="changePwdForm.confirmPassword"
show-password
class="!w-[220px]"
placeholder="确认密码"
/>
</el-form-item>
</el-form>
</template>

View File

@ -6,15 +6,22 @@ import LayNavMix from "../lay-sidebar/NavMix.vue";
import LaySidebarFullScreen from "../lay-sidebar/components/SidebarFullScreen.vue";
import LaySidebarBreadCrumb from "../lay-sidebar/components/SidebarBreadCrumb.vue";
import LaySidebarTopCollapse from "../lay-sidebar/components/SidebarTopCollapse.vue";
import LogoutCircleRLine from "@iconify-icons/ri/logout-circle-r-line";
import Setting from "@iconify-icons/ri/settings-3-line";
import { h, ref } from "vue";
import { addDialog } from "@/components/ReDialog/index";
import { editUser as editUserApi, getUser, userList } from "@/api/user";
import {
changePassword,
editUser as editUserApi,
getUser,
userList
} from "@/api/user";
import { storageLocal } from "@pureadmin/utils";
import { setUser, userKey } from "@/utils/auth";
import forms, { type FormProps } from "./component/user.vue";
import changePwdForms, {
type ChangePwdFormProps
} from "./component/change-password.vue";
import { useRouter } from "vue-router";
import useGetGlobalProperties from "@/hooks/useGetGlobalProperties";
@ -34,6 +41,7 @@ const { $bus } = useGetGlobalProperties();
const router = useRouter();
const userEditFormRef = ref();
const changePwdFormRef = ref();
// eslint-disable-next-line vue/valid-define-emits
const emit = defineEmits();
@ -85,6 +93,34 @@ const openUserInfoDialog = () => {
}
});
};
const openChangePasswordDialog = () => {
const loginUser = storageLocal().getItem(userKey);
addDialog({
width: "20%",
title: loginUser.name,
contentRenderer: () => h(changePwdForms, { ref: changePwdFormRef }),
props: {
formInline: {
id: loginUser.id,
originPassword: "",
newPassword: "",
confirmPassword: ""
}
},
beforeSure: (done, { options }) => {
const FormRef = changePwdFormRef.value.getUserChangePwdFormRef();
FormRef.validate(valid => {
if (!valid) return;
changePassword(options.props.formInline).then(res => {
if (res.code === 200) {
done();
}
});
});
}
});
};
</script>
<template>
@ -126,6 +162,15 @@ const openUserInfoDialog = () => {
个人信息
</el-dropdown-item>
</el-dropdown-menu>
<el-dropdown-menu class="logout">
<el-dropdown-item @click="openChangePasswordDialog">
<IconifyIconOnline
icon="ic:baseline-lock-person"
style="margin: 5px"
/>
修改密码
</el-dropdown-item>
</el-dropdown-menu>
<el-dropdown-menu class="logout">
<el-dropdown-item @click="logout">
<IconifyIconOffline