阅行客电子档案
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.

395 lines
14 KiB

2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
1 year ago
1 year ago
2 years ago
2 years 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
1 year ago
2 years ago
2 years ago
1 year ago
2 years ago
2 years ago
1 year 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="center">
  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>
  60. <i class="fileIcon icon-other" />
  61. </div>
  62. </template>
  63. </el-table-column>
  64. <el-table-column prop="create_time" label="创建时间" min-width="130" align="center" />
  65. <!-- && !recycleMain.isRecycle -->
  66. <el-table-column v-if="!isUploadDetail && !parentsData.isRecycle" label="操作" min-width="80" align="center">
  67. <template slot-scope="scope">
  68. <div class="handle-btn">
  69. <el-button class="iconfont icon-sulan" @click="toPreview(scope.row)" />
  70. <el-button class="iconfont icon-xiazai" @click="downloadFile(scope.row)" />
  71. <!-- <el-button class="iconfont icon-dayin" /> -->
  72. </div>
  73. </template>
  74. </el-table-column>
  75. </el-table>
  76. <!-- 点击缩略图看大图 -->
  77. <el-dialog class="preview-dialog" :append-to-body="true" :close-on-click-modal="false" :before-close="handleClose" :visible="showCoverVisible" title="查看大图">
  78. <span class="dialog-right-top" />
  79. <span class="dialog-left-bottom" />
  80. <div class="setting-dialog" style="max-height:calc(100vh - 230px); overflow:auto;">
  81. <img style="max-width:100%; object-fit: contain;" :src="previewSrc" :onerror="defaultImg">
  82. </div>
  83. </el-dialog>
  84. <!-- 排序 -->
  85. <el-dialog :close-on-click-modal="false" :append-to-body="true" title="排序" :visible.sync="sortVisible" @opened="opened">
  86. <span class="dialog-right-top" />
  87. <span class="dialog-left-bottom" />
  88. <div class="setting-dialog">
  89. <i class="drag-tip">提示请通过拖动鼠标来调整当前顺序</i>
  90. <el-table :data="sortTableData" class="file-sort" style="width: 100%;max-height: 70vh;" row-key="id">
  91. <el-table-column type="index" label="序号" width="100" align="center" />
  92. <el-table-column prop="file_name" label="文件名称" />
  93. </el-table>
  94. <div slot="footer" class="dialog-footer">
  95. <el-button type="primary" @click.native="handleSort">保存</el-button>
  96. </div>
  97. </div>
  98. </el-dialog>
  99. <!-- 删除附件 -->
  100. <el-dialog title="删除附件" :append-to-body="true" :close-on-click-modal="false" :visible.sync="deleteVisible" :before-close="handleClose">
  101. <span class="dialog-right-top" />
  102. <span class="dialog-left-bottom" />
  103. <div class="setting-dialog">
  104. <div class="dialog-delt">
  105. <p><span>确定删除已选择的附件吗</span></p>
  106. </div>
  107. <div slot="footer" class="dialog-footer">
  108. <el-button type="primary" @click.native="handleDeltConfirm">确定</el-button>
  109. </div>
  110. </div>
  111. </el-dialog>
  112. </div>
  113. </template>
  114. <script>
  115. // import { FetchInitArchiveFilesView, FetchEditFile, FetchDeleteFile, FetchFileSort } from '@/api/archivesManage/archivesList'
  116. import { FetchInitFileCategoryView } from '@/api/collect/collect'
  117. import { archivesUpload } from '@/utils/upload'
  118. import { downloadFile, getCurrentTime } from '@/utils/index'
  119. import { mapGetters } from 'vuex'
  120. import { form } from '@crud/crud'
  121. import Sortable from 'sortablejs'
  122. export default {
  123. name: 'UploadFile',
  124. components: {},
  125. mixins: [
  126. form({})
  127. ],
  128. inject: ['parentsData'],
  129. props: {
  130. isUploadDetail: {
  131. type: Boolean,
  132. default: true
  133. },
  134. selectedCategory: {
  135. type: Object,
  136. default: function() {
  137. return {}
  138. }
  139. },
  140. arcId: {
  141. type: String,
  142. default: function() {
  143. return ''
  144. }
  145. }
  146. },
  147. data() {
  148. return {
  149. defaultImg: 'this.src="' + require('@/assets/images/cover-bg.png') + '"',
  150. tableData: [], // 附件list
  151. selections: [], // table - 选中的
  152. showCoverVisible: false, // 查看大图dialog
  153. sortTableData: [], // 排序data
  154. sortVisible: false, // 排序dialog
  155. deleteVisible: false, // 删除附件 dialog
  156. deleteData: [], // 删除选中的data
  157. file: null, // 附件 change
  158. fileNames: '', // 附件 - name
  159. formatType: '', // 附件 - type
  160. postfix: '', // 附件 - 文件后缀
  161. fileSize: '', // 附件 - 大小
  162. filePath: '', // 附件 - path
  163. px: '', // 附件 - 分辨率
  164. nowDate: '', // 当前时间
  165. previewSrc: '', // 查看大图src
  166. parentInfo: null
  167. }
  168. },
  169. computed: {
  170. ...mapGetters([
  171. 'baseApi'
  172. ])
  173. },
  174. watch: {
  175. arcId: function(newValue, oldValue) {
  176. }
  177. },
  178. mounted() {
  179. },
  180. methods: {
  181. getFileSize(fileSize) {
  182. const fileSizeInKB = (fileSize / 1024).toFixed(2) + 'kB'
  183. const fileSizeInB = fileSize + 'B'
  184. return (fileSize / 1024) <= 0.01 ? fileSizeInB : fileSizeInKB
  185. },
  186. // 选择附件
  187. async changeFile(e) {
  188. this.file = e.target.files[0]
  189. this.fileSize = this.file.size
  190. this.formatType = this.file.type.substring(0, this.file.type.indexOf('/'))
  191. this.fileNames = this.file.name
  192. this.postfix = this.file.name.substring(
  193. this.fileNames.lastIndexOf('.') + 1,
  194. this.fileNames.length
  195. )
  196. if (this.formatType === 'image') {
  197. const fileBase64 = await this.getBase64(this.file)
  198. const res = await this.getImgPx(fileBase64)
  199. this.px = res.width + 'px*' + res.height + 'px'
  200. } else {
  201. this.px = ''
  202. }
  203. // 上传附件
  204. archivesUpload(this.baseApi + '/api/archives/uploadFile', this.file, this.categoryId).then(res => {
  205. if (res.data.code === 200) {
  206. this.filePath = res.data.data
  207. this.uploadSave()
  208. }
  209. })
  210. },
  211. // 上传附件 - 选择上传即保存
  212. uploadSave() {
  213. this.nowDate = getCurrentTime()
  214. const json = {
  215. 'file_name': this.fileNames,
  216. 'file_size': this.fileSize,
  217. 'file_type': this.postfix,
  218. 'file_path': this.filePath,
  219. 'sequence': null,
  220. 'archive_id': this.arcId,
  221. 'file_dpi': this.px,
  222. 'file_thumbnail': '',
  223. 'create_time': this.nowDate,
  224. 'id': null
  225. }
  226. const arrayUpload = []
  227. arrayUpload.push(json)
  228. // const params = {
  229. // 'categoryId': this.categoryId,
  230. // 'jsonString': JSON.stringify(arrayUpload)
  231. // }
  232. // console.log(params)
  233. // FetchEditFile(params).then(data => {
  234. // this.$message.success('上传附件成功!')
  235. // this.crud.refresh()
  236. // this.getFileList()
  237. // })
  238. },
  239. // 将上传的图片转为base64
  240. getBase64(file) {
  241. const reader = new FileReader()
  242. reader.readAsDataURL(file)
  243. return new Promise((resolve) => {
  244. reader.onload = () => {
  245. resolve(reader.result)
  246. }
  247. })
  248. },
  249. // 获取图片的分辨率
  250. getImgPx(img) {
  251. const image = new Image()
  252. image.src = img
  253. return new Promise((resolve) => {
  254. image.onload = () => {
  255. const width = image.width
  256. const height = image.height
  257. resolve({ width, height })
  258. }
  259. })
  260. },
  261. // 上传list
  262. getFileList() {
  263. const params = {
  264. 'categoryId': this.selectedCategory.id,
  265. 'archivesId': this.arcId,
  266. 'page': 0,
  267. 'size': 10
  268. }
  269. FetchInitFileCategoryView(params).then(data => {
  270. this.tableData = data.returnlist
  271. })
  272. },
  273. toPreview(row) {
  274. const routeData = this.$router.resolve({
  275. path: '/preview',
  276. query: {
  277. 'archiveNo': this.parentInfo.find(item => item.fieldName === 'archive_no').context
  278. }})
  279. window.open(routeData.href, '_blank')
  280. localStorage.setItem('fileParentInfo', JSON.stringify(this.parentInfo))
  281. localStorage.setItem('fileTables', JSON.stringify(this.tableData))
  282. localStorage.setItem('fileCurrent', JSON.stringify(row))
  283. },
  284. // 下载附件
  285. downloadFile(row) {
  286. const url = this.baseApi + '/downloadFile' + row.file_path
  287. fetch(url).then(res => res.blob()).then(blob => {
  288. downloadFile(blob, row.file_name.split('.')[0], row.file_type)
  289. }).catch(() => {
  290. this.$message({ message: '下载文件失败!', type: 'error', offset: 8 })
  291. })
  292. },
  293. // 选择删除
  294. toDelete(data) {
  295. this.deleteData = data
  296. this.deleteVisible = true
  297. },
  298. // 确认删除
  299. handleDeltConfirm() {
  300. this.deleteVisible = false
  301. const ids = []
  302. this.deleteData.forEach(val => {
  303. ids.push(val.id)
  304. })
  305. // const params = {
  306. // 'ids': ids,
  307. // 'categoryId': this.categoryId
  308. // }
  309. // console.log(params)
  310. // 删除fetch
  311. // FetchDeleteFile(params).then(res => {
  312. // this.crud.delAllLoading = false
  313. // this.$message.success('删除成功!')
  314. // this.crud.refresh()
  315. // this.getFileList()
  316. // })
  317. },
  318. // 排序 - 行拖拽
  319. rowDrop(className, targetName) {
  320. // 此时找到的元素是要拖拽元素的父容器
  321. const tbody = document.querySelector('.' + className + ' .el-table__body-wrapper tbody')
  322. const that = this
  323. Sortable.create(tbody, {
  324. // 指定父元素下可被拖拽的子元素
  325. draggable: '.el-table__row',
  326. onEnd({ newIndex, oldIndex }) {
  327. if (newIndex === oldIndex) return
  328. that[targetName].splice(newIndex, 0, that[targetName].splice(oldIndex, 1)[0])
  329. }
  330. })
  331. },
  332. // 排序
  333. opened() {
  334. this.rowDrop('file-sort', 'sortTableData')
  335. },
  336. showSort() {
  337. this.sortVisible = true
  338. this.sortTableData = JSON.parse(JSON.stringify(this.tableData))
  339. },
  340. // 排序 - 保存
  341. handleSort() {
  342. const ids = []
  343. const sequences = []
  344. this.sortTableData.map((value, index) => {
  345. ids.push(value.id)
  346. sequences.push(index + 1)
  347. })
  348. // const params = {
  349. // 'categoryId': this.categoryId,
  350. // 'ids': ids,
  351. // 'sequences': sequences
  352. // }
  353. // console.log(params)
  354. // FetchFileSort(params).then((res) => {
  355. // this.sortVisible = false
  356. // this.$message.success('附件排序成功!')
  357. // this.crud.refresh()
  358. // this.getFileList()
  359. // })
  360. },
  361. // table
  362. clickRowHandler(row) {
  363. this.$refs.table.toggleRowSelection(row)
  364. },
  365. // table
  366. selectionChangeHandler(val) {
  367. this.selections = val
  368. },
  369. // dialog - close
  370. handleClose(done) {
  371. this.showCoverVisible = false
  372. done()
  373. },
  374. // 查看大图
  375. showCoverPreview(row) {
  376. this.showCoverVisible = true
  377. this.previewSrc = this.baseApi + '/downloadFile' + row.file_path
  378. }
  379. }
  380. }
  381. </script>
  382. <style lang="scss" scoped>
  383. .svg-style{
  384. width: 60px;
  385. height: 32px;
  386. }
  387. </style>