From 6764070ed70b4595c01ef436c31c21a3bb559f2f Mon Sep 17 00:00:00 2001 From: wangxiang <1827945911@qq.com> Date: Thu, 4 Aug 2022 10:21:07 +0800 Subject: [PATCH] =?UTF-8?q?:rocket:=20=E8=8F=9C=E5=8D=95=E5=A4=A7=E8=B0=83?= =?UTF-8?q?=E6=95=B4,=E6=94=AF=E6=8C=81=E5=A4=96=E9=93=BE=20=E5=86=85?= =?UTF-8?q?=E5=B5=8C=20=E5=A4=9A=E7=BA=A7=E8=8F=9C=E5=8D=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/components/Table/src/hooks/useRowSelection.ts | 4 ++-- src/utils/helper/treeHelper.ts | 4 ++-- src/views/system/menu/MenuModal.vue | 15 ++++++++++++--- src/views/system/menu/menu.data.ts | 2 ++ 4 files changed, 18 insertions(+), 7 deletions(-) diff --git a/src/components/Table/src/hooks/useRowSelection.ts b/src/components/Table/src/hooks/useRowSelection.ts index 02119c7..55375b6 100644 --- a/src/components/Table/src/hooks/useRowSelection.ts +++ b/src/components/Table/src/hooks/useRowSelection.ts @@ -3,7 +3,7 @@ import type { BasicTableProps, TableRowSelection } from '../types/table'; import { computed, ComputedRef, nextTick, Ref, ref, toRaw, unref, watch } from 'vue'; import { ROW_KEY } from '../const'; import { omit } from 'lodash-es'; -import { findNodeAll } from '/@/utils/helper/treeHelper'; +import { findNodeIn } from '/@/utils/helper/treeHelper'; export function useRowSelection( propsRef: ComputedRef, @@ -67,7 +67,7 @@ export function useRowSelection( function setSelectedRowKeys(rowKeys: string[]) { selectedRowKeysRef.value = rowKeys; - const allSelectedRows = findNodeAll( + const allSelectedRows = findNodeIn( toRaw(unref(tableData)).concat(toRaw(unref(selectedRowRef))), (item) => rowKeys.includes(item[unref(getRowKey) as string]), { diff --git a/src/utils/helper/treeHelper.ts b/src/utils/helper/treeHelper.ts index 62b2069..efc7370 100644 --- a/src/utils/helper/treeHelper.ts +++ b/src/utils/helper/treeHelper.ts @@ -56,8 +56,8 @@ export function findNode(tree: any, func: Fn, config: Partial(tree: any, func: Fn, config: Partial = {}): T[] { +/** 查找树形匹配 in 的节点信息,以集合的形式返回 */ +export function findNodeIn(tree: any, func: Fn, config: Partial = {}): T[] { config = getConfig(config); const { children } = config; const list = [...tree]; diff --git a/src/views/system/menu/MenuModal.vue b/src/views/system/menu/MenuModal.vue index a9694ac..8479107 100644 --- a/src/views/system/menu/MenuModal.vue +++ b/src/views/system/menu/MenuModal.vue @@ -14,15 +14,20 @@ * Copyright © 2020-2022 entfrm All rights reserved. * author entfrm开发团队-王翔 */ - import { ref, unref } from 'vue'; + import { ref, unref, reactive, toRaw } from 'vue'; import { BasicForm, useForm } from '/@/components/Form/index'; import { formSchema } from './menu.data'; import { BasicModal, ModalProps, useModalInner } from '/@/components/Modal'; import { listMenu, addMenu, editMenu, getMenu } from '/@/api/platform/system/controller/menu'; - import { listToTree } from '/@/utils/helper/treeHelper'; + import { listToTree, findPath } from '/@/utils/helper/treeHelper'; /** 通用变量统一声明区域 */ + const state = reactive({ + tag: '', + menuTree: [] + }); const tag = ref>(''); + const menuTree = ref([]); /** https://v3.cn.vuejs.org/api/options-data.html#emits */ const emit = defineEmits(['success', 'register']); const [registerForm, { resetFields, setFieldsValue, updateSchema, validate, clearValidate }] = useForm({ @@ -38,7 +43,8 @@ // 处理设置数据 tag.value = data._tag; const topMenu = { id: '0', name: '顶级菜单', children: [] }; - topMenu.children = listToTree(await listMenu()); + state.menuTree = listToTree(await listMenu()); + topMenu.children = state.menuTree; await updateSchema({ field: 'parentId', componentProps: { @@ -72,6 +78,9 @@ // 采用tag标签区分操作 switch (unref(tag)) { case 'add': + // 处理拿取当前菜单所有父级进行修改角色模块的勾选类型 + const superMenus = findPath(toRaw(state.menuTree),(node) => node.id == formData?.parentId); + formData.parentIds = (superMenus||[]).map(item => item.id); await addMenu(formData); break; case 'edit': diff --git a/src/views/system/menu/menu.data.ts b/src/views/system/menu/menu.data.ts index f418040..fc2bbe6 100644 --- a/src/views/system/menu/menu.data.ts +++ b/src/views/system/menu/menu.data.ts @@ -120,7 +120,9 @@ export const formSchema: FormSchema[] = [ label: '上级菜单', component: 'TreeSelect', defaultValue: '0', + required: true, componentProps: { + allowClear: false, replaceFields: { title: 'name', key: 'id',