DeviceUpload.vue 10 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328
  1. <template>
  2. <div class="container-tree" ref="container">
  3. <el-row>
  4. <div class="left-tree" :style="{ width: leftWidth + 'px' }">
  5. <ContentWrapNoBottom>
  6. <FileTree @node-click="handleFileNodeClick" @success="successList" :deviceId="id" />
  7. </ContentWrapNoBottom>
  8. </div>
  9. <div class="divider-tree" @mousedown="startDrag"></div>
  10. <div class="right-tree" :style="{ width: rightWidth + 'px' }">
  11. <ContentWrap>
  12. <el-form
  13. class="-mb-15px"
  14. :model="queryParams"
  15. ref="queryFormRef"
  16. :inline="true"
  17. label-width="68px"
  18. >
  19. <el-form-item :label="t('file.name')" prop="filename">
  20. <el-input
  21. v-model="queryParams.filename"
  22. :placeholder="t('file.nameHolder')"
  23. clearable
  24. @keyup.enter="handleQuery"
  25. class="!w-240px"
  26. />
  27. </el-form-item>
  28. <el-form-item>
  29. <el-button @click="handleQuery"><Icon icon="ep:search" />
  30. {{ t('file.search') }}</el-button>
  31. <el-button @click="resetQuery"><Icon icon="ep:refresh" />
  32. {{ t('file.reset') }}</el-button>
  33. <el-button type="primary" plain @click="openForm('create')">
  34. <Icon icon="ep:plus" />
  35. {{ t('file.upload') }}
  36. </el-button>
  37. </el-form-item>
  38. </el-form>
  39. </ContentWrap>
  40. <ContentWrap>
  41. <el-table
  42. v-loading="formLoading"
  43. :data="list"
  44. :stripe="true"
  45. :show-overflow-tooltip="true"
  46. >
  47. <!-- <el-table-column label="设备名称" align="center" prop="deviceId" />-->
  48. <!-- <el-table-column label="资料分类" align="center" prop="classId" />-->
  49. <el-table-column :label="t('file.name')" align="center" prop="filename" />
  50. <el-table-column :label="t('file.fileType')" align="center" prop="fileType" >
  51. <template #default="scope">
  52. <dict-tag :type="DICT_TYPE.PMS_FILE_TYPE" :value="scope.row.fileType" />
  53. </template>
  54. </el-table-column>
  55. <el-table-column :label="t('file.fileSize')" align="center" prop="fileSize" />
  56. <el-table-column :label="t('file.preview')" align="center" prop="filePath">
  57. <template #default="scope">
  58. <el-button link type="primary" @click="openWeb(scope.row.filePath)">
  59. <Icon size="19" icon="ep:view" />
  60. </el-button>
  61. </template>
  62. </el-table-column>
  63. <el-table-column :label="t('file.operation')" align="center" width="160">
  64. <template #default="scope">
  65. <div class="flex items-center justify-center">
  66. <el-button type="primary" link @click="openForm('update', scope.row.id)">
  67. <Icon icon="ep:edit" />
  68. {{ t('iotDevice.update') }}
  69. </el-button>
  70. <el-dropdown
  71. @command="(command) => handleCommand(command, scope.row)"
  72. v-hasPermi="[
  73. 'system:user:delete',
  74. 'system:user:update-password',
  75. 'system:permission:assign-user-role'
  76. ]"
  77. >
  78. <el-button type="primary" link><Icon icon="ep:d-arrow-right" /> {{ t('action.more') }}</el-button>
  79. <template #dropdown>
  80. <el-dropdown-menu>
  81. <el-dropdown-item command="handleDelete">
  82. <Icon icon="ep:delete" />{{ t('iotDevice.delete') }}
  83. </el-dropdown-item>
  84. <!-- <el-dropdown-item command="fileView">-->
  85. <!-- <Icon icon="ep:view" />预览-->
  86. <!-- </el-dropdown-item>-->
  87. <el-dropdown-item command="fileDownload" v-hasPermi="['rq:iot-info:download']">
  88. <Icon icon="ep:view" />
  89. {{ t('file.dow') }}
  90. </el-dropdown-item>
  91. </el-dropdown-menu>
  92. </template>
  93. </el-dropdown>
  94. </div>
  95. </template>
  96. </el-table-column>
  97. </el-table>
  98. <Pagination
  99. :total="total"
  100. v-model:page="queryParams.pageNo"
  101. v-model:limit="queryParams.pageSize"
  102. @pagination="getList"
  103. />
  104. </ContentWrap> </div
  105. ></el-row>
  106. </div>
  107. <IotInfoForm
  108. ref="formRef"
  109. type="device"
  110. @success="getList"
  111. :deviceId="deviceId"
  112. :classId="queryParams.classId"
  113. />
  114. </template>
  115. <script lang="ts" setup>
  116. import { IotDeviceVO } from '@/api/pms/device'
  117. import FileTree from '@/views/pms/device/FileTree.vue'
  118. import { dateFormatter } from '@/utils/formatTime'
  119. import IotInfoForm from '@/views/pms/iotinfo/IotInfoForm.vue'
  120. import * as IotInfoApi from '@/api/pms/iotinfo'
  121. import { IotInfoVO } from '@/api/pms/iotinfo'
  122. import { onMounted, ref } from 'vue'
  123. import {DICT_TYPE} from "@/utils/dict";
  124. defineOptions({ name: 'DeviceUpload' })
  125. const queryFormRef = ref() // 搜索的表单
  126. const { t } = useI18n() // 国际化
  127. const message = useMessage() // 消息弹窗
  128. const loading = ref(true) // 列表的加载中
  129. const { params } = useRoute() // 查询参数
  130. const formLoading = ref(false) // 表单的加载中:1)修改时的数据加载;2)提交的按钮禁用
  131. const list = ref<IotDeviceVO[]>([]) // 列表的数据
  132. const total = ref(0) // 列表的总页数
  133. const id = params.id as unknown as number
  134. const container = ref(null)
  135. const leftWidth = ref(350) // 初始左侧宽度
  136. const rightWidth = ref(window.innerWidth * 0.69)
  137. let isDragging = false
  138. const openWeb = (url) => {
  139. window.open(
  140. 'http://1.94.244.160:8012/onlinePreview?url=' + encodeURIComponent(Base64.encode(url))
  141. )
  142. }
  143. const startDrag = (e) => {
  144. isDragging = true
  145. document.addEventListener('mousemove', onDrag)
  146. document.addEventListener('mouseup', stopDrag)
  147. }
  148. const onDrag = (e) => {
  149. if (!isDragging) return
  150. const containerRect = container.value.getBoundingClientRect()
  151. const newWidth = e.clientX - containerRect.left
  152. // 设置最小和最大宽度限制
  153. if (newWidth > 300 && newWidth < containerRect.width - 100) {
  154. leftWidth.value = newWidth
  155. }
  156. }
  157. const stopDrag = () => {
  158. isDragging = false
  159. document.removeEventListener('mousemove', onDrag)
  160. document.removeEventListener('mouseup', stopDrag)
  161. }
  162. const queryParams = reactive({
  163. pageNo: 1,
  164. pageSize: 10,
  165. filename: null,
  166. createTime: [],
  167. deviceId: null,
  168. classId: null
  169. })
  170. // SPU 表单数据
  171. // const formData = ref({
  172. // id: undefined,
  173. // deviceId: undefined,
  174. // deptId: undefined,
  175. // filename: undefined,
  176. // fileType: undefined,
  177. // filePath: undefined,
  178. // remark: undefined,
  179. // classId: undefined
  180. // })
  181. const handleCommand = (command: string, row: IotInfoVO) => {
  182. switch (command) {
  183. case 'handleDelete':
  184. handleDelete(row.id)
  185. break
  186. case 'handleUpdate':
  187. openForm('update', row.id)
  188. break
  189. case 'fileView':
  190. handleFileView(row.filePath)
  191. break
  192. case 'fileDownload':
  193. handleDownload(row.filePath)
  194. break
  195. default:
  196. break
  197. }
  198. }
  199. const handleDownload = async (url) => {
  200. try {
  201. const response = await fetch(url)
  202. const blob = await response.blob()
  203. const downloadUrl = window.URL.createObjectURL(blob)
  204. const link = document.createElement('a')
  205. link.href = downloadUrl
  206. link.download = url.split('/').pop() // 自动获取文件名‌:ml-citation{ref="3" data="citationList"}
  207. link.click()
  208. URL.revokeObjectURL(downloadUrl)
  209. } catch (error) {
  210. console.error('下载失败:', error)
  211. }
  212. }
  213. const handleFileView = (url: string) => {
  214. window.open(
  215. 'http://1.94.244.160:8012/onlinePreview?url=' + encodeURIComponent(Base64.encode(url))
  216. )
  217. }
  218. const handleDelete = async (id: number) => {
  219. try {
  220. // 删除的二次确认
  221. await message.delConfirm()
  222. // 发起删除
  223. await IotInfoApi.IotInfoApi.deleteIotInfo(id)
  224. message.success(t('common.delSuccess'))
  225. // 刷新列表
  226. await getList()
  227. } catch {}
  228. }
  229. const formRef = ref()
  230. const openForm = (type: string, id?: number) => {
  231. if (!queryParams.classId) {
  232. message.error('请选择左侧资料分类')
  233. return
  234. }
  235. formRef.value.open(type, id)
  236. }
  237. const deviceId = ref('')
  238. const handleFileNodeClick = async (row) => {
  239. queryParams.classId = row.id
  240. await getList()
  241. }
  242. /** 获得详情 */
  243. // const getDetail = async () => {
  244. // if (id) {
  245. // formLoading.value = true
  246. // try {
  247. // formData.value = (await IotDeviceApi.getIotDevice(id)) as IotDeviceVO
  248. // } finally {
  249. // formLoading.value = false
  250. // }
  251. // }
  252. // }
  253. /** 查询列表 */
  254. const getList = async () => {
  255. formLoading.value = true
  256. try {
  257. // queryParams.deviceId = deviceId.value
  258. const data = await IotInfoApi.IotInfoApi.getIotInfoPage(queryParams)
  259. list.value = data.list
  260. total.value = data.total
  261. } finally {
  262. formLoading.value = false
  263. }
  264. }
  265. const successList = async (id) => {
  266. queryParams.classId = id
  267. await getList()
  268. // queryParams.classId = ''
  269. }
  270. /** 搜索按钮操作 */
  271. const handleQuery = () => {
  272. queryParams.pageNo = 1
  273. getList()
  274. }
  275. /** 重置按钮操作 */
  276. const resetQuery = () => {
  277. queryFormRef.value?.resetFields()
  278. handleQuery()
  279. }
  280. /** 初始化 */
  281. onMounted(async () => {
  282. // await getDetail()
  283. //await getList()
  284. deviceId.value = params.id as unknown as number
  285. })
  286. </script>
  287. <style scoped>
  288. .container-tree {
  289. display: flex;
  290. height: 100%;
  291. user-select: none; /* 防止拖动时选中文本 */
  292. }
  293. .left-tree {
  294. background: #f0f0f0;
  295. height: 100%;
  296. overflow: auto;
  297. }
  298. .right-tree {
  299. flex: 1;
  300. height: 100%;
  301. overflow: auto;
  302. margin-left: 15px;
  303. }
  304. .divider-tree {
  305. width: 2px;
  306. background: #ccc;
  307. cursor: col-resize;
  308. position: relative;
  309. }
  310. .divider-tree:hover {
  311. background: #666;
  312. }
  313. </style>