8
0

temp.vue 4.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137
  1. <template>
  2. <hc-drawer v-model="isShow" to-id="hc-main-box" is-close @close="drawerClose">
  3. <hc-body split>
  4. <template #left>
  5. <hc-card scrollbar>
  6. <hc-lazy-tree
  7. v-if="isTreeMode" :root-menu="treeMenuData" :menus="treeMenuData" :h-props="treeProps"
  8. tree-key="id" @load="treeLoadNode" @node-tap="treeNodeTap" @menu-tap="treeMenuClick"
  9. >
  10. <template #nodeName="{ data }">
  11. <span class="text-16px font-400">{{ data.nodeName }}</span>
  12. </template>
  13. </hc-lazy-tree>
  14. </hc-card>
  15. </template>
  16. <hc-card class="hc-desk-system-unit-temp">
  17. <hc-card-item title="节点信息">
  18. <el-descriptions :column="3" border>
  19. <el-descriptions-item label="节点编码:">{{ nodeInfo.nodeCode ?? '-' }}</el-descriptions-item>
  20. <el-descriptions-item label="节点名称:">{{ nodeInfo.nodeName ?? '-' }}</el-descriptions-item>
  21. <el-descriptions-item label="节点类型:">{{ nodeInfo.nodeTypeName ?? '-' }}</el-descriptions-item>
  22. <el-descriptions-item label="工程类型:">{{ nodeInfo.engineeringTypeName ?? '-' }}</el-descriptions-item>
  23. <el-descriptions-item label="备注:">{{ nodeInfo.remarks ?? '-' }}</el-descriptions-item>
  24. </el-descriptions>
  25. </hc-card-item>
  26. <hc-card-item title="下节节点列表">
  27. 222
  28. </hc-card-item>
  29. </hc-card>
  30. </hc-body>
  31. </hc-drawer>
  32. </template>
  33. <script setup>
  34. import { ref, watch } from 'vue'
  35. import { HcDelMsg } from 'hc-vue3-ui'
  36. import { getDictionaryData, getDictionaryName } from '~src/utils/tools'
  37. import { getArrValue, getObjValue } from 'js-fast-way'
  38. import mainApi from '~api/desk/system-unit'
  39. const props = defineProps({
  40. data: {
  41. type: Object,
  42. default: () => ({}),
  43. },
  44. })
  45. const emit = defineEmits(['close'])
  46. //双向绑定
  47. const isShow = defineModel('modelValue', {
  48. default: false,
  49. })
  50. //监听数据
  51. const dataInfo = ref(props.data)
  52. watch(() => props.data, (data) => {
  53. dataInfo.value = data
  54. }, { immediate: true, deep: true })
  55. //监听显示
  56. watch(isShow, (val) => {
  57. if (val) getDataApi()
  58. })
  59. //处理相关数据
  60. const meterUnitType = ref([])
  61. const getDataApi = async () => {
  62. isTreeMode.value = true
  63. meterUnitType.value = await getDictionaryData('meter_unit_type', true)
  64. console.log(meterUnitType.value)
  65. }
  66. //树配置
  67. const isTreeMode = ref(false)
  68. const treeProps = {
  69. label: 'nodeName',
  70. children: 'children',
  71. isLeaf: 'notExsitChild',
  72. }
  73. //懒加载树
  74. const treeLoadNode = async ({ item, level }, resolve) => {
  75. const parentId = level === 0 ? 0 : item.id
  76. const { id } = getObjValue(dataInfo.value)
  77. const { data } = await mainApi.getLazyTree({
  78. id: parentId,
  79. templateId: id,
  80. })
  81. resolve(getArrValue(data))
  82. }
  83. //树菜单根节点
  84. const treeMenuData = [
  85. { icon: 'add-circle', label: '新增节点', key: 'add' },
  86. { icon: 'draft', label: '编辑节点', key: 'edit' },
  87. { icon: 'arrow-up-down', label: '排序节点', key: 'rank' },
  88. { icon: 'delete-bin', label: '删除节点', key: 'del' },
  89. ]
  90. //菜单被点击
  91. const treeMenuClick = ({ key, data, node }) => {
  92. console.log(key)
  93. }
  94. //树节点被点击
  95. const nodeInfo = ref({})
  96. const treeNodeTap = ({ data }) => {
  97. const label = getDictionaryName(meterUnitType.value, data.nodeType)
  98. data.nodeTypeName = label ?? '-'
  99. nodeInfo.value = data
  100. console.log(data)
  101. }
  102. //关闭抽屉
  103. const drawerClose = () => {
  104. isShow.value = false
  105. isTreeMode.value = false
  106. emit('close')
  107. }
  108. </script>
  109. <style lang="scss">
  110. .hc-desk-system-unit-temp .el-card {
  111. .hc-card-item-box {
  112. height: auto;
  113. padding: 10px 14px;
  114. .hc-card-item-header {
  115. color: #4a4a4a;
  116. margin-bottom: 6px;
  117. }
  118. }
  119. .hc-card-item-box + .hc-card-item-box {
  120. margin-top: 20px;
  121. }
  122. }
  123. </style>