exports.vue 4.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148
  1. <template>
  2. <div class="upload_box">
  3. <el-button :disabled="existence" type="text" @click="upload"><i class="el-dropdown-link el-icon-download"></i>{{ typeName || '文件导出' }}</el-button>
  4. <el-dialog :close-on-click-modal="false" :title="typeName" :visible.sync="dialogVisible" width="400px" @close="closes">
  5. <div>
  6. <el-input size="small" v-model="fileName" placeholder="请选输入导出文件名"></el-input>
  7. <div style="margin: 30px 0;"></div>
  8. </div>
  9. <span slot="footer" class="dialog-footer">
  10. <el-button size="small" @click="dialogVisible = false">取 消</el-button>
  11. <el-button size="small" type="primary" @click="uploadFile">确 定</el-button>
  12. </span>
  13. </el-dialog>
  14. <el-dialog :close-on-click-modal="false" :title="successDate ? '数据导出进度' : '数据导出结果'" :visible.sync="progress" width="400px">
  15. <!-- 显示进度 -->
  16. <div v-if="successDate">
  17. <h3>{{ typeName }}</h3>
  18. <div style="margin: 30px 0;"></div>
  19. <el-progress :percentage="percentage"></el-progress>
  20. <div style="margin: 30px 0;"></div>
  21. </div>
  22. <!-- 显示成功后信息下载日志 -->
  23. <div v-else>
  24. <h3 class="success">{{ summary }}</h3>
  25. <div style="margin: 30px 0;"></div>
  26. <span slot="footer" class="dialog-footer">
  27. <el-button type="text" @click="btn">导出文件下载</el-button>
  28. </span>
  29. </div>
  30. </el-dialog>
  31. </div>
  32. </template>
  33. <script>
  34. import { mapActions } from 'vuex';
  35. export default {
  36. props: {
  37. // 数据导入类型 (user,vip)
  38. type: String,
  39. // 业务名称
  40. typeName: { type: String, default: '' }
  41. },
  42. data() {
  43. return {
  44. // 下载文件类型
  45. fileType: 'excel',
  46. // 选择信息弹出
  47. dialogVisible: false,
  48. // 按钮禁用
  49. existence: false,
  50. // 进度
  51. percentage: 0,
  52. // 上传前选择
  53. option: 'overwrite',
  54. // 进度弹出
  55. progress: false,
  56. // 成功后切换
  57. successDate: true,
  58. // 成功后文字
  59. summary: null,
  60. // 任务id
  61. id: null,
  62. // 导入模板命名
  63. fileName: null,
  64. // 文件流
  65. file: null
  66. };
  67. },
  68. methods: {
  69. ...mapActions(['exports', 'progressInfo']),
  70. // 点击上传按钮
  71. upload() {
  72. this.dialogVisible = true;
  73. },
  74. // 确定
  75. async uploadFile() {
  76. this.dialogVisible = false;
  77. this.summary = null;
  78. const res = await this.exports({ type: this.type, fileType: this.fileType });
  79. if (res && !res.errcode) {
  80. this.progress = true;
  81. this.timeout(res.taskId);
  82. } else {
  83. this.$message.error(res.errmsg);
  84. }
  85. },
  86. timeout(res) {
  87. const Interval = setTimeout(async () => {
  88. const info = await this.progressInfo({ taskId: res });
  89. console.log(info);
  90. if (info && info.status !== 'error') {
  91. this.percentage = info.progress || 0;
  92. if (info.progress == 100) {
  93. this.id = info.taskId;
  94. this.successDate = false;
  95. this.summary = '导出成功';
  96. clearInterval(Interval);
  97. this.$emit('refreshData');
  98. this.percentage = 0;
  99. } else {
  100. this.timeout(info.taskId);
  101. }
  102. } else {
  103. clearInterval(Interval);
  104. this.$message.error(info?.errmsg || '错误');
  105. }
  106. }, 1000);
  107. },
  108. // 详情下载
  109. async btn() {
  110. window.open(`/api/importandexport/handle/exportsDownload?fileName=${this.typeName}&taskId=${this.id}`);
  111. },
  112. // 关闭窗口
  113. closes() {
  114. this.successDate = true;
  115. this.file = null;
  116. this.fileName = null;
  117. this.$emit('closes');
  118. }
  119. }
  120. };
  121. </script>
  122. <style lang="scss" scoped>
  123. input {
  124. display: none;
  125. }
  126. .el-button--text {
  127. padding: 0;
  128. }
  129. .upload_box {
  130. line-height: 0;
  131. }
  132. .success {
  133. width: 100%;
  134. color: #67c23a;
  135. }
  136. .error {
  137. width: 100%;
  138. color: #f56c6c;
  139. }
  140. .jump {
  141. width: 100%;
  142. color: #e6a23c;
  143. }
  144. .left-footer {
  145. float: left;
  146. margin-top: 10px;
  147. }
  148. </style>