image-view.vue 17 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514
  1. <template>
  2. <div class="hc-layout-box">
  3. <div :style="`width:${leftWidth}px;`" class="hc-layout-left-box bg-white">
  4. <template v-if="dataType === 1">
  5. <div class="hc-project-box">
  6. <div class="hc-project-icon-box">
  7. <HcIcon name="stack" />
  8. </div>
  9. <div class="ml-2 project-name-box">
  10. <span class="project-alias">{{ projectInfo.projectName }}</span>
  11. </div>
  12. </div>
  13. <div v-if="dataType === 1" class="hc-tree-box">
  14. <el-scrollbar>
  15. <WbsTree
  16. :auto-expand-keys="TreeAutoExpandKeys" :contract-id="contractId" :project-id="projectId"
  17. :class-id="dataId" @node-tap="nodeWbsElTreeClick"
  18. />
  19. </el-scrollbar>
  20. </div>
  21. </template>
  22. <div v-else class="hc-tree-box date-tree">
  23. <el-scrollbar v-if="dataType === 2">
  24. <HcTreeData
  25. :auto-expand-keys="TreeExpandedKeys" :datas="dateElTreeData"
  26. @node-tap="dateWbsElTreeClick"
  27. />
  28. </el-scrollbar>
  29. </div>
  30. <!-- 左右拖动 -->
  31. <div class="horizontal-drag-line" @mousedown="onmousedown" />
  32. </div>
  33. <div class="hc-layout-content-box">
  34. <HcNewCard :scrollbar="false" action-size="lg">
  35. <template #header>
  36. <HcTooltip keys="image-data-add">
  37. <el-button :disabled="!queryKey && dataType === 1" hc-btn type="primary" @click="addFormFile">
  38. <HcIcon name="add_box" />
  39. <span>新增文件</span>
  40. </el-button>
  41. </HcTooltip>
  42. <HcTooltip keys="image-data-download">
  43. <el-button
  44. :disabled="tableCheckedKeys.length <= 0" :loading="downloadLoading" hc-btn
  45. @click="downloadClick"
  46. >
  47. <HcIcon name="download" />
  48. <span>下载</span>
  49. </el-button>
  50. </HcTooltip>
  51. <HcTooltip keys="image-data-del">
  52. <el-button
  53. :disabled="tableCheckedKeys.length <= 0" :loading="delLoading" hc-btn
  54. @click="delClick"
  55. >
  56. <HcIcon name="delete" />
  57. <span>删除</span>
  58. </el-button>
  59. </HcTooltip>
  60. </template>
  61. <template #extra>
  62. <div class="w-60">
  63. <el-input v-model="searchForm.queryStr" clearable placeholder="根据题名名称或拍摄者搜索" @keyup="keyUpEvent" />
  64. </div>
  65. <div class="ml-2">
  66. <el-button type="primary" @click="searchClick">搜索</el-button>
  67. </div>
  68. </template>
  69. <HcTable
  70. ref="tableListRef" :column="tableListColumn" :datas="tableListData" :loading="tableLoading"
  71. is-new :index-style="{ width: 60 }" is-check :check-style="{ width: 29 }"
  72. @selection-change="tableSelectionChange"
  73. >
  74. <template #info="{ row }">
  75. <div class="hc-table-col-item">
  76. <div v-if="row.type !== 1" class="img-box">
  77. <HcImg :src="setImageUrl(row.imageUrl)" class="hc-image" />
  78. </div>
  79. <div v-else class="img-box">
  80. <video :src="row.imageUrl">
  81. 您的浏览器不支持 video
  82. </video>
  83. </div>
  84. <div class="content-box">
  85. <div class="text-cut title">{{ row.title }}</div>
  86. <div class="shootingUser">拍摄者:{{ row.shootingUser }}</div>
  87. <div class="shootingTimeStr">拍摄时间:{{ row.shootingTimeStr }}</div>
  88. <div class="fileSize">文件大小:{{ row.fileSize }}</div>
  89. </div>
  90. </div>
  91. </template>
  92. <template #operate="{ row }">
  93. <HcTooltip keys="image-data-preview">
  94. <el-button
  95. :loading="previewLoading" size="small" text type="primary"
  96. @click="previewClick(row)"
  97. >
  98. 查看
  99. </el-button>
  100. </HcTooltip>
  101. <HcTooltip keys="image-data-edit">
  102. <el-button size="small" text type="primary" @click="editClick(row)">编辑</el-button>
  103. </HcTooltip>
  104. </template>
  105. </HcTable>
  106. <template #action>
  107. <div class="lr-dialog-footer">
  108. <div class="left">
  109. <el-button size="large" @click="goToBack">
  110. <HcIcon name="arrow-go-back" />
  111. <span>返回</span>
  112. </el-button>
  113. </div>
  114. <div class="right">
  115. <HcPages :pages="searchForm" @change="pageChange" />
  116. </div>
  117. </div>
  118. </template>
  119. </HcNewCard>
  120. </div>
  121. <!-- 视频预览 弹框 -->
  122. <hc-new-dialog v-model="previewVideoModal" title="预览" widths="47rem">
  123. <video
  124. v-if="previewVideoUrl" :src="previewVideoUrl" autoplay="autoplay" class="preview-video"
  125. controls="controls"
  126. >
  127. 您的浏览器不支持 video
  128. </video>
  129. </hc-new-dialog>
  130. </div>
  131. </template>
  132. <script setup>
  133. import { onActivated, onMounted, ref, watch } from 'vue'
  134. import { useAppStore } from '~src/store'
  135. import { useRoute, useRouter } from 'vue-router'
  136. import WbsTree from './components/WbsTree.vue'
  137. import HcTreeData from './components/HcTreeData.vue'
  138. import imageApi from '~api/other-file/imageData'
  139. import { getStoreValue, setStoreValue } from '~src/utils/storage'
  140. import { arrToId, downloadBlob, getArrValue, isString } from 'js-fast-way'
  141. import { HcDelMsg } from 'hc-vue3-ui'
  142. import { toPdfPage } from '~uti/btn-auth'
  143. //变量
  144. const router = useRouter()
  145. const useRoutes = useRoute()
  146. const useAppState = useAppStore()
  147. const projectId = ref(useAppState.getProjectId)
  148. const contractId = ref(useAppState.getContractId)
  149. const projectInfo = ref(useAppState.getProjectInfo)
  150. const isCollapse = ref(useAppState.getCollapse)
  151. //路由参数
  152. const routerQuery = useRoutes?.query
  153. //存储目录格式 1按部位存储,2按日期存储
  154. const dataId = ref(routerQuery?.id || '')
  155. const dataType = ref(parseInt(routerQuery?.type + '') )
  156. const fileType = ref(parseInt(routerQuery?.fileType + '') || 2)
  157. //监听
  158. watch(() => [
  159. useAppState.getCollapse,
  160. useAppState.getContractId,
  161. ], ([Collapse, ContractId]) => {
  162. isCollapse.value = Collapse
  163. contractId.value = ContractId
  164. })
  165. //监听路由参数改变
  166. watch(() => [
  167. useRoutes?.query,
  168. ], ([query]) => {
  169. console.log(query, 'query')
  170. dataId.value = query?.id || ''
  171. dataType.value = parseInt(query?.type + '')
  172. fileType.value = parseInt(query?.fileType + '') || 2
  173. searchForm.value.classifyId = query?.id || ''
  174. initMounted()
  175. }, { deep: true })
  176. watch(contractId, (val) => {
  177. if (val) {
  178. console.log(val)
  179. router.push({
  180. path: '/other-file/image-data',
  181. })
  182. }
  183. })
  184. //自动展开缓存
  185. const TreeAutoExpandKeys = ref([])
  186. const TreeExpandedKeys = ref([])
  187. const TreeCurrentNodeKey = ref(getStoreValue('TreeCurrentNodeKey') || '')
  188. //渲染完成
  189. // onMounted(() => {
  190. // initMounted()
  191. // })
  192. onActivated(()=>{
  193. initMounted()
  194. })
  195. const initMounted = () => {
  196. console.log('onMounted')
  197. const nodeKey = TreeCurrentNodeKey.value
  198. if (dataType.value === 1) {
  199. TreeAutoExpandKeys.value = getStoreValue('TreeExpandKeys') || []
  200. } else {
  201. TreeExpandedKeys.value = getStoreValue('TreeExpandedKeys') || []
  202. }
  203. if (dataType.value === 2 && dataId.value) {
  204. getYearDateTree()
  205. queryKey.value = nodeKey
  206. //console.log(queryKey.value, ' queryKey.value');
  207. if (isNaN(queryKey.value) && !isNaN(Date.parse(queryKey.value))) {
  208. queryKey.value = ''
  209. }
  210. searchForm.value.queryDate = nodeKey
  211. searchForm.value.current = 1
  212. getTableData()
  213. } else {
  214. queryKey.value = ''
  215. getTableData()
  216. }
  217. }
  218. //获取时间结构
  219. const dateElTreeData = ref([])
  220. const getYearDateTree = async () => {
  221. const { error, code, data } = await imageApi.getYearDateTree({
  222. projectId: projectId.value,
  223. contractId: contractId.value,
  224. classifyId: dataId.value,
  225. })
  226. //处理数据
  227. if (!error && code === 200) {
  228. dateElTreeData.value = getArrValue(data)
  229. } else {
  230. dateElTreeData.value = []
  231. }
  232. }
  233. //日期树被点击
  234. const nodeDataInfo = ref({})
  235. const dateWbsElTreeClick = ({ data, keys, key }) => {
  236. // queryKey.value = key
  237. queryKey.value = ''
  238. nodeDataInfo.value = data
  239. //缓存自动展开
  240. TreeExpandedKeys.value = keys
  241. TreeCurrentNodeKey.value = key
  242. setStoreValue('TreeExpandedKeys', keys)
  243. setStoreValue('TreeCurrentNodeKey', key)
  244. //改变搜索表单数据
  245. searchForm.value.queryDate = data['hierarchy'] || ''
  246. searchForm.value.wbsIdsStr = null
  247. searchForm.value.current = 1
  248. getTableData()
  249. }
  250. //项目树被点击
  251. const nodeWbsElTreeClick = ({ data, keys }) => {
  252. searchForm.value.wbsIdsStr = data?.primaryKeyId || ''
  253. if (data?.notExsitChild === true) {
  254. nodeDataInfo.value = data
  255. queryKey.value = data['primaryKeyId'] || ''
  256. //缓存自动展开
  257. TreeAutoExpandKeys.value = keys
  258. setStoreValue('TreeExpandKeys', keys)
  259. //改变搜索表单数据
  260. searchForm.value.queryDate = null
  261. // searchForm.value.wbsIdsStr = data?.primaryKeyId || ''
  262. searchForm.value.current = 1
  263. getTableData()
  264. } else {
  265. getTableData()
  266. queryKey.value = ''
  267. nodeDataInfo.value = {}
  268. searchForm.value.queryDate = null
  269. searchForm.value.wbsIdsStr = null
  270. tableListData.value = []
  271. searchForm.value.total = 0
  272. }
  273. }
  274. //搜索和分页数据
  275. const queryKey = ref(null)
  276. const searchForm = ref({
  277. queryStr: null, classifyId: dataId.value, wbsIdsStr: null,
  278. current: 1, size: 20, total: 0,
  279. })
  280. //回车搜索
  281. const keyUpEvent = (e) => {
  282. if (e.key === 'Enter') {
  283. searchClick()
  284. }
  285. }
  286. //搜索
  287. const searchClick = () => {
  288. if (queryKey.value) {
  289. searchForm.value.current = 1
  290. getTableData()
  291. } else {
  292. window?.$message?.warning('请先在左边选择一个树节点')
  293. }
  294. }
  295. //分页被点击
  296. const pageChange = ({ current, size }) => {
  297. searchForm.value.current = current
  298. searchForm.value.size = size
  299. getTableData()
  300. }
  301. //获取数据
  302. const tableListRef = ref(null)
  303. const tableLoading = ref(false)
  304. const tableListData = ref([])
  305. const tableListColumn = ref([
  306. { key: 'info', name: '文件详情' },
  307. { key: 'textContent', name: '文字说明' },
  308. { key: 'operate', name: '操作', align: 'center', width: '140' },
  309. ])
  310. const getTableData = async () => {
  311. tableLoading.value = true
  312. const { error, code, data } = await imageApi.getPageList({
  313. ...searchForm.value,
  314. projectId: projectId.value,
  315. contractId: contractId.value,
  316. })
  317. //判断状态
  318. tableLoading.value = false
  319. if (!error && code === 200) {
  320. tableListData.value = getArrValue(data['records'])
  321. searchForm.value.total = data['total'] || 0
  322. } else {
  323. tableListData.value = []
  324. searchForm.value.total = 0
  325. }
  326. }
  327. //多选
  328. const tableCheckedKeys = ref([])
  329. const tableSelectionChange = (rows) => {
  330. tableCheckedKeys.value = rows.filter((item) => {
  331. return (item ?? '') !== ''
  332. })
  333. }
  334. //处理图片预览问题
  335. const setImageUrl = (url) => {
  336. if (url) {
  337. const urlArr = url.split(',')
  338. if (urlArr.length > 0 && urlArr[0]) {
  339. return urlArr[0]
  340. } else {
  341. return ''
  342. }
  343. } else {
  344. return ''
  345. }
  346. }
  347. //预览
  348. const previewVideoUrl = ref('')
  349. const previewVideoModal = ref(false)
  350. const previewLoading = ref(false)
  351. const previewClick = async (item) => {
  352. const { id, type, imageUrl, margePdfUrl } = item
  353. console.log(parseInt(type), 'parseInt(type)')
  354. if (parseInt(type) === 1 ) {
  355. if (imageUrl) {
  356. previewVideoUrl.value = imageUrl
  357. previewVideoModal.value = true
  358. } else {
  359. window.$message?.warning('暂无可预览的资料文件')
  360. }
  361. } else if (parseInt(type) === 2 || type === null || type === -1) {
  362. if (margePdfUrl) {
  363. toPdfPage(margePdfUrl)
  364. //window.open(margePdfUrl, '_blank')
  365. } else {
  366. window.$message?.warning('暂无可预览的资料文件')
  367. }
  368. // else {
  369. // previewLoading.value = true
  370. // const { error, code, data } = await imageApi.imageClassificationFile({
  371. // ids: id,
  372. // }, false)
  373. // //判断状态
  374. // previewLoading.value = false
  375. // if (!error && code === 200 && isString(data)) {
  376. // item.margePdfUrl = data
  377. // toPdfPage(data)
  378. // //window.open(data, '_blank')
  379. // } else {
  380. // window.$message?.warning('预览资料文件异常')
  381. // }
  382. // }
  383. }
  384. }
  385. //新增文件
  386. const addFormFile = () => {
  387. router.push({
  388. path: '/other-file/image-form',
  389. query: {
  390. wbsId: queryKey.value, //树节点ID
  391. dataType: dataType.value, //存储目录格式 1按部位存储,2按日期存储
  392. fileType: fileType.value, //文件类型,1视频文件,2图片文件
  393. classifyId: dataId.value, //classifyId,分类ID,
  394. },
  395. })
  396. }
  397. //编辑修改
  398. const editClick = ({ id }) => {
  399. router.push({
  400. path: '/other-file/image-form',
  401. query: {
  402. wbsId: queryKey.value, //树节点ID
  403. dataType: dataType.value, //存储目录格式 1按部位存储,2按日期存储
  404. fileType: fileType.value, //文件类型,1视频文件,2图片文件
  405. classifyId: dataId.value, //classifyId,分类ID,
  406. id: id, //数据ID
  407. },
  408. })
  409. }
  410. //下载文件
  411. const downloadLoading = ref(false)
  412. const downloadClick = async () => {
  413. const rows = tableCheckedKeys.value
  414. if (rows.length > 0) {
  415. downloadLoading.value = true
  416. const ids = arrToId(rows)
  417. const { error, disposition, res } = await imageApi.batchDownloadFileToZip({ ids: ids }, false)
  418. //判断状态
  419. if (!error) {
  420. if (disposition) {
  421. downloadBlob(res, disposition)
  422. } else {
  423. window.$message?.error('下载异常')
  424. }
  425. }
  426. } else {
  427. window.$message?.warning('请先勾选需要下载的资料文件')
  428. }
  429. }
  430. //删除文件
  431. const delLoading = ref(false)
  432. const delClick = () => {
  433. const rows = tableCheckedKeys.value
  434. if (rows.length > 0) {
  435. const ids = arrToId(rows)
  436. HcDelMsg({}, async (instance, resolve) => {
  437. instance.confirmButtonLoading = true
  438. instance.confirmButtonText = '删除中...'
  439. await removeImageclassifyFile(ids)
  440. resolve() //关闭弹窗的回调
  441. instance.confirmButtonLoading = false
  442. })
  443. } else {
  444. window.$message?.warning('请先勾选需要删除的资料文件')
  445. }
  446. }
  447. const removeImageclassifyFile = async (ids) => {
  448. delLoading.value = true
  449. const { error, code } = await imageApi.removeImageclassifyFile({ ids: ids }, false)
  450. //判断状态
  451. delLoading.value = false
  452. if (!error && code === 200) {
  453. window.$message?.success('删除成功')
  454. getTableData()
  455. } else {
  456. window.$message?.error('删除异常')
  457. }
  458. }
  459. //回到影像资料页
  460. const goToBack = () => {
  461. router.push({ path: '/other-file/image-data' })
  462. }
  463. //左右拖动,改变树形结构宽度
  464. const leftWidth = ref(dataType.value === 1 ? 382 : 220)
  465. const onmousedown = () => {
  466. const leftNum = isCollapse.value ? 142 : 272
  467. document.onmousemove = (ve) => {
  468. const diffVal = ve.clientX - leftNum
  469. const minWidth = dataType.value === 1 ? 310 : 200
  470. const maxWidth = dataType.value === 1 ? 900 : 300
  471. if (diffVal >= minWidth && diffVal <= maxWidth) {
  472. leftWidth.value = diffVal
  473. }
  474. }
  475. document.onmouseup = () => {
  476. document.onmousemove = null
  477. document.onmouseup = null
  478. }
  479. }
  480. </script>
  481. <style lang="scss" scoped>
  482. @import '../../styles/other-file/image-view.scss';
  483. </style>
  484. <style lang="scss">
  485. .preview-video {
  486. width: 100%;
  487. }
  488. </style>