refactor: ♻️ 用户页面代码优化,使用字典翻译组件

This commit is contained in:
ray
2024-10-31 01:20:41 +08:00
parent ea6feac8ce
commit 7e554a7751
2 changed files with 59 additions and 58 deletions

View File

@@ -257,7 +257,7 @@ export interface UserPageVO {
/** 用户邮箱 */ /** 用户邮箱 */
email?: string; email?: string;
/** 性别 */ /** 性别 */
genderLabel?: string; gender?: number;
/** 用户ID */ /** 用户ID */
id?: number; id?: number;
/** 手机号 */ /** 手机号 */

View File

@@ -59,9 +59,8 @@
</el-form> </el-form>
</div> </div>
<el-card shadow="never" class="table-wrapper"> <el-card shadow="never">
<template #header> <div class="flex-x-between mb-10px">
<div class="flex-x-between">
<div> <div>
<el-button <el-button
v-hasPerm="['sys:user:add']" v-hasPerm="['sys:user:add']"
@@ -82,18 +81,25 @@
</el-button> </el-button>
</div> </div>
<div> <div>
<el-button class="ml-3" @click="handleOpenImportDialog"> <el-button
<template #icon><Upload /></template> v-hasPerm="['sys:user:import']"
type="default"
icon="upload"
@click="handleOpenImportDialog"
>
导入 导入
</el-button> </el-button>
<el-button class="ml-3" @click="handleExport"> <el-button
<template #icon><Download /></template> v-hasPerm="['sys:user:export']"
type="default"
icon="download"
@click="handleExport"
>
导出 导出
</el-button> </el-button>
</div> </div>
</div> </div>
</template>
<el-table <el-table
v-loading="loading" v-loading="loading"
@@ -116,12 +122,11 @@
/> />
<el-table-column label="用户昵称" align="center" prop="nickname" /> <el-table-column label="用户昵称" align="center" prop="nickname" />
<el-table-column <el-table-column label="性别" width="100" align="center">
label="性别" <template #default="scope">
width="100" <DictLabel :v-modle="scope.row.gender" code="gender" />
align="center" </template>
prop="genderLabel" </el-table-column>
/>
<el-table-column <el-table-column
label="部门" label="部门"
@@ -291,7 +296,7 @@
<!-- 用户导入弹窗 --> <!-- 用户导入弹窗 -->
<UserImport <UserImport
v-model:visible="importDialogVisible" v-model:visible="importDialogVisible"
@import-success="handleUserImportSuccess" @import-success="handleQuery()"
/> />
</div> </div>
</template> </template>
@@ -337,7 +342,7 @@ const dialog = reactive({
title: "", title: "",
}); });
/** 导入弹窗显示状态 */ // 导入弹窗显示状态
const importDialogVisible = ref(false); const importDialogVisible = ref(false);
// 用户表单数据 // 用户表单数据
@@ -345,7 +350,7 @@ const formData = reactive<UserForm>({
status: 1, status: 1,
}); });
/** 用户表单校验规则 */ // 用户表单校验规则
const rules = reactive({ const rules = reactive({
username: [{ required: true, message: "用户名不能为空", trigger: "blur" }], username: [{ required: true, message: "用户名不能为空", trigger: "blur" }],
nickname: [{ required: true, message: "用户昵称不能为空", trigger: "blur" }], nickname: [{ required: true, message: "用户昵称不能为空", trigger: "blur" }],
@@ -367,7 +372,7 @@ const rules = reactive({
], ],
}); });
/** 查询 */ //查询
function handleQuery() { function handleQuery() {
loading.value = true; loading.value = true;
UserAPI.getPage(queryParams) UserAPI.getPage(queryParams)
@@ -380,7 +385,7 @@ function handleQuery() {
}); });
} }
/** 重置查询 */ // 重置查询
function handleResetQuery() { function handleResetQuery() {
queryFormRef.value.resetFields(); queryFormRef.value.resetFields();
queryParams.pageNum = 1; queryParams.pageNum = 1;
@@ -389,16 +394,12 @@ function handleResetQuery() {
handleQuery(); handleQuery();
} }
/** 行复选框选中记录选中ID集合 */ // 行复选框选中记录选中ID集合
function handleSelectionChange(selection: any) { function handleSelectionChange(selection: any) {
removeIds.value = selection.map((item: any) => item.id); removeIds.value = selection.map((item: any) => item.id);
} }
/** // 重置密码
* 重置密码
*
*
*/
function hancleResetPassword(row: { [key: string]: any }) { function hancleResetPassword(row: { [key: string]: any }) {
ElMessageBox.prompt( ElMessageBox.prompt(
"请输入用户「" + row.username + "」的新密码", "请输入用户「" + row.username + "」的新密码",
@@ -446,7 +447,7 @@ async function handleOpenDialog(id?: number) {
} }
} }
/** 关闭弹窗 */ // 关闭弹窗
function handleCloseDialog() { function handleCloseDialog() {
dialog.visible = false; dialog.visible = false;
userFormRef.value.resetFields(); userFormRef.value.resetFields();
@@ -456,7 +457,7 @@ function handleCloseDialog() {
formData.status = 1; formData.status = 1;
} }
/** 表单提交 */ // 表单提交
const handleSubmit = useThrottleFn(() => { const handleSubmit = useThrottleFn(() => {
userFormRef.value.validate((valid: any) => { userFormRef.value.validate((valid: any) => {
if (valid) { if (valid) {
@@ -483,7 +484,7 @@ const handleSubmit = useThrottleFn(() => {
}); });
}, 3000); }, 3000);
/** 删除用户 */ // 删除用户
function handleDelete(id?: number) { function handleDelete(id?: number) {
const userIds = [id || removeIds.value].join(","); const userIds = [id || removeIds.value].join(",");
if (!userIds) { if (!userIds) {
@@ -510,17 +511,17 @@ function handleDelete(id?: number) {
} }
); );
} }
/** 打开导入弹窗 */ // 打开导入弹窗 *
function handleOpenImportDialog() { function handleOpenImportDialog() {
importDialogVisible.value = true; importDialogVisible.value = true;
} }
/** 导入用户成功 */ // 导入用户成功
function handleUserImportSuccess() { function handleUserImportSuccess() {
handleQuery(); handleQuery();
} }
/** 导出用户 */ // 导出用户
function handleExport() { function handleExport() {
UserAPI.export(queryParams).then((response: any) => { UserAPI.export(queryParams).then((response: any) => {
const fileData = response.data; const fileData = response.data;