Commit 8fdb5adf7e5b69ac5d9460304f866d6b5b2b940c

Authored by fengwotao
1 parent 9bac6f19

fix: DEFECT-1544 编辑角色授权的时候 取消上下层级联后,选择几个功能确认后一直转圈,编辑界面关闭后重新打开也是一直转圈

... ... @@ -66,7 +66,7 @@ export interface RoleReqDTO {
66 66 name?: string;
67 67 remark?: string;
68 68 status: number;
69   - menu: Array<string>;
  69 + menu: Array<string | number>;
70 70 }
71 71
72 72 export interface ChangeAccountParams {
... ...
... ... @@ -32,7 +32,7 @@
32 32 import { BasicForm, useForm } from '/@/components/Form/index';
33 33 import { formSchema } from './role.data';
34 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 36 const { t } = useI18n(); //加载国际化
37 37 // 加载菜单数据
38 38 import { getAdminMenuList, getMenuList, getMenusIdsByRoleId } from '/@/api/sys/menu';
... ... @@ -60,7 +60,7 @@
60 60 const treeRef = ref<Nullable<TreeActionType>>(null);
61 61 const checked = ref<string[]>([]); //需要选中的节点
62 62 const spinning = ref(false);
63   - const checkedKeysWithHalfChecked = ref<string[]>([]);
  63 + const checkedKeysWithHalfChecked = ref<(string | number)[]>([]);
64 64
65 65 const [registerForm, { resetFields, setFieldsValue, validate }] = useForm({
66 66 labelWidth: 90,
... ... @@ -137,7 +137,12 @@
137 137 async function handleSubmit() {
138 138 setDrawerProps({ loading: true, confirmLoading: true });
139 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 146 const menu = [...new Set([...unref(checkedKeysWithHalfChecked), ...treeCheckedKeys])];
142 147 try {
143 148 const values = await validate();
... ... @@ -237,7 +242,12 @@
237 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 251 checkedKeysWithHalfChecked.value = [
242 252 ...selectedKeys,
243 253 ...(event.halfCheckedKeys as string[]),
... ...