Prechádzať zdrojové kódy

修改头部为请求接口及图标

秦鹏 3 rokov pred
rodič
commit
ad3f9f4954
4 zmenil súbory, kde vykonal 279 pridanie a 263 odobranie
  1. 156 147
      src/api/api.js
  2. 37 37
      src/components/Header.vue
  3. 81 77
      src/utils/request.js
  4. 5 2
      src/views/login.vue

+ 156 - 147
src/api/api.js

@@ -3,206 +3,215 @@ import Cookies from "js-cookie";
 import { getToken } from "@/utils/auth"
 let userInfor = getToken()
 let UserCode = '',
-  UserType = '',
-  SessionID = ''
+    UserType = '',
+    SessionID = ''
 if (userInfor) {
-  userInfor = JSON.parse(getToken())
-  UserCode = userInfor.user_code;
-  UserType = userInfor.user_type;
-  SessionID = userInfor.session_id;
+    userInfor = JSON.parse(getToken())
+    UserCode = userInfor.user_code;
+    UserType = userInfor.user_type;
+    SessionID = userInfor.session_id;
 }
 
 export function getStaticContent(MethodName, data) {
-  return request({
-    url: `/GCLSFileServer/ServiceInterface?MethodName=${MethodName}`,
-    method: 'post',
-    data
-  })
+    return request({
+        url: `/GCLSFileServer/ServiceInterface?MethodName=${MethodName}`,
+        method: 'post',
+        data
+    })
 }
 export function LearnWebSI(MethodName, data) {
-  let userInfor = JSON.parse(getToken());
-  let UserCode = "",
-    UserType = "",
-    SessionID = "";
-  if (userInfor) {
-    UserCode = userInfor.user_code;
-    UserType = userInfor.user_type;
-    SessionID = userInfor.session_id;
-  }
-  return request({
-    url: `/GCLSLearnWebSI/ServiceInterface?MethodName=${MethodName}&UserCode=${UserCode}&UserType=${UserType}&SessionID=${SessionID}`,
-    method: 'post',
-    data,
-  })
+    let userInfor = JSON.parse(getToken());
+    let UserCode = "",
+        UserType = "",
+        SessionID = "";
+    if (userInfor) {
+        UserCode = userInfor.user_code;
+        UserType = userInfor.user_type;
+        SessionID = userInfor.session_id;
+    }
+    return request({
+        url: `/GCLSLearnWebSI/ServiceInterface?MethodName=${MethodName}&UserCode=${UserCode}&UserType=${UserType}&SessionID=${SessionID}`,
+        method: 'post',
+        data,
+    })
 }
 // 根据id获取文件信息 
 export function GetFillemessage(MethodName, data) {
-  return request({
-    url: `/GCLSFileServer/ServiceInterface?MethodName=${MethodName}`,
-    method: 'post',
-    data,
-  })
-}
-export function getContent(MethodName, UserCode, UserType, SessionID, data) {
-  return request({
-    url: `/GCLSFileServer/ServiceInterface?MethodName=${MethodName}&UserCode=${UserCode}&UserType=${UserType}&SessionID=${SessionID}`,
-    method: 'post',
-    data
-  })
+    return request({
+        url: `/GCLSFileServer/ServiceInterface?MethodName=${MethodName}`,
+        method: 'post',
+        data,
+    })
+}
+export function getContent(MethodName, data) {
+    let userInfor = JSON.parse(getToken());
+    let UserCode = "",
+        UserType = "",
+        SessionID = "";
+    if (userInfor) {
+        UserCode = userInfor.user_code;
+        UserType = userInfor.user_type;
+        SessionID = userInfor.session_id;
+    }
+    return request({
+        url: `/GCLSFileServer/ServiceInterface?MethodName=${MethodName}&UserCode=${UserCode}&UserType=${UserType}&SessionID=${SessionID}`,
+        method: 'post',
+        data
+    })
 }
 // 验证是否登录
 export function VerifyLogin() {
-  let userInfor = getToken()
-  let UserCode = '',
-    UserType = '',
-    SessionID = ''
-  if (userInfor) {
-    userInfor = JSON.parse(getToken())
-    UserCode = userInfor.user_code;
-    UserType = userInfor.user_type;
-    SessionID = userInfor.session_id;
-  }
-  let data = {
-    userCode: UserCode,
-    userType: UserType,
-    sessionId: SessionID,
-  }
-  return request({
-    url: `/GCLSTCServer/login?UserCode=${UserCode}&UserType=${UserType}&SessionID=${SessionID}`,
-    method: "post",
-    data,
-  })
+    let userInfor = getToken()
+    let UserCode = '',
+        UserType = '',
+        SessionID = ''
+    if (userInfor) {
+        userInfor = JSON.parse(getToken())
+        UserCode = userInfor.user_code;
+        UserType = userInfor.user_type;
+        SessionID = userInfor.session_id;
+    }
+    let data = {
+        userCode: UserCode,
+        userType: UserType,
+        sessionId: SessionID,
+    }
+    return request({
+        url: `/GCLSTCServer/login?UserCode=${UserCode}&UserType=${UserType}&SessionID=${SessionID}`,
+        method: "post",
+        data,
+    })
 }
 // 查询学习资料列表
 export function materiallist(data) {
-  return request({
-    url: `/GCLSTCServer/material/list?UserCode=${UserCode}&UserType=${UserType}&SessionID=${SessionID}`,
-    method: "post",
-    data,
-  })
+    return request({
+        url: `/GCLSTCServer/material/list?UserCode=${UserCode}&UserType=${UserType}&SessionID=${SessionID}`,
+        method: "post",
+        data,
+    })
 }
 // 查询学习资料详情
 export function materialdetail(data) {
-  let userInfor = getToken()
-  let UserCode = '',
-    UserType = '',
-    SessionID = ''
-  if (userInfor) {
-    userInfor = JSON.parse(getToken())
-    UserCode = userInfor.user_code;
-    UserType = userInfor.user_type;
-    SessionID = userInfor.session_id;
-  }
+    let userInfor = getToken()
+    let UserCode = '',
+        UserType = '',
+        SessionID = ''
+    if (userInfor) {
+        userInfor = JSON.parse(getToken())
+        UserCode = userInfor.user_code;
+        UserType = userInfor.user_type;
+        SessionID = userInfor.session_id;
+    }
 
-  return request({
-    url: `/GCLSTCServer/material/detail?UserCode=${UserCode}&UserType=${UserType}&SessionID=${SessionID}`,
-    method: "post",
-    data,
-  })
+    return request({
+        url: `/GCLSTCServer/material/detail?UserCode=${UserCode}&UserType=${UserType}&SessionID=${SessionID}`,
+        method: "post",
+        data,
+    })
 }
 // 上传附件(课程资源)
 export function attachmentinsert(data) {
-  return request({
-    url: `/GCLSTCServer/attachment/insert?UserCode=${UserCode}&UserType=${UserType}&SessionID=${SessionID}`,
-    method: "post",
-    data,
-  })
+    return request({
+        url: `/GCLSTCServer/attachment/insert?UserCode=${UserCode}&UserType=${UserType}&SessionID=${SessionID}`,
+        method: "post",
+        data,
+    })
 }
 // 下架学习资料  /material/outOfStockAction
 export function materialoutOfStockAction(data) {
-  return request({
-    url: `/GCLSTCServer/material/outOfStockAction?UserCode=${UserCode}&UserType=${UserType}&SessionID=${SessionID}`,
-    method: "post",
-    data,
-  })
+    return request({
+        url: `/GCLSTCServer/material/outOfStockAction?UserCode=${UserCode}&UserType=${UserType}&SessionID=${SessionID}`,
+        method: "post",
+        data,
+    })
 }
 // 上架学习资料  /material/inStockAction
 export function materialinStockAction(data) {
-  return request({
-    url: `/GCLSTCServer/material/inStockAction?UserCode=${UserCode}&UserType=${UserType}&SessionID=${SessionID}`,
-    method: "post",
-    data,
-  })
+    return request({
+        url: `/GCLSTCServer/material/inStockAction?UserCode=${UserCode}&UserType=${UserType}&SessionID=${SessionID}`,
+        method: "post",
+        data,
+    })
 }
 // 删除学习资料/material/delete
 export function materialdelete(data) {
-  return request({
-    url: `/GCLSTCServer/material/delete?UserCode=${UserCode}&UserType=${UserType}&SessionID=${SessionID}`,
-    method: "post",
-    data,
-  })
+    return request({
+        url: `/GCLSTCServer/material/delete?UserCode=${UserCode}&UserType=${UserType}&SessionID=${SessionID}`,
+        method: "post",
+        data,
+    })
 }
 // 更新学习资料
 export function materialupdate(data) {
-  return request({
-    url: `/GCLSTCServer/material/update?UserCode=${UserCode}&UserType=${UserType}&SessionID=${SessionID}`,
-    method: "post",
-    data,
-  })
+    return request({
+        url: `/GCLSTCServer/material/update?UserCode=${UserCode}&UserType=${UserType}&SessionID=${SessionID}`,
+        method: "post",
+        data,
+    })
 }
 // 插入学习资料
 export function materialinsert(data) {
-  return request({
-    url: `/GCLSTCServer/material/insert?UserCode=${UserCode}&UserType=${UserType}&SessionID=${SessionID}`,
-    method: "post",
-    data,
-  })
+    return request({
+        url: `/GCLSTCServer/material/insert?UserCode=${UserCode}&UserType=${UserType}&SessionID=${SessionID}`,
+        method: "post",
+        data,
+    })
 }
 // 查询企业信息 (机构信息)
 export function usertenant(data) {
-  return request({
-    url: `/GCLSTCServer/user/tenant?UserCode=${UserCode}&UserType=${UserType}&SessionID=${SessionID}`,
-    method: "post",
-    data,
-  })
+    return request({
+        url: `/GCLSTCServer/user/tenant?UserCode=${UserCode}&UserType=${UserType}&SessionID=${SessionID}`,
+        method: "post",
+        data,
+    })
 }
 // 收藏 /material/favorite/insert
 export function materialfavoriteinsert(data) {
-  return request({
-    url: `/GCLSTCServer/material/favorite/insert?UserCode=${UserCode}&UserType=${UserType}&SessionID=${SessionID}`,
-    method: "post",
-    data,
-  })
+    return request({
+        url: `/GCLSTCServer/material/favorite/insert?UserCode=${UserCode}&UserType=${UserType}&SessionID=${SessionID}`,
+        method: "post",
+        data,
+    })
 }
 // 取消收藏/material/favorite/delete
 export function materialfavoritedelete(data) {
-  return request({
-    url: `/GCLSTCServer/material/favorite/delete?UserCode=${UserCode}&UserType=${UserType}&SessionID=${SessionID}`,
-    method: "post",
-    data,
-  })
+    return request({
+        url: `/GCLSTCServer/material/favorite/delete?UserCode=${UserCode}&UserType=${UserType}&SessionID=${SessionID}`,
+        method: "post",
+        data,
+    })
 }
 // 浏览次数计数/material/visit
 export function materialvisit(data) {
-  return request({
-    url: `/GCLSTCServer/material/visit?UserCode=${UserCode}&UserType=${UserType}&SessionID=${SessionID}`,
-    method: "post",
-    data,
-  })
+    return request({
+        url: `/GCLSTCServer/material/visit?UserCode=${UserCode}&UserType=${UserType}&SessionID=${SessionID}`,
+        method: "post",
+        data,
+    })
 }
 // 查询作者列表 /material/teacher/list
 export function teacherlist(data) {
-  return request({
-    url: `/GCLSTCServer/material/teacher/list?UserCode=${UserCode}&UserType=${UserType}&SessionID=${SessionID}`,
-    method: "post",
-    data,
-  })
+    return request({
+        url: `/GCLSTCServer/material/teacher/list?UserCode=${UserCode}&UserType=${UserType}&SessionID=${SessionID}`,
+        method: "post",
+        data,
+    })
 }
 // 消息部分
 export function getLearnWebContent(MethodName, data) {
-  let userInfor = getToken();
-  let UserCode = '',
-    UserType = '',
-    SessionID = ''
-  if (userInfor) {
-    let user = JSON.parse(getToken());
-    UserCode = user.user_code;
-    UserType = user.user_type;
-    SessionID = user.session_id;
-  }
-  return request({
-    url: `/GCLSLearnWebSI/ServiceInterface?MethodName=${MethodName}&UserCode=${UserCode}&UserType=${UserType}&SessionID=${SessionID}`,
-    method: 'post',
-    data
-  })
+    let userInfor = getToken();
+    let UserCode = '',
+        UserType = '',
+        SessionID = ''
+    if (userInfor) {
+        let user = JSON.parse(getToken());
+        UserCode = user.user_code;
+        UserType = user.user_type;
+        SessionID = user.session_id;
+    }
+    return request({
+        url: `/GCLSLearnWebSI/ServiceInterface?MethodName=${MethodName}&UserCode=${UserCode}&UserType=${UserType}&SessionID=${SessionID}`,
+        method: 'post',
+        data
+    })
 }

+ 37 - 37
src/components/Header.vue

@@ -47,7 +47,7 @@
                 >
                   <img
                     style="position: relative; width: 24px"
-                    :src="require('../assets/login/' + item.img + '.png')"
+                    :src="item.icon_url_memu_default"
                     alt=""
                   />
                   <span style="margin-left: 16px">
@@ -133,6 +133,7 @@ import Cookies from "js-cookie";
 import { getContent, getStaticContent, getLearnWebContent } from "@/api/api";
 import { setI18nLang } from "@/utils/i18n";
 import { getConfig } from "@/utils/auth";
+import { saveSession, getSession, removeSession } from "@/utils/role";
 
 export default {
   name: "LayoutHeader",
@@ -246,35 +247,6 @@ export default {
         window.location.href = "/";
         return;
       }
-      let MethodName = "login_control-CreateAccessCode";
-      let acsCode = null;
-      // getContent(MethodName, UserCode, UserType, SessionID).then((res) => {
-      //   acsCode = res.access_code;
-      //   _this.projectName = this.projectList[command].name;
-      let id = this.projectList[command].id;
-      if (id == 0) {
-        // 教学管理系统
-        location.href = `/GCLS-Learn/#/EnterSys`;
-      } else if (id == 1) {
-        // 教材管理系统
-        location.href = `/GCLS-Book/#/EnterSys`;
-      } else if (id == 2) {
-        // 教培中心
-        location.href = `/GCLS-TRC/#/EnterSys`;
-      } else if (id == 3) {
-        // 教研中心
-        location.href = `/GCLS-TC/#/EnterSys`;
-      } else if (id == 4) {
-        // 考试中心
-        location.href = `/GCLS-Test/#/EnterSys`;
-      } else if (id == 5) {
-        // 学习中心
-        location.href = `/GCLS-LC/#/EnterSys`;
-      } else {
-        // 个人中心
-        location.href = `/GCLS-Personal/#/EnterSys`;
-      }
-      // });
     },
     // 切换登录的注册
     cutLoginReg() {
@@ -282,6 +254,7 @@ export default {
     },
     QuitLogin() {
       window.location.href = "/";
+      removeSession("SysList");
       removeToken();
       Cookies.remove("JSESSIONID");
       this.userShow = false;
@@ -414,8 +387,40 @@ export default {
     // async _getConfig() {
     //   this.configInfor = await getConfigInfor();
     // },
+    getChildSysList() {
+      let _this = this;
+      let MethodName = "login_control-GetChildSysList_CanEnter_PC";
+      getContent(MethodName, {})
+        .then((res) => {
+          if (res.child_sys_list && res.child_sys_list.length > 0) {
+            _this.projectList = res.child_sys_list;
+            _this.projectList.forEach((item, index) => {
+              if (item.key == "GCLS-TRC") {
+                _this.LoginNavIndex = index;
+              }
+            });
+            saveSession("SysList", this.projectList);
+          }
+        })
+        .catch((err) => {
+          console.log(err);
+        });
+    },
+  },
+  created() {
+    let _this = this;
+    let SysList = getSession("SysList");
+    if (!SysList) {
+      _this.getChildSysList();
+    } else {
+      _this.projectList = SysList;
+      _this.projectList.forEach((item, index) => {
+        if (item.key == "GCLS-TRC") {
+          _this.LoginNavIndex = index;
+        }
+      });
+    }
   },
-  created() {},
   mounted() {
     let _this = this;
     let user = getToken();
@@ -423,15 +428,10 @@ export default {
       _this.userMessage = JSON.parse(user);
       let popedom_code_list = _this.userMessage.popedom_code_list;
       if (_this.userMessage.user_type == "TEACHER") {
-        _this.projectList = _this.handleProList(popedom_code_list);
+        // _this.projectList = _this.handleProList(popedom_code_list);
       } else if (_this.userMessage.user_type == "STUDENT") {
         _this.projectList = _this.stuProList;
       }
-      _this.projectList.forEach((item, index) => {
-        if (item.id == 3) {
-          _this.LoginNavIndex = index;
-        }
-      });
     }
     _this.configInfor = JSON.parse(getConfig());
     _this.getLangList();

+ 81 - 77
src/utils/request.js

@@ -4,96 +4,100 @@ import store from '../store'
 import Cookies from 'js-cookie'
 import { Message } from 'element-ui'
 import { getToken, removeToken } from "../utils/auth"
+import { saveSession, getSession, removeSession } from "@/utils/role";
+
 axios.defaults.withCredentials = true
 axios.defaults.dataType = 'json'
 axios.defaults.headers['cache-control'] = 'no-cache'
 axios.defaults.headers['Content-Type'] = 'application/json'
 axios.defaults.headers['X-Requested-With'] = 'XMLHttpRequest'
-// create an axios instance
+    // create an axios instance
 const service = axios.create({
-  baseURL: process.env.VUE_APP_BASE_API, // url = base url + request url
-  // withCredentials: true, // send cookies when cross-domain requests
-  timeout: 60000 // request timeout
-})
-// request interceptor
+        baseURL: process.env.VUE_APP_BASE_API, // url = base url + request url
+        // withCredentials: true, // send cookies when cross-domain requests
+        timeout: 60000 // request timeout
+    })
+    // request interceptor
 service.interceptors.request.use(
-  config => {
-    // do something before request is sent
-    // let each request carry token
-    // ['X-Token'] is a custom headers key
-    // please modify it according to the actual situation
-    config.headers['Content-Type'] = 'application/json'
-    return config
-  },
-  error => {
-    // do something with request error
-    console.log(error) // for debug
-    return Promise.reject(error)
-  }
+    config => {
+        // do something before request is sent
+        // let each request carry token
+        // ['X-Token'] is a custom headers key
+        // please modify it according to the actual situation
+        config.headers['Content-Type'] = 'application/json'
+        return config
+    },
+    error => {
+        // do something with request error
+        console.log(error) // for debug
+        return Promise.reject(error)
+    }
 )
 
 // response interceptor
 service.interceptors.response.use(
-  /**
-   * If you want to get http information such as headers or status
-   * Please return  response => response
-   */
+    /**
+     * If you want to get http information such as headers or status
+     * Please return  response => response
+     */
 
-  /**
-   * Determine the request status by custom code
-   * Here is just an example
-   * You can also judge the status by HTTP Status Code
-   */
-  response => {
+    /**
+     * Determine the request status by custom code
+     * Here is just an example
+     * You can also judge the status by HTTP Status Code
+     */
+    response => {
 
-    const res = response.data;
-    let msg = null
-    // if the custom code is not 20000, it is judged as an error.
-    if (res.status == 0 || res.status == -2) {
-      // 执行错误  JSON 数据格式错误
-      msg = Message({
-        message: res.msg || res.error || 'Error',
-        type: 'error',
-        showClose: true,
-        duration: 0
-      })
-      return Promise.reject(new Error(res.message || res.error || 'Error'))
-    } else if (res.status === -1) {
-      console.log("登录会话失效,请重新登录");
-      // 登录失效
-      sessionStorage.removeItem("twoId");
-      //removeToken()
-      msg = Message({
-        message: '登录会话失效,请重新登录',
-        type: 'error',
-        showClose: true,
-        duration: 0
-      });
-      if (process.env.NODE_ENV == "development") {
-        router.push("/login")
-      } else {
-        window.location.href = "/"
-      }
-      return false
-    } else {
-      console.log("成功返回数据");
-      Message.closeAll()
-      return res
-    }
-  },
-  error => {
-    // || (error+1).indexOf('500') > -1
-    if ((error + 1).indexOf('401') > -1) {
-      // console.log(router)
-      // store.dispatch('user/postError')
-      // router.push(`/login`)
+        const res = response.data;
+        let msg = null
+            // if the custom code is not 20000, it is judged as an error.
+        if (res.status == 0 || res.status == -2) {
+            // 执行错误  JSON 数据格式错误
+            msg = Message({
+                message: res.msg || res.error || 'Error',
+                type: 'error',
+                showClose: true,
+                duration: 0
+            })
+            return Promise.reject(new Error(res.message || res.error || 'Error'))
+        } else if (res.status === -1) {
+            console.log("登录会话失效,请重新登录");
+            // 登录失效
+            sessionStorage.removeItem("twoId");
+            removeSession("SysList")
+
+            //removeToken()
+            msg = Message({
+                message: '登录会话失效,请重新登录',
+                type: 'error',
+                showClose: true,
+                duration: 0
+            });
+            if (process.env.NODE_ENV == "development") {
+                router.push("/login")
+            } else {
+                window.location.href = "/"
+            }
+            return false
+        } else {
+            console.log("成功返回数据");
+            Message.closeAll()
+            return res
+        }
+    },
+    error => {
+        // || (error+1).indexOf('500') > -1
+        if ((error + 1).indexOf('401') > -1) {
+            // console.log(router)
+            // store.dispatch('user/postError')
+            // router.push(`/login`)
+        }
+        Message({
+            message: '网络错误,请稍后重试',
+            type: 'error',
+            duration: 2 * 1000
+        })
+        return Promise.reject(error)
     }
-    Message({
-      message: '网络错误,请稍后重试',
-      type: 'error',
-      duration: 2 * 1000
-    })
-    return Promise.reject(error)
-  }
 )
 export default service

+ 5 - 2
src/views/login.vue

@@ -81,11 +81,12 @@
 
 <script>
 import { validUsername, validPass } from "@/utils/validate";
-import { getContent } from "@/api/api";
+import { getStaticContent } from "@/api/api";
 import { getObjArr, saveObjArr } from "@/utils/role";
 import Cookies from "js-cookie";
 import { setToken } from "@/utils/auth";
 import { getConfigInfor } from "@/utils/index";
+import { removeSession } from "@/utils/role";
 
 export default {
   name: "Login",
@@ -152,6 +153,7 @@ export default {
     },
     //登录
     handleLogin() {
+      removeSession("SysList");
       this.$refs.loginForm.validate((valid) => {
         if (valid) {
           this.loading = true;
@@ -164,7 +166,7 @@ export default {
             user_name: this.loginForm.username,
             password: this.loginForm.password,
           };
-          getContent(MethodName, UserCode, UserType, SessionID, data)
+          getStaticContent(MethodName, data)
             .then((res) => {
               setToken(res);
               //   判断有没有包含教研管理的权限码 如果有就是管理员身份前往录入,没有就是普通教师前往首页
@@ -188,6 +190,7 @@ export default {
     },
   },
   mounted() {
+    removeSession("SysList");
     this._getConfig();
   },
 };