AppUpgrade.vue 2.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788
  1. <template>
  2. <div>
  3. <el-upload
  4. ref="fileUpload"
  5. :show-file-list="true"
  6. :file-list="fileList"
  7. :limit="limit"
  8. :headers="upload.headers"
  9. :action="upload.url"
  10. :before-upload="handleBeforeUpload"
  11. :on-error="handleUploadError"
  12. :on-exceed="handleExceed"
  13. :on-success="handleUploadSuccess"
  14. :on-progress="handleFileUploadProgress"
  15. :on-remove="handleDelete"
  16. accept=".apk, .ipa"
  17. >
  18. <el-button icon="el-icon-upload" :loading="upload.isUploading" :disabled="upload.isUploading">{{ name }}</el-button>
  19. <div class="el-upload__tip" style="margin-top: 0px; margin-bottom: -10px" slot="tip">只能上传.apk, .ipa文件,且不超过200M</div>
  20. </el-upload>
  21. </div>
  22. </template>
  23. <script>
  24. import { getToken } from '@/utils/auth';
  25. export default {
  26. props: {
  27. value: {
  28. type: Object
  29. },
  30. limit: {
  31. type: Number,
  32. default: 1
  33. },
  34. name: {
  35. type: String,
  36. default: '上传安装包'
  37. }
  38. },
  39. data() {
  40. return {
  41. baseUrl: process.env.VUE_APP_BASE_API,
  42. open: false,
  43. fileList: [],
  44. upload: {
  45. headers: { Authorization: 'Bearer ' + getToken() },
  46. url: process.env.VUE_APP_BASE_API + '/work/upgrade/upload',
  47. isUploading: false
  48. }
  49. };
  50. },
  51. methods: {
  52. // 上传前校检格式和大小
  53. handleBeforeUpload(file) {
  54. this.upload.isUploading = true;
  55. return true;
  56. },
  57. // 文件个数超出
  58. handleExceed() {
  59. this.$modal.msgError('上传文件数量不能超过' + this.limit + '个');
  60. },
  61. // 上传失败
  62. handleUploadError(err) {
  63. this.$modal.msgError('上传失败,请重试');
  64. this.upload.isUploading = false;
  65. },
  66. // 上传成功回调
  67. handleUploadSuccess(res, file) {
  68. this.upload.isUploading = false;
  69. if (res.code === 200) {
  70. this.$emit('input', res.data);
  71. this.$modal.msgSuccess('上传成功');
  72. } else {
  73. this.$modal.msgError(res.msg);
  74. this.$refs.fileUpload.handleRemove(file);
  75. }
  76. },
  77. // 文件上传中处理
  78. handleFileUploadProgress(event, file, fileList) {
  79. this.upload.isUploading = true;
  80. },
  81. // 删除文件
  82. handleDelete(file, fileList) {
  83. this.$emit('input', fileList);
  84. }
  85. }
  86. };
  87. </script>