ModelTree.vue 5.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177
  1. <template>
  2. <div>
  3. <div class="bigBox">
  4. <el-dialog v-loading="loading" v-model="dialogVisible" title="选择模型" width="30%" @close="sureclose" :close-on-click-modal="false">
  5. <el-tree ref="treeRef" :data="treeData" style="height: calc(100vh - 500px);overflow-y: auto;" show-checkbox
  6. node-key="id" @check-change="handleCheckChange" :check-strictly="true" default-expand-all
  7. :expand-on-click-node="false" :props="defaultProps" />
  8. <template #footer>
  9. <span class="dialog-footer">
  10. <el-button @click="cleanBox">取消</el-button>
  11. <el-button type="primary" @click="sureArr">
  12. 确认
  13. </el-button>
  14. </span>
  15. </template>
  16. </el-dialog>
  17. </div>
  18. <div id="lord" v-loading="loading" element-loading-text="加载数据中"
  19. style="width: 100vw;height: 100vh;position: fixed;top: 0px;left: 0px;z-index: 3000;">
  20. </div>
  21. </div>
  22. </template>
  23. <script>
  24. import { ref, onMounted, toRefs, watch } from 'vue';
  25. import litLine from '@/api/litLine';
  26. import systemRow from '@/api/systemRow';
  27. import { ElLoading } from 'element-plus';
  28. export default {
  29. props: {
  30. treeMool: {
  31. type: Boolean,
  32. required: true
  33. },
  34. treeNeed: {
  35. type: Array,
  36. required: true,
  37. }
  38. },
  39. setup(props, { emit }) {
  40. let loading = ref(true)
  41. let treeData = ref([
  42. ])
  43. let defaultProps = ref({
  44. label: "model_name",
  45. children: "children",
  46. id: "id"
  47. })
  48. let result = props.treeMool
  49. let mdId = ref([])//模型id
  50. let mdName = ref([])
  51. let { cleanBox, sureArr } = toRefs(props)
  52. let dialogVisible = ref(false)
  53. let checkKey = ref([])//默认选中的key
  54. let treeRef = ref(null)
  55. watch(() => props.treeNeed, (newVal) => {
  56. checkKey.value = newVal
  57. })
  58. function reload() {
  59. if (props.treeNeed&&treeRef.value) {
  60. checkKey.value = props.treeNeed
  61. }
  62. }
  63. function getLine() {
  64. let lord = document.getElementById("lord")
  65. loading.value = true
  66. let level = [] // 电压等级
  67. let line = [] // 接线方式
  68. let mine = [] // 所有模型
  69. dialogVisible.value = result
  70. // 用 Promise.all 等待所有异步操作完成
  71. Promise.all([
  72. litLine.getAllLine({ pageno: 1, pagesize: 30 }),
  73. litLine.getAllm({ pageno: 1, pagesize: 100 }),
  74. systemRow.getChildren({ code: "voltage_level" })
  75. ]).then(([lineRes, mineRes, levelRes]) => {
  76. line = lineRes.data
  77. mine = mineRes.data
  78. level = levelRes.data
  79. if (level.length > 0 && line.length > 0 && mine.length > 0) {
  80. let a = level.map(item => {
  81. let filteredLine = line.filter(param => item.name === param.vol_level_name);
  82. if (filteredLine.length > 0) {
  83. let children = filteredLine.map(filteredItem => {
  84. let filteredMine = mine.filter(mineItem => mineItem.line_link_style_name === filteredItem.name);
  85. return {
  86. model_name: filteredItem.name,
  87. children: filteredMine
  88. };
  89. });
  90. return {
  91. model_name: item.name,
  92. children
  93. };
  94. }
  95. return null;
  96. }).filter(item => item !== null);
  97. treeData.value = a
  98. loading.value = false
  99. lord.style.display = 'none'
  100. }
  101. }).catch(error => {
  102. // 处理错误
  103. console.error("Error:", error);
  104. });
  105. }
  106. function handleCheckChange(e) {
  107. const id = e.id;
  108. const model_name = e.model_name;
  109. if (!mdId.value.includes(id)) {
  110. mdId.value.push(id);
  111. mdName.value.push(model_name);
  112. } else {
  113. const idIndex = mdId.value.indexOf(id);
  114. mdId.value.splice(idIndex, 1);
  115. mdName.value.splice(idIndex, 1);
  116. }
  117. emit("treeNum", mdId.value, mdName.value);
  118. }
  119. function getBack() {
  120. dialogVisible.value = false
  121. emit("treeBack", dialogVisible.value)
  122. }
  123. function nowBack() {
  124. dialogVisible.value = false
  125. emit("treeBack", dialogVisible.value)
  126. }
  127. function sureclose() {
  128. dialogVisible.value = false
  129. emit("treeBack", dialogVisible.value)
  130. }
  131. onMounted(() => {
  132. getLine()
  133. reload()
  134. })
  135. return {
  136. treeData,
  137. dialogVisible,
  138. cleanBox: getBack,
  139. sureArr: nowBack,
  140. sureclose,
  141. getLine,
  142. result,
  143. defaultProps,
  144. handleCheckChange,
  145. mdName,
  146. loading,
  147. checkKey,
  148. treeRef,
  149. }
  150. }
  151. }
  152. </script>
  153. <style scoped>
  154. .is-penultimate>.el-tree-node__content {
  155. color: #626aef;
  156. }
  157. .el-tree-node.is-expanded.is-penultimate>.el-tree-node__children {
  158. display: flex;
  159. flex-direction: row;
  160. }
  161. .is-penultimate>.el-tree-node__children>div {
  162. width: 25%;
  163. }
  164. /* :deep(.el-tree-node.is-expanded>.el-tree-node__children) {
  165. display: flex;
  166. flex-wrap: wrap;
  167. } */
  168. </style>