refactor: ♻️ 角色管理代码优化

This commit is contained in:
ray
2024-11-04 08:22:45 +08:00
parent d37d70b04c
commit 04605b891e

View File

@@ -24,8 +24,8 @@
</el-form> </el-form>
</div> </div>
<el-card shadow="never" class="table-wrapper"> <el-card shadow="never">
<template #header> <div class="mb-10px">
<el-button type="success" @click="handleOpenDialog()"> <el-button type="success" @click="handleOpenDialog()">
<template #icon><Plus /></template> <template #icon><Plus /></template>
新增 新增
@@ -38,7 +38,7 @@
<template #icon><Delete /></template> <template #icon><Delete /></template>
删除 删除
</el-button> </el-button>
</template> </div>
<el-table <el-table
ref="dataTableRef" ref="dataTableRef"
@@ -67,27 +67,27 @@
type="primary" type="primary"
size="small" size="small"
link link
icon="position"
@click="handleOpenAssignPermDialog(scope.row)" @click="handleOpenAssignPermDialog(scope.row)"
> >
<template #icon><Position /></template>
分配权限 分配权限
</el-button> </el-button>
<el-button <el-button
type="primary" type="primary"
size="small" size="small"
link link
icon="edit"
@click="handleOpenDialog(scope.row.id)" @click="handleOpenDialog(scope.row.id)"
> >
<template #icon><Edit /></template>
编辑 编辑
</el-button> </el-button>
<el-button <el-button
type="danger" type="danger"
size="small" size="small"
link link
icon="delete"
@click="handleDelete(scope.row.id)" @click="handleDelete(scope.row.id)"
> >
<template #icon><Delete /></template>
删除 删除
</el-button> </el-button>
</template> </template>
@@ -218,7 +218,6 @@
{{ data.label }} {{ data.label }}
</template> </template>
</el-tree> </el-tree>
<template #footer> <template #footer>
<div class="dialog-footer"> <div class="dialog-footer">
<el-button type="primary" @click="handleAssignPermSubmit"> <el-button type="primary" @click="handleAssignPermSubmit">
@@ -271,8 +270,6 @@ const dialog = reactive({
const formData = reactive<RoleForm>({ const formData = reactive<RoleForm>({
sort: 1, sort: 1,
status: 1, status: 1,
code: "",
name: "",
}); });
const rules = reactive({ const rules = reactive({
@@ -295,7 +292,7 @@ const isExpanded = ref(true);
const parentChildLinked = ref(true); const parentChildLinked = ref(true);
/** 查询 */ // 查询
function handleQuery() { function handleQuery() {
loading.value = true; loading.value = true;
RoleAPI.getPage(queryParams) RoleAPI.getPage(queryParams)
@@ -308,19 +305,19 @@ function handleQuery() {
}); });
} }
/** 重置查询 */ // 重置查询
function handleResetQuery() { function handleResetQuery() {
queryFormRef.value.resetFields(); queryFormRef.value.resetFields();
queryParams.pageNum = 1; queryParams.pageNum = 1;
handleQuery(); handleQuery();
} }
/** 行复选框选中记录选中ID集合 */ // 行复选框选中
function handleSelectionChange(selection: any) { function handleSelectionChange(selection: any) {
ids.value = selection.map((item: any) => item.id); ids.value = selection.map((item: any) => item.id);
} }
/** 打开角色弹窗 */ // 打开角色弹窗
function handleOpenDialog(roleId?: number) { function handleOpenDialog(roleId?: number) {
dialog.visible = true; dialog.visible = true;
if (roleId) { if (roleId) {
@@ -333,7 +330,7 @@ function handleOpenDialog(roleId?: number) {
} }
} }
/** 提交角色表单 */ // 提交角色表单
function handleSubmit() { function handleSubmit() {
roleFormRef.value.validate((valid: any) => { roleFormRef.value.validate((valid: any) => {
if (valid) { if (valid) {
@@ -360,7 +357,7 @@ function handleSubmit() {
}); });
} }
/** 关闭角色弹窗 */ // 关闭弹窗
function handleCloseDialog() { function handleCloseDialog() {
dialog.visible = false; dialog.visible = false;
@@ -372,7 +369,7 @@ function handleCloseDialog() {
formData.status = 1; formData.status = 1;
} }
/** 删除角色 */ // 删除角色
function handleDelete(roleId?: number) { function handleDelete(roleId?: number) {
const roleIds = [roleId || ids.value].join(","); const roleIds = [roleId || ids.value].join(",");
if (!roleIds) { if (!roleIds) {
@@ -400,7 +397,7 @@ function handleDelete(roleId?: number) {
); );
} }
/** 打开分配菜单权限弹窗 */ // 打开分配菜单权限弹窗
async function handleOpenAssignPermDialog(row: RolePageVO) { async function handleOpenAssignPermDialog(row: RolePageVO) {
const roleId = row.id; const roleId = row.id;
if (roleId) { if (roleId) {
@@ -427,7 +424,7 @@ async function handleOpenAssignPermDialog(row: RolePageVO) {
} }
} }
/** 分配菜单权限提交 */ // 分配菜单权限提交
function handleAssignPermSubmit() { function handleAssignPermSubmit() {
const roleId = checkedRole.value.id; const roleId = checkedRole.value.id;
if (roleId) { if (roleId) {
@@ -448,7 +445,7 @@ function handleAssignPermSubmit() {
} }
} }
/** 展开/收缩 菜单权限树 */ // 展开/收缩 菜单权限树
function togglePermTree() { function togglePermTree() {
isExpanded.value = !isExpanded.value; isExpanded.value = !isExpanded.value;
if (permTreeRef.value) { if (permTreeRef.value) {
@@ -462,7 +459,7 @@ function togglePermTree() {
} }
} }
/** 权限筛选 */ // 权限筛选
watch(permKeywords, (val) => { watch(permKeywords, (val) => {
permTreeRef.value!.filter(val); permTreeRef.value!.filter(val);
}); });
@@ -477,7 +474,7 @@ function handlePermFilter(
return data.label.includes(value); return data.label.includes(value);
} }
/** 父子菜单节点是否联动 change*/ // 父子菜单节点是否联动
function handleparentChildLinkedChange(val: any) { function handleparentChildLinkedChange(val: any) {
parentChildLinked.value = val; parentChildLinked.value = val;
} }