index.vue 5.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191
  1. <template>
  2. <ContentWrap>
  3. <!-- 搜索工作栏 -->
  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="产品名称" prop="name">
  12. <el-input
  13. v-model="queryParams.name"
  14. placeholder="请输入产品名称"
  15. clearable
  16. @keyup.enter="handleQuery"
  17. class="!w-240px"
  18. />
  19. </el-form-item>
  20. <el-form-item label="ProductKey" prop="productKey">
  21. <el-input
  22. v-model="queryParams.productKey"
  23. placeholder="请输入产品标识"
  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" /> 搜索</el-button>
  31. <el-button @click="resetQuery"><Icon icon="ep:refresh" class="mr-5px" /> 重置</el-button>
  32. <el-button
  33. type="primary"
  34. plain
  35. @click="openForm('create')"
  36. v-hasPermi="['iot:product:create']"
  37. >
  38. <Icon icon="ep:plus" class="mr-5px" /> 新增
  39. </el-button>
  40. </el-form-item>
  41. </el-form>
  42. </ContentWrap>
  43. <!-- 列表 -->
  44. <ContentWrap>
  45. <el-table v-loading="loading" :data="list" :stripe="true" :show-overflow-tooltip="true">
  46. <el-table-column label="产品名称" align="center" prop="name">
  47. <template #default="scope">
  48. <el-link @click="openDetail(scope.row.id)">{{ scope.row.name }}</el-link>
  49. </template>
  50. </el-table-column>
  51. <el-table-column label="ProductKey" align="center" prop="productKey" />
  52. <el-table-column label="设备类型" align="center" prop="deviceType">
  53. <template #default="scope">
  54. <dict-tag :type="DICT_TYPE.IOT_PRODUCT_DEVICE_TYPE" :value="scope.row.deviceType" />
  55. </template>
  56. </el-table-column>
  57. <el-table-column
  58. label="创建时间"
  59. align="center"
  60. prop="createTime"
  61. :formatter="dateFormatter"
  62. width="180px"
  63. />
  64. <el-table-column label="产品状态" align="center" prop="status">
  65. <template #default="scope">
  66. <dict-tag :type="DICT_TYPE.IOT_PRODUCT_STATUS" :value="scope.row.status" />
  67. </template>
  68. </el-table-column>
  69. <el-table-column label="操作" align="center">
  70. <template #default="scope">
  71. <el-button
  72. link
  73. type="primary"
  74. @click="openDetail(scope.row.id)"
  75. v-hasPermi="['iot:product:query']"
  76. >
  77. 查看
  78. </el-button>
  79. <el-button
  80. link
  81. type="danger"
  82. @click="handleDelete(scope.row.id)"
  83. v-hasPermi="['iot:product:delete']"
  84. :disabled="scope.row.status === 1"
  85. >
  86. 删除
  87. </el-button>
  88. </template>
  89. </el-table-column>
  90. </el-table>
  91. <!-- 分页 -->
  92. <Pagination
  93. :total="total"
  94. v-model:page="queryParams.pageNo"
  95. v-model:limit="queryParams.pageSize"
  96. @pagination="getList"
  97. />
  98. </ContentWrap>
  99. <!-- 表单弹窗:添加/修改 -->
  100. <ProductForm ref="formRef" @success="getList" />
  101. </template>
  102. <script setup lang="ts">
  103. import { dateFormatter } from '@/utils/formatTime'
  104. import { ProductApi, ProductVO } from '@/api/iot/product'
  105. import ProductForm from './ProductForm.vue'
  106. import { DICT_TYPE } from '@/utils/dict'
  107. /** iot 产品 列表 */
  108. defineOptions({ name: 'IoTProduct' })
  109. const message = useMessage() // 消息弹窗
  110. const { t } = useI18n() // 国际化
  111. const loading = ref(true) // 列表的加载中
  112. const list = ref<ProductVO[]>([]) // 列表的数据
  113. const total = ref(0) // 列表的总页数
  114. const queryParams = reactive({
  115. pageNo: 1,
  116. pageSize: 10,
  117. name: undefined,
  118. createTime: [],
  119. productKey: undefined,
  120. protocolId: undefined,
  121. categoryId: undefined,
  122. description: undefined,
  123. validateType: undefined,
  124. status: undefined,
  125. deviceType: undefined,
  126. netType: undefined,
  127. protocolType: undefined,
  128. dataFormat: undefined
  129. })
  130. const queryFormRef = ref() // 搜索的表单
  131. /** 查询列表 */
  132. const getList = async () => {
  133. loading.value = true
  134. try {
  135. const data = await ProductApi.getProductPage(queryParams)
  136. list.value = data.list
  137. total.value = data.total
  138. } finally {
  139. loading.value = false
  140. }
  141. }
  142. /** 搜索按钮操作 */
  143. const handleQuery = () => {
  144. queryParams.pageNo = 1
  145. getList()
  146. }
  147. /** 重置按钮操作 */
  148. const resetQuery = () => {
  149. queryFormRef.value.resetFields()
  150. handleQuery()
  151. }
  152. /** 添加/修改操作 */
  153. const formRef = ref()
  154. const openForm = (type: string, id?: number) => {
  155. formRef.value.open(type, id)
  156. }
  157. /** 打开详情 */
  158. const { push } = useRouter()
  159. const openDetail = (id: number) => {
  160. push({ name: 'IoTProductDetail', params: { id } })
  161. }
  162. /** 删除按钮操作 */
  163. const handleDelete = async (id: number) => {
  164. try {
  165. // 删除的二次确认
  166. await message.delConfirm()
  167. // 发起删除
  168. await ProductApi.deleteProduct(id)
  169. message.success(t('common.delSuccess'))
  170. // 刷新列表
  171. await getList()
  172. } catch {}
  173. }
  174. /** 初始化 **/
  175. onMounted(() => {
  176. getList()
  177. })
  178. </script>