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

327 lines
9.7 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
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
2 years ago
2 years ago
2 years ago
  1. <template>
  2. <div>
  3. <!-- 原文上传 -->
  4. <el-dialog class="fileUpload-dialog" :title="uploadTitle" :close-on-click-modal="false" :modal-append-to-body="false" append-to-body :visible.sync="uploadVisible">
  5. <div class="setting-dialog">
  6. <div class="upload-container">
  7. <i v-if="uploadType !== 1 && fileList.length === 0" class="iconfont icon-tianjiawenjian upload-icon" />
  8. <div v-for="item in fileList" :key="item.name" class="file-list">
  9. <i class="iconfont icon-xiaowenjian" />
  10. {{ item.name }}
  11. <i class="el-icon-close" @click="deleteFile(item)" />
  12. </div>
  13. <div v-if="uploadType !== 1" class="upload-input">
  14. <input ref="fileInput" :key="key" type="file" :multiple="isMultiple" :accept="uploadType === 2 ? '.zip' :''" @change="handleFileChange">
  15. <div class="upload-zip"><i class="iconfont icon-shangchuan2" />点击上传</div>
  16. </div>
  17. <BigUpload v-else-if="uploadType === 1" :selected-category="selectedCategory" :arc-id="arcId" />
  18. <div v-if="uploadType === 2" class="el-upload__tip">上传限制文件类型zip</div>
  19. </div>
  20. <div slot="footer" class="dialog-footer">
  21. <el-button type="text" @click="uploadVisible = false">取消</el-button>
  22. <el-button type="primary" @click="handleUploadConfirm">保存</el-button>
  23. </div>
  24. </div>
  25. </el-dialog>
  26. <!-- 上传详情 -->
  27. <el-dialog class="collectUpload-dialog" :title="detailUploadTitle" :close-on-click-modal="false" :modal-append-to-body="false" append-to-body :visible.sync="uploadDetialVisible">
  28. <div class="setting-dialog">
  29. <div class="upload-detail">
  30. <el-table :data="uploadDetailData" style="width: 100%">
  31. <el-table-column prop="number" label="编号" width="120" />
  32. <el-table-column prop="operator" label="操作人" width="120" />
  33. <el-table-column prop="operationType" label="操作类型" width="120" />
  34. <el-table-column prop="file" label="文件" width="160" />
  35. <el-table-column prop="createDate" label="操作时间" width="200" />
  36. <el-table-column prop="conclusion" label="结论" width="200">
  37. <template slot-scope="scope">
  38. <div>成功 {{ scope.row.successNumber }} ; 失败 {{ scope.row.failNumber }} </div>
  39. </template>
  40. </el-table-column>
  41. </el-table>
  42. <!--分页组件-->
  43. <el-pagination
  44. :current-page="page.page"
  45. :total="page.total"
  46. :page-size="page.size"
  47. :pager-count="5"
  48. layout="total, prev, pager, next, sizes"
  49. @size-change="handleSizeChange"
  50. @current-change="handleCurrentPage"
  51. />
  52. </div>
  53. </div>
  54. </el-dialog>
  55. </div>
  56. </template>
  57. <script>
  58. // import { FetchAddArchivesFile } from '@/api/collect/collect'
  59. import { getCurrentTime } from '@/utils/index'
  60. import { upload, archivesUpload } from '@/utils/upload'
  61. import { mapGetters } from 'vuex'
  62. export default {
  63. name: 'UploadOriginal',
  64. components: { },
  65. props: {
  66. selectedCategory: {
  67. type: Object,
  68. default: function() {
  69. return {}
  70. }
  71. },
  72. arcId: {
  73. type: String,
  74. default: function() {
  75. return ''
  76. }
  77. }
  78. },
  79. data() {
  80. return {
  81. uploadVisible: false,
  82. uploadTitle: '普通上传',
  83. detailUploadTitle: '上传详情',
  84. key: 0,
  85. file: null, // 附件 change
  86. fileNames: '', // 附件 - name
  87. formatType: '', // 附件 - type
  88. postfix: '', // 附件 - 文件后缀
  89. fileSize: '', // 附件 - 大小
  90. filePath: [], // 附件 - path
  91. px: '', // 附件 - 分辨率
  92. nowDate: '', // 当前时间
  93. fileList: [],
  94. uploadType: 0,
  95. // 上传详情
  96. uploadDetialVisible: false,
  97. uploadDetailData: [],
  98. page: {
  99. page: 1,
  100. size: 10,
  101. total: 0
  102. }
  103. }
  104. },
  105. computed: {
  106. ...mapGetters([
  107. 'baseApi'
  108. ]),
  109. isMultiple() {
  110. return this.uploadType === 0
  111. }
  112. },
  113. created() {
  114. },
  115. mounted() {
  116. },
  117. methods: {
  118. handleFileChange(e) {
  119. const files = e.target.files
  120. this.file = files[0]
  121. this.key++
  122. const maxMessage = '上传文件大小不能超过 10MB,可使用大文件上传!'
  123. const maxSize = 10 * 1024 * 1024
  124. if (this.file && this.file.size > maxSize) {
  125. this.$message.warning(maxMessage)
  126. this.fileList = []
  127. e.target.value = ''
  128. return false
  129. }
  130. if (this.fileList.length !== 0) {
  131. const existingFile = this.fileList.some(file => file.name === this.file.name)
  132. if (existingFile) {
  133. this.$message.warning('文件已存在')
  134. return false
  135. }
  136. }
  137. for (let i = 0; i < files.length; i++) {
  138. if (this.uploadType === 2) {
  139. this.fileList = []
  140. this.fileList.push(files[i])
  141. } else {
  142. this.fileList.push(files[i])
  143. }
  144. }
  145. },
  146. handleUploadConfirm() {
  147. if (this.fileList.length === 0) {
  148. this.$message.info('请先选择相关文件!')
  149. return false
  150. }
  151. if (this.uploadType === 2) {
  152. // 原文目录上传
  153. upload(this.baseApi + '/api/collect/catalogUpload',
  154. this.fileList[0]
  155. ).then(res => {
  156. if (res.data.code === 200) {
  157. this.$message.success('成功追加' + res.data.data + '附件')
  158. this.$emit('close-dialog')
  159. this.uploadVisible = false
  160. } else {
  161. this.$message.error('上传附件失败!')
  162. }
  163. })
  164. } else {
  165. this.uplaodToList(this.fileList)
  166. }
  167. },
  168. uplaodToList(files) {
  169. // 原文上传
  170. this.nowDate = getCurrentTime()
  171. const promiseArray = files.map(async(item, index) => {
  172. const json = {}
  173. if (item.type.substring(0, item.type.indexOf('/')) === 'image') {
  174. const fileBase64 = await this.getBase64(item)
  175. const imgRes = await this.getImgPx(fileBase64)
  176. item.px = imgRes.width + 'px*' + imgRes.height + 'px'
  177. } else {
  178. item.px = ''
  179. }
  180. json.file_name = item.name
  181. json.file_size = item.size
  182. json.file_type = item.name.substring(item.name.lastIndexOf('.') + 1, item.name.length)
  183. // json.file_path = this.filePath[index].path
  184. json.file_path = ''
  185. json.sequence = null
  186. json.archive_id = this.arcId
  187. json.file_dpi = item.px
  188. json.file_thumbnail = ''
  189. json.create_time = this.nowDate
  190. json.id = null
  191. return json
  192. })
  193. Promise.all(promiseArray)
  194. .then((arrayUpload) => {
  195. // 上传附件
  196. archivesUpload(this.baseApi + '/api/collect/uploadFiles',
  197. files,
  198. this.selectedCategory.id,
  199. this.arcId,
  200. JSON.stringify(arrayUpload)
  201. ).then(res => {
  202. if (res.data.code === 200) {
  203. this.$message.success(res.data.data)
  204. this.$emit('close-dialog')
  205. this.uploadVisible = false
  206. } else {
  207. this.$message.error('上传附件失败!')
  208. }
  209. })
  210. })
  211. .catch((error) => {
  212. console.error(error)
  213. })
  214. },
  215. // 附件旁边的X
  216. deleteFile(file) {
  217. const index = this.fileList.indexOf(file)
  218. this.fileList.splice(index, 1)
  219. if (this.fileList.length !== 0) {
  220. archivesUpload(this.baseApi + '/api/collect/uploadFiles', this.fileList, this.selectedCategory.id).then(res => {
  221. if (res.data.code === 200) {
  222. this.filePath = res.data.data
  223. }
  224. })
  225. } else {
  226. this.$message.info('已清空所有要上传的附件!')
  227. }
  228. },
  229. // 将上传的图片转为base64
  230. getBase64(file) {
  231. const reader = new FileReader()
  232. reader.readAsDataURL(file)
  233. return new Promise((resolve) => {
  234. reader.onload = () => {
  235. resolve(reader.result)
  236. }
  237. })
  238. },
  239. // 获取图片的分辨率
  240. getImgPx(img) {
  241. const image = new Image()
  242. image.src = img
  243. return new Promise((resolve) => {
  244. image.onload = () => {
  245. const width = image.width
  246. const height = image.height
  247. resolve({ width, height })
  248. }
  249. })
  250. },
  251. handleSizeChange(size) {
  252. this.page.size = size
  253. this.page.page = 1
  254. },
  255. handleCurrentPage(val) {
  256. this.page.page = val
  257. }
  258. }
  259. }
  260. </script>
  261. <style lang='scss' scoped>
  262. .upload-container{
  263. display: flex;
  264. flex-direction: column;
  265. align-items: center;
  266. justify-content: center;
  267. width: 496px;
  268. min-height: 178px;
  269. padding: 12px;
  270. border-radius: 3px;
  271. background: #EDEFF3;
  272. border: 1px dashed #BCC2C7;
  273. .upload-icon{
  274. font-size: 32px;
  275. color: #1F55EB;
  276. }
  277. .el-upload__tip{
  278. font-size: 12px;
  279. color: #A6ADB6;
  280. }
  281. .file-list{
  282. font-size: 12px;
  283. line-height: 24px;
  284. color: #545B65;
  285. }
  286. }
  287. .upload-input{
  288. position: relative;
  289. margin-top: 16px;
  290. width: 104px;
  291. height: 32px;
  292. & input{
  293. position: absolute;
  294. left: 0;
  295. top: 0;
  296. height: 32px;
  297. opacity: 0;
  298. }
  299. }
  300. .upload-zip{
  301. width: 104px;
  302. height: 32px;
  303. line-height: 32px;
  304. font-size: 14px;
  305. color: #fff;
  306. text-align: center;
  307. border-radius: 3px;
  308. background: #1F55EB;
  309. & i{
  310. font-size: 13px;
  311. }
  312. }
  313. .collectUpload-dialog{
  314. ::v-deep .el-dialog{
  315. width: 970px;
  316. }
  317. }
  318. </style>