index.vue 5.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176
  1. <template>
  2. <ContentWrap>
  3. <!-- 搜索工作栏 -->
  4. <el-form
  5. ref="queryFormRef"
  6. :inline="true"
  7. :model="queryParams"
  8. class="-mb-15px"
  9. label-width="68px"
  10. >
  11. <el-form-item label="功能类型" prop="name">
  12. <el-select
  13. v-model="queryParams.type"
  14. class="!w-240px"
  15. clearable
  16. placeholder="请选择功能类型"
  17. >
  18. <el-option
  19. v-for="dict in getIntDictOptions(DICT_TYPE.IOT_PRODUCT_THING_MODEL_TYPE)"
  20. :key="dict.value"
  21. :label="dict.label"
  22. :value="dict.value"
  23. />
  24. </el-select>
  25. </el-form-item>
  26. <el-form-item>
  27. <el-button @click="handleQuery">
  28. <Icon class="mr-5px" icon="ep:search" />
  29. 搜索
  30. </el-button>
  31. <el-button @click="resetQuery">
  32. <Icon class="mr-5px" icon="ep:refresh" />
  33. 重置
  34. </el-button>
  35. <el-button
  36. v-hasPermi="[`iot:product-thing-model:create`]"
  37. plain
  38. type="primary"
  39. @click="openForm('create')"
  40. >
  41. <Icon class="mr-5px" icon="ep:plus" />
  42. 添加功能
  43. </el-button>
  44. </el-form-item>
  45. </el-form>
  46. </ContentWrap>
  47. <ContentWrap>
  48. <el-tabs>
  49. <el-table v-loading="loading" :data="list" :show-overflow-tooltip="true" :stripe="true">
  50. <el-table-column align="center" label="功能类型" prop="type">
  51. <template #default="scope">
  52. <dict-tag :type="DICT_TYPE.IOT_PRODUCT_THING_MODEL_TYPE" :value="scope.row.type" />
  53. </template>
  54. </el-table-column>
  55. <el-table-column align="center" label="功能名称" prop="name" />
  56. <el-table-column align="center" label="标识符" prop="identifier" />
  57. <el-table-column align="center" label="数据类型" prop="identifier">
  58. <template #default="{ row }">
  59. {{ dataTypeOptionsLabel(row.property.dataType) ?? '-' }}
  60. </template>
  61. </el-table-column>
  62. <el-table-column align="center" label="数据定义" prop="identifier">
  63. <template #default="{ row }">
  64. <!-- TODO puhui999: 数据定义展示待完善 -->
  65. {{ row.property.dataSpecs ?? row.property.dataSpecsList }}
  66. </template>
  67. </el-table-column>
  68. <el-table-column align="center" label="操作">
  69. <template #default="scope">
  70. <el-button
  71. v-hasPermi="[`iot:product-thing-model:update`]"
  72. link
  73. type="primary"
  74. @click="openForm('update', scope.row.id)"
  75. >
  76. 编辑
  77. </el-button>
  78. <el-button
  79. v-hasPermi="['iot:product-thing-model:delete']"
  80. link
  81. type="danger"
  82. @click="handleDelete(scope.row.id)"
  83. >
  84. 删除
  85. </el-button>
  86. </template>
  87. </el-table-column>
  88. </el-table>
  89. <!-- 分页 -->
  90. <Pagination
  91. v-model:limit="queryParams.pageSize"
  92. v-model:page="queryParams.pageNo"
  93. :total="total"
  94. @pagination="getList"
  95. />
  96. </el-tabs>
  97. </ContentWrap>
  98. <!-- 表单弹窗:添加/修改 -->
  99. <ThingModelForm ref="formRef" @success="getList" />
  100. </template>
  101. <script lang="ts" setup>
  102. import { ThingModelApi, ThingModelData } from '@/api/iot/thingmodel'
  103. import { DICT_TYPE, getIntDictOptions } from '@/utils/dict'
  104. import ThingModelForm from './ThingModelForm.vue'
  105. import { ProductVO } from '@/api/iot/product/product'
  106. import { IOT_PROVIDE_KEY } from '@/views/iot/utils/constants'
  107. import { getDataTypeOptionsLabel } from '@/views/iot/thingmodel/config'
  108. defineOptions({ name: 'IoTProductThingModel' })
  109. const { t } = useI18n() // 国际化
  110. const message = useMessage() // 消息弹窗
  111. const loading = ref(true) // 列表的加载中
  112. const list = ref<ThingModelData[]>([]) // 列表的数据
  113. const total = ref(0) // 列表的总页数
  114. const queryParams = reactive({
  115. pageNo: 1,
  116. pageSize: 10,
  117. type: undefined,
  118. productId: -1
  119. })
  120. const queryFormRef = ref() // 搜索的表单
  121. const product = inject<Ref<ProductVO>>(IOT_PROVIDE_KEY.PRODUCT) // 注入产品信息
  122. const dataTypeOptionsLabel = computed(() => (value: string) => getDataTypeOptionsLabel(value)) // 解析数据类型
  123. /** 查询列表 */
  124. const getList = async () => {
  125. loading.value = true
  126. try {
  127. queryParams.productId = product?.value?.id || -1
  128. const data = await ThingModelApi.getThingModelPage(queryParams)
  129. list.value = data.list
  130. total.value = data.total
  131. } finally {
  132. loading.value = false
  133. }
  134. }
  135. /** 搜索按钮操作 */
  136. const handleQuery = () => {
  137. queryParams.pageNo = 1
  138. getList()
  139. }
  140. /** 重置按钮操作 */
  141. const resetQuery = () => {
  142. queryFormRef.value.resetFields()
  143. queryParams.type = undefined
  144. handleQuery()
  145. }
  146. /** 添加/修改操作 */
  147. const formRef = ref()
  148. const openForm = (type: string, id?: number) => {
  149. formRef.value.open(type, id)
  150. }
  151. /** 删除按钮操作 */
  152. const handleDelete = async (id: number) => {
  153. try {
  154. // 删除的二次确认
  155. await message.delConfirm()
  156. // 发起删除
  157. await ThingModelApi.deleteThingModel(id)
  158. message.success(t('common.delSuccess'))
  159. // 刷新列表
  160. await getList()
  161. } catch {}
  162. }
  163. /** 初始化 **/
  164. onMounted(() => {
  165. getList()
  166. })
  167. </script>