Commit 8fdb5adf7e5b69ac5d9460304f866d6b5b2b940c
1 parent
9bac6f19
fix: DEFECT-1544 编辑角色授权的时候 取消上下层级联后,选择几个功能确认后一直转圈,编辑界面关闭后重新打开也是一直转圈
Showing
2 changed files
with
15 additions
and
5 deletions
@@ -66,7 +66,7 @@ export interface RoleReqDTO { | @@ -66,7 +66,7 @@ export interface RoleReqDTO { | ||
66 | name?: string; | 66 | name?: string; |
67 | remark?: string; | 67 | remark?: string; |
68 | status: number; | 68 | status: number; |
69 | - menu: Array<string>; | 69 | + menu: Array<string | number>; |
70 | } | 70 | } |
71 | 71 | ||
72 | export interface ChangeAccountParams { | 72 | export interface ChangeAccountParams { |
@@ -32,7 +32,7 @@ | @@ -32,7 +32,7 @@ | ||
32 | import { BasicForm, useForm } from '/@/components/Form/index'; | 32 | import { BasicForm, useForm } from '/@/components/Form/index'; |
33 | import { formSchema } from './role.data'; | 33 | import { formSchema } from './role.data'; |
34 | import { BasicDrawer, useDrawerInner } from '/@/components/Drawer'; | 34 | import { BasicDrawer, useDrawerInner } from '/@/components/Drawer'; |
35 | - import { BasicTree, CheckEvent, TreeActionType, TreeItem } from '/@/components/Tree'; | 35 | + import { BasicTree, CheckEvent, TreeActionType, TreeItem, CheckKeys } from '/@/components/Tree'; |
36 | const { t } = useI18n(); //加载国际化 | 36 | const { t } = useI18n(); //加载国际化 |
37 | // 加载菜单数据 | 37 | // 加载菜单数据 |
38 | import { getAdminMenuList, getMenuList, getMenusIdsByRoleId } from '/@/api/sys/menu'; | 38 | import { getAdminMenuList, getMenuList, getMenusIdsByRoleId } from '/@/api/sys/menu'; |
@@ -60,7 +60,7 @@ | @@ -60,7 +60,7 @@ | ||
60 | const treeRef = ref<Nullable<TreeActionType>>(null); | 60 | const treeRef = ref<Nullable<TreeActionType>>(null); |
61 | const checked = ref<string[]>([]); //需要选中的节点 | 61 | const checked = ref<string[]>([]); //需要选中的节点 |
62 | const spinning = ref(false); | 62 | const spinning = ref(false); |
63 | - const checkedKeysWithHalfChecked = ref<string[]>([]); | 63 | + const checkedKeysWithHalfChecked = ref<(string | number)[]>([]); |
64 | 64 | ||
65 | const [registerForm, { resetFields, setFieldsValue, validate }] = useForm({ | 65 | const [registerForm, { resetFields, setFieldsValue, validate }] = useForm({ |
66 | labelWidth: 90, | 66 | labelWidth: 90, |
@@ -137,7 +137,12 @@ | @@ -137,7 +137,12 @@ | ||
137 | async function handleSubmit() { | 137 | async function handleSubmit() { |
138 | setDrawerProps({ loading: true, confirmLoading: true }); | 138 | setDrawerProps({ loading: true, confirmLoading: true }); |
139 | const { createMessage } = useMessage(); | 139 | const { createMessage } = useMessage(); |
140 | - const treeCheckedKeys: string[] = (unref(treeRef)?.getCheckedKeys() as string[]) || []; | 140 | + let treeCheckedKeys: string[] | CheckKeys = |
141 | + (unref(treeRef)?.getCheckedKeys() as string[] | CheckKeys) || []; | ||
142 | + //fix 取消层级独立后(unref(treeRef)?.getCheckedKeys() as string[])的数据不是数组,是{checked:[],halfChecked:[]}对象,迭代报错 | ||
143 | + if (!Array.isArray(treeCheckedKeys)) { | ||
144 | + treeCheckedKeys = treeCheckedKeys?.checked; | ||
145 | + } | ||
141 | const menu = [...new Set([...unref(checkedKeysWithHalfChecked), ...treeCheckedKeys])]; | 146 | const menu = [...new Set([...unref(checkedKeysWithHalfChecked), ...treeCheckedKeys])]; |
142 | try { | 147 | try { |
143 | const values = await validate(); | 148 | const values = await validate(); |
@@ -237,7 +242,12 @@ | @@ -237,7 +242,12 @@ | ||
237 | return needExcludeKeys; | 242 | return needExcludeKeys; |
238 | }; | 243 | }; |
239 | 244 | ||
240 | - const handleCheckClick = (selectedKeys: string[], event: CheckEvent) => { | 245 | + const handleCheckClick = (selectedKeys: CheckKeys, event: CheckEvent) => { |
246 | + //fix 取消层级独立后selectedKeys不是数组,是{checked:[],halfChecked:[]}对象 迭代报错 | ||
247 | + if (!Array.isArray(selectedKeys)) { | ||
248 | + selectedKeys = selectedKeys?.checked; | ||
249 | + event.halfCheckedKeys = []; | ||
250 | + } | ||
241 | checkedKeysWithHalfChecked.value = [ | 251 | checkedKeysWithHalfChecked.value = [ |
242 | ...selectedKeys, | 252 | ...selectedKeys, |
243 | ...(event.halfCheckedKeys as string[]), | 253 | ...(event.halfCheckedKeys as string[]), |