Browse Source

架构优化更新,请求添加遮罩功能,全局遮罩功能

yangbo 4 years ago
parent
commit
058f25cde6
3 changed files with 29 additions and 5 deletions
  1. 3 2
      eccs-ui/src/api/mall/mallshopmng.js
  2. 9 1
      eccs-ui/src/main.js
  3. 17 2
      eccs-ui/src/utils/request.js

+ 3 - 2
eccs-ui/src/api/mall/mallshopmng.js

@@ -52,12 +52,13 @@ export function exportMallshopmng(query) {
   })
 }
 
-pullKmallStoreInvemng
 // 拉取kmall的所有商品数据
 export function pullKmallStoreInvemng(query) {
   return request({
     url: '/biz/mallshopmng/pullKmallStoreInveMng',
     method: 'POST',
-    params: query
+    params: query,
+    timeout: 3600 * 1000,
+    loading: document.body
   })
 }

+ 9 - 1
eccs-ui/src/main.js

@@ -35,6 +35,14 @@ Vue.prototype.selectDictLabels = selectDictLabels
 Vue.prototype.download = download
 Vue.prototype.handleTree = handleTree
 
+Vue.prototype.fullLoading = function (msg) {
+  this.$loading({ lock: true, text: msg || "加载中...", spinner: 'el-icon-loading', background: 'rgba(0, 0, 0, 0.7)' });
+}
+
+Vue.prototype.tabLoading = function (target, msg) {
+  this.$loading({ lock: true, target: target || document.body, text: msg || "加载中...", spinner: 'el-icon-loading', background: 'rgba(0, 0, 0, 0.7)' });
+}
+
 Vue.prototype.msgSuccess = function (msg) {
   this.$message({ showClose: true, message: msg, type: "success" });
 }
@@ -46,7 +54,7 @@ Vue.prototype.msgError = function (msg) {
 Vue.prototype.msgInfo = function (msg) {
   this.$message.info(msg);
 }
-
+export let a = { lock: true, text:  "加载中...", spinner: 'el-icon-loading', background: 'rgba(0, 0, 0, 0.7)' }
 // 全局组件挂载
 Vue.component('Pagination', Pagination)
 Vue.component('RightToolbar', RightToolbar)

+ 17 - 2
eccs-ui/src/utils/request.js

@@ -1,16 +1,19 @@
 import axios from 'axios'
-import { Notification, MessageBox, Message } from 'element-ui'
+import { Notification, MessageBox, Message, Loading } from 'element-ui'
 import store from '@/store'
 import { getToken } from '@/utils/auth'
 import errorCode from '@/utils/errorCode'
 
 axios.defaults.headers['Content-Type'] = 'application/json;charset=utf-8'
+
+let loadingInstance = undefined;
+
 // 创建axios实例
 const service = axios.create({
   // axios中请求配置有baseURL选项,表示请求URL公共部分
   baseURL: process.env.VUE_APP_BASE_API,
   // 超时
-  timeout: 36000 * 1000
+  timeout: 10000
 })
 // request拦截器
 service.interceptors.request.use(config => {
@@ -41,6 +44,12 @@ service.interceptors.request.use(config => {
     config.params = {};
     config.url = url;
   }
+  if (config["loading"]) {
+    if (loadingInstance) {
+      loadingInstance.close();
+    }
+    loadingInstance = Loading.service({ lock: true, target: config["loading"], text: "处理中...", spinner: 'el-icon-loading', background: 'rgba(0, 0, 0, 0.7)' })
+  }
   return config
 }, error => {
     console.log(error)
@@ -49,6 +58,9 @@ service.interceptors.request.use(config => {
 
 // 响应拦截器
 service.interceptors.response.use(res => {
+    if (loadingInstance) {
+      loadingInstance.close();
+    }
     // 未设置状态码则默认成功状态
     const code = res.data.code || 200;
     // 获取错误信息
@@ -80,6 +92,9 @@ service.interceptors.response.use(res => {
     }
   },
   error => {
+    if (loadingInstance) {
+      loadingInstance.close();
+    }
     console.log('err' + error)
     let { message } = error;
     if (message == "Network Error") {