Browse Source

🚀 菜单大调整,支持外链 内嵌 多级菜单

master
wangxiang 3 years ago
parent
commit
6764070ed7
  1. 4
      src/components/Table/src/hooks/useRowSelection.ts
  2. 4
      src/utils/helper/treeHelper.ts
  3. 15
      src/views/system/menu/MenuModal.vue
  4. 2
      src/views/system/menu/menu.data.ts

4
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 { computed, ComputedRef, nextTick, Ref, ref, toRaw, unref, watch } from 'vue';
import { ROW_KEY } from '../const'; import { ROW_KEY } from '../const';
import { omit } from 'lodash-es'; import { omit } from 'lodash-es';
import { findNodeAll } from '/@/utils/helper/treeHelper'; import { findNodeIn } from '/@/utils/helper/treeHelper';
export function useRowSelection( export function useRowSelection(
propsRef: ComputedRef<BasicTableProps>, propsRef: ComputedRef<BasicTableProps>,
@ -67,7 +67,7 @@ export function useRowSelection(
function setSelectedRowKeys(rowKeys: string[]) { function setSelectedRowKeys(rowKeys: string[]) {
selectedRowKeysRef.value = rowKeys; selectedRowKeysRef.value = rowKeys;
const allSelectedRows = findNodeAll( const allSelectedRows = findNodeIn(
toRaw(unref(tableData)).concat(toRaw(unref(selectedRowRef))), toRaw(unref(tableData)).concat(toRaw(unref(selectedRowRef))),
(item) => rowKeys.includes(item[unref(getRowKey) as string]), (item) => rowKeys.includes(item[unref(getRowKey) as string]),
{ {

4
src/utils/helper/treeHelper.ts

@ -56,8 +56,8 @@ export function findNode<T = any>(tree: any, func: Fn, config: Partial<TreeHelpe
return null; return null;
} }
/** 查找树形匹配的节点信息,包含当前节点数据以及他父级的节点数据,以集合的形式返回 */ /** 查找树形匹配 in 的节点信息,以集合的形式返回 */
export function findNodeAll<T = any>(tree: any, func: Fn, config: Partial<TreeHelperConfig> = {}): T[] { export function findNodeIn<T = any>(tree: any, func: Fn, config: Partial<TreeHelperConfig> = {}): T[] {
config = getConfig(config); config = getConfig(config);
const { children } = config; const { children } = config;
const list = [...tree]; const list = [...tree];

15
src/views/system/menu/MenuModal.vue

@ -14,15 +14,20 @@
* Copyright © 2020-2022 <a href="http://www.entfrm.com/">entfrm</a> All rights reserved. * Copyright © 2020-2022 <a href="http://www.entfrm.com/">entfrm</a> All rights reserved.
* author entfrm开发团队-王翔 * author entfrm开发团队-王翔
*/ */
import { ref, unref } from 'vue'; import { ref, unref, reactive, toRaw } from 'vue';
import { BasicForm, useForm } from '/@/components/Form/index'; import { BasicForm, useForm } from '/@/components/Form/index';
import { formSchema } from './menu.data'; import { formSchema } from './menu.data';
import { BasicModal, ModalProps, useModalInner } from '/@/components/Modal'; import { BasicModal, ModalProps, useModalInner } from '/@/components/Modal';
import { listMenu, addMenu, editMenu, getMenu } from '/@/api/platform/system/controller/menu'; 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<Nullable<string>>(''); const tag = ref<Nullable<string>>('');
const menuTree = ref<Recordable[]>([]);
/** https://v3.cn.vuejs.org/api/options-data.html#emits */ /** https://v3.cn.vuejs.org/api/options-data.html#emits */
const emit = defineEmits(['success', 'register']); const emit = defineEmits(['success', 'register']);
const [registerForm, { resetFields, setFieldsValue, updateSchema, validate, clearValidate }] = useForm({ const [registerForm, { resetFields, setFieldsValue, updateSchema, validate, clearValidate }] = useForm({
@ -38,7 +43,8 @@
// //
tag.value = data._tag; tag.value = data._tag;
const topMenu = { id: '0', name: '顶级菜单', children: [] }; const topMenu = { id: '0', name: '顶级菜单', children: [] };
topMenu.children = listToTree(await listMenu()); state.menuTree = listToTree(await listMenu());
topMenu.children = state.menuTree;
await updateSchema({ await updateSchema({
field: 'parentId', field: 'parentId',
componentProps: { componentProps: {
@ -72,6 +78,9 @@
// tag // tag
switch (unref(tag)) { switch (unref(tag)) {
case 'add': case 'add':
//
const superMenus = findPath(toRaw(state.menuTree),(node) => node.id == formData?.parentId);
formData.parentIds = (superMenus||[]).map(item => item.id);
await addMenu(formData); await addMenu(formData);
break; break;
case 'edit': case 'edit':

2
src/views/system/menu/menu.data.ts

@ -120,7 +120,9 @@ export const formSchema: FormSchema[] = [
label: '上级菜单', label: '上级菜单',
component: 'TreeSelect', component: 'TreeSelect',
defaultValue: '0', defaultValue: '0',
required: true,
componentProps: { componentProps: {
allowClear: false,
replaceFields: { replaceFields: {
title: 'name', title: 'name',
key: 'id', key: 'id',

Loading…
Cancel
Save