hbchen 5 miesięcy temu
rodzic
commit
b2484ad794

+ 58 - 10
src/api/http.js

@@ -1,6 +1,16 @@
 "use strict";
 import axios from "axios";
 import bus from "./bus.js";
+let store=null
+// 异步加载store模块 不异步加载的话,@/api/modules/oldApi.js的导入导出写法会有问题
+import('@/vuex/index.js')
+.then(module => {
+  store=module.default
+})
+.catch(err => {
+  console.error(err,'vuex加载错误');
+});
+
 axios.defaults.withCredentials = true;
 axios.defaults.timeout = 0;
 axios.interceptors.request.use(
@@ -43,16 +53,29 @@ function getData(val, url) {
   return val;
 }
 
-function checkStatus(response) {
+function errorMsgShow(closableErrMsg,msg){
+  if(closableErrMsg){
+    let messageHint = bus.$message.error({
+      message:msg,
+      duration:0,
+      showClose:true
+    })
+    store.mutations.PUSH_CLOSABLE_HINT(store.state,messageHint)
+  }else{
+    bus.$message.error(msg);
+  }
+}
+
+function checkStatus(response,closableErrMsg) {
   //处理响应数据
   if (response && response.status === 200) {
     // loading,如果http状态码正常,则直接返回数据
     let res = bus.$parseData(response);
     if (!res) {
-      bus.$message.error("服务器开了个小差");
+      errorMsgShow(closableErrMsg,'服务器开了个小差')
       return false;
     } else if (res.Ret == 403) {
-      bus.$message.error(res.Msg);
+      errorMsgShow(closableErrMsg,res.Msg)
     } else if (res.Ret === 408) {
       localStorage.setItem("auth", "")
       localStorage.setItem("loginTime", "")
@@ -66,14 +89,19 @@ function checkStatus(response) {
     }
     return res;
   } else {
-    bus.$message.error("网络异常");
+    errorMsgShow(closableErrMsg,'网络异常')
     return false;
   }
 }
 
-function checkCode(res) {
-  bus.$message.error("网络异常");
+function checkCode(res,closableErrMsg) {
+  errorMsgShow(closableErrMsg,'网络异常')
 }
+
+function isFormData(obj) {
+  return typeof obj === 'object' && obj instanceof FormData;
+}
+
 // 请求时间需要过长,取消限制
 const cancelTimeoutUrlPost = ["/cloud_disk/resource/upload"];
 
@@ -81,6 +109,16 @@ export default {
   post(url, data) {
     //post请求方式
     let timeout = cancelTimeoutUrlPost.includes(url) ? 0 : 600000;
+    // 自定义参数
+    /**
+     * closableErrMsg123 -- 错误提示需要时可关闭类型的
+     */
+    let closableErrMsg=false
+    if(data){
+      // 区分formData格式
+      closableErrMsg = isFormData(data)?!!data.get('closableErrMsg123'):!!data.closableErrMsg123
+      isFormData(data)?data.delete('closableErrMsg123'):(data.closableErrMsg123=undefined)
+    }
     return axios({
       method: "post",
       url: url,
@@ -90,13 +128,23 @@ export default {
       headers: { "Content-Type": "application/json; charset=utf-8" },
     })
       .then((response) => {
-        return checkStatus(response);
+        return checkStatus(response,closableErrMsg);
       })
       .catch((res) => {
-        return checkCode(res);
+        return checkCode(res,closableErrMsg);
       });
   },
   get(url, data, responseType = "json") {
+    // 自定义参数
+    /**
+     * closableErrMsg123 -- 错误提示需要时可关闭类型的
+     */
+    let closableErrMsg=false
+    if(data){
+      closableErrMsg = !!data.closableErrMsg123
+      data.closableErrMsg123=undefined
+    }
+
     //get请求方式
     return axios({
       method: "get",
@@ -123,10 +171,10 @@ export default {
         if(responseType==='blob'){
           return response
         }
-        return checkStatus(response);
+        return checkStatus(response,closableErrMsg);
       })
       .catch((res) => {
-        return checkCode(res);
+        return checkCode(res,closableErrMsg);
       });
   },
   Base64,

+ 10 - 0
src/styles/element-ui.scss

@@ -64,3 +64,13 @@ $--font-path: '~element-ui/lib/theme-chalk/fonts';
   max-height: 100vh;
   overflow-y: auto;
 }
+.el-message--error{
+  .el-message__closeBtn{
+    color: $danger-btn-color;
+  }
+}
+.el-message--success{
+  .el-message__closeBtn{
+    color: $--color-success;
+  }
+}

+ 56 - 13
src/views/datasheet_manage/customAnalysis/list.vue

@@ -245,6 +245,7 @@
                 ref="sheetRef"
                 v-if="sheetConfigOpt.data"
                 :option="sheetConfigOpt"
+                @updated="hasChange=true"
               />
             </div>
           </template>
@@ -427,6 +428,8 @@ export default {
       saveTime:"",
 
       isEdbReFreshLoading: false,//指标刷新
+      // 内容是否更新
+      hasChange:false,
     };
   },
   watch: {
@@ -443,6 +446,7 @@ export default {
       this.sheetAllcellData = [],//全部单元格数据 分页push
       this.dataToalPage = 0;
       this.sheetConfigOpt.data = null;
+      this.hasChange=false
       newval && this.getDetailHandle();
     },
 
@@ -677,7 +681,10 @@ export default {
       this.handleDownloadResource(url,filename)
     },
     /* 保存表格 */
-    saveHandle: _.debounce(async function () {
+    saveHandle: _.debounce(function () {
+      this.saveApi()
+    }, 300),
+    async saveApi(){
       luckysheet.exitEditMode();
       let data = luckysheet.getAllSheets();
 
@@ -692,6 +699,7 @@ export default {
       let img = getSheetImage(data[0]);
       const form = new FormData();
       form.append("Image", img);
+      form.append("closableErrMsg123", true);
       const { Data } = await sheetInterface.uploadImg(form);
 
       data.luckysheet_select_save = [];
@@ -703,14 +711,16 @@ export default {
         ExcelClassifyId,
         ExcelImage: Data.ResourceUrl,
         Content: JSON.stringify(data),
+        closableErrMsg123:true
       });
       this.loading.close();
-      if (res.Ret !== 200) return;
+      if (res.Ret !== 200) return false;
+      this.hasChange=false
       this.saveTime = this.$moment().format('YYYY-MM-DD HH:mm:ss')
-      this.$message.success(this.$t('MsgPrompt.saved_msg'));
+      this.shouldClosedHintshow(this.$t('MsgPrompt.saved_msg'))
       this.getTreeData();
-    }, 300),
-
+      return true
+    },
     /* 获取表格列表 */
     getPublicList() {
       sheetInterface
@@ -854,15 +864,31 @@ export default {
     },
 
     /* 刷新表格 */
-    refreshSheet: _.debounce(async function() {
+    refreshSheet: _.debounce(function() {
       if(this.isEdbReFreshLoading) return
-      
-      this.isEdbReFreshLoading = true;
-      let res = await sheetInterface.sheetAnalysisInterface.sheetRefresh({ExcelInfoId: this.sheetDetailInfo.ExcelInfoId})
+      //退出编辑模式,让文本框失焦 
+      luckysheet.exitEditMode();
+      // 保存逻辑延后 让hasChange取得正确的值
+      setTimeout(async()=>{
+        this.isEdbReFreshLoading = true;
+        let res={}
+        // 内容有改变 刷新前需要先保存
+        if(this.hasChange){
+          let saveSuccess = await this.saveApi()
+          if(!saveSuccess){
+            // 没保存成功
+            this.isEdbReFreshLoading = false;
+            return
+          }
+          res = await sheetInterface.sheetAnalysisInterface.sheetRefresh({ExcelInfoId: this.sheetDetailInfo.ExcelInfoId,closableErrMsg123:true})
+        }else{
+          res = await sheetInterface.sheetAnalysisInterface.sheetRefresh({ExcelInfoId: this.sheetDetailInfo.ExcelInfoId,closableErrMsg123:true})
+        }
 
-      this.isEdbReFreshLoading = false;
-      if(res.Ret !== 200) return 
-      this.$message.success(res.Msg)
+        this.isEdbReFreshLoading = false;
+        if(res.Ret !== 200) return 
+        this.shouldClosedHintshow(res.Msg)
+      })
     },300),
 
     /* 重绘右侧区域宽度 */
@@ -899,7 +925,22 @@ export default {
         code: this.sheetDetailInfo.UniqueCode 
       }});
     },
-
+    shouldClosedHintshow(msg){
+      let messageHint=this.$message.success({
+        message:msg,
+        duration:0,
+        showClose:true
+      })
+      this.$store.commit('PUSH_CLOSABLE_HINT',messageHint)
+    },
+    closeHint(){
+      // console.log(this.$store.state.closableHints,'closableHints');
+      if(!(this.$store.state.closableHints && this.$store.state.closableHints.length>0)) return 
+      this.$store.state.closableHints.map(hint =>{
+        hint.close()
+      })
+      this.$store.commit('CLEAR_CLOSABLE_HINT')
+    }
   },
   mounted() {
     if (this.$route.query.code) {
@@ -913,9 +954,11 @@ export default {
     }
 
     window.addEventListener("resize", this.reloadRightWid);
+    document.addEventListener("click", this.closeHint);
   },
   destroyed() {
     window.removeEventListener("resize", this.reloadRightWid);
+    document.removeEventListener("click", this.closeHint);
   },
 };
 </script>

+ 1 - 1
src/vuex/index.js

@@ -34,8 +34,8 @@ const state = {
   hasTrialUserPermisson:false,
   permissionRoute:[], //用于需要验证是否有某个菜单的权限
   baseInfo:{},
-
   lang: localStorage.getItem('i18n') || 'zh',//全局语言版本 zh en
+  closableHints:[], //可关闭的信息提示
 };
 
 export default {

+ 9 - 2
src/vuex/mutations.js

@@ -81,10 +81,17 @@ const mutations = {
   SET_BASE_INFO(state,obj) {
     state.baseInfo={...state.baseInfo,...obj};
   },
-
   SET_LANG(state,lang) {
     state.lang = lang;
-  }
+  },
+  //添加可关闭的信息提示
+  PUSH_CLOSABLE_HINT(state,hintObj) {
+    state.closableHints.push(hintObj)
+  },
+  //清空可关闭的信息提示
+  CLEAR_CLOSABLE_HINT(state) {
+    state.closableHints=[]
+  },
 };
 
 export default mutations;