From aad94b236ee3d6996cc3cfe1bfd6334a0c3557e9 Mon Sep 17 00:00:00 2001 From: RuoYi <yzz_ivy@163.com> Date: 星期一, 19 九月 2022 13:22:52 +0800 Subject: [PATCH] 通用下载方法新增config配置选项 --- src/utils/request.js | 24 +++++++++++------------- 1 files changed, 11 insertions(+), 13 deletions(-) diff --git a/src/utils/request.js b/src/utils/request.js index 46b55b2..b0a528f 100644 --- a/src/utils/request.js +++ b/src/utils/request.js @@ -1,15 +1,15 @@ import axios from 'axios' import { ElNotification , ElMessageBox, ElMessage, ElLoading } from 'element-plus' -import store from '@/store' import { getToken } from '@/utils/auth' import errorCode from '@/utils/errorCode' import { tansParams, blobValidate } from '@/utils/ruoyi' import cache from '@/plugins/cache' import { saveAs } from 'file-saver' +import useUserStore from '@/store/modules/user' let downloadLoadingInstance; // 鏄惁鏄剧ず閲嶆柊鐧诲綍 -let isReloginShow; +export let isRelogin = { show: false }; axios.defaults.headers['Content-Type'] = 'application/json;charset=utf-8' // 鍒涘缓axios瀹炰緥 @@ -76,23 +76,20 @@ return res.data } if (code === 401) { - if (!isReloginShow) { - isReloginShow = true; + if (!isRelogin.show) { + isRelogin.show = true; ElMessageBox.confirm('鐧诲綍鐘舵�佸凡杩囨湡锛屾偍鍙互缁х画鐣欏湪璇ラ〉闈紝鎴栬�呴噸鏂扮櫥褰�', '绯荤粺鎻愮ず', { confirmButtonText: '閲嶆柊鐧诲綍', cancelButtonText: '鍙栨秷', type: 'warning' } ).then(() => { - isReloginShow = false; - store.dispatch('LogOut').then(() => { - // 濡傛灉鏄櫥褰曢〉闈笉闇�瑕侀噸鏂板姞杞� - if (window.location.hash.indexOf("#/login") != 0) { - location.href = '/index'; - } + isRelogin.show = false; + useUserStore().logOut().then(() => { + location.href = '/index'; }) }).catch(() => { - isReloginShow = false; + isRelogin.show = false; }); } return Promise.reject('鏃犳晥鐨勪細璇濓紝鎴栬�呬細璇濆凡杩囨湡锛岃閲嶆柊鐧诲綍銆�') @@ -133,12 +130,13 @@ ) // 閫氱敤涓嬭浇鏂规硶 -export function download(url, params, filename) { +export function download(url, params, filename, config) { downloadLoadingInstance = ElLoading.service({ text: "姝e湪涓嬭浇鏁版嵁锛岃绋嶅��", background: "rgba(0, 0, 0, 0.7)", }) return service.post(url, params, { transformRequest: [(params) => { return tansParams(params) }], headers: { 'Content-Type': 'application/x-www-form-urlencoded' }, - responseType: 'blob' + responseType: 'blob', + ...config }).then(async (data) => { const isLogin = await blobValidate(data); if (isLogin) { -- Gitblit v1.9.3