|
@@ -1,88 +1,91 @@
|
|
<template>
|
|
<template>
|
|
- <ElTree ref="ElTreeRef"
|
|
|
|
- :class="ui"
|
|
|
|
- :default-expanded-keys="defaultExpandedCids"
|
|
|
|
- :indent="0"
|
|
|
|
- :load="ElTreeLoadNode"
|
|
|
|
- :props="ElTreeProps"
|
|
|
|
- accordion
|
|
|
|
- class="hc-tree-node tree-line"
|
|
|
|
- highlight-current
|
|
|
|
- lazy
|
|
|
|
- node-key="primaryKeyId"
|
|
|
|
- @node-click="ElTreeClick">
|
|
|
|
|
|
+ <ElTree
|
|
|
|
+ ref="ElTreeRef"
|
|
|
|
+ :class="ui"
|
|
|
|
+ :default-expanded-keys="defaultExpandedCids"
|
|
|
|
+ :indent="0"
|
|
|
|
+ :load="ElTreeLoadNode"
|
|
|
|
+ :props="ElTreeProps"
|
|
|
|
+ accordion
|
|
|
|
+ class="hc-tree-node tree-line"
|
|
|
|
+ highlight-current
|
|
|
|
+ lazy
|
|
|
|
+ node-key="primaryKeyId"
|
|
|
|
+ @node-click="ElTreeClick"
|
|
|
|
+ >
|
|
<template #default="{ node, data }">
|
|
<template #default="{ node, data }">
|
|
- <div :id="`${idPrefix}${data['primaryKeyId']}`" class="data-custom-tree-node">
|
|
|
|
- <div :class="node.level === 1?'level-name':''" class="label">{{ node.label }}</div>
|
|
|
|
|
|
+ <div :id="`${idPrefix}${data.primaryKeyId}`" class="data-custom-tree-node">
|
|
|
|
+ <div :class="node.level === 1 ? 'level-name' : ''" class="label">{{ node.label }}</div>
|
|
</div>
|
|
</div>
|
|
</template>
|
|
</template>
|
|
</ElTree>
|
|
</ElTree>
|
|
-
|
|
|
|
</template>
|
|
</template>
|
|
|
|
|
|
<script setup>
|
|
<script setup>
|
|
-import {ref, nextTick, watch} from "vue";
|
|
|
|
-import samplingApi from "~api/tentative/material/sampling"
|
|
|
|
-import {isArrItem, getArrValue} from "js-fast-way"
|
|
|
|
|
|
+import { nextTick, ref, watch } from 'vue'
|
|
|
|
+import samplingApi from '~api/tentative/material/sampling'
|
|
|
|
+import { getArrValue, isArrItem } from 'js-fast-way'
|
|
|
|
|
|
//参数
|
|
//参数
|
|
const props = defineProps({
|
|
const props = defineProps({
|
|
projectId: {
|
|
projectId: {
|
|
type: [String, Number],
|
|
type: [String, Number],
|
|
- default: ''
|
|
|
|
|
|
+ default: '',
|
|
},
|
|
},
|
|
contractId: {
|
|
contractId: {
|
|
type: [String, Number],
|
|
type: [String, Number],
|
|
- default: ''
|
|
|
|
|
|
+ default: '',
|
|
},
|
|
},
|
|
wbsTempId: {
|
|
wbsTempId: {
|
|
type: [String, Number],
|
|
type: [String, Number],
|
|
- default: ''
|
|
|
|
|
|
+ default: '',
|
|
},
|
|
},
|
|
tenantId: {
|
|
tenantId: {
|
|
type: [String, Number],
|
|
type: [String, Number],
|
|
- default: ''
|
|
|
|
|
|
+ default: '',
|
|
},
|
|
},
|
|
wbsType: {
|
|
wbsType: {
|
|
type: [String, Number],
|
|
type: [String, Number],
|
|
- default: ''
|
|
|
|
|
|
+ default: '',
|
|
},
|
|
},
|
|
autoExpandKeys: {
|
|
autoExpandKeys: {
|
|
type: Array,
|
|
type: Array,
|
|
- default: () => ([])
|
|
|
|
|
|
+ default: () => ([]),
|
|
},
|
|
},
|
|
idPrefix: {
|
|
idPrefix: {
|
|
type: String,
|
|
type: String,
|
|
- default: 'test-tree-'
|
|
|
|
|
|
+ default: 'test-tree-',
|
|
},
|
|
},
|
|
ui: {
|
|
ui: {
|
|
type: String,
|
|
type: String,
|
|
- default: ''
|
|
|
|
|
|
+ default: '',
|
|
},
|
|
},
|
|
fromType: {
|
|
fromType: {
|
|
type: Boolean,
|
|
type: Boolean,
|
|
- default: false
|
|
|
|
|
|
+ default: false,
|
|
},
|
|
},
|
|
nodeId: {
|
|
nodeId: {
|
|
type: [String, Number],
|
|
type: [String, Number],
|
|
- default: ''
|
|
|
|
- }
|
|
|
|
|
|
+ default: '',
|
|
|
|
+ },
|
|
})
|
|
})
|
|
|
|
|
|
|
|
+//事件
|
|
|
|
+const emit = defineEmits(['menuTap', 'nodeTap', 'nodeLoading'])
|
|
//变量
|
|
//变量
|
|
const ElTreeRef = ref(null)
|
|
const ElTreeRef = ref(null)
|
|
const ElTreeProps = ref({
|
|
const ElTreeProps = ref({
|
|
label: 'title',
|
|
label: 'title',
|
|
children: 'children',
|
|
children: 'children',
|
|
- isLeaf: 'hasChildren'
|
|
|
|
|
|
+ isLeaf: 'hasChildren',
|
|
})
|
|
})
|
|
const TreeExpandKey = ref(props.autoExpandKeys)
|
|
const TreeExpandKey = ref(props.autoExpandKeys)
|
|
-const projectId = ref(props.projectId);
|
|
|
|
-const contractId = ref(props.contractId);
|
|
|
|
-const wbsTempId = ref(props.wbsTempId);
|
|
|
|
-const tenantId = ref(props.tenantId);
|
|
|
|
-const wbsType = ref(props.wbsType);
|
|
|
|
-const idPrefix = ref(props.idPrefix);
|
|
|
|
|
|
+const projectId = ref(props.projectId)
|
|
|
|
+const contractId = ref(props.contractId)
|
|
|
|
+const wbsTempId = ref(props.wbsTempId)
|
|
|
|
+const tenantId = ref(props.tenantId)
|
|
|
|
+const wbsType = ref(props.wbsType)
|
|
|
|
+const idPrefix = ref(props.idPrefix)
|
|
const fromTypedata = ref(props.fromType)
|
|
const fromTypedata = ref(props.fromType)
|
|
//监听
|
|
//监听
|
|
watch(() => [
|
|
watch(() => [
|
|
@@ -93,7 +96,7 @@ watch(() => [
|
|
props.tenantId,
|
|
props.tenantId,
|
|
props.idPrefix,
|
|
props.idPrefix,
|
|
props.wbsType,
|
|
props.wbsType,
|
|
- props.fromType
|
|
|
|
|
|
+ props.fromType,
|
|
], ([expandKeys, UserProjectId, UserContractId, UserWbsTempId, UserTenantId, UserIdPrefix, wbs_type, fromType]) => {
|
|
], ([expandKeys, UserProjectId, UserContractId, UserWbsTempId, UserTenantId, UserIdPrefix, wbs_type, fromType]) => {
|
|
TreeExpandKey.value = expandKeys
|
|
TreeExpandKey.value = expandKeys
|
|
projectId.value = UserProjectId
|
|
projectId.value = UserProjectId
|
|
@@ -105,32 +108,29 @@ watch(() => [
|
|
fromTypedata.value = fromType
|
|
fromTypedata.value = fromType
|
|
})
|
|
})
|
|
|
|
|
|
-//事件
|
|
|
|
-const emit = defineEmits(['menuTap', 'nodeTap', 'nodeLoading'])
|
|
|
|
-
|
|
|
|
//树形结构异步加载数据
|
|
//树形结构异步加载数据
|
|
const defaultExpandedCids = ref([])
|
|
const defaultExpandedCids = ref([])
|
|
const ElTreeLoadNode = async (node, resolve) => {
|
|
const ElTreeLoadNode = async (node, resolve) => {
|
|
- console.log(fromTypedata.value, ' fromTypedata.value');
|
|
|
|
- let parentId = '0';
|
|
|
|
|
|
+ console.log(fromTypedata.value, ' fromTypedata.value')
|
|
|
|
+ let parentId = '0'
|
|
if (node.level !== 0) {
|
|
if (node.level !== 0) {
|
|
parentId = node?.data?.id
|
|
parentId = node?.data?.id
|
|
}
|
|
}
|
|
if (fromTypedata.value) {
|
|
if (fromTypedata.value) {
|
|
//获取数据
|
|
//获取数据
|
|
- const {error, code, data} = await samplingApi.getMixRatioTestTree({
|
|
|
|
|
|
+ const { error, code, data } = await samplingApi.getMixRatioTestTree({
|
|
pKeyId: props.nodeId,
|
|
pKeyId: props.nodeId,
|
|
})
|
|
})
|
|
//处理数据
|
|
//处理数据
|
|
if (!error && code === 200) {
|
|
if (!error && code === 200) {
|
|
- let clickKey = '', defaultExpandedArr = [];
|
|
|
|
|
|
+ let clickKey = '', defaultExpandedArr = []
|
|
const keys = TreeExpandKey.value || []
|
|
const keys = TreeExpandKey.value || []
|
|
const resData = getArrValue(data)
|
|
const resData = getArrValue(data)
|
|
for (let i = 0; i < resData.length; i++) {
|
|
for (let i = 0; i < resData.length; i++) {
|
|
resData[i].hasChildren = !resData[i].hasChildren
|
|
resData[i].hasChildren = !resData[i].hasChildren
|
|
}
|
|
}
|
|
if (keys.length > 0) {
|
|
if (keys.length > 0) {
|
|
- let lastKey = keys[keys.length - 1];
|
|
|
|
|
|
+ let lastKey = keys[keys.length - 1]
|
|
for (const item of resData) {
|
|
for (const item of resData) {
|
|
//自动展开
|
|
//自动展开
|
|
if (isArrItem(keys, item?.primaryKeyId)) {
|
|
if (isArrItem(keys, item?.primaryKeyId)) {
|
|
@@ -165,23 +165,23 @@ const ElTreeLoadNode = async (node, resolve) => {
|
|
|
|
|
|
} else {
|
|
} else {
|
|
//获取数据
|
|
//获取数据
|
|
- const {error, code, data} = await samplingApi.queryLazyTree({
|
|
|
|
|
|
+ const { error, code, data } = await samplingApi.queryLazyTree({
|
|
wbsId: wbsTempId.value,
|
|
wbsId: wbsTempId.value,
|
|
tenantId: tenantId.value,
|
|
tenantId: tenantId.value,
|
|
projectId: projectId.value,
|
|
projectId: projectId.value,
|
|
parentId,
|
|
parentId,
|
|
- wbsType: wbsType.value
|
|
|
|
|
|
+ wbsType: wbsType.value,
|
|
})
|
|
})
|
|
//处理数据
|
|
//处理数据
|
|
if (!error && code === 200) {
|
|
if (!error && code === 200) {
|
|
- let clickKey = '', defaultExpandedArr = [];
|
|
|
|
|
|
+ let clickKey = '', defaultExpandedArr = []
|
|
const keys = TreeExpandKey.value || []
|
|
const keys = TreeExpandKey.value || []
|
|
const resData = getArrValue(data)
|
|
const resData = getArrValue(data)
|
|
for (let i = 0; i < resData.length; i++) {
|
|
for (let i = 0; i < resData.length; i++) {
|
|
resData[i].hasChildren = !resData[i].hasChildren
|
|
resData[i].hasChildren = !resData[i].hasChildren
|
|
}
|
|
}
|
|
if (keys.length > 0) {
|
|
if (keys.length > 0) {
|
|
- let lastKey = keys[keys.length - 1];
|
|
|
|
|
|
+ let lastKey = keys[keys.length - 1]
|
|
for (const item of resData) {
|
|
for (const item of resData) {
|
|
//自动展开
|
|
//自动展开
|
|
if (isArrItem(keys, item?.primaryKeyId)) {
|
|
if (isArrItem(keys, item?.primaryKeyId)) {
|
|
@@ -222,7 +222,7 @@ const ElTreeClick = async (data, node) => {
|
|
let autoKeysArr = []
|
|
let autoKeysArr = []
|
|
await getNodeExpandKeys(node, autoKeysArr)
|
|
await getNodeExpandKeys(node, autoKeysArr)
|
|
const autoKeys = autoKeysArr.reverse()
|
|
const autoKeys = autoKeysArr.reverse()
|
|
- emit('nodeTap', {node, data, keys: autoKeys})
|
|
|
|
|
|
+ emit('nodeTap', { node, data, keys: autoKeys })
|
|
}
|
|
}
|
|
|
|
|
|
//处理自动展开的节点KEY
|
|
//处理自动展开的节点KEY
|