index.vue 7.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233
  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="left" label="数据定义" prop="identifier">
  63. <template #default="{ row }">
  64. <!-- 属性 -->
  65. <template v-if="row.type === ThingModelType.PROPERTY">
  66. <!-- 非列表型:数值 -->
  67. <div
  68. v-if="
  69. [
  70. DataSpecsDataType.INT,
  71. DataSpecsDataType.DOUBLE,
  72. DataSpecsDataType.FLOAT
  73. ].includes(row.property.dataType)
  74. "
  75. >
  76. 取值范围:{{ `${row.property.dataSpecs.min}~${row.property.dataSpecs.max}` }}
  77. </div>
  78. <!-- 非列表型:文本 -->
  79. <div v-if="DataSpecsDataType.TEXT === row.property.dataType">
  80. 数据长度:{{ row.property.dataSpecs.length }}
  81. </div>
  82. <!-- 列表型: 数组、结构、时间(特殊) -->
  83. <div
  84. v-if="
  85. [
  86. DataSpecsDataType.ARRAY,
  87. DataSpecsDataType.STRUCT,
  88. DataSpecsDataType.DATE
  89. ].includes(row.property.dataType)
  90. "
  91. >
  92. -
  93. </div>
  94. <!-- 列表型: 布尔值、枚举 -->
  95. <div
  96. v-if="
  97. [DataSpecsDataType.BOOL, DataSpecsDataType.ENUM].includes(row.property.dataType)
  98. "
  99. >
  100. <div>
  101. {{ DataSpecsDataType.BOOL === row.property.dataType ? '布尔值' : '枚举值' }}:
  102. </div>
  103. <div v-for="item in row.property.dataSpecsList" :key="item.value">
  104. {{ `${item.name}-${item.value}` }}
  105. </div>
  106. </div>
  107. </template>
  108. <!-- 服务 -->
  109. <div v-if="row.type === ThingModelType.SERVICE">
  110. 调用方式:{{ getCallTypeByValue(row.service.callType) }}
  111. </div>
  112. <!-- 事件 -->
  113. <div v-if="row.type === ThingModelType.EVENT">
  114. 事件类型:{{ getEventTypeByValue(row.event.type) }}
  115. </div>
  116. </template>
  117. </el-table-column>
  118. <el-table-column align="center" label="操作">
  119. <template #default="scope">
  120. <el-button
  121. v-hasPermi="[`iot:product-thing-model:update`]"
  122. link
  123. type="primary"
  124. @click="openForm('update', scope.row.id)"
  125. >
  126. 编辑
  127. </el-button>
  128. <el-button
  129. v-hasPermi="['iot:product-thing-model:delete']"
  130. link
  131. type="danger"
  132. @click="handleDelete(scope.row.id)"
  133. >
  134. 删除
  135. </el-button>
  136. </template>
  137. </el-table-column>
  138. </el-table>
  139. <!-- 分页 -->
  140. <Pagination
  141. v-model:limit="queryParams.pageSize"
  142. v-model:page="queryParams.pageNo"
  143. :total="total"
  144. @pagination="getList"
  145. />
  146. </el-tabs>
  147. </ContentWrap>
  148. <!-- 表单弹窗:添加/修改 -->
  149. <ThingModelForm ref="formRef" @success="getList" />
  150. </template>
  151. <script lang="ts" setup>
  152. import { ThingModelApi, ThingModelData } from '@/api/iot/thingmodel'
  153. import { DICT_TYPE, getIntDictOptions } from '@/utils/dict'
  154. import ThingModelForm from './ThingModelForm.vue'
  155. import { ProductVO } from '@/api/iot/product/product'
  156. import { IOT_PROVIDE_KEY } from '@/views/iot/utils/constants'
  157. import {
  158. DataSpecsDataType,
  159. getCallTypeByValue,
  160. getDataTypeOptionsLabel,
  161. getEventTypeByValue,
  162. ThingModelType
  163. } from './config'
  164. import { ThingModelNumberDataSpecs } from '@/views/iot/thingmodel/dataSpecs'
  165. defineOptions({ name: 'IoTProductThingModel' })
  166. const { t } = useI18n() // 国际化
  167. const message = useMessage() // 消息弹窗
  168. const loading = ref(true) // 列表的加载中
  169. const list = ref<ThingModelData[]>([]) // 列表的数据
  170. const total = ref(0) // 列表的总页数
  171. const queryParams = reactive({
  172. pageNo: 1,
  173. pageSize: 10,
  174. type: undefined,
  175. productId: -1
  176. })
  177. const queryFormRef = ref() // 搜索的表单
  178. const product = inject<Ref<ProductVO>>(IOT_PROVIDE_KEY.PRODUCT) // 注入产品信息
  179. const dataTypeOptionsLabel = computed(() => (value: string) => getDataTypeOptionsLabel(value)) // 解析数据类型
  180. /** 查询列表 */
  181. const getList = async () => {
  182. loading.value = true
  183. try {
  184. queryParams.productId = product?.value?.id || -1
  185. const data = await ThingModelApi.getThingModelPage(queryParams)
  186. list.value = data.list
  187. total.value = data.total
  188. } finally {
  189. loading.value = false
  190. }
  191. }
  192. /** 搜索按钮操作 */
  193. const handleQuery = () => {
  194. queryParams.pageNo = 1
  195. getList()
  196. }
  197. /** 重置按钮操作 */
  198. const resetQuery = () => {
  199. queryFormRef.value.resetFields()
  200. queryParams.type = undefined
  201. handleQuery()
  202. }
  203. /** 添加/修改操作 */
  204. const formRef = ref()
  205. const openForm = (type: string, id?: number) => {
  206. formRef.value.open(type, id)
  207. }
  208. /** 删除按钮操作 */
  209. const handleDelete = async (id: number) => {
  210. try {
  211. // 删除的二次确认
  212. await message.delConfirm()
  213. // 发起删除
  214. await ThingModelApi.deleteThingModel(id)
  215. message.success(t('common.delSuccess'))
  216. // 刷新列表
  217. await getList()
  218. } catch {}
  219. }
  220. /** 初始化 **/
  221. onMounted(() => {
  222. getList()
  223. })
  224. </script>