DeviceList.vue 4.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165
  1. <template>
  2. <Dialog v-model="dialogVisible" :title="t('deviceList.selectDevice')" style="width: 1100px; max-height: 800px">
  3. <ContentWrap>
  4. <el-form
  5. class="-mb-15px"
  6. :model="queryParams"
  7. ref="queryFormRef"
  8. :inline="true"
  9. label-width="68px"
  10. >
  11. <el-form-item :label="t('deviceList.deviceName')" prop="deviceName" style="margin-left: 25px">
  12. <el-input
  13. v-model="queryParams.deviceName"
  14. :placeholder="t('deviceList.nameHolder')"
  15. clearable
  16. @keyup.enter="handleQuery"
  17. class="!w-240px"
  18. />
  19. </el-form-item>
  20. <el-form-item :label="t('deviceList.deviceCode')" prop="deviceCode">
  21. <el-input
  22. v-model="queryParams.deviceCode"
  23. :placeholder="t('deviceList.codeHolder')"
  24. clearable
  25. @keyup.enter="handleQuery"
  26. class="!w-240px"
  27. />
  28. </el-form-item>
  29. <el-form-item>
  30. <el-button @click="handleQuery"><Icon icon="ep:search" class="mr-5px" />
  31. {{ t('deviceList.search') }}</el-button>
  32. <el-button @click="resetQuery"><Icon icon="ep:refresh" class="mr-5px" /> {{ t('deviceList.reset') }}</el-button>
  33. </el-form-item>
  34. </el-form>
  35. </ContentWrap>
  36. <ContentWrap>
  37. <el-table
  38. v-loading="loading"
  39. :data="list"
  40. :stripe="true"
  41. :show-overflow-tooltip="true"
  42. @row-click="handleRowClick"
  43. >
  44. <el-table-column width="120" :label="t('deviceList.select')">
  45. <template #default="{ row }">
  46. <el-radio
  47. :model-value="selectedRow?.id"
  48. :label="row.id"
  49. @click.stop="selectRow(row)"
  50. class="no-label-radio"
  51. />
  52. </template>
  53. </el-table-column>
  54. <el-table-column :label="t('deviceList.deviceCode')" align="center" prop="deviceCode" />
  55. <el-table-column :label="t('deviceList.deviceName')" align="center" prop="deviceName" />
  56. <el-table-column :label="t('deviceStatus.dept')" align="center" prop="deptName" />
  57. <el-table-column :label="t('maintain.status')" align="center" prop="deviceStatus">
  58. <template #default="scope">
  59. <dict-tag :type="DICT_TYPE.PMS_DEVICE_STATUS" :value="scope.row.deviceStatus" />
  60. </template>
  61. </el-table-column>
  62. <el-table-column
  63. :label="t('deviceList.createTime')"
  64. align="center"
  65. prop="createTime"
  66. width="180"
  67. :formatter="dateFormatter"
  68. />
  69. </el-table>
  70. <!-- 分页 -->
  71. <Pagination
  72. :total="total"
  73. v-model:page="queryParams.pageNo"
  74. v-model:limit="queryParams.pageSize"
  75. @pagination="getList"
  76. />
  77. </ContentWrap>
  78. </Dialog>
  79. </template>
  80. <script setup lang="ts">
  81. import { IotDeviceApi, IotDeviceVO } from '@/api/pms/device'
  82. import { DICT_TYPE } from '@/utils/dict'
  83. import { dateFormatter } from '@/utils/formatTime'
  84. import { CACHE_KEY, useCache } from '@/hooks/web/useCache'
  85. const emit = defineEmits(['choose']) // 定义 success 事件,用于操作成功后的回调
  86. const dialogVisible = ref(false) // 弹窗的是否展示
  87. const loading = ref(true) // 列表的加载中
  88. const queryFormRef = ref() // 搜索的表单
  89. const list = ref<IotDeviceVO[]>([]) // 列表的数据
  90. const total = ref(0) // 列表的总页数
  91. const { t } = useI18n() // 国际化
  92. const queryParams = reactive({
  93. pageNo: 1,
  94. pageSize: 10,
  95. label: '',
  96. status: undefined,
  97. deptId: undefined,
  98. assetClass: undefined,
  99. deviceName: undefined,
  100. deviceCode: undefined,
  101. })
  102. const selectedRow = ref(null)
  103. // 处理单选逻辑
  104. const selectRow = (row) => {
  105. selectedRow.value = selectedRow.value?.id === row.id ? null : row
  106. emit('choose', row)
  107. dialogVisible.value = false
  108. }
  109. // 点击整行选中
  110. const handleRowClick = (row) => {
  111. selectRow(row)
  112. }
  113. const open = async (classify) => {
  114. dialogVisible.value = true
  115. queryParams.assetClass = classify
  116. selectedRow.value = ''
  117. queryParams.deviceName = undefined
  118. queryParams.deviceCode = undefined
  119. queryParams.pageNo = 1
  120. await getList()
  121. }
  122. defineExpose({ open })
  123. const { wsCache } = useCache()
  124. const getList = async () => {
  125. loading.value = true
  126. try {
  127. // const user = wsCache.get(CACHE_KEY.USER)
  128. // queryParams.deptId = user.user.deptId
  129. const data = await IotDeviceApi.getIotDevicePage(queryParams)
  130. list.value = data.list
  131. total.value = data.total
  132. } finally {
  133. loading.value = false
  134. }
  135. }
  136. /** 搜索按钮操作 */
  137. const handleQuery = () => {
  138. queryParams.pageNo = 1
  139. getList()
  140. }
  141. const choose = (row: DictDataVO) => {
  142. emit('choose', row)
  143. dialogVisible.value = false
  144. }
  145. /** 重置按钮操作 */
  146. const resetQuery = () => {
  147. queryFormRef.value.resetFields()
  148. handleQuery()
  149. }
  150. </script>
  151. <style lang="scss">
  152. .no-label-radio .el-radio__label {
  153. display: none;
  154. }
  155. .no-label-radio .el-radio__inner {
  156. margin-right: 0;
  157. }
  158. </style>