index.vue 2.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116
  1. <script>
  2. import { getToken } from "@/utils/auth";
  3. import { IMPORTTEMPLATE } from "@/api/business/purchase/contract";
  4. export default {
  5. name: "ImportDialog",
  6. data() {
  7. return {
  8. visible: false,
  9. upload: {
  10. // 是否禁用上传
  11. isUploading: false,
  12. // 是否更新已经存在的用户数据
  13. updateSupport: 0,
  14. // 设置上传的请求头部
  15. headers: {
  16. Authorization: "Bearer " + getToken(),
  17. },
  18. // 上传的地址
  19. url: "/drp-file/document-center/fastdfs/upload",
  20. },
  21. };
  22. },
  23. computed: {},
  24. watch: {},
  25. methods: {
  26. //
  27. open(prop) {
  28. this.visible = true;
  29. },
  30. //
  31. hide() {
  32. this.visible = false;
  33. },
  34. //
  35. async importTemplate() {
  36. try {
  37. const { msg, code } = await IMPORTTEMPLATE();
  38. if (code === 200) {
  39. this.download(msg, {});
  40. }
  41. } catch (err) {
  42. // catch
  43. console.error(err);
  44. } finally {
  45. // finally
  46. }
  47. },
  48. // 文件上传中处理
  49. progress(event, file, fileList) {
  50. console.log(event, file, fileList);
  51. this.upload.isUploading = true;
  52. },
  53. // 文件上传成功处理
  54. success(response, file, fileList) {
  55. const { message: msg } = response;
  56. this.upload.open = false;
  57. this.upload.isUploading = false;
  58. this.$refs.upload.clearFiles();
  59. this.$alert(msg, "导入结果", {
  60. dangerouslyUseHTMLString: true,
  61. });
  62. this.getList();
  63. },
  64. //
  65. confirm() {
  66. this.$refs.upload.submit();
  67. },
  68. },
  69. created() {},
  70. mounted() {},
  71. destroyed() {},
  72. };
  73. </script>
  74. <template>
  75. <el-dialog title="导入" width="fit-content" :visible.sync="visible">
  76. <el-upload
  77. ref="upload"
  78. :limit="1"
  79. accept=".xlsx, .xls"
  80. :headers="upload.headers"
  81. :action="upload.url + '?updateSupport=' + upload.updateSupport"
  82. :disabled="upload.isUploading"
  83. :on-progress="progress"
  84. :on-success="success"
  85. :auto-upload="false"
  86. drag
  87. >
  88. <i class="el-icon-upload"></i>
  89. <div class="el-upload__text">
  90. 将文件拖到此处,或
  91. <em>点击上传</em>
  92. </div>
  93. <div
  94. class="el-upload__tip"
  95. slot="tip"
  96. style="display: flex; align-items: center"
  97. >
  98. <el-checkbox v-model="upload.updateSupport" />是否更新已经存在的用户数据
  99. <el-link
  100. type="info"
  101. style="font-size: 12px; margin-left: 10px"
  102. @click="importTemplate"
  103. >
  104. 下载模板
  105. </el-link>
  106. </div>
  107. <div class="el-upload__tip" style="color: red" slot="tip">
  108. 提示:仅允许导入“xls”或“xlsx”格式文件!
  109. </div>
  110. </el-upload>
  111. <div slot="footer" class="dialog-footer">
  112. <el-button type="primary" @click="confirm">确 定</el-button>
  113. <el-button @click="hide">取 消</el-button>
  114. </div>
  115. </el-dialog>
  116. </template>