perf: 提取tree props
parent
61f647b385
commit
3fd6193ac1
|
@ -8,6 +8,11 @@ const DEFAULT_CONFIG: TreeHelperConfig = {
|
||||||
children: 'children',
|
children: 'children',
|
||||||
pid: 'pid'
|
pid: 'pid'
|
||||||
}
|
}
|
||||||
|
export const defaultProps = {
|
||||||
|
children: 'children',
|
||||||
|
label: 'name',
|
||||||
|
value: 'id'
|
||||||
|
}
|
||||||
|
|
||||||
const getConfig = (config: Partial<TreeHelperConfig>) => Object.assign({}, DEFAULT_CONFIG, config)
|
const getConfig = (config: Partial<TreeHelperConfig>) => Object.assign({}, DEFAULT_CONFIG, config)
|
||||||
|
|
||||||
|
@ -214,6 +219,10 @@ export const eachTree = (treeDatas: any[], callBack: Fn, parentNode = {}) => {
|
||||||
* @param {*} children 孩子节点字段 默认 'children'
|
* @param {*} children 孩子节点字段 默认 'children'
|
||||||
*/
|
*/
|
||||||
export const handleTree = (data: any[], id?: string, parentId?: string, children?: string) => {
|
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 = {
|
const config = {
|
||||||
id: id || 'id',
|
id: id || 'id',
|
||||||
parentId: parentId || 'parentId',
|
parentId: parentId || 'parentId',
|
||||||
|
|
|
@ -6,7 +6,7 @@ import { onMounted, PropType, reactive, ref, watch } from 'vue'
|
||||||
import { Form } from '@/components/Form'
|
import { Form } from '@/components/Form'
|
||||||
import { useForm } from '@/hooks/web/useForm'
|
import { useForm } from '@/hooks/web/useForm'
|
||||||
import { required } from '@/utils/formRules'
|
import { required } from '@/utils/formRules'
|
||||||
import { handleTree } from '@/utils/tree'
|
import { handleTree, defaultProps } from '@/utils/tree'
|
||||||
import { DICT_TYPE, getIntDictOptions } from '@/utils/dict'
|
import { DICT_TYPE, getIntDictOptions } from '@/utils/dict'
|
||||||
import { listSimpleMenusApi } from '@/api/system/menu'
|
import { listSimpleMenusApi } from '@/api/system/menu'
|
||||||
import { CodegenTableVO } from '@/api/infra/codegen/types'
|
import { CodegenTableVO } from '@/api/infra/codegen/types'
|
||||||
|
@ -17,12 +17,6 @@ const props = defineProps({
|
||||||
default: () => null
|
default: () => null
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
const menuProps = {
|
|
||||||
checkStrictly: true,
|
|
||||||
children: 'children',
|
|
||||||
label: 'name',
|
|
||||||
value: 'id'
|
|
||||||
}
|
|
||||||
const rules = reactive({
|
const rules = reactive({
|
||||||
templateType: [required],
|
templateType: [required],
|
||||||
scene: [required],
|
scene: [required],
|
||||||
|
@ -104,7 +98,7 @@ const schema = reactive<FormSchema[]>([
|
||||||
component: 'TreeSelect',
|
component: 'TreeSelect',
|
||||||
componentProps: {
|
componentProps: {
|
||||||
data: menuOptions,
|
data: menuOptions,
|
||||||
props: menuProps,
|
props: defaultProps,
|
||||||
checkStrictly: true,
|
checkStrictly: true,
|
||||||
nodeKey: 'id'
|
nodeKey: 'id'
|
||||||
},
|
},
|
||||||
|
|
|
@ -78,7 +78,7 @@
|
||||||
import { nextTick, onMounted, reactive, ref, unref } from 'vue'
|
import { nextTick, onMounted, reactive, ref, unref } from 'vue'
|
||||||
import { ElSelect, ElTreeSelect, ElOption } from 'element-plus'
|
import { ElSelect, ElTreeSelect, ElOption } from 'element-plus'
|
||||||
import { VxeGridInstance } from 'vxe-table'
|
import { VxeGridInstance } from 'vxe-table'
|
||||||
import { handleTree } from '@/utils/tree'
|
import { handleTree, defaultProps } from '@/utils/tree'
|
||||||
import { required } from '@/utils/formRules.js'
|
import { required } from '@/utils/formRules.js'
|
||||||
import { useI18n } from '@/hooks/web/useI18n'
|
import { useI18n } from '@/hooks/web/useI18n'
|
||||||
import { useMessage } from '@/hooks/web/useMessage'
|
import { useMessage } from '@/hooks/web/useMessage'
|
||||||
|
@ -115,13 +115,6 @@ const rules = reactive({
|
||||||
status: [required]
|
status: [required]
|
||||||
})
|
})
|
||||||
|
|
||||||
// 下拉框[上级]的配置项目
|
|
||||||
const defaultProps = {
|
|
||||||
checkStrictly: true,
|
|
||||||
children: 'children',
|
|
||||||
label: 'name',
|
|
||||||
value: 'id'
|
|
||||||
}
|
|
||||||
const getUserList = async () => {
|
const getUserList = async () => {
|
||||||
const res = await getListSimpleUsersApi()
|
const res = await getListSimpleUsersApi()
|
||||||
userOption.value = res
|
userOption.value = res
|
||||||
|
|
|
@ -103,7 +103,7 @@
|
||||||
<el-tree-select
|
<el-tree-select
|
||||||
node-key="id"
|
node-key="id"
|
||||||
v-model="menuForm.parentId"
|
v-model="menuForm.parentId"
|
||||||
:props="menuProps"
|
:props="defaultProps"
|
||||||
:data="menuOptions"
|
:data="menuOptions"
|
||||||
:default-expanded-keys="[0]"
|
:default-expanded-keys="[0]"
|
||||||
check-strictly
|
check-strictly
|
||||||
|
@ -237,8 +237,7 @@ import * as MenuApi from '@/api/system/menu'
|
||||||
import { required } from '@/utils/formRules.js'
|
import { required } from '@/utils/formRules.js'
|
||||||
import { DICT_TYPE, getIntDictOptions } from '@/utils/dict'
|
import { DICT_TYPE, getIntDictOptions } from '@/utils/dict'
|
||||||
import { SystemMenuTypeEnum, CommonStatusEnum } from '@/utils/constants'
|
import { SystemMenuTypeEnum, CommonStatusEnum } from '@/utils/constants'
|
||||||
import { handleTree } from '@/utils/tree'
|
import { handleTree, defaultProps } from '@/utils/tree'
|
||||||
import { deepCopy } from 'windicss/utils'
|
|
||||||
|
|
||||||
const { t } = useI18n() // 国际化
|
const { t } = useI18n() // 国际化
|
||||||
const message = useMessage() // 消息弹窗
|
const message = useMessage() // 消息弹窗
|
||||||
|
@ -253,7 +252,7 @@ const actionType = ref('') // 操作按钮的类型
|
||||||
const actionLoading = ref(false) // 遮罩层
|
const actionLoading = ref(false) // 遮罩层
|
||||||
// 新增和修改的表单值
|
// 新增和修改的表单值
|
||||||
const formRef = ref<FormInstance>()
|
const formRef = ref<FormInstance>()
|
||||||
const menuFormNull = {
|
const menuForm = ref<MenuApi.MenuVO>({
|
||||||
id: 0,
|
id: 0,
|
||||||
name: '',
|
name: '',
|
||||||
permission: '',
|
permission: '',
|
||||||
|
@ -266,9 +265,8 @@ const menuFormNull = {
|
||||||
status: CommonStatusEnum.ENABLE,
|
status: CommonStatusEnum.ENABLE,
|
||||||
visible: true,
|
visible: true,
|
||||||
keepAlive: true,
|
keepAlive: true,
|
||||||
createTime: ''
|
createTime: new Date()
|
||||||
}
|
})
|
||||||
const menuForm = ref<MenuApi.MenuVO>(menuFormNull)
|
|
||||||
// 新增和修改的表单校验
|
// 新增和修改的表单校验
|
||||||
const rules = reactive({
|
const rules = reactive({
|
||||||
name: [required],
|
name: [required],
|
||||||
|
@ -278,13 +276,6 @@ const rules = reactive({
|
||||||
})
|
})
|
||||||
|
|
||||||
// ========== 下拉框[上级菜单] ==========
|
// ========== 下拉框[上级菜单] ==========
|
||||||
// 下拉框[上级菜单]的配置项目
|
|
||||||
const menuProps = {
|
|
||||||
checkStrictly: true,
|
|
||||||
children: 'children',
|
|
||||||
label: 'name',
|
|
||||||
value: 'id'
|
|
||||||
}
|
|
||||||
const menuOptions = ref<any[]>([]) // 树形结构
|
const menuOptions = ref<any[]>([]) // 树形结构
|
||||||
// 获取下拉框[上级菜单]的数据
|
// 获取下拉框[上级菜单]的数据
|
||||||
const getTree = async () => {
|
const getTree = async () => {
|
||||||
|
@ -335,7 +326,21 @@ const handleCreate = () => {
|
||||||
setDialogTile('create')
|
setDialogTile('create')
|
||||||
// 重置表单
|
// 重置表单
|
||||||
formRef.value?.resetFields()
|
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()
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// 修改操作
|
// 修改操作
|
||||||
|
|
|
@ -164,7 +164,7 @@ import { FormExpose } from '@/components/Form'
|
||||||
import { useI18n } from '@/hooks/web/useI18n'
|
import { useI18n } from '@/hooks/web/useI18n'
|
||||||
import { useMessage } from '@/hooks/web/useMessage'
|
import { useMessage } from '@/hooks/web/useMessage'
|
||||||
import { useVxeGrid } from '@/hooks/web/useVxeGrid'
|
import { useVxeGrid } from '@/hooks/web/useVxeGrid'
|
||||||
import { handleTree } from '@/utils/tree'
|
import { handleTree, defaultProps } from '@/utils/tree'
|
||||||
import { SystemDataScopeEnum } from '@/utils/constants'
|
import { SystemDataScopeEnum } from '@/utils/constants'
|
||||||
import { DICT_TYPE, getDictOptions } from '@/utils/dict'
|
import { DICT_TYPE, getDictOptions } from '@/utils/dict'
|
||||||
import { rules, allSchemas } from './role.data'
|
import { rules, allSchemas } from './role.data'
|
||||||
|
@ -259,11 +259,6 @@ const dataScopeForm = reactive({
|
||||||
dataScope: 0,
|
dataScope: 0,
|
||||||
checkList: []
|
checkList: []
|
||||||
})
|
})
|
||||||
const defaultProps = {
|
|
||||||
children: 'children',
|
|
||||||
label: 'name',
|
|
||||||
value: 'id'
|
|
||||||
}
|
|
||||||
const treeOptions = ref<any[]>([]) // 菜单树形结构
|
const treeOptions = ref<any[]>([]) // 菜单树形结构
|
||||||
const treeRef = ref<InstanceType<typeof ElTree>>()
|
const treeRef = ref<InstanceType<typeof ElTree>>()
|
||||||
const dialogScopeVisible = ref(false)
|
const dialogScopeVisible = ref(false)
|
||||||
|
|
|
@ -66,7 +66,7 @@
|
||||||
</template>
|
</template>
|
||||||
<script setup lang="ts" name="TenantPackage">
|
<script setup lang="ts" name="TenantPackage">
|
||||||
import { onMounted, ref, unref } from 'vue'
|
import { onMounted, ref, unref } from 'vue'
|
||||||
import { handleTree } from '@/utils/tree'
|
import { handleTree, defaultProps } from '@/utils/tree'
|
||||||
import { useI18n } from '@/hooks/web/useI18n'
|
import { useI18n } from '@/hooks/web/useI18n'
|
||||||
import { useMessage } from '@/hooks/web/useMessage'
|
import { useMessage } from '@/hooks/web/useMessage'
|
||||||
import { useVxeGrid } from '@/hooks/web/useVxeGrid'
|
import { useVxeGrid } from '@/hooks/web/useVxeGrid'
|
||||||
|
@ -93,12 +93,6 @@ const actionType = ref('') // 操作按钮的类型
|
||||||
const dialogVisible = ref(false) // 是否显示弹出层
|
const dialogVisible = ref(false) // 是否显示弹出层
|
||||||
const dialogTitle = ref('edit') // 弹出层标题
|
const dialogTitle = ref('edit') // 弹出层标题
|
||||||
|
|
||||||
const defaultProps = {
|
|
||||||
children: 'children',
|
|
||||||
label: 'name',
|
|
||||||
value: 'id'
|
|
||||||
}
|
|
||||||
|
|
||||||
// 全选/全不选
|
// 全选/全不选
|
||||||
const handleCheckedTreeNodeAll = () => {
|
const handleCheckedTreeNodeAll = () => {
|
||||||
treeRef.value!.setCheckedNodes(treeNodeAll.value ? menuOptions.value : [])
|
treeRef.value!.setCheckedNodes(treeNodeAll.value ? menuOptions.value : [])
|
||||||
|
|
|
@ -284,7 +284,7 @@ import {
|
||||||
} from 'element-plus'
|
} from 'element-plus'
|
||||||
import { useRouter } from 'vue-router'
|
import { useRouter } from 'vue-router'
|
||||||
import { VxeGridInstance } from 'vxe-table'
|
import { VxeGridInstance } from 'vxe-table'
|
||||||
import { handleTree } from '@/utils/tree'
|
import { handleTree, defaultProps } from '@/utils/tree'
|
||||||
import download from '@/utils/download'
|
import download from '@/utils/download'
|
||||||
import { CommonStatusEnum } from '@/utils/constants'
|
import { CommonStatusEnum } from '@/utils/constants'
|
||||||
import { getAccessToken, getTenantId } from '@/utils/auth'
|
import { getAccessToken, getTenantId } from '@/utils/auth'
|
||||||
|
@ -306,11 +306,6 @@ import {
|
||||||
const { t } = useI18n() // 国际化
|
const { t } = useI18n() // 国际化
|
||||||
const message = useMessage() // 消息弹窗
|
const message = useMessage() // 消息弹窗
|
||||||
|
|
||||||
const defaultProps = {
|
|
||||||
children: 'children',
|
|
||||||
label: 'name',
|
|
||||||
value: 'id'
|
|
||||||
}
|
|
||||||
const queryParams = reactive({
|
const queryParams = reactive({
|
||||||
deptId: null
|
deptId: null
|
||||||
})
|
})
|
||||||
|
@ -327,7 +322,7 @@ const { gridOptions, getList, deleteData, exportList } = useVxeGrid<UserApi.User
|
||||||
})
|
})
|
||||||
// ========== 创建部门树结构 ==========
|
// ========== 创建部门树结构 ==========
|
||||||
const filterText = ref('')
|
const filterText = ref('')
|
||||||
const deptOptions = ref<any[]>([]) // 树形结构
|
const deptOptions = ref<Tree[]>([]) // 树形结构
|
||||||
const treeRef = ref<InstanceType<typeof ElTree>>()
|
const treeRef = ref<InstanceType<typeof ElTree>>()
|
||||||
const getTree = async () => {
|
const getTree = async () => {
|
||||||
const res = await listSimpleDeptApi()
|
const res = await listSimpleDeptApi()
|
||||||
|
|
Loading…
Reference in New Issue