index.vue 11 KB

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