image-view.vue 16 KB

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