image-view.vue 15 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435
  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="layers"/>
  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 && fileType === 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 @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">返回上级</el-button>
  90. </div>
  91. <div class="right">
  92. <HcPages :pages="searchForm" @change="pageChange"/>
  93. </div>
  94. </div>
  95. </template>
  96. </HcCard>
  97. </div>
  98. <!--视频预览 弹框-->
  99. <el-dialog v-model="previewVideoModal" title="预览" width="47rem" destroy-on-close custom-class="hc-modal-border">
  100. <video class="preview-video" :src="previewVideoUrl" controls="controls" autoplay="autoplay" v-if="previewVideoUrl">
  101. 您的浏览器不支持 video
  102. </video>
  103. </el-dialog>
  104. </div>
  105. </template>
  106. <script setup>
  107. import {onMounted, ref, watch} from 'vue'
  108. import {useAppStore} from "~src/store";
  109. import {useRouter, useRoute} from 'vue-router'
  110. import WbsTree from "./components/WbsTree.vue"
  111. import HcTreeData from "./components/HcTreeData.vue"
  112. import imageApi from '~api/other-file/imageData';
  113. import {getStoreData, setStoreData} from '~src/utils/storage'
  114. import {downloadBlob, getArrValue, getObjNullValue} from "vue-utils-plus"
  115. //变量
  116. const router = useRouter()
  117. const useRoutes = useRoute()
  118. const useAppState = useAppStore()
  119. const projectId = ref(useAppState.getProjectId);
  120. const contractId = ref(useAppState.getContractId);
  121. const projectInfo = ref(useAppState.getProjectInfo);
  122. const isCollapse = ref(useAppState.getCollapse)
  123. //路由参数
  124. const routerQuery = useRoutes?.query;
  125. //存储目录格式 1按部位存储,2按日期存储
  126. const dataId = routerQuery?.id || '';
  127. const dataType = parseInt(routerQuery?.type + '') || 1;
  128. const fileType = parseInt(routerQuery?.fileType + '') || 2;
  129. //监听
  130. watch(() => [
  131. useAppState.getCollapse
  132. ], ([Collapse]) => {
  133. isCollapse.value = Collapse
  134. })
  135. //自动展开缓存
  136. const TreeAutoExpandKeys = ref(getStoreData('TreeExpandKeys') || [])
  137. const TreeExpandedKeys = ref(getStoreData('TreeExpandedKeys') || [])
  138. const TreeCurrentNodeKey = ref(getStoreData('TreeCurrentNodeKey') || '')
  139. //渲染完成
  140. onMounted(() => {
  141. const nodeKey = TreeCurrentNodeKey.value
  142. if (dataType === 2 && dataId) {
  143. getYearDateTree()
  144. queryKey.value = nodeKey
  145. searchForm.value.queryDate = nodeKey
  146. searchForm.value.current = 1;
  147. getTableData()
  148. } else {
  149. queryKey.value = ''
  150. }
  151. })
  152. //获取时间结构
  153. const dateElTreeData = ref([])
  154. const getYearDateTree = async () => {
  155. const { error, code, data } = await imageApi.getYearDateTree({
  156. projectId: projectId.value,
  157. contractId: contractId.value,
  158. classifyId: dataId
  159. })
  160. //处理数据
  161. if (!error && code === 200) {
  162. dateElTreeData.value = getArrValue(data)
  163. } else {
  164. dateElTreeData.value = []
  165. }
  166. }
  167. //日期树被点击
  168. const nodeDataInfo = ref({})
  169. const dateWbsElTreeClick = ({data, keys, key}) => {
  170. queryKey.value = key
  171. nodeDataInfo.value = data
  172. //缓存自动展开
  173. TreeExpandedKeys.value = keys
  174. TreeCurrentNodeKey.value = key
  175. setStoreData('TreeExpandedKeys', keys)
  176. setStoreData('TreeCurrentNodeKey', key)
  177. //改变搜索表单数据
  178. searchForm.value.queryDate = data['hierarchy'] || ''
  179. searchForm.value.wbsIdsStr = null
  180. searchForm.value.current = 1;
  181. getTableData()
  182. }
  183. //项目树被点击
  184. const nodeWbsElTreeClick = ({data, keys}) => {
  185. if (data.leaf === true) {
  186. nodeDataInfo.value = data
  187. queryKey.value = data['primaryKeyId'] || ''
  188. //缓存自动展开
  189. TreeAutoExpandKeys.value = keys
  190. setStoreData('TreeExpandKeys', keys)
  191. //改变搜索表单数据
  192. searchForm.value.queryDate = null
  193. searchForm.value.wbsIdsStr = data?.primaryKeyId || ''
  194. searchForm.value.current = 1;
  195. getTableData()
  196. } else {
  197. queryKey.value = ''
  198. nodeDataInfo.value = {}
  199. searchForm.value.queryDate = null
  200. searchForm.value.wbsIdsStr = null
  201. tableListData.value = []
  202. searchForm.value.total = 0
  203. }
  204. }
  205. //搜索和分页数据
  206. const queryKey = ref(null)
  207. const searchForm = ref({
  208. queryStr: null, classifyId: dataId, wbsIdsStr: null,
  209. current: 1, size: 20, total: 0
  210. })
  211. //回车搜索
  212. const keyUpEvent = (e) => {
  213. if (e.key === "Enter") {
  214. searchClick()
  215. }
  216. }
  217. //搜索
  218. const searchClick = () => {
  219. if (queryKey.value) {
  220. searchForm.value.current = 1;
  221. getTableData()
  222. } else {
  223. window?.$message?.warning('请先在左边选择一个树节点')
  224. }
  225. }
  226. //分页被点击
  227. const pageChange = ({current, size}) => {
  228. searchForm.value.current = current
  229. searchForm.value.size = size
  230. getTableData()
  231. }
  232. //获取数据
  233. const tableListRef = ref(null)
  234. const tableLoading = ref(false)
  235. const tableListData = ref([])
  236. const tableListColumn = ref([
  237. {key:'info', name: '文件详情'},
  238. {key:'textContent', name: '文字说明'},
  239. {key:'operate', name: '操作', align: 'center', width: '130'},
  240. ])
  241. const getTableData = async () => {
  242. tableLoading.value = true
  243. const {error, code, data} = await imageApi.getPageList({
  244. ...searchForm.value,
  245. projectId: projectId.value,
  246. contractId: contractId.value
  247. })
  248. //判断状态
  249. tableLoading.value = false
  250. if (!error && code === 200) {
  251. tableListData.value = getArrValue(data['records'])
  252. searchForm.value.total = data['total'] || 0
  253. } else {
  254. tableListData.value = []
  255. searchForm.value.total = 0
  256. }
  257. }
  258. //多选
  259. const tableCheckedKeys = ref([]);
  260. const tableSelectionChange = (rows) => {
  261. tableCheckedKeys.value = rows.filter((item) => {
  262. return (item??'') !== '';
  263. })
  264. }
  265. //处理图片预览问题
  266. const setImageUrl = (url) => {
  267. if (url) {
  268. const urlArr = url.split(',')
  269. if (urlArr.length > 0 && urlArr[0]) {
  270. return urlArr[0]
  271. } else {
  272. return ''
  273. }
  274. } else {
  275. return ''
  276. }
  277. }
  278. //预览
  279. const previewVideoUrl = ref('')
  280. const previewVideoModal = ref(false)
  281. const previewClick = async ({id,type,imageUrl}) => {
  282. if (imageUrl) {
  283. if (parseInt(type) === 1) {
  284. previewVideoUrl.value = imageUrl
  285. previewVideoModal.value = true
  286. } else {
  287. const {error, code, data} = await imageApi.imageClassificationFile({ids: id}, false)
  288. //判断状态
  289. const imgUrl = getObjNullValue(data)
  290. if (!error && code === 200 && imgUrl) {
  291. window.open(data?.data,"_blank");
  292. } else {
  293. window.$message?.warning('预览资料文件异常');
  294. }
  295. }
  296. } else {
  297. window.$message?.warning('暂无可预览的资料文件');
  298. }
  299. }
  300. //新增文件
  301. const addFormFile = () => {
  302. router.push({
  303. path: '/other-file/image-form',
  304. query: {
  305. wbsId: queryKey.value, //树节点ID
  306. dataType: dataType, //存储目录格式 1按部位存储,2按日期存储
  307. fileType: fileType, //文件类型,1视频文件,2图片文件
  308. classifyId: dataId, //classifyId,分类ID,
  309. }
  310. })
  311. }
  312. //编辑修改
  313. const editClick = ({id}) => {
  314. router.push({
  315. path: '/other-file/image-form',
  316. query: {
  317. wbsId: queryKey.value, //树节点ID
  318. dataType: dataType, //存储目录格式 1按部位存储,2按日期存储
  319. fileType: fileType, //文件类型,1视频文件,2图片文件
  320. classifyId: dataId, //classifyId,分类ID,
  321. id: id //数据ID
  322. }
  323. })
  324. }
  325. //拼接ID
  326. const rowsToId = (rows) => {
  327. return rows.map((obj) => {
  328. return obj.id;
  329. }).join(",")
  330. }
  331. //下载文件
  332. const downloadLoading = ref(false)
  333. const downloadClick = async () => {
  334. const rows = tableCheckedKeys.value
  335. if (rows.length > 0) {
  336. downloadLoading.value = true
  337. const ids = rowsToId(rows)
  338. const { error, disposition, res } = await imageApi.batchDownloadFileToZip({ids: ids}, false)
  339. //判断状态
  340. if (!error) {
  341. if (disposition) {
  342. downloadBlob(res,disposition)
  343. } else {
  344. window.$message?.error('下载异常')
  345. }
  346. }
  347. } else {
  348. window.$message?.warning('请先勾选需要下载的资料文件');
  349. }
  350. }
  351. //删除文件
  352. const delLoading = ref(false)
  353. const delClick = async () => {
  354. const rows = tableCheckedKeys.value
  355. if (rows.length > 0) {
  356. const ids = rowsToId(rows)
  357. window?.$messageBox?.alert('是否删除勾选的资料文件?', '删除提醒', {
  358. showCancelButton: true,
  359. confirmButtonText: '确定删除',
  360. cancelButtonText: '取消',
  361. callback: (action) => {
  362. if (action === 'confirm') {
  363. removeImageclassifyFile(ids)
  364. }
  365. }
  366. })
  367. } else {
  368. window.$message?.warning('请先勾选需要删除的资料文件');
  369. }
  370. }
  371. const removeImageclassifyFile = async (ids) => {
  372. delLoading.value = true
  373. const {error, code} = await imageApi.removeImageclassifyFile({ids: ids}, false)
  374. //判断状态
  375. delLoading.value = false
  376. if (!error && code === 200) {
  377. window.$message?.success('删除成功')
  378. getTableData()
  379. } else {
  380. window.$message?.error('删除异常')
  381. }
  382. }
  383. //回到影像资料页
  384. const goToBack = () => {
  385. router.push({path: '/other-file/image-data'})
  386. }
  387. //左右拖动,改变树形结构宽度
  388. const leftWidth = ref(dataType === 1 ? 382 : 220);
  389. const onmousedown = () => {
  390. const leftNum = isCollapse.value ? 142 : 272
  391. document.onmousemove = (ve) => {
  392. const diffVal = ve.clientX - leftNum;
  393. const minWidth = dataType === 1 ? 310 : 200
  394. const maxWidth = dataType === 1 ? 900 : 300
  395. if(diffVal >= minWidth && diffVal <= maxWidth) {
  396. leftWidth.value = diffVal;
  397. }
  398. }
  399. document.onmouseup = () => {
  400. document.onmousemove = null;
  401. document.onmouseup = null;
  402. }
  403. }
  404. </script>
  405. <style lang="scss" scoped>
  406. @import '../../styles/other-file/image-view.scss';
  407. </style>
  408. <style lang="scss">
  409. </style>