birt
2025-04-13 b0530ed9211230227a8f94e394eda779d5ae5fc1
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
<template>
  <div class="tree">
    <el-tree :data="nodeOptions" :props="{ label: 'label', children: 'children' }" :expand-on-click-node="false"
      :filter-node-method="filterNode" ref="nodeTreeRef" node-key="id" highlight-current
      :default-expanded-keys="defaultExpandedKeys" @node-click="nodeClick" accordion>
      <template #default="{ node, data }">
        <span class="item" style="" :title="node.label">
          {{ node.label }}
        </span>
      </template>
    </el-tree>
  </div>
</template>
 
<script setup>
const { proxy } = getCurrentInstance();
const emit = defineEmits();
const props = defineProps({
  ParentModelCode: {
    // 参数类型
    type: String,
    // 参数默认值
    default: "",
  },
});
 
watch(
  () => props.ParentModelCode,
  (newValue, oldValue) => {
    if (newValue) {
      getTree();
    }
  }
);
 
const data = reactive({
  query: {
    modelCode: null,
  },
});
const { query } = toRefs(data);
import { useRoute } from "vue-router";
import { treeList } from "@/api/modelConfiguration/indexWarehouse";
import { el } from "element-plus/es/locales.mjs";
const nodeOptions = ref(undefined);
let defaultExpandedKeys = ref([]);
defineExpose({ getTree });
/** 通过条件过滤节点  */
const filterNode = (value, data) => {
  if (!value) return true;
  return data.label.indexOf(value) !== -1;
};
getTree();
/** 查询部门下拉树结构 */
function getTree() {
  // 确保query.value有初始值
  query.value = query.value || {};
  
  // 优先使用props中传入的ParentModelCode
  if (props.ParentModelCode) {
    query.value.modelCode = props.ParentModelCode;
  } else if (useRoute().query.modelCode) {
    // 其次使用路由中的modelCode
    query.value.modelCode = useRoute().query.modelCode;
  } else {
    // 最后使用默认值
    query.value.modelCode = 'JCZBK_CODE';
  }
  
  console.log('LeftTree getTree modelCode:', query.value.modelCode);
  
  treeList(query.value).then((response) => {
    nodeOptions.value = response.data;
    if (response.data.length > 0) {
      defaultExpandedKeys.value = []; // 清空已有的key,避免重复
      response.data.map((item) => {
        defaultExpandedKeys.value.push(item.id);
      });
      nextTick(() => {
        nodeClick(response.data[0]);
      });
    }
  });
}
/** 节点单击事件 */
function nodeClick(data) {
  proxy.$refs["nodeTreeRef"].setCurrentKey(data.id, true);
  emit("handleNodeClick", data, nodeOptions.value);
}
</script>
 
<style lang="scss" scoped>
.themeDark {
  .mycard {
    margin: 0 13px;
    margin-top: 10px;
    border-radius: 10px 10px 10px 10px;
    border: 1px solid #22408c;
    padding-bottom: 10px;
 
    .mycard-title {
      display: flex;
      justify-content: flex-start;
      align-items: center;
      height: 50px;
      border-radius: 7px 7px 0 0;
      padding: 20px;
      background-color: #22408c;
 
      .name {
        font-family: OPPOSans, OPPOSans;
        font-weight: bold;
        font-size: 18px;
        color: #fff;
      }
    }
  }
}
 
.themeLight {
  .mycard {
    margin: 0 13px;
    margin-top: 10px;
    border-radius: 10px 10px 10px 10px;
    border: 1px solid #ebebeb;
    padding-bottom: 10px;
    background-color: #fff;
 
    .mycard-title {
      display: flex;
      justify-content: flex-start;
      align-items: center;
      height: 50px;
      border-radius: 7px 7px 0 0;
      padding: 20px;
      background-color: #e7eefd;
 
      .name {
        font-family: OPPOSans, OPPOSans;
        font-weight: bold;
        font-size: 18px;
        color: #2d2e31;
      }
    }
  }
}
 
.item {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
</style>