image-view.vue 16 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471
  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. queryKey.value = ''
  221. nodeDataInfo.value = {}
  222. searchForm.value.queryDate = null
  223. searchForm.value.wbsIdsStr = null
  224. tableListData.value = []
  225. searchForm.value.total = 0
  226. }
  227. }
  228. //搜索和分页数据
  229. const queryKey = ref(null)
  230. const searchForm = ref({
  231. queryStr: null, classifyId: dataId, wbsIdsStr: null,
  232. current: 1, size: 20, total: 0
  233. })
  234. //回车搜索
  235. const keyUpEvent = (e) => {
  236. if (e.key === "Enter") {
  237. searchClick()
  238. }
  239. }
  240. //搜索
  241. const searchClick = () => {
  242. if (queryKey.value) {
  243. searchForm.value.current = 1;
  244. getTableData()
  245. } else {
  246. window?.$message?.warning('请先在左边选择一个树节点')
  247. }
  248. }
  249. //分页被点击
  250. const pageChange = ({current, size}) => {
  251. searchForm.value.current = current
  252. searchForm.value.size = size
  253. getTableData()
  254. }
  255. //获取数据
  256. const tableListRef = ref(null)
  257. const tableLoading = ref(false)
  258. const tableListData = ref([])
  259. const tableListColumn = ref([
  260. {key:'info', name: '文件详情'},
  261. {key:'textContent', name: '文字说明'},
  262. {key:'operate', name: '操作', align: 'center', width: '140'},
  263. ])
  264. const getTableData = async () => {
  265. tableLoading.value = true
  266. const {error, code, data} = await imageApi.getPageList({
  267. ...searchForm.value,
  268. projectId: projectId.value,
  269. contractId: contractId.value
  270. })
  271. //判断状态
  272. tableLoading.value = false
  273. if (!error && code === 200) {
  274. tableListData.value = getArrValue(data['records'])
  275. searchForm.value.total = data['total'] || 0
  276. } else {
  277. tableListData.value = []
  278. searchForm.value.total = 0
  279. }
  280. }
  281. //多选
  282. const tableCheckedKeys = ref([]);
  283. const tableSelectionChange = (rows) => {
  284. tableCheckedKeys.value = rows.filter((item) => {
  285. return (item??'') !== '';
  286. })
  287. }
  288. //处理图片预览问题
  289. const setImageUrl = (url) => {
  290. if (url) {
  291. const urlArr = url.split(',')
  292. if (urlArr.length > 0 && urlArr[0]) {
  293. return urlArr[0]
  294. } else {
  295. return ''
  296. }
  297. } else {
  298. return ''
  299. }
  300. }
  301. //预览
  302. const previewVideoUrl = ref('')
  303. const previewVideoModal = ref(false)
  304. const previewLoading = ref(false)
  305. const previewClick = async (item) => {
  306. const {id,type,imageUrl,margePdfUrl} = item
  307. if (parseInt(type) === 1) {
  308. if (imageUrl) {
  309. previewVideoUrl.value = imageUrl
  310. previewVideoModal.value = true
  311. } else {
  312. window.$message?.warning('暂无可预览的资料文件');
  313. }
  314. } else if (parseInt(type) === 2) {
  315. if(margePdfUrl) {
  316. window.open(margePdfUrl, "_blank");
  317. } else {
  318. previewLoading.value = true
  319. const {error, code, data} = await imageApi.imageClassificationFile({
  320. ids: id
  321. }, false)
  322. //判断状态
  323. previewLoading.value = false
  324. if (!error && code === 200 && isString(data)) {
  325. item.margePdfUrl = data
  326. window.open(data,"_blank");
  327. } else {
  328. window.$message?.warning('预览资料文件异常');
  329. }
  330. }
  331. }
  332. }
  333. //新增文件
  334. const addFormFile = () => {
  335. router.push({
  336. path: '/other-file/image-form',
  337. query: {
  338. wbsId: queryKey.value, //树节点ID
  339. dataType: dataType, //存储目录格式 1按部位存储,2按日期存储
  340. fileType: fileType, //文件类型,1视频文件,2图片文件
  341. classifyId: dataId, //classifyId,分类ID,
  342. }
  343. })
  344. }
  345. //编辑修改
  346. const editClick = ({id}) => {
  347. router.push({
  348. path: '/other-file/image-form',
  349. query: {
  350. wbsId: queryKey.value, //树节点ID
  351. dataType: dataType, //存储目录格式 1按部位存储,2按日期存储
  352. fileType: fileType, //文件类型,1视频文件,2图片文件
  353. classifyId: dataId, //classifyId,分类ID,
  354. id: id //数据ID
  355. }
  356. })
  357. }
  358. //拼接ID
  359. const rowsToId = (rows) => {
  360. return rows.map((obj) => {
  361. return obj.id;
  362. }).join(",")
  363. }
  364. //下载文件
  365. const downloadLoading = ref(false)
  366. const downloadClick = async () => {
  367. const rows = tableCheckedKeys.value
  368. if (rows.length > 0) {
  369. downloadLoading.value = true
  370. const ids = rowsToId(rows)
  371. const { error, disposition, res } = await imageApi.batchDownloadFileToZip({ids: ids}, false)
  372. //判断状态
  373. if (!error) {
  374. if (disposition) {
  375. downloadBlob(res,disposition)
  376. } else {
  377. window.$message?.error('下载异常')
  378. }
  379. }
  380. } else {
  381. window.$message?.warning('请先勾选需要下载的资料文件');
  382. }
  383. }
  384. //删除文件
  385. const delLoading = ref(false)
  386. const delClick = async () => {
  387. const rows = tableCheckedKeys.value
  388. if (rows.length > 0) {
  389. const ids = rowsToId(rows)
  390. window?.$messageBox?.alert('是否删除勾选的资料文件?', '删除提醒', {
  391. showCancelButton: true,
  392. confirmButtonText: '确定删除',
  393. cancelButtonText: '取消',
  394. callback: (action) => {
  395. if (action === 'confirm') {
  396. removeImageclassifyFile(ids)
  397. }
  398. }
  399. })
  400. } else {
  401. window.$message?.warning('请先勾选需要删除的资料文件');
  402. }
  403. }
  404. const removeImageclassifyFile = async (ids) => {
  405. delLoading.value = true
  406. const {error, code} = await imageApi.removeImageclassifyFile({ids: ids}, false)
  407. //判断状态
  408. delLoading.value = false
  409. if (!error && code === 200) {
  410. window.$message?.success('删除成功')
  411. getTableData()
  412. } else {
  413. window.$message?.error('删除异常')
  414. }
  415. }
  416. //回到影像资料页
  417. const goToBack = () => {
  418. router.push({path: '/other-file/image-data'})
  419. }
  420. //左右拖动,改变树形结构宽度
  421. const leftWidth = ref(dataType === 1 ? 382 : 220);
  422. const onmousedown = () => {
  423. const leftNum = isCollapse.value ? 142 : 272
  424. document.onmousemove = (ve) => {
  425. const diffVal = ve.clientX - leftNum;
  426. const minWidth = dataType === 1 ? 310 : 200
  427. const maxWidth = dataType === 1 ? 900 : 300
  428. if(diffVal >= minWidth && diffVal <= maxWidth) {
  429. leftWidth.value = diffVal;
  430. }
  431. }
  432. document.onmouseup = () => {
  433. document.onmousemove = null;
  434. document.onmouseup = null;
  435. }
  436. }
  437. </script>
  438. <style lang="scss" scoped>
  439. @import '../../styles/other-file/image-view.scss';
  440. </style>
  441. <style lang="scss">
  442. .preview-video {
  443. width: 100%;
  444. }
  445. </style>