fix: 角色右上角关闭未清空数据问题修复(Closes #I6483U)

Former-commit-id: 545a34deddb7b632ca5a87efc036f7d19aef5b01
This commit is contained in:
haoxr
2022-12-03 10:57:10 +08:00
parent aee7a3fd9b
commit baae5ca613
3 changed files with 22 additions and 22 deletions

View File

@@ -25,10 +25,10 @@ export interface Role {
export type RolePageResult = PageResult<Role[]>; export type RolePageResult = PageResult<Role[]>;
/** /**
* 角色表单类型 * 角色表单
*/ */
export interface RoleForm { export interface RoleForm {
id?: string; id?: number;
name: string; name: string;
code: string; code: string;
sort: number; sort: number;

View File

@@ -47,7 +47,7 @@ const state = reactive({
dataScope: [{ required: true, message: '请选择数据权限', trigger: 'blur' }], dataScope: [{ required: true, message: '请选择数据权限', trigger: 'blur' }],
status: [{ required: true, message: '请选择状态', trigger: 'blur' }] status: [{ required: true, message: '请选择状态', trigger: 'blur' }]
}, },
menuDialogVisible: false, allocationDialogVisible: false,
resourceOptions: [] as OptionType[], resourceOptions: [] as OptionType[],
// 勾选的菜单ID // 勾选的菜单ID
checkedMenuIds: new Set([]), checkedMenuIds: new Set([]),
@@ -67,7 +67,7 @@ const {
dialog, dialog,
formData, formData,
rules, rules,
menuDialogVisible, allocationDialogVisible,
checkedRole, checkedRole,
resourceOptions resourceOptions
} = toRefs(state); } = toRefs(state);
@@ -117,12 +117,12 @@ function handleUpdate(row: any) {
}); });
} }
function submitFormData() { function handleSubmit() {
loading.value = true; loading.value = true;
dataFormRef.value.validate((valid: any) => { dataFormRef.value.validate((valid: any) => {
if (valid) { if (valid) {
if (state.formData.id) { if (state.formData.id) {
updateRole(state.formData.id as any, state.formData).then(() => { updateRole(state.formData.id, state.formData).then(() => {
ElMessage.success('修改角色成功'); ElMessage.success('修改角色成功');
closeDialog(); closeDialog();
handleQuery(); handleQuery();
@@ -130,8 +130,8 @@ function submitFormData() {
}); });
} else { } else {
addRole(state.formData).then(() => { addRole(state.formData).then(() => {
closeDialog();
ElMessage.success('新增角色成功'); ElMessage.success('新增角色成功');
closeDialog();
handleQuery(); handleQuery();
loading.value = false; loading.value = false;
}); });
@@ -169,10 +169,10 @@ function handleDelete(row: any) {
} }
/** /**
* 资源分配 * 资源分配弹窗
*/ */
function showRoleMenuDialog(row: Role) { function showAllocationDialog(row: Role) {
menuDialogVisible.value = true; allocationDialogVisible.value = true;
loading.value = true; loading.value = true;
const roleId: any = row.id; const roleId: any = row.id;
@@ -197,16 +197,16 @@ function showRoleMenuDialog(row: Role) {
}); });
} }
/** /**
* 分配资源提交 * 资源分配提交
*/ */
function handleRoleResourceSubmit() { function handleAllocationSubmit() {
const checkedMenuIds: number[] = resourceRef.value const checkedMenuIds: number[] = resourceRef.value
.getCheckedNodes(false, true) .getCheckedNodes(false, true)
.map((node: any) => node.value); .map((node: any) => node.value);
updateRoleMenus(checkedRole.value.id, checkedMenuIds).then(res => { updateRoleMenus(checkedRole.value.id, checkedMenuIds).then(res => {
ElMessage.success('分配权限成功'); ElMessage.success('分配权限成功');
menuDialogVisible.value = false; allocationDialogVisible.value = false;
handleQuery(); handleQuery();
}); });
} }
@@ -214,8 +214,8 @@ function handleRoleResourceSubmit() {
/** /**
* 关闭资源弹窗 * 关闭资源弹窗
*/ */
function closeMenuDialogVisible() { function closeAllocationDialog() {
menuDialogVisible.value = false; allocationDialogVisible.value = false;
} }
onMounted(() => { onMounted(() => {
@@ -288,7 +288,7 @@ onMounted(() => {
<el-button <el-button
type="success" type="success"
link link
@click.stop="showRoleMenuDialog(scope.row)" @click.stop="showAllocationDialog(scope.row)"
> >
资源分配 资源分配
</el-button> </el-button>
@@ -322,7 +322,7 @@ onMounted(() => {
:title="dialog.title" :title="dialog.title"
v-model="dialog.visible" v-model="dialog.visible"
width="500px" width="500px"
destroy-on-close @close="closeDialog"
> >
<el-form <el-form
ref="dataFormRef" ref="dataFormRef"
@@ -366,7 +366,7 @@ onMounted(() => {
<template #footer> <template #footer>
<div class="dialog-footer"> <div class="dialog-footer">
<el-button type="primary" @click="submitFormData"> </el-button> <el-button type="primary" @click="handleSubmit"> </el-button>
<el-button @click="closeDialog"> </el-button> <el-button @click="closeDialog"> </el-button>
</div> </div>
</template> </template>
@@ -375,7 +375,7 @@ onMounted(() => {
<!-- assign permission dialog --> <!-- assign permission dialog -->
<el-dialog <el-dialog
:title="'【' + checkedRole.name + '】资源分配'" :title="'【' + checkedRole.name + '】资源分配'"
v-model="menuDialogVisible" v-model="allocationDialogVisible"
width="800px" width="800px"
> >
<el-scrollbar max-height="600px" v-loading="loading"> <el-scrollbar max-height="600px" v-loading="loading">
@@ -394,10 +394,10 @@ onMounted(() => {
<template #footer> <template #footer>
<div class="dialog-footer"> <div class="dialog-footer">
<el-button type="primary" @click="handleRoleResourceSubmit" <el-button type="primary" @click="handleAllocationSubmit"
> </el-button > </el-button
> >
<el-button @click="closeMenuDialogVisible"> </el-button> <el-button @click="closeAllocationDialog"> </el-button>
</div> </div>
</template> </template>
</el-dialog> </el-dialog>

2
types/index.d.ts vendored
View File

@@ -1,5 +1,5 @@
declare type DialogType = { declare type DialogType = {
title: string; title?: string;
visible: boolean; visible: boolean;
}; };