diff --git a/src/views/processManagement/components/processMainte/partDetails.vue b/src/views/processManagement/components/processMainte/partDetails.vue
index 0220c6f..a2668d4 100644
--- a/src/views/processManagement/components/processMainte/partDetails.vue
+++ b/src/views/processManagement/components/processMainte/partDetails.vue
@@ -482,7 +482,9 @@
@node-click="handleNodeClick"
:default-expand-all="true"
:expand-on-click-node="false"
+ node-key="id"
ref="tree"
+ :current-node-key="currentNodeKey"
/>
@@ -617,6 +619,7 @@ export default {
},
data() {
return {
+ currentNodeKey: '',
showProcessVersion: false,
setCrewShow: false,
activeName: '1',
@@ -628,7 +631,20 @@ export default {
processLevel: '1',
rankList: [],
rank: '2',
- priorityList: [],
+ priorityList: [
+ {
+ label: '本次使用',
+ value: 1,
+ },
+ {
+ label: '正式工艺',
+ value: 2,
+ },
+ {
+ label: '临时工艺',
+ value: 3,
+ },
+ ],
form1: {
tableData1: [], //工序
},
@@ -824,15 +840,12 @@ export default {
},
// 组织树点击
handleNodeClick(nodes, node, self) {
- console.log(9999999,nodes,node)
if (nodes.disabled) {
return false;
}
this.treeNodes = nodes;
this.treeLeave = node.level;
-
-
// 清空现有表格数据
this.form1.tableData1 = [];
this.form2.tableData2 = [];
@@ -842,8 +855,8 @@ export default {
if (this.treeLeave === 2) {
this.activeName = '1';
this.form1.tableData1 = nodes.processList;
- console.log('默认点击选中第一个数据')
- this.treeNodes.rawData.prority = this.treeNodes.rawData.prority+'';
+ console.log('默认点击选中第一个数据', this.treeNodes);
+ this.treeNodes.rawData.prority = Number(this.treeNodes.rawData.prority);
}
// 根据节点层级加载对应数据
if (this.treeLeave === 3) {
@@ -891,35 +904,52 @@ export default {
// ✅ 自动选中第一个子节点
autoSelectFirstNode() {
this.$nextTick(() => {
+ if (!this.$refs || !this.$refs.tree) {
+ console.warn('el-tree 组件未找到,跳过自动选中');
+ return;
+ }
if (!this.data || this.data.length === 0) {
console.log('树数据为空,不自动选中');
return;
}
-
+
const rootNode = this.data[0];
- console.log('根节点:', rootNode);
-
- // 如果根节点有子节点,选中第一个子节点
- if (rootNode.children && rootNode.children.length > 0) {
- const firstChild = rootNode.children[0];
- console.log('第一个子节点:', firstChild);
-
- // 设置当前选中节点
- if (this.$refs.tree) {
- this.$refs.tree.setCurrentKey(firstChild.id);
- }
-
- // 模拟点击事件,加载对应数据
- this.handleNodeClick(firstChild, {
- level: firstChild.level,
- parent: {
- data: rootNode,
- isRoot: false,
- },
+
+ if (
+ !rootNode.children ||
+ !Array.isArray(rootNode.children) ||
+ rootNode.children.length === 0
+ ) {
+ console.warn('根节点无子节点,跳过自动选中');
+ return;
+ }
+
+ const firstChild = rootNode.children[0];
+ // 4. 检查节点 ID
+ if (!firstChild.id) {
+ console.error('第一个子节点 ID 为空,请检查 generateId 函数');
+ return;
+ }
+
+ // 5. 设置选中状态
+ try {
+ this.$nextTick(() => {
+ this.currentNodeKey = firstChild.id
+ this.$refs.tree.setCurrentKey([firstChild.id], false);
});
- } else {
- console.log('根节点无子节点,不自动选中');
+ } catch (error) {
+ console.error('setCurrentKey 执行失败:', error);
+ return;
}
+
+ // 6. 触发节点点击,加载数据
+ this.handleNodeClick(firstChild, {
+ level: firstChild.level,
+ parent: {
+ data: rootNode,
+ isRoot: false,
+ },
+ });
});
},
// 获取工艺信息
@@ -1019,9 +1049,7 @@ export default {
const partCode = partInfo.partCode;
const generateId = (prefix, id, fallback) => {
- return (
- id || `${prefix}_${fallback}_${Date.now()}_${Math.random().toString(36).substr(2, 9)}`
- );
+ return id;
};
const formatCraftLabel = craftInfo => {
@@ -1065,7 +1093,7 @@ export default {
return {
...processInfo,
id: generateId('process', processInfo.id, processInfo.processNo),
- label: processInfo.processNo+'-'+processInfo.processName,
+ label: processInfo.processNo + '-' + processInfo.processName,
level: 3,
rawData: {
processInfo,
@@ -1076,7 +1104,7 @@ export default {
// ✅ 子节点(项目)
children: (projectList || []).map(project => ({
id: generateId('project', project.id, project.projectCode),
- label: project.trialNo+'-'+project.projectName,
+ label: project.trialNo + '-' + project.projectName,
level: 4,
disabled: true,
rawData: project,