index.vue 5.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204
  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. <el-table-column label="ProductKey" align="center" prop="productKey" />
  48. <el-table-column label="设备类型" align="center" prop="deviceType">
  49. <template #default="scope">
  50. <dict-tag :type="DICT_TYPE.IOT_PRODUCT_DEVICE_TYPE" :value="scope.row.deviceType" />
  51. </template>
  52. </el-table-column>
  53. <el-table-column
  54. label="创建时间"
  55. align="center"
  56. prop="createTime"
  57. :formatter="dateFormatter"
  58. width="180px"
  59. />
  60. <el-table-column label="产品状态" align="center" prop="status">
  61. <template #default="scope">
  62. <dict-tag :type="DICT_TYPE.IOT_PRODUCT_STATUS" :value="scope.row.status" />
  63. </template>
  64. </el-table-column>
  65. <el-table-column label="操作" align="center">
  66. <template #default="scope">
  67. <el-button
  68. link
  69. type="primary"
  70. @click="openDetail(scope.row.id)"
  71. v-hasPermi="['iot:product:query']"
  72. >
  73. 查看
  74. </el-button>
  75. <el-button
  76. link
  77. type="danger"
  78. @click="handleDelete(scope.row.id)"
  79. v-hasPermi="['iot:product:delete']"
  80. :disabled="scope.row.status === 1"
  81. >
  82. 删除
  83. </el-button>
  84. </template>
  85. </el-table-column>
  86. </el-table>
  87. <!-- 分页 -->
  88. <Pagination
  89. :total="total"
  90. v-model:page="queryParams.pageNo"
  91. v-model:limit="queryParams.pageSize"
  92. @pagination="getList"
  93. />
  94. </ContentWrap>
  95. <!-- 表单弹窗:添加/修改 -->
  96. <ProductForm ref="formRef" @success="getList" />
  97. </template>
  98. <script setup lang="ts">
  99. import { dateFormatter } from '@/utils/formatTime'
  100. import download from '@/utils/download'
  101. import { ProductApi, ProductVO } from '@/api/iot/product'
  102. import ProductForm from './ProductForm.vue'
  103. import { DICT_TYPE } from '@/utils/dict'
  104. /** iot 产品 列表 */
  105. defineOptions({ name: 'Product' })
  106. const message = useMessage() // 消息弹窗
  107. const { t } = useI18n() // 国际化
  108. const loading = ref(true) // 列表的加载中
  109. const list = ref<ProductVO[]>([]) // 列表的数据
  110. const total = ref(0) // 列表的总页数
  111. const queryParams = reactive({
  112. pageNo: 1,
  113. pageSize: 10,
  114. name: undefined,
  115. createTime: [],
  116. productKey: undefined,
  117. protocolId: undefined,
  118. categoryId: undefined,
  119. description: undefined,
  120. validateType: undefined,
  121. status: undefined,
  122. deviceType: undefined,
  123. netType: undefined,
  124. protocolType: undefined,
  125. dataFormat: undefined
  126. })
  127. const queryFormRef = ref() // 搜索的表单
  128. const exportLoading = ref(false) // 导出的加载中
  129. /** 查询列表 */
  130. const getList = async () => {
  131. loading.value = true
  132. try {
  133. const data = await ProductApi.getProductPage(queryParams)
  134. list.value = data.list
  135. total.value = data.total
  136. } finally {
  137. loading.value = false
  138. }
  139. }
  140. /** 搜索按钮操作 */
  141. const handleQuery = () => {
  142. queryParams.pageNo = 1
  143. getList()
  144. }
  145. /** 重置按钮操作 */
  146. const resetQuery = () => {
  147. queryFormRef.value.resetFields()
  148. handleQuery()
  149. }
  150. /** 添加/修改操作 */
  151. const formRef = ref()
  152. const openForm = (type: string, id?: number) => {
  153. formRef.value.open(type, id)
  154. }
  155. /** 打开详情 */
  156. const { currentRoute, push } = useRouter()
  157. const openDetail = (id: number) => {
  158. push({ name: 'IotProductDetail', params: { id } })
  159. }
  160. /** 删除按钮操作 */
  161. const handleDelete = async (id: number) => {
  162. try {
  163. // 删除的二次确认
  164. await message.delConfirm()
  165. // 发起删除
  166. await ProductApi.deleteProduct(id)
  167. message.success(t('common.delSuccess'))
  168. // 刷新列表
  169. await getList()
  170. } catch {}
  171. }
  172. /** 导出按钮操作 */
  173. const handleExport = async () => {
  174. try {
  175. // 导出的二次确认
  176. await message.exportConfirm()
  177. // 发起导出
  178. exportLoading.value = true
  179. const data = await ProductApi.exportProduct(queryParams)
  180. download.excel(data, 'iot 产品.xls')
  181. } catch {
  182. } finally {
  183. exportLoading.value = false
  184. }
  185. }
  186. /** 初始化 **/
  187. onMounted(() => {
  188. getList()
  189. })
  190. </script>