DeviceUpload.vue 10.0 KB

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