BaseinfoVue.vue 2.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131
  1. <template>
  2. <div class="select-device">
  3. 选择设备:
  4. <el-select style="width: 15vw" v-model="deviceKey" @change="deviceChnage" placeholder="">
  5. <el-option v-for="row in deviceList" :key="row.key" :label="row.name" :value="row.key"></el-option>
  6. </el-select>
  7. </div>
  8. <section class="baseinfo" v-loading="loading">
  9. <div class="flex-item" v-for="row in propertiyList" :key="row.devicePropertiyKey">
  10. <div class="label">{{ row.devicePropertiyName }}</div>
  11. <div class="val">
  12. {{ row.devicePropertiyValue }}
  13. <span class="unit" v-if="row.devicePropertiyUnit">{{ row.devicePropertiyUnit }}</span>
  14. </div>
  15. </div>
  16. <template v-if="propertiyList.length % 3">
  17. <div class="flex-item space" v-for="i in 3 - (propertiyList.length % 3)" :key="i"></div>
  18. </template>
  19. </section>
  20. </template>
  21. <script setup lang="ts">
  22. import { ref, inject, watch, Ref } from 'vue'
  23. import api from '/@/api/projects'
  24. const emit = defineEmits(['change'])
  25. const projectCode = inject<Ref<string>>('projectCode', ref(''))
  26. const loading = ref(true)
  27. const deviceKey = ref('')
  28. const deviceList = ref<any[]>([])
  29. const propertiyList = ref<any[]>([])
  30. watch(() => projectCode.value, getData)
  31. function getData(code: string) {
  32. if (!code) return
  33. loading.value = true
  34. deviceKey.value = ''
  35. deviceList.value = []
  36. propertiyList.value = []
  37. api.screen.projectDevices(code).then((res: any) => {
  38. if (!res?.length) return (loading.value = false)
  39. const keys = (res || []).filter((row: any) => row.resourcesTypes === 1).map((item: any) => item.resourcesKey)
  40. loading.value = true
  41. api.screen.projectDevicesList(keys).then((res: any) => {
  42. const list = res.device || []
  43. deviceList.value = list
  44. if (list.length) {
  45. deviceKey.value = list[0].key
  46. deviceChnage()
  47. } else {
  48. emit('change', '')
  49. loading.value = false
  50. }
  51. })
  52. })
  53. }
  54. function deviceChnage() {
  55. emit('change', deviceKey.value)
  56. loading.value = true
  57. api.screen
  58. .propertyListValue(projectCode.value, deviceKey.value)
  59. .then((res: any) => {
  60. propertiyList.value = res || []
  61. })
  62. .finally(() => (loading.value = false))
  63. }
  64. </script>
  65. <style lang="scss" scoped>
  66. .select-device {
  67. display: flex;
  68. align-items: center;
  69. font-size: 1.5vh;
  70. font-weight: 500;
  71. }
  72. .baseinfo {
  73. background-size: 100% 100%;
  74. margin-top: 1.5vh;
  75. display: flex;
  76. flex-flow: row wrap;
  77. justify-content: space-between;
  78. gap: 2vh;
  79. height: 20vh;
  80. overflow-y: auto;
  81. .flex-item {
  82. background-size: 100% 100%;
  83. display: flex;
  84. align-items: center;
  85. flex: 1;
  86. height: 3.5vh;
  87. max-width: 33%;
  88. min-width: 30%;
  89. text-indent: 1.1em;
  90. font-size: 1.55vh;
  91. white-space: nowrap;
  92. overflow: hidden;
  93. &.space {
  94. background: none;
  95. }
  96. .label {
  97. flex: 1;
  98. }
  99. .val {
  100. font-size: 2.2vh;
  101. font-weight: bold;
  102. flex: 1;
  103. .unit {
  104. font-weight: normal;
  105. font-size: 1.4vh;
  106. }
  107. }
  108. }
  109. }
  110. </style>