index.vue 6.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232
  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="产品" prop="productId">
  21. <el-select
  22. v-model="queryParams.productId"
  23. placeholder="请选择产品"
  24. clearable
  25. @keyup.enter="handleQuery"
  26. class="!w-240px"
  27. >
  28. <el-option
  29. v-for="product in productList"
  30. :key="product.id"
  31. :label="product.name"
  32. :value="product.id"
  33. />
  34. </el-select>
  35. </el-form-item>
  36. <el-form-item label="创建时间" prop="createTime">
  37. <el-date-picker
  38. v-model="queryParams.createTime"
  39. value-format="YYYY-MM-DD HH:mm:ss"
  40. type="daterange"
  41. start-placeholder="开始日期"
  42. end-placeholder="结束日期"
  43. :default-time="[new Date('1 00:00:00'), new Date('1 23:59:59')]"
  44. class="!w-220px"
  45. />
  46. </el-form-item>
  47. <el-form-item>
  48. <el-button @click="handleQuery"><Icon icon="ep:search" class="mr-5px" /> 搜索</el-button>
  49. <el-button @click="resetQuery"><Icon icon="ep:refresh" class="mr-5px" /> 重置</el-button>
  50. <el-button
  51. type="primary"
  52. plain
  53. @click="openForm('create')"
  54. v-hasPermi="['iot:ota-firmware:create']"
  55. >
  56. <Icon icon="ep:plus" class="mr-5px" /> 新增
  57. </el-button>
  58. </el-form-item>
  59. </el-form>
  60. </ContentWrap>
  61. <!-- 列表 -->
  62. <ContentWrap>
  63. <el-table
  64. row-key="id"
  65. v-loading="loading"
  66. :data="list"
  67. :stripe="true"
  68. :show-overflow-tooltip="true"
  69. >
  70. <el-table-column label="固件编号" align="center" prop="id" />
  71. <el-table-column label="固件名称" align="center" prop="name" />
  72. <el-table-column label="固件版本" align="center" prop="description" />
  73. <el-table-column label="版本号" align="center" prop="version" />
  74. <el-table-column label="所属产品" align="center" prop="productId">
  75. <template #default="scope">
  76. <el-link
  77. @click="openProductDetail(scope.row.productId)"
  78. v-if="getProductName(scope.row.productId)"
  79. >
  80. {{ getProductName(scope.row.productId) }}
  81. </el-link>
  82. <span v-else>加载中...</span>
  83. </template>
  84. </el-table-column>
  85. <el-table-column label="固件文件" align="center" prop="fileUrl">
  86. <template #default="scope">
  87. <el-link :href="scope.row.fileUrl" target="_blank" download>
  88. <Icon icon="ep:download" class="mr-5px" />
  89. 下载固件
  90. </el-link>
  91. </template>
  92. </el-table-column>
  93. <el-table-column
  94. label="创建时间"
  95. align="center"
  96. prop="createTime"
  97. :formatter="dateFormatter"
  98. width="180px"
  99. />
  100. <el-table-column label="操作" align="center" min-width="180px">
  101. <template #default="scope">
  102. <el-button
  103. link
  104. @click="openFirmwareDetail(scope.row.id)"
  105. v-hasPermi="['iot:ota-firmware:query']"
  106. >
  107. 详情
  108. </el-button>
  109. <el-button
  110. link
  111. type="primary"
  112. @click="openForm('update', scope.row.id)"
  113. v-hasPermi="['iot:ota-firmware:update']"
  114. >
  115. 编辑
  116. </el-button>
  117. <el-button
  118. link
  119. type="danger"
  120. @click="handleDelete(scope.row.id)"
  121. v-hasPermi="['iot:ota-firmware:delete']"
  122. >
  123. 删除
  124. </el-button>
  125. </template>
  126. </el-table-column>
  127. </el-table>
  128. <!-- 分页 -->
  129. <Pagination
  130. :total="total"
  131. v-model:page="queryParams.pageNo"
  132. v-model:limit="queryParams.pageSize"
  133. @pagination="getList"
  134. />
  135. </ContentWrap>
  136. <!-- 表单弹窗:添加/修改 -->
  137. <OtaFirmwareForm ref="formRef" @success="getList" />
  138. </template>
  139. <script setup lang="ts">
  140. import { dateFormatter } from '@/utils/formatTime'
  141. import { IoTOtaFirmwareApi, IoTOtaFirmware } from '@/api/iot/ota/firmware'
  142. import { ProductApi, ProductVO } from '@/api/iot/product/product'
  143. import OtaFirmwareForm from './OtaFirmwareForm.vue'
  144. /** IoT OTA 固件列表 */
  145. defineOptions({ name: 'IoTOtaFirmware' })
  146. const message = useMessage() // 消息弹窗
  147. const { t } = useI18n() // 国际化
  148. const { push } = useRouter() // 路由
  149. const loading = ref(true) // 列表的加载中
  150. const list = ref<IoTOtaFirmware[]>([]) // 列表的数据
  151. const total = ref(0) // 列表的总页数
  152. const productList = ref<ProductVO[]>([]) // 产品列表
  153. const queryParams = reactive({
  154. pageNo: 1,
  155. pageSize: 10,
  156. name: undefined,
  157. productId: undefined,
  158. createTime: []
  159. })
  160. const queryFormRef = ref() // 搜索的表单
  161. /** 查询列表 */
  162. const getList = async () => {
  163. loading.value = true
  164. try {
  165. const data = await IoTOtaFirmwareApi.getOtaFirmwarePage(queryParams)
  166. list.value = data.list
  167. total.value = data.total
  168. } finally {
  169. loading.value = false
  170. }
  171. }
  172. /** 根据产品编号,获取产品名称 */
  173. const getProductName = (productId: number) => {
  174. const product = productList.value.find((p) => p.id === productId)
  175. return product?.name || ''
  176. }
  177. /** 打开产品详情 */
  178. const openProductDetail = (productId: number) => {
  179. push({ name: 'IoTProductDetail', params: { id: productId } })
  180. }
  181. /** 打开固件详情 */
  182. const openFirmwareDetail = (firmwareId: number) => {
  183. push({ name: 'IoTOtaFirmwareDetail', params: { id: firmwareId } })
  184. }
  185. /** 搜索按钮操作 */
  186. const handleQuery = () => {
  187. queryParams.pageNo = 1
  188. getList()
  189. }
  190. /** 重置按钮操作 */
  191. const resetQuery = () => {
  192. queryFormRef.value.resetFields()
  193. handleQuery()
  194. }
  195. /** 添加/修改操作 */
  196. const formRef = ref()
  197. const openForm = (type: string, id?: number) => {
  198. formRef.value.open(type, id)
  199. }
  200. /** 删除按钮操作 */
  201. const handleDelete = async (id: number) => {
  202. try {
  203. // 删除的二次确认
  204. await message.delConfirm()
  205. // 发起删除
  206. await IoTOtaFirmwareApi.deleteOtaFirmware(id)
  207. message.success(t('common.delSuccess'))
  208. // 刷新列表
  209. await getList()
  210. } catch {}
  211. }
  212. /** 初始化 **/
  213. onMounted(async () => {
  214. productList.value = await ProductApi.getSimpleProductList()
  215. getList()
  216. })
  217. </script>