image-view.vue 15 KB

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