<!--
|
* @Description: 组合页面左侧树形
|
* @Author: Ben Lin
|
* @version:
|
* @Date: 2024-06-26 15:31:43
|
* @LastEditors: Ben Lin
|
* @LastEditTime: 2024-07-23 23:40:41
|
-->
|
<template>
|
<GeneralTree
|
@select="handleSelect"
|
@UnSelect="UnSelect"
|
:title="title"
|
:treeData="treeData"
|
:create-icon="createIcon"
|
:fieldNames="fieldNames"
|
:beforeRightClick="getRightMenu"
|
/><!--
|
add
|
@handle-add="handleAdd" -->
|
</template>
|
<script lang="ts" setup>
|
import { Ref, inject, onMounted, ref } from 'vue';
|
import { isNullOrUnDef } from '/@/utils/is';
|
import GeneralTree from '/@/views/components/GeneralTree.vue';
|
import { TreeItem } from '/@/components/TigerTree';
|
import { EntityCustFunctionType } from '/@/api/tigerapi/model/basModel';
|
import { EventDataNode } from 'ant-design-vue/es/tree';
|
|
const emit = defineEmits(['select', 'deletenode']);
|
const objParams = inject('objParams') as Ref<any>;
|
const selectedNodes = inject('selectedNodes') as Ref<any>;
|
const custImport = ref<any[]>([]);
|
const EntityCustFunction = ref([
|
{
|
CreateIcon(params: Recordable<any>) {},
|
SelectNode(selectedNodes: Ref<any[]>) {},
|
GetRightMenuList(node: EventDataNode) {},
|
} as EntityCustFunctionType,
|
]);
|
/* 动态import实体名.ts的自定义方法 */
|
try {
|
custImport.value = await import(`../entityts/${objParams.value['Name']}.ts`);
|
} catch (e) {}
|
const [{ CreateIcon, SelectNode, fetchTreeData, GetRightMenuList }] = isNullOrUnDef(
|
custImport.value['default'],
|
)
|
? EntityCustFunction.value
|
: custImport.value['default']();
|
const treeData = ref<TreeItem[]>([]);
|
const title = ref('');
|
const fieldNames = ref({});
|
|
onMounted(async () => {
|
await fetch(objParams.value['Name']);
|
});
|
|
/**
|
* @description: 树形节点图标
|
* @param {*} params
|
* @param {*} type
|
* @return {*}
|
*/
|
function createIcon(params: Recordable<any>) {
|
return CreateIcon(params);
|
}
|
|
/**
|
* @description: 获取树形数据
|
* @param {*} type
|
* @return {*}
|
*/
|
async function fetch(type: string) {
|
if (!isNullOrUnDef(custImport.value)) {
|
// const [{ fetchTreeData }] = custImport.value['default']();
|
//根据type获取树形数据
|
const data = await fetchTreeData(type, objParams.value['CODE']);
|
title.value = data.title;
|
treeData.value = data.treeData;
|
fieldNames.value = data.fieldNames;
|
}
|
}
|
|
function handleSelect(Id = '', info) {
|
selectedNodes.value = info.selectedNodes;
|
emit('select', SelectNode(selectedNodes));
|
}
|
|
/**
|
* @description: 取消选择时事件返回方法
|
* @param {*} node
|
* @return {*}
|
*/
|
function UnSelect(node) {
|
emit('select', SelectNode(undefined));
|
// reload();
|
}
|
|
/**
|
* @description: 获取右键菜单列表,带入emit事件
|
* @param {*} node
|
* @return {*}
|
*/
|
function getRightMenu(node: EventDataNode) {
|
return GetRightMenuList(node, emit, objParams.value['CODE']);
|
}
|
</script>
|