DeviceUpload.vue 7.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244
  1. <template>
  2. <el-row :gutter="20">
  3. <el-col :span="5" :xs="24">
  4. <ContentWrap class="h-1/1">
  5. <FileTree @node-click="handleFileNodeClick" :deviceId="id" />
  6. </ContentWrap>
  7. </el-col>
  8. <el-col :span="19">
  9. <ContentWrap>
  10. <el-form
  11. class="-mb-15px"
  12. :model="queryParams"
  13. ref="queryFormRef"
  14. :inline="true"
  15. label-width="68px"
  16. >
  17. <el-form-item label="文件名称" prop="fileName">
  18. <el-input
  19. v-model="queryParams.fileName"
  20. placeholder="请输入文件名称"
  21. clearable
  22. @keyup.enter="handleQuery"
  23. class="!w-240px"
  24. />
  25. </el-form-item>
  26. <el-form-item>
  27. <el-button @click="handleQuery"><Icon icon="ep:search" />搜索</el-button>
  28. <el-button @click="resetQuery"><Icon icon="ep:refresh" />重置</el-button>
  29. <el-button type="primary" plain @click="openForm('create')">
  30. <Icon icon="ep:plus" /> 文件上传
  31. </el-button>
  32. </el-form-item>
  33. </el-form>
  34. </ContentWrap>
  35. <ContentWrap>
  36. <el-table v-loading="formLoading" :data="list" :stripe="true" :show-overflow-tooltip="true">
  37. <!-- <el-table-column label="设备名称" align="center" prop="deviceId" />-->
  38. <!-- <el-table-column label="资料分类" align="center" prop="classId" />-->
  39. <el-table-column label="文件名称" align="center" prop="filename" />
  40. <el-table-column label="文件类型" align="center" prop="fileType" />
  41. <el-table-column label="文件路径" align="center" prop="filePath" />
  42. <el-table-column label="备注" align="center" prop="remark" />
  43. <el-table-column
  44. label="创建时间"
  45. align="center"
  46. prop="createTime"
  47. :formatter="dateFormatter"
  48. width="180px"
  49. />
  50. <el-table-column label="操作" align="center" width="160">
  51. <template #default="scope">
  52. <div class="flex items-center justify-center">
  53. <el-button
  54. type="primary"
  55. link
  56. @click="openForm('update', scope.row.id)"
  57. >
  58. <Icon icon="ep:edit" />修改
  59. </el-button>
  60. <el-dropdown
  61. @command="(command) => handleCommand(command, scope.row)"
  62. v-hasPermi="[
  63. 'system:user:delete',
  64. 'system:user:update-password',
  65. 'system:permission:assign-user-role'
  66. ]"
  67. >
  68. <el-button type="primary" link><Icon icon="ep:d-arrow-right" /> 更多</el-button>
  69. <template #dropdown>
  70. <el-dropdown-menu>
  71. <el-dropdown-item
  72. command="handleDelete"
  73. >
  74. <Icon icon="ep:delete" />删除
  75. </el-dropdown-item>
  76. <el-dropdown-item
  77. command="fileView"
  78. >
  79. <Icon icon="ep:view" />预览
  80. </el-dropdown-item>
  81. <el-dropdown-item
  82. command="fileDownload"
  83. >
  84. <Icon icon="ep:view" />下载
  85. </el-dropdown-item>
  86. </el-dropdown-menu>
  87. </template>
  88. </el-dropdown>
  89. </div>
  90. </template>
  91. </el-table-column>
  92. </el-table>
  93. <Pagination
  94. :total="total"
  95. v-model:page="queryParams.pageNo"
  96. v-model:limit="queryParams.pageSize"
  97. @pagination="getList"
  98. />
  99. </ContentWrap>
  100. </el-col>
  101. </el-row>
  102. <IotInfoForm ref="formRef" @success="getList" :deviceId="deviceId" :classId="queryParams.classId"/>
  103. </template>
  104. <script lang="ts" setup>
  105. import { IotDeviceApi, IotDeviceVO } from '@/api/pms/device'
  106. import FileTree from '@/views/pms/device/FileTree.vue'
  107. import { dateFormatter } from '@/utils/formatTime'
  108. import IotInfoForm from "@/views/pms/iotinfo/IotInfoForm.vue";
  109. import * as IotInfoApi from '@/api/pms/iotinfo'
  110. import {SupplierVO} from "@/api/supplier/base";
  111. import {IotInfoVO} from "@/api/pms/iotinfo";
  112. defineOptions({ name: 'DeviceUpload' })
  113. const queryFormRef = ref() // 搜索的表单
  114. const { t } = useI18n() // 国际化
  115. const message = useMessage() // 消息弹窗
  116. const loading = ref(true) // 列表的加载中
  117. const { params } = useRoute() // 查询参数
  118. const formLoading = ref(false) // 表单的加载中:1)修改时的数据加载;2)提交的按钮禁用
  119. const list = ref<IotDeviceVO[]>([]) // 列表的数据
  120. const total = ref(0) // 列表的总页数
  121. const id = params.id as unknown as number
  122. const queryParams = reactive({
  123. pageNo: 1,
  124. pageSize: 10,
  125. fileName: null,
  126. createTime: [],
  127. deviceId: null,
  128. classId: null,
  129. })
  130. // SPU 表单数据
  131. const formData = ref({
  132. id: undefined,
  133. deviceId: undefined,
  134. orgId: undefined,
  135. filename: undefined,
  136. fileType: undefined,
  137. filePath: undefined,
  138. remark: undefined,
  139. classId: undefined,
  140. })
  141. const handleCommand = (command: string, row: IotInfoVO) => {
  142. switch (command) {
  143. case 'handleDelete':
  144. handleDelete(row.id)
  145. break
  146. case 'handleUpdate':
  147. openForm('update', row.id)
  148. break
  149. case 'fileView':
  150. handleFileView(row.filePath)
  151. break
  152. case 'fileDownload':
  153. handleDownload(row.filePath)
  154. break
  155. default:
  156. break
  157. }
  158. }
  159. const handleDownload = async (url) => {
  160. try {
  161. const response = await fetch(url);
  162. const blob = await response.blob();
  163. const downloadUrl = window.URL.createObjectURL(blob);
  164. const link = document.createElement('a');
  165. link.href = downloadUrl;
  166. link.download = url.split('/').pop(); // 自动获取文件名‌:ml-citation{ref="3" data="citationList"}
  167. link.click();
  168. URL.revokeObjectURL(downloadUrl);
  169. } catch (error) {
  170. console.error('下载失败:', error);
  171. }
  172. }
  173. const handleFileView = (url: string) => {
  174. window.open('http://1.94.244.160:8012/onlinePreview?url='+encodeURIComponent(Base64.encode(url)));
  175. }
  176. const handleDelete = async (id: number) => {
  177. try {
  178. // 删除的二次确认
  179. await message.delConfirm()
  180. // 发起删除
  181. await IotInfoApi.IotInfoApi.deleteIotInfo(id)
  182. message.success(t('common.delSuccess'))
  183. // 刷新列表
  184. await getList()
  185. } catch {}
  186. }
  187. const formRef = ref()
  188. const openForm = (type: string, id?: number) => {
  189. if (!queryParams.classId){
  190. message.error("请选择左侧资料分类")
  191. return
  192. }
  193. formRef.value.open(type, id)
  194. }
  195. const deviceId = ref('')
  196. const handleFileNodeClick = async (row) => {
  197. queryParams.classId = row.id
  198. await getList()
  199. }
  200. /** 获得详情 */
  201. const getDetail = async () => {
  202. if (id) {
  203. formLoading.value = true
  204. try {
  205. formData.value = (await IotDeviceApi.getIotDevice(id)) as IotDeviceVO
  206. } finally {
  207. formLoading.value = false
  208. }
  209. }
  210. }
  211. /** 查询列表 */
  212. const getList = async () => {
  213. loading.value = true
  214. try {
  215. queryParams.deviceId = deviceId.value
  216. const data = await IotInfoApi.IotInfoApi.getIotInfoPage(queryParams)
  217. list.value = data.list
  218. total.value = data.total
  219. } finally {
  220. loading.value = false
  221. }
  222. }
  223. /** 搜索按钮操作 */
  224. const handleQuery = () => {
  225. queryParams.pageNo = 1
  226. getList()
  227. }
  228. /** 重置按钮操作 */
  229. const resetQuery = () => {
  230. queryFormRef.value?.resetFields()
  231. handleQuery()
  232. }
  233. /** 初始化 */
  234. onMounted(async () => {
  235. await getDetail()
  236. deviceId.value = params.id as unknown as number
  237. })
  238. </script>
  239. <style scoped></style>