123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148 |
- <template>
- <div class="upload_box">
- <el-button :disabled="existence" type="text" @click="upload"><i class="el-dropdown-link el-icon-download"></i>{{ typeName || '文件导出' }}</el-button>
- <el-dialog :close-on-click-modal="false" :title="typeName" :visible.sync="dialogVisible" width="400px" @close="closes">
- <div>
- <el-input size="small" v-model="fileName" placeholder="请选输入导出文件名"></el-input>
- <div style="margin: 30px 0;"></div>
- </div>
- <span slot="footer" class="dialog-footer">
- <el-button size="small" @click="dialogVisible = false">取 消</el-button>
- <el-button size="small" type="primary" @click="uploadFile">确 定</el-button>
- </span>
- </el-dialog>
- <el-dialog :close-on-click-modal="false" :title="successDate ? '数据导出进度' : '数据导出结果'" :visible.sync="progress" width="400px">
- <!-- 显示进度 -->
- <div v-if="successDate">
- <h3>{{ typeName }}</h3>
- <div style="margin: 30px 0;"></div>
- <el-progress :percentage="percentage"></el-progress>
- <div style="margin: 30px 0;"></div>
- </div>
- <!-- 显示成功后信息下载日志 -->
- <div v-else>
- <h3 class="success">{{ summary }}</h3>
- <div style="margin: 30px 0;"></div>
- <span slot="footer" class="dialog-footer">
- <el-button type="text" @click="btn">导出文件下载</el-button>
- </span>
- </div>
- </el-dialog>
- </div>
- </template>
- <script>
- import { mapActions } from 'vuex';
- export default {
- props: {
- // 数据导入类型 (user,vip)
- type: String,
- // 业务名称
- typeName: { type: String, default: '' }
- },
- data() {
- return {
- // 下载文件类型
- fileType: 'excel',
- // 选择信息弹出
- dialogVisible: false,
- // 按钮禁用
- existence: false,
- // 进度
- percentage: 0,
- // 上传前选择
- option: 'overwrite',
- // 进度弹出
- progress: false,
- // 成功后切换
- successDate: true,
- // 成功后文字
- summary: null,
- // 任务id
- id: null,
- // 导入模板命名
- fileName: null,
- // 文件流
- file: null
- };
- },
- methods: {
- ...mapActions(['exports', 'progressInfo']),
- // 点击上传按钮
- upload() {
- this.dialogVisible = true;
- },
- // 确定
- async uploadFile() {
- this.dialogVisible = false;
- this.summary = null;
- const res = await this.exports({ type: this.type, fileType: this.fileType });
- if (res && !res.errcode) {
- this.progress = true;
- this.timeout(res.taskId);
- } else {
- this.$message.error(res.errmsg);
- }
- },
- timeout(res) {
- const Interval = setTimeout(async () => {
- const info = await this.progressInfo({ taskId: res });
- console.log(info);
- if (info && info.status !== 'error') {
- this.percentage = info.progress || 0;
- if (info.progress == 100) {
- this.id = info.taskId;
- this.successDate = false;
- this.summary = '导出成功';
- clearInterval(Interval);
- this.$emit('refreshData');
- this.percentage = 0;
- } else {
- this.timeout(info.taskId);
- }
- } else {
- clearInterval(Interval);
- this.$message.error(info?.errmsg || '错误');
- }
- }, 1000);
- },
- // 详情下载
- async btn() {
- window.open(`/api/importandexport/handle/exportsDownload?fileName=${this.typeName}&taskId=${this.id}`);
- },
- // 关闭窗口
- closes() {
- this.successDate = true;
- this.file = null;
- this.fileName = null;
- this.$emit('closes');
- }
- }
- };
- </script>
- <style lang="scss" scoped>
- input {
- display: none;
- }
- .el-button--text {
- padding: 0;
- }
- .upload_box {
- line-height: 0;
- }
- .success {
- width: 100%;
- color: #67c23a;
- }
- .error {
- width: 100%;
- color: #f56c6c;
- }
- .jump {
- width: 100%;
- color: #e6a23c;
- }
- .left-footer {
- float: left;
- margin-top: 10px;
- }
- </style>
|