perf: 提取tree props

This commit is contained in:
xingyu4j 2022-12-06 15:23:09 +08:00
parent 61f647b385
commit 3fd6193ac1
7 changed files with 36 additions and 51 deletions

View File

@ -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<TreeHelperConfig>) => 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',

View File

@ -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<FormSchema[]>([
component: 'TreeSelect',
componentProps: {
data: menuOptions,
props: menuProps,
props: defaultProps,
checkStrictly: true,
nodeKey: 'id'
},

View File

@ -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

View File

@ -103,7 +103,7 @@
<el-tree-select
node-key="id"
v-model="menuForm.parentId"
:props="menuProps"
:props="defaultProps"
:data="menuOptions"
:default-expanded-keys="[0]"
check-strictly
@ -237,8 +237,7 @@ import * as MenuApi from '@/api/system/menu'
import { required } from '@/utils/formRules.js'
import { DICT_TYPE, getIntDictOptions } from '@/utils/dict'
import { SystemMenuTypeEnum, CommonStatusEnum } from '@/utils/constants'
import { handleTree } from '@/utils/tree'
import { deepCopy } from 'windicss/utils'
import { handleTree, defaultProps } from '@/utils/tree'
const { t } = useI18n() //
const message = useMessage() //
@ -253,7 +252,7 @@ const actionType = ref('') // 操作按钮的类型
const actionLoading = ref(false) //
//
const formRef = ref<FormInstance>()
const menuFormNull = {
const menuForm = ref<MenuApi.MenuVO>({
id: 0,
name: '',
permission: '',
@ -266,9 +265,8 @@ const menuFormNull = {
status: CommonStatusEnum.ENABLE,
visible: true,
keepAlive: true,
createTime: ''
}
const menuForm = ref<MenuApi.MenuVO>(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<any[]>([]) //
// []
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()
}
}
//

View File

@ -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<any[]>([]) //
const treeRef = ref<InstanceType<typeof ElTree>>()
const dialogScopeVisible = ref(false)

View File

@ -66,7 +66,7 @@
</template>
<script setup lang="ts" name="TenantPackage">
import { onMounted, ref, unref } from 'vue'
import { handleTree } from '@/utils/tree'
import { handleTree, defaultProps } from '@/utils/tree'
import { useI18n } from '@/hooks/web/useI18n'
import { useMessage } from '@/hooks/web/useMessage'
import { useVxeGrid } from '@/hooks/web/useVxeGrid'
@ -93,12 +93,6 @@ const actionType = ref('') // 操作按钮的类型
const dialogVisible = ref(false) //
const dialogTitle = ref('edit') //
const defaultProps = {
children: 'children',
label: 'name',
value: 'id'
}
// /
const handleCheckedTreeNodeAll = () => {
treeRef.value!.setCheckedNodes(treeNodeAll.value ? menuOptions.value : [])

View File

@ -284,7 +284,7 @@ import {
} from 'element-plus'
import { useRouter } from 'vue-router'
import { VxeGridInstance } from 'vxe-table'
import { handleTree } from '@/utils/tree'
import { handleTree, defaultProps } from '@/utils/tree'
import download from '@/utils/download'
import { CommonStatusEnum } from '@/utils/constants'
import { getAccessToken, getTenantId } from '@/utils/auth'
@ -306,11 +306,6 @@ import {
const { t } = useI18n() //
const message = useMessage() //
const defaultProps = {
children: 'children',
label: 'name',
value: 'id'
}
const queryParams = reactive({
deptId: null
})
@ -327,7 +322,7 @@ const { gridOptions, getList, deleteData, exportList } = useVxeGrid<UserApi.User
})
// ========== ==========
const filterText = ref('')
const deptOptions = ref<any[]>([]) //
const deptOptions = ref<Tree[]>([]) //
const treeRef = ref<InstanceType<typeof ElTree>>()
const getTree = async () => {
const res = await listSimpleDeptApi()