index.vue 4.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167
  1. <!-- 设备分类属性列表 -->
  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>
  13. <el-button @click="handleQuery">
  14. <Icon class="mr-5px" icon="ep:search" />
  15. 搜索
  16. </el-button>
  17. <el-button @click="resetQuery">
  18. <Icon class="mr-5px" icon="ep:refresh" />
  19. 重置
  20. </el-button>
  21. <el-button
  22. v-hasPermi="[`pms:iot-device-category-template-attrs:create`]"
  23. plain
  24. type="primary"
  25. @click="openForm('create')"
  26. >
  27. <Icon class="mr-5px" icon="ep:plus" />
  28. 添加属性
  29. </el-button>
  30. </el-form-item>
  31. </el-form>
  32. </ContentWrap>
  33. <!-- 列表 -->
  34. <ContentWrap>
  35. <el-tabs>
  36. <el-table v-loading="loading" :data="list" :show-overflow-tooltip="true" :stripe="true">
  37. <el-table-column align="center" label="属性名称" prop="name" />
  38. <el-table-column align="center" label="标识符" prop="code" />
  39. <el-table-column align="center" label="数据类型" prop="code">
  40. <template #default="{ row }">
  41. {{ dataTypeOptionsLabel(row.selectOptions?.type) ?? '-' }}
  42. </template>
  43. </el-table-column>
  44. <el-table-column align="left" label="数据定义" prop="code">
  45. <template #default="{ row }">
  46. <DataDefinition :data="row" />
  47. </template>
  48. </el-table-column>
  49. <el-table-column align="center" label="操作">
  50. <template #default="scope">
  51. <el-button
  52. v-hasPermi="[`pms:iot-device-category-template-attrs:update`]"
  53. link
  54. type="primary"
  55. @click="openForm('update', scope.row.id)"
  56. >
  57. 编辑
  58. </el-button>
  59. <el-button
  60. v-hasPermi="['pms:iot-device-category-template-attrs:delete']"
  61. link
  62. type="danger"
  63. @click="handleDelete(scope.row.id)"
  64. >
  65. 删除
  66. </el-button>
  67. </template>
  68. </el-table-column>
  69. </el-table>
  70. <!-- 分页 -->
  71. <Pagination
  72. v-model:limit="queryParams.pageSize"
  73. v-model:page="queryParams.pageNo"
  74. :total="total"
  75. @pagination="getList"
  76. />
  77. </el-tabs>
  78. </ContentWrap>
  79. <!-- 表单弹窗:添加/修改 -->
  80. <AttrTemplateModelForm ref="formRef" @success="getList" :deviceCategoryId="deviceCategoryId" />
  81. </template>
  82. <script lang="ts" setup>
  83. import { DeviceAttrModelApi, DeviceAttrModelData } from '@/api/pms/deviceattrmodel'
  84. import AttrTemplateModelForm from './AttrTemplateModelForm.vue'
  85. import { getDataTypeOptionsLabel } from './config'
  86. import { DataDefinition } from '../components'
  87. import {useTagsViewStore} from "@/store/modules/tagsView";
  88. const { delView } = useTagsViewStore() // 视图操作
  89. const route = useRoute()
  90. const { currentRoute } = useRouter()
  91. defineOptions({ name: 'DeviceAttrTemplateModel' })
  92. const deviceCategoryId = route.params.id // 设备分类id
  93. const { t } = useI18n() // 国际化
  94. const message = useMessage() // 消息弹窗
  95. const loading = ref(true) // 列表的加载中
  96. const list = ref<DeviceAttrModelData[]>([]) // 列表的数据
  97. const total = ref(0) // 列表的总页数
  98. const queryParams = reactive({
  99. pageNo: 1,
  100. pageSize: 10,
  101. type: undefined,
  102. deviceCategoryId: -1
  103. })
  104. const queryFormRef = ref() // 搜索的表单
  105. const dataTypeOptionsLabel = computed(() => (value: string) => getDataTypeOptionsLabel(value)) // 解析数据类型
  106. /** 查询列表 */
  107. const getList = async () => {
  108. loading.value = true
  109. try {
  110. queryParams.deviceCategoryId = deviceCategoryId
  111. const data = await DeviceAttrModelApi.getDeviceAttrModelPage(queryParams)
  112. list.value = data.list
  113. total.value = data.total
  114. } finally {
  115. loading.value = false
  116. }
  117. }
  118. /** 搜索按钮操作 */
  119. const handleQuery = () => {
  120. queryParams.pageNo = 1
  121. getList()
  122. }
  123. /** 重置按钮操作 */
  124. const resetQuery = () => {
  125. queryFormRef.value.resetFields()
  126. queryParams.type = undefined
  127. handleQuery()
  128. }
  129. /** 添加/修改操作 */
  130. const formRef = ref()
  131. const openForm = (type: string, id?: number) => {
  132. formRef.value.open(type, id)
  133. }
  134. /** 删除按钮操作 */
  135. const handleDelete = async (id: number) => {
  136. try {
  137. // 删除的二次确认
  138. await message.delConfirm()
  139. // 发起删除
  140. await DeviceAttrModelApi.deleteDeviceAttrModel(id)
  141. message.success(t('common.delSuccess'))
  142. // 刷新列表
  143. await getList()
  144. } catch {}
  145. }
  146. /** 初始化 **/
  147. onMounted(() => {
  148. if (!deviceCategoryId) {
  149. message.warning('参数错误,设备属性模板不能为空!')
  150. delView(unref(currentRoute))
  151. return
  152. }
  153. getList()
  154. })
  155. </script>