image-view.vue 17 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520
  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="project-name-box ml-2">
  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" :is-https="isHttps" />
  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 } from 'js-fast-way'
  141. import { HcDelMsg } from 'hc-vue3-ui'
  142. import { toPdfPage } from '~uti/btn-auth'
  143. import website from '~src/config'
  144. //变量
  145. const router = useRouter()
  146. const useRoutes = useRoute()
  147. const useAppState = useAppStore()
  148. const projectId = ref(useAppState.getProjectId)
  149. const contractId = ref(useAppState.getContractId)
  150. const projectInfo = ref(useAppState.getProjectInfo)
  151. const isCollapse = ref(useAppState.getCollapse)
  152. //路由参数
  153. const routerQuery = useRoutes?.query
  154. //存储目录格式 1按部位存储,2按日期存储
  155. const dataId = ref(routerQuery?.id || '')
  156. const dataType = ref(parseInt(routerQuery?.type + '') )
  157. const fileType = ref(parseInt(routerQuery?.fileType + '') || 2)
  158. //监听
  159. watch(() => [
  160. useAppState.getCollapse,
  161. useAppState.getContractId,
  162. ], ([Collapse, ContractId]) => {
  163. isCollapse.value = Collapse
  164. contractId.value = ContractId
  165. })
  166. //监听路由参数改变
  167. watch(() => [
  168. useRoutes?.query,
  169. ], ([query]) => {
  170. console.log(query, 'query')
  171. dataId.value = query?.id || ''
  172. dataType.value = parseInt(query?.type + '')
  173. fileType.value = parseInt(query?.fileType + '') || 2
  174. searchForm.value.classifyId = query?.id || ''
  175. initMounted()
  176. }, { deep: true })
  177. watch(contractId, (val) => {
  178. if (val) {
  179. console.log(val)
  180. router.push({
  181. path: '/other-file/image-data',
  182. })
  183. }
  184. })
  185. //自动展开缓存
  186. const TreeAutoExpandKeys = ref([])
  187. const TreeExpandedKeys = ref([])
  188. const TreeCurrentNodeKey = ref(getStoreValue('TreeCurrentNodeKey') || '')
  189. //渲染完成
  190. // onMounted(() => {
  191. // initMounted()
  192. // })
  193. const isHttps = ref(false)
  194. onMounted(() => {
  195. isHttps.value = !website.localModel
  196. })
  197. onActivated(()=>{
  198. initMounted()
  199. })
  200. const initMounted = () => {
  201. console.log('onMounted')
  202. const nodeKey = TreeCurrentNodeKey.value
  203. if (dataType.value === 1) {
  204. TreeAutoExpandKeys.value = getStoreValue('TreeExpandKeys') || []
  205. } else {
  206. TreeExpandedKeys.value = getStoreValue('TreeExpandedKeys') || []
  207. }
  208. if (dataType.value === 2 && dataId.value) {
  209. getYearDateTree()
  210. queryKey.value = nodeKey
  211. //console.log(queryKey.value, ' queryKey.value');
  212. if (isNaN(queryKey.value) && !isNaN(Date.parse(queryKey.value))) {
  213. queryKey.value = ''
  214. }
  215. searchForm.value.queryDate = nodeKey
  216. searchForm.value.current = 1
  217. getTableData()
  218. } else {
  219. queryKey.value = ''
  220. getTableData()
  221. }
  222. }
  223. //获取时间结构
  224. const dateElTreeData = ref([])
  225. const getYearDateTree = async () => {
  226. const { error, code, data } = await imageApi.getYearDateTree({
  227. projectId: projectId.value,
  228. contractId: contractId.value,
  229. classifyId: dataId.value,
  230. })
  231. //处理数据
  232. if (!error && code === 200) {
  233. dateElTreeData.value = getArrValue(data)
  234. } else {
  235. dateElTreeData.value = []
  236. }
  237. }
  238. //日期树被点击
  239. const nodeDataInfo = ref({})
  240. const dateWbsElTreeClick = ({ data, keys, key }) => {
  241. // queryKey.value = key
  242. queryKey.value = ''
  243. nodeDataInfo.value = data
  244. //缓存自动展开
  245. TreeExpandedKeys.value = keys
  246. TreeCurrentNodeKey.value = key
  247. setStoreValue('TreeExpandedKeys', keys)
  248. setStoreValue('TreeCurrentNodeKey', key)
  249. //改变搜索表单数据
  250. searchForm.value.queryDate = data['hierarchy'] || ''
  251. searchForm.value.wbsIdsStr = null
  252. searchForm.value.current = 1
  253. getTableData()
  254. }
  255. //项目树被点击
  256. const nodeWbsElTreeClick = ({ data, keys }) => {
  257. searchForm.value.wbsIdsStr = data?.primaryKeyId || ''
  258. if (data?.notExsitChild === true) {
  259. nodeDataInfo.value = data
  260. queryKey.value = data['primaryKeyId'] || ''
  261. //缓存自动展开
  262. TreeAutoExpandKeys.value = keys
  263. setStoreValue('TreeExpandKeys', keys)
  264. //改变搜索表单数据
  265. searchForm.value.queryDate = null
  266. // searchForm.value.wbsIdsStr = data?.primaryKeyId || ''
  267. searchForm.value.current = 1
  268. getTableData()
  269. } else {
  270. getTableData()
  271. queryKey.value = ''
  272. nodeDataInfo.value = {}
  273. searchForm.value.queryDate = null
  274. searchForm.value.wbsIdsStr = null
  275. tableListData.value = []
  276. searchForm.value.total = 0
  277. }
  278. }
  279. //搜索和分页数据
  280. const queryKey = ref(null)
  281. const searchForm = ref({
  282. queryStr: null, classifyId: dataId.value, wbsIdsStr: null,
  283. current: 1, size: 20, total: 0,
  284. })
  285. //回车搜索
  286. const keyUpEvent = (e) => {
  287. if (e.key === 'Enter') {
  288. searchClick()
  289. }
  290. }
  291. //搜索
  292. const searchClick = () => {
  293. if (queryKey.value) {
  294. searchForm.value.current = 1
  295. getTableData()
  296. } else {
  297. window?.$message?.warning('请先在左边选择一个树节点')
  298. }
  299. }
  300. //分页被点击
  301. const pageChange = ({ current, size }) => {
  302. searchForm.value.current = current
  303. searchForm.value.size = size
  304. getTableData()
  305. }
  306. //获取数据
  307. const tableListRef = ref(null)
  308. const tableLoading = ref(false)
  309. const tableListData = ref([])
  310. const tableListColumn = ref([
  311. { key: 'info', name: '文件详情' },
  312. { key: 'textContent', name: '文字说明' },
  313. { key: 'operate', name: '操作', align: 'center', width: '140' },
  314. ])
  315. const getTableData = async () => {
  316. tableLoading.value = true
  317. const { error, code, data } = await imageApi.getPageList({
  318. ...searchForm.value,
  319. projectId: projectId.value,
  320. contractId: contractId.value,
  321. })
  322. //判断状态
  323. tableLoading.value = false
  324. if (!error && code === 200) {
  325. tableListData.value = getArrValue(data['records'])
  326. searchForm.value.total = data['total'] || 0
  327. } else {
  328. tableListData.value = []
  329. searchForm.value.total = 0
  330. }
  331. }
  332. //多选
  333. const tableCheckedKeys = ref([])
  334. const tableSelectionChange = (rows) => {
  335. tableCheckedKeys.value = rows.filter((item) => {
  336. return (item ?? '') !== ''
  337. })
  338. }
  339. //处理图片预览问题
  340. const setImageUrl = (url) => {
  341. if (url) {
  342. const urlArr = url.split(',')
  343. if (urlArr.length > 0 && urlArr[0]) {
  344. return urlArr[0]
  345. } else {
  346. return ''
  347. }
  348. } else {
  349. return ''
  350. }
  351. }
  352. //预览
  353. const previewVideoUrl = ref('')
  354. const previewVideoModal = ref(false)
  355. const previewLoading = ref(false)
  356. const previewClick = async (item) => {
  357. const { id, type, imageUrl, margePdfUrl } = item
  358. console.log(parseInt(type), 'parseInt(type)')
  359. if (parseInt(type) === 1 ) {
  360. if (imageUrl) {
  361. previewVideoUrl.value = imageUrl
  362. previewVideoModal.value = true
  363. } else {
  364. window.$message?.warning('暂无可预览的资料文件')
  365. }
  366. } else if (parseInt(type) === 2 || type === null || type === -1) {
  367. if (margePdfUrl) {
  368. toPdfPage(margePdfUrl)
  369. //window.open(margePdfUrl, '_blank')
  370. } else {
  371. window.$message?.warning('暂无可预览的资料文件')
  372. }
  373. // else {
  374. // previewLoading.value = true
  375. // const { error, code, data } = await imageApi.imageClassificationFile({
  376. // ids: id,
  377. // }, false)
  378. // //判断状态
  379. // previewLoading.value = false
  380. // if (!error && code === 200 && isString(data)) {
  381. // item.margePdfUrl = data
  382. // toPdfPage(data)
  383. // //window.open(data, '_blank')
  384. // } else {
  385. // window.$message?.warning('预览资料文件异常')
  386. // }
  387. // }
  388. }
  389. }
  390. //新增文件
  391. const addFormFile = () => {
  392. router.push({
  393. path: '/other-file/image-form',
  394. query: {
  395. wbsId: queryKey.value, //树节点ID
  396. dataType: dataType.value, //存储目录格式 1按部位存储,2按日期存储
  397. fileType: fileType.value, //文件类型,1视频文件,2图片文件
  398. classifyId: dataId.value, //classifyId,分类ID,
  399. },
  400. })
  401. }
  402. //编辑修改
  403. const editClick = ({ id }) => {
  404. router.push({
  405. path: '/other-file/image-form',
  406. query: {
  407. wbsId: queryKey.value, //树节点ID
  408. dataType: dataType.value, //存储目录格式 1按部位存储,2按日期存储
  409. fileType: fileType.value, //文件类型,1视频文件,2图片文件
  410. classifyId: dataId.value, //classifyId,分类ID,
  411. id: id, //数据ID
  412. },
  413. })
  414. }
  415. //下载文件
  416. const downloadLoading = ref(false)
  417. const downloadClick = async () => {
  418. const rows = tableCheckedKeys.value
  419. if (rows.length > 0) {
  420. downloadLoading.value = true
  421. const ids = arrToId(rows)
  422. const { error, disposition, res } = await imageApi.batchDownloadFileToZip({ ids: ids }, false)
  423. //判断状态
  424. if (!error) {
  425. if (disposition) {
  426. downloadBlob(res, disposition)
  427. } else {
  428. window.$message?.error('下载异常')
  429. }
  430. }
  431. } else {
  432. window.$message?.warning('请先勾选需要下载的资料文件')
  433. }
  434. }
  435. //删除文件
  436. const delLoading = ref(false)
  437. const delClick = () => {
  438. const rows = tableCheckedKeys.value
  439. if (rows.length > 0) {
  440. const ids = arrToId(rows)
  441. HcDelMsg( async ( resolve) => {
  442. await removeImageclassifyFile(ids)
  443. resolve() //关闭弹窗的回调
  444. })
  445. } else {
  446. window.$message?.warning('请先勾选需要删除的资料文件')
  447. }
  448. }
  449. const removeImageclassifyFile = async (ids) => {
  450. delLoading.value = true
  451. const { error, code } = await imageApi.removeImageclassifyFile({ ids: ids }, false)
  452. //判断状态
  453. delLoading.value = false
  454. if (!error && code === 200) {
  455. window.$message?.success('删除成功')
  456. getTableData()
  457. } else {
  458. window.$message?.error('删除异常')
  459. }
  460. }
  461. //回到影像资料页
  462. const goToBack = () => {
  463. router.push({ path: '/other-file/image-data' })
  464. }
  465. //左右拖动,改变树形结构宽度
  466. const leftWidth = ref(dataType.value === 1 ? 382 : 220)
  467. const onmousedown = () => {
  468. const leftNum = isCollapse.value ? 142 : 272
  469. document.onmousemove = (ve) => {
  470. const diffVal = ve.clientX - leftNum
  471. const minWidth = dataType.value === 1 ? 310 : 200
  472. const maxWidth = dataType.value === 1 ? 900 : 300
  473. if (diffVal >= minWidth && diffVal <= maxWidth) {
  474. leftWidth.value = diffVal
  475. }
  476. }
  477. document.onmouseup = () => {
  478. document.onmousemove = null
  479. document.onmouseup = null
  480. }
  481. }
  482. </script>
  483. <style lang="scss" scoped>
  484. @import '../../styles/other-file/image-view.scss';
  485. </style>
  486. <style lang="scss">
  487. .preview-video {
  488. width: 100%;
  489. }
  490. </style>