阅行客电子档案
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

452 lines
16 KiB

2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
1 year ago
2 years ago
1 year ago
2 years ago
1 year ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
1 year ago
2 years ago
2 years ago
2 years ago
1 year ago
2 years ago
2 years ago
1 year ago
1 year ago
1 year ago
2 years ago
1 year ago
2 years ago
1 month ago
2 years ago
2 years ago
2 years ago
2 years ago
  1. <template>
  2. <div class="upload-file">
  3. <!-- 上传附件curd -->
  4. <div v-if="isUploadDetail" class="upload-curd">
  5. <div class="upload-btn">
  6. <el-button icon="el-icon-plus" size="small" type="primary">添加</el-button>
  7. <input id="upFile" type="file" name="upFile" @change="changeFile($event)">
  8. </div>
  9. <el-button icon="el-icon-delete" :disabled="selections.length === 0" @click="toDelete(selections)">删除</el-button>
  10. <el-button icon="el-icon-sort" @click="showSort">排序</el-button>
  11. </div>
  12. <!--表格渲染-->
  13. <el-table
  14. ref="table"
  15. :data="tableData"
  16. style="min-width: 100%"
  17. height="calc(100vh - 382px)"
  18. @row-click="clickRowHandler"
  19. @selection-change="selectionChangeHandler"
  20. >
  21. <el-table-column v-if="isUploadDetail" type="selection" width="55" align="center" />
  22. <el-table-column type="index" label="序号" width="55" align="center" />
  23. <el-table-column prop="file_name" label="文件名称" show-overflow-tooltip min-width="140" />
  24. <el-table-column prop="file_type" label="格式" min-width="60" align="center" />
  25. <el-table-column prop="file_size" label="大小" min-width="85" align="right">
  26. <template slot-scope="scope">
  27. {{ getFileSize(scope.row.file_size) }}
  28. </template>
  29. </el-table-column>
  30. <!-- <el-table-column prop="file_dpi" label="分辨率" min-width="120" align="center">
  31. <template slot-scope="scope">
  32. <div v-if="!scope.row.file_dpi || scope.row.file_dpi === 'null'"> - </div>
  33. <div v-else> {{ scope.row.file_dpi }} </div>
  34. </template>
  35. </el-table-column> -->
  36. <el-table-column prop="file_thumbnail" label="缩略图" min-width="60" align="center">
  37. <template slot-scope="scope">
  38. <div v-if="scope.row.file_type === 'jpg' || scope.row.file_type === 'jpeg' || scope.row.file_type === 'png' || scope.row.file_type === 'bmp'|| scope.row.file_type === 'gif'">
  39. <i class="fileIcon icon-image" />
  40. </div>
  41. <div v-else-if="scope.row.file_type === 'xlsx' || scope.row.file_type === 'xls'">
  42. <i class="fileIcon icon-excel" />
  43. </div>
  44. <div v-else-if="scope.row.file_type === 'docx' || scope.row.file_type === 'doc'">
  45. <i class="fileIcon icon-word" />
  46. </div>
  47. <div v-else-if="scope.row.file_type === 'pdf'">
  48. <i class="fileIcon icon-pdf" />
  49. </div>
  50. <div v-else-if="scope.row.file_type === 'ppt' || scope.row.file_type === 'pptx'">
  51. <i class="fileIcon icon-ppt" />
  52. </div>
  53. <div v-else-if="scope.row.file_type === 'zip' || scope.row.file_type === 'rar'">
  54. <i class="fileIcon icon-zip" />
  55. </div>
  56. <div v-else-if="scope.row.file_type === 'txt'">
  57. <i class="fileIcon icon-txt" />
  58. </div>
  59. <div v-else-if="scope.row.file_type === 'ofd'">
  60. <i class="fileIcon icon-ofd" />
  61. </div>
  62. <div v-else>
  63. <i class="fileIcon icon-other" />
  64. </div>
  65. </template>
  66. </el-table-column>
  67. <el-table-column prop="create_time" label="创建时间" min-width="130" align="center" />
  68. <el-table-column v-if="isShowUtilizeHandleBtn" label="操作" min-width="80" align="center">
  69. <template slot-scope="scope">
  70. <div class="handle-btn">
  71. <el-button v-if="authUtilize.look" class="iconfont icon-sulan" @click="toPreview(scope.row)" />
  72. <el-button v-if="authUtilize.download" class="iconfont icon-xiazai" @click="downloadFile(scope.row)" />
  73. <el-button v-if="authUtilize.print" class="iconfont icon-dayin" />
  74. </div>
  75. </template>
  76. </el-table-column>
  77. </el-table>
  78. <!-- 点击缩略图看大图 -->
  79. <!-- <el-dialog class="preview-dialog" :append-to-body="true" :close-on-click-modal="false" :before-close="handleClose" :visible="showCoverVisible" title="查看大图">
  80. <span class="dialog-right-top" />
  81. <span class="dialog-left-bottom" />
  82. <div class="setting-dialog" style="max-height:calc(100vh - 230px); overflow:auto;">
  83. <img style="max-width:100%; object-fit: contain;" :src="previewSrc" :onerror="defaultImg">
  84. </div>
  85. </el-dialog> -->
  86. <!-- 排序 -->
  87. <!-- <el-dialog :close-on-click-modal="false" :append-to-body="true" title="排序" :visible.sync="sortVisible" @opened="opened">
  88. <span class="dialog-right-top" />
  89. <span class="dialog-left-bottom" />
  90. <div class="setting-dialog">
  91. <i class="drag-tip">提示请通过拖动鼠标来调整当前顺序</i>
  92. <el-table :data="sortTableData" class="file-sort" style="width: 100%;max-height: 70vh;" row-key="id">
  93. <el-table-column type="index" label="序号" width="100" align="center" />
  94. <el-table-column prop="file_name" label="文件名称" />
  95. </el-table>
  96. <div slot="footer" class="dialog-footer">
  97. <el-button type="primary" @click.native="handleSort">保存</el-button>
  98. </div>
  99. </div>
  100. </el-dialog> -->
  101. <!-- 删除附件 -->
  102. <!-- <el-dialog title="删除附件" :append-to-body="true" :close-on-click-modal="false" :visible.sync="deleteVisible" :before-close="handleClose">
  103. <span class="dialog-right-top" />
  104. <span class="dialog-left-bottom" />
  105. <div class="setting-dialog">
  106. <div class="dialog-delt">
  107. <p><span>确定删除已选择的附件吗</span></p>
  108. </div>
  109. <div slot="footer" class="dialog-footer">
  110. <el-button type="primary" @click.native="handleDeltConfirm">确定</el-button>
  111. </div>
  112. </div>
  113. </el-dialog> -->
  114. </div>
  115. </template>
  116. <script>
  117. // import { FetchInitArchiveFilesView, FetchEditFile, FetchDeleteFile, FetchFileSort } from '@/api/archivesManage/archivesList'
  118. import { FetchInitFileCategoryView } from '@/api/collect/collect'
  119. import { archivesUpload } from '@/utils/upload'
  120. import { downloadFile, getCurrentTime } from '@/utils/index'
  121. import { mapGetters } from 'vuex'
  122. import { FetchIsAuthByLookType } from '@/api/archivesManage/library'
  123. // import Sortable from 'sortablejs'
  124. export default {
  125. name: 'UploadFile',
  126. components: {},
  127. mixins: [],
  128. props: {
  129. isUploadDetail: {
  130. type: Boolean,
  131. default: true
  132. },
  133. selectedCategory: {
  134. type: Object,
  135. default: function() {
  136. return {}
  137. }
  138. },
  139. arcId: {
  140. type: String,
  141. default: function() {
  142. return ''
  143. }
  144. },
  145. categoryId: {
  146. type: String,
  147. default: function() {
  148. return ''
  149. }
  150. },
  151. isShowUtilizeHandleBtn: {
  152. type: Boolean,
  153. default: false
  154. },
  155. archivesDetailsData: {
  156. type: Array,
  157. default: function() {
  158. return []
  159. }
  160. }
  161. },
  162. data() {
  163. return {
  164. // defaultImg: 'this.src="' + require('@/assets/images/cover-bg.png') + '"',
  165. tableData: [], // 附件list
  166. selections: [], // table - 选中的
  167. // showCoverVisible: false, // 查看大图dialog
  168. // sortTableData: [], // 排序data
  169. // sortVisible: false, // 排序dialog
  170. // deleteVisible: false, // 删除附件 dialog
  171. // deleteData: [], // 删除选中的data
  172. file: null, // 附件 change
  173. fileNames: '', // 附件 - name
  174. formatType: '', // 附件 - type
  175. postfix: '', // 附件 - 文件后缀
  176. fileSize: '', // 附件 - 大小
  177. filePath: '', // 附件 - path
  178. px: '', // 附件 - 分辨率
  179. nowDate: '', // 当前时间
  180. previewSrc: '', // 查看大图src
  181. authUtilize: {
  182. 'look': false,
  183. 'download': false,
  184. 'print': false,
  185. 'endTime': null,
  186. 'startTime': null
  187. }
  188. }
  189. },
  190. computed: {
  191. ...mapGetters([
  192. 'baseApi'
  193. ])
  194. },
  195. watch: {
  196. arcId: function(newValue, oldValue) {
  197. }
  198. },
  199. mounted() {
  200. this.getIsAuthByLookType()
  201. console.log('archivesDetailsData', this.archivesDetailsData)
  202. },
  203. methods: {
  204. getIsAuthByLookType() {
  205. const params = {
  206. 'archivesId': this.arcId
  207. }
  208. FetchIsAuthByLookType(params).then(res => {
  209. this.authUtilize = res
  210. })
  211. },
  212. toPreview(row) {
  213. const routeData = this.$router.resolve({
  214. path: '/preview',
  215. query: {
  216. 'archiveNo': this.archivesDetailsData.find(item => item.fieldName === 'archive_no').context
  217. }})
  218. window.open(routeData.href, '_blank')
  219. if (localStorage.getItem('documentId')) {
  220. localStorage.removeItem('documentId')
  221. }
  222. // localStorage.setItem('fileParentInfo', JSON.stringify(this.archivesDetailsData))
  223. localStorage.setItem('fileTables', JSON.stringify(this.tableData))
  224. localStorage.setItem('fileCurrent', JSON.stringify(row))
  225. },
  226. getFileSize(fileSize) {
  227. // 1. 先将接口返回的KB值转为数字,处理非数字/空值情况
  228. const sizeInKB = Number(fileSize)
  229. if (isNaN(sizeInKB) || sizeInKB < 0) {
  230. return '0 KB' // 异常值默认显示0 KB
  231. }
  232. // 2. 定义单位换算关系(1 MB = 1024 KB,1 GB = 1024 MB)
  233. const KB = 1
  234. const MB = 1024 * KB
  235. const GB = 1024 * MB
  236. // 3. 根据大小自动选择单位并格式化
  237. if (sizeInKB >= GB) {
  238. // 大于等于1GB,显示GB(保留2位小数)
  239. return (sizeInKB / GB).toFixed(2) + ' GB'
  240. } else if (sizeInKB >= MB) {
  241. // 大于等于1MB且小于1GB,显示MB(保留2位小数)
  242. return (sizeInKB / MB).toFixed(2) + ' MB'
  243. } else if (sizeInKB < 1) {
  244. // 不足1KB,统一显示1 KB(保持你之前的需求)
  245. return '1 KB'
  246. } else {
  247. // 1KB到1MB之间,显示KB(保留2位小数)
  248. return sizeInKB + ' KB'
  249. }
  250. },
  251. // 选择附件
  252. async changeFile(e) {
  253. this.file = e.target.files[0]
  254. this.fileSize = this.file.size
  255. this.formatType = this.file.type.substring(0, this.file.type.indexOf('/'))
  256. this.fileNames = this.file.name
  257. this.postfix = this.file.name.substring(
  258. this.fileNames.lastIndexOf('.') + 1,
  259. this.fileNames.length
  260. )
  261. if (this.formatType === 'image') {
  262. const fileBase64 = await this.getBase64(this.file)
  263. const res = await this.getImgPx(fileBase64)
  264. this.px = res.width + 'px*' + res.height + 'px'
  265. } else {
  266. this.px = ''
  267. }
  268. // 上传附件
  269. archivesUpload(this.baseApi + '/api/archives/uploadFile', this.file, this.categoryId).then(res => {
  270. if (res.data.code === 200) {
  271. this.filePath = res.data.data
  272. this.uploadSave()
  273. }
  274. })
  275. },
  276. // 上传附件 - 选择上传即保存
  277. uploadSave() {
  278. this.nowDate = getCurrentTime()
  279. const json = {
  280. 'file_name': this.fileNames,
  281. 'file_size': this.fileSize,
  282. 'file_type': this.postfix,
  283. 'file_path': this.filePath,
  284. 'sequence': null,
  285. 'archive_id': this.arcId,
  286. 'file_dpi': this.px,
  287. 'file_thumbnail': '',
  288. 'create_time': this.nowDate,
  289. 'id': null
  290. }
  291. const arrayUpload = []
  292. arrayUpload.push(json)
  293. const params = {
  294. 'categoryId': this.categoryId,
  295. 'jsonString': JSON.stringify(arrayUpload)
  296. }
  297. console.log(params)
  298. // FetchEditFile(params).then(data => {
  299. // this.$message.success('上传附件成功!')
  300. // this.crud.refresh()
  301. // this.getFileList()
  302. // })
  303. },
  304. // 将上传的图片转为base64
  305. getBase64(file) {
  306. const reader = new FileReader()
  307. reader.readAsDataURL(file)
  308. return new Promise((resolve) => {
  309. reader.onload = () => {
  310. resolve(reader.result)
  311. }
  312. })
  313. },
  314. // 获取图片的分辨率
  315. getImgPx(img) {
  316. const image = new Image()
  317. image.src = img
  318. return new Promise((resolve) => {
  319. image.onload = () => {
  320. const width = image.width
  321. const height = image.height
  322. resolve({ width, height })
  323. }
  324. })
  325. },
  326. // 上传list
  327. getFileList() {
  328. const params = {
  329. 'categoryId': this.categoryId !== '' ? this.categoryId : this.selectedCategory.id,
  330. 'archivesId': this.arcId,
  331. 'page': 0,
  332. 'size': 10
  333. }
  334. console.log(params)
  335. FetchInitFileCategoryView(params).then(data => {
  336. console.log('darta', data)
  337. this.tableData = data.returnlist
  338. })
  339. },
  340. // 下载附件
  341. downloadFile(row) {
  342. const url = this.baseApi + '/downloadFile' + row.file_path
  343. fetch(url).then(res => res.blob()).then(blob => {
  344. downloadFile(blob, row.file_name.split('.')[0], row.file_type)
  345. }).catch(() => {
  346. this.$message.error('下载文件失败!')
  347. })
  348. },
  349. // 选择删除
  350. toDelete(data) {
  351. this.deleteData = data
  352. this.deleteVisible = true
  353. },
  354. // 确认删除
  355. handleDeltConfirm() {
  356. this.deleteVisible = false
  357. const ids = []
  358. this.deleteData.forEach(val => {
  359. ids.push(val.id)
  360. })
  361. const params = {
  362. 'ids': ids,
  363. 'categoryId': this.categoryId
  364. }
  365. console.log(params)
  366. // 删除fetch
  367. // FetchDeleteFile(params).then(res => {
  368. // this.crud.delAllLoading = false
  369. // this.$message.success('删除成功!')
  370. // this.crud.refresh()
  371. // this.getFileList()
  372. // })
  373. },
  374. // 排序 - 行拖拽
  375. // rowDrop(className, targetName) {
  376. // // 此时找到的元素是要拖拽元素的父容器
  377. // const tbody = document.querySelector('.' + className + ' .el-table__body-wrapper tbody')
  378. // const that = this
  379. // Sortable.create(tbody, {
  380. // // 指定父元素下可被拖拽的子元素
  381. // draggable: '.el-table__row',
  382. // onEnd({ newIndex, oldIndex }) {
  383. // if (newIndex === oldIndex) return
  384. // that[targetName].splice(newIndex, 0, that[targetName].splice(oldIndex, 1)[0])
  385. // }
  386. // })
  387. // },
  388. // 排序
  389. // opened() {
  390. // this.rowDrop('file-sort', 'sortTableData')
  391. // },
  392. // showSort() {
  393. // this.sortVisible = true
  394. // this.sortTableData = JSON.parse(JSON.stringify(this.tableData))
  395. // },
  396. // // 排序 - 保存
  397. // handleSort() {
  398. // const ids = []
  399. // const sequences = []
  400. // this.sortTableData.map((value, index) => {
  401. // ids.push(value.id)
  402. // sequences.push(index + 1)
  403. // })
  404. // const params = {
  405. // 'categoryId': this.categoryId,
  406. // 'ids': ids,
  407. // 'sequences': sequences
  408. // }
  409. // console.log(params)
  410. // // FetchFileSort(params).then((res) => {
  411. // // this.sortVisible = false
  412. // // this.$message.success('附件排序成功!')
  413. // // this.crud.refresh()
  414. // // this.getFileList()
  415. // // })
  416. // },
  417. // table
  418. clickRowHandler(row) {
  419. this.$refs.table.toggleRowSelection(row)
  420. },
  421. // table
  422. selectionChangeHandler(val) {
  423. this.selections = val
  424. },
  425. // dialog - close
  426. handleClose(done) {
  427. this.showCoverVisible = false
  428. done()
  429. }
  430. // 查看大图
  431. // showCoverPreview(row) {
  432. // this.showCoverVisible = true
  433. // this.previewSrc = this.baseApi + '/downloadFile' + row.file_path
  434. // }
  435. }
  436. }
  437. </script>
  438. <style lang="scss" scoped>
  439. .svg-style{
  440. width: 60px;
  441. height: 32px;
  442. }
  443. </style>