image-view.vue 17 KB

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