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

373 lines
13 KiB

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