index.vue 5.3 KB

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