From 3fd6193ac1a7d2b3d9df0301697a80c61926355a Mon Sep 17 00:00:00 2001 From: xingyu4j Date: Tue, 6 Dec 2022 15:23:09 +0800 Subject: [PATCH] =?UTF-8?q?perf:=20=E6=8F=90=E5=8F=96tree=20props?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- yudao-ui-admin-vue3/src/utils/tree.ts | 9 +++++ .../infra/codegen/components/GenInfoForm.vue | 10 ++---- .../src/views/system/dept/index.vue | 9 +---- .../src/views/system/menu/index.vue | 35 +++++++++++-------- .../src/views/system/role/index.vue | 7 +--- .../src/views/system/tenantPackage/index.vue | 8 +---- .../src/views/system/user/index.vue | 9 ++--- 7 files changed, 36 insertions(+), 51 deletions(-) diff --git a/yudao-ui-admin-vue3/src/utils/tree.ts b/yudao-ui-admin-vue3/src/utils/tree.ts index 76ec0a2e1..8f1f92cc4 100644 --- a/yudao-ui-admin-vue3/src/utils/tree.ts +++ b/yudao-ui-admin-vue3/src/utils/tree.ts @@ -8,6 +8,11 @@ const DEFAULT_CONFIG: TreeHelperConfig = { children: 'children', pid: 'pid' } +export const defaultProps = { + children: 'children', + label: 'name', + value: 'id' +} const getConfig = (config: Partial) => Object.assign({}, DEFAULT_CONFIG, config) @@ -214,6 +219,10 @@ export const eachTree = (treeDatas: any[], callBack: Fn, parentNode = {}) => { * @param {*} children 孩子节点字段 默认 'children' */ export const handleTree = (data: any[], id?: string, parentId?: string, children?: string) => { + if (!Array.isArray(data)) { + console.warn('data must be an array') + return [] + } const config = { id: id || 'id', parentId: parentId || 'parentId', diff --git a/yudao-ui-admin-vue3/src/views/infra/codegen/components/GenInfoForm.vue b/yudao-ui-admin-vue3/src/views/infra/codegen/components/GenInfoForm.vue index b67795cf9..fd729ce8a 100644 --- a/yudao-ui-admin-vue3/src/views/infra/codegen/components/GenInfoForm.vue +++ b/yudao-ui-admin-vue3/src/views/infra/codegen/components/GenInfoForm.vue @@ -6,7 +6,7 @@ import { onMounted, PropType, reactive, ref, watch } from 'vue' import { Form } from '@/components/Form' import { useForm } from '@/hooks/web/useForm' import { required } from '@/utils/formRules' -import { handleTree } from '@/utils/tree' +import { handleTree, defaultProps } from '@/utils/tree' import { DICT_TYPE, getIntDictOptions } from '@/utils/dict' import { listSimpleMenusApi } from '@/api/system/menu' import { CodegenTableVO } from '@/api/infra/codegen/types' @@ -17,12 +17,6 @@ const props = defineProps({ default: () => null } }) -const menuProps = { - checkStrictly: true, - children: 'children', - label: 'name', - value: 'id' -} const rules = reactive({ templateType: [required], scene: [required], @@ -104,7 +98,7 @@ const schema = reactive([ component: 'TreeSelect', componentProps: { data: menuOptions, - props: menuProps, + props: defaultProps, checkStrictly: true, nodeKey: 'id' }, diff --git a/yudao-ui-admin-vue3/src/views/system/dept/index.vue b/yudao-ui-admin-vue3/src/views/system/dept/index.vue index f8cc39df6..d03f2124a 100644 --- a/yudao-ui-admin-vue3/src/views/system/dept/index.vue +++ b/yudao-ui-admin-vue3/src/views/system/dept/index.vue @@ -78,7 +78,7 @@ import { nextTick, onMounted, reactive, ref, unref } from 'vue' import { ElSelect, ElTreeSelect, ElOption } from 'element-plus' import { VxeGridInstance } from 'vxe-table' -import { handleTree } from '@/utils/tree' +import { handleTree, defaultProps } from '@/utils/tree' import { required } from '@/utils/formRules.js' import { useI18n } from '@/hooks/web/useI18n' import { useMessage } from '@/hooks/web/useMessage' @@ -115,13 +115,6 @@ const rules = reactive({ status: [required] }) -// 下拉框[上级]的配置项目 -const defaultProps = { - checkStrictly: true, - children: 'children', - label: 'name', - value: 'id' -} const getUserList = async () => { const res = await getListSimpleUsersApi() userOption.value = res diff --git a/yudao-ui-admin-vue3/src/views/system/menu/index.vue b/yudao-ui-admin-vue3/src/views/system/menu/index.vue index 8d756f5a9..7bae86418 100644 --- a/yudao-ui-admin-vue3/src/views/system/menu/index.vue +++ b/yudao-ui-admin-vue3/src/views/system/menu/index.vue @@ -103,7 +103,7 @@ () -const menuFormNull = { +const menuForm = ref({ id: 0, name: '', permission: '', @@ -266,9 +265,8 @@ const menuFormNull = { status: CommonStatusEnum.ENABLE, visible: true, keepAlive: true, - createTime: '' -} -const menuForm = ref(menuFormNull) + createTime: new Date() +}) // 新增和修改的表单校验 const rules = reactive({ name: [required], @@ -278,13 +276,6 @@ const rules = reactive({ }) // ========== 下拉框[上级菜单] ========== -// 下拉框[上级菜单]的配置项目 -const menuProps = { - checkStrictly: true, - children: 'children', - label: 'name', - value: 'id' -} const menuOptions = ref([]) // 树形结构 // 获取下拉框[上级菜单]的数据 const getTree = async () => { @@ -335,7 +326,21 @@ const handleCreate = () => { setDialogTile('create') // 重置表单 formRef.value?.resetFields() - menuForm.value = deepCopy(menuFormNull) + menuForm.value = { + id: 0, + name: '', + permission: '', + type: SystemMenuTypeEnum.DIR, + sort: 1, + parentId: 0, + path: '', + icon: '', + component: '', + status: CommonStatusEnum.ENABLE, + visible: true, + keepAlive: true, + createTime: new Date() + } } // 修改操作 diff --git a/yudao-ui-admin-vue3/src/views/system/role/index.vue b/yudao-ui-admin-vue3/src/views/system/role/index.vue index 9b1323281..e00854a23 100644 --- a/yudao-ui-admin-vue3/src/views/system/role/index.vue +++ b/yudao-ui-admin-vue3/src/views/system/role/index.vue @@ -164,7 +164,7 @@ import { FormExpose } from '@/components/Form' import { useI18n } from '@/hooks/web/useI18n' import { useMessage } from '@/hooks/web/useMessage' import { useVxeGrid } from '@/hooks/web/useVxeGrid' -import { handleTree } from '@/utils/tree' +import { handleTree, defaultProps } from '@/utils/tree' import { SystemDataScopeEnum } from '@/utils/constants' import { DICT_TYPE, getDictOptions } from '@/utils/dict' import { rules, allSchemas } from './role.data' @@ -259,11 +259,6 @@ const dataScopeForm = reactive({ dataScope: 0, checkList: [] }) -const defaultProps = { - children: 'children', - label: 'name', - value: 'id' -} const treeOptions = ref([]) // 菜单树形结构 const treeRef = ref>() const dialogScopeVisible = ref(false) diff --git a/yudao-ui-admin-vue3/src/views/system/tenantPackage/index.vue b/yudao-ui-admin-vue3/src/views/system/tenantPackage/index.vue index c80996a80..c45e9adc0 100644 --- a/yudao-ui-admin-vue3/src/views/system/tenantPackage/index.vue +++ b/yudao-ui-admin-vue3/src/views/system/tenantPackage/index.vue @@ -66,7 +66,7 @@