guanchunjie 3 years ago
parent
commit
a0131f4193
6 changed files with 327 additions and 324 deletions
  1. 131 130
      src/api/api.js
  2. 1 1
      src/components/Header.vue
  3. 33 33
      src/permission.js
  4. 79 79
      src/router/index.js
  5. 79 79
      src/utils/request.js
  6. 4 2
      src/views/teacher-dev/Preview.vue

+ 131 - 130
src/api/api.js

@@ -3,190 +3,191 @@ 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,
-    })
+  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}&UserCode=${UserCode}&UserType=${UserType}&SessionID=${SessionID}`,
+    method: 'post',
+    data
+  })
 }
 // 验证是否登录
 export function VerifyLogin(data) {
-    return request({
-        url: `/GCLSTCServer/login?UserCode=${UserCode}&UserType=${UserType}&SessionID=${SessionID}`,
-        method: "post",
-        data,
-    })
+  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;
-    }
-    return request({
-        url: `/GCLSTCServer/material/detail?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;
+  }
+
+  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
+  })
 }

+ 1 - 1
src/components/Header.vue

@@ -427,7 +427,7 @@ export default {
     _this.getNotReadMessage();
     setInterval(() => {
       _this.getNotReadMessage();
-    }, 10000);
+    }, 120000);
   },
 };
 </script>

+ 33 - 33
src/permission.js

@@ -10,43 +10,43 @@ NProgress.configure({ showSpinner: false }) // NProgress Configuration
 
 const whiteList = ['/login'] // no redirect whitelist
 
-router.beforeEach(async(to, from, next) => {
-    // start progress bar
-    NProgress.start()
-        // set page title
-    document.title = getPageTitle(to.meta.title)
-        //next();
-    NProgress.done()
-    const hasToken = getToken()
+router.beforeEach(async (to, from, next) => {
+  // start progress bar
+  NProgress.start()
+  // set page title
+  document.title = getPageTitle(to.meta.title)
+  //next();
+  NProgress.done()
+  const hasToken = getToken()
 
-    if (hasToken) {
-        if (to.path === '/login') {
-            // if is logged in, redirect to the home page
-            next({ path: '/' })
-            NProgress.done()
-        } else {
-            try {
-                next()
-            } catch (error) {
-                Message.error(error || 'Has Error')
-                next(`/login?redirect=${to.path}`)
-                NProgress.done()
-            }
-        }
+  if (hasToken) {
+    if (to.path === '/login') {
+      // if is logged in, redirect to the home page
+      next({ path: '/' })
+      NProgress.done()
     } else {
-        /* has no token*/
-        if (whiteList.indexOf(to.path) !== -1) {
-            // in the free login whitelist, go directly
-            next()
-        } else {
-            // other pages that do not have permission to access are redirected to the login page.
-            next(`/login?redirect=${to.path}`)
-            NProgress.done()
-        }
+      try {
+        next()
+      } catch (error) {
+        Message.error(error || 'Has Error')
+        next(`/login?redirect=${to.path}`)
+        NProgress.done()
+      }
     }
+  } else {
+    /* has no token*/
+    if (whiteList.indexOf(to.path) !== -1) {
+      // in the free login whitelist, go directly
+      next()
+    } else {
+      // other pages that do not have permission to access are redirected to the login page.
+      next(`/login?redirect=${to.path}`)
+      NProgress.done()
+    }
+  }
 })
 
 router.afterEach(() => {
-    // finish progress bar
-    NProgress.done()
+  // finish progress bar
+  NProgress.done()
 })

+ 79 - 79
src/router/index.js

@@ -6,96 +6,96 @@ import { Loading } from 'element-ui';
 import { getToken } from '@/utils/auth' // get token from cookie
 
 const routes = [{
-        path: '/EnterSys',
-        // component: Index,
-        beforeEnter: (to, from, next) => {
-            let loadingInstance = Loading.service({
-                text: '跳转中...'
-            });
-            let token = getToken();
-            if (token) {
-                if (JSON.parse(token).popedom_code_list.indexOf(2000006) != -1) {
-                    next("/teacherdevEntering");
-                    loadingInstance.close()
-                } else {
-                    next({ path: "/" });
-                    loadingInstance.close()
-                }
-            }
-        }
-    },
-    {
-        path: '/GoodsDetail',
-        beforeEnter: (to, from, next) => {
-            let loadingInstance = Loading.service({
-                text: '跳转中...'
-            });
-            if (to.query.goods_type == 401) {
-                next({
-                    path: "/Preview",
-                    query: {
-                        id: to.query.goods_id,
-                    },
-                })
-                loadingInstance.close()
-            }
-        }
-    },
-    // 教研中心
-    {
-        path: '/',
-        name: 'Index',
-        component: Index
-    },
-    {
-        path: '/login',
-        name: 'login',
-        component: () =>
-            import ('../views/login.vue'),
-    },
-    {
-        path: '/Preview',
-        name: 'Preview',
-        component: () =>
-            import ('../views/teacher-dev/Preview.vue')
-    },
-    {
-        path: "/Viewmore",
-        name: 'Viewmore',
-        component: () =>
-            import ('../views/teacher-dev/Viewmore.vue')
-    },
-    {
-        path: '/teacherdevEntering',
-        name: 'teacherdevEntering',
-        component: () =>
-            import ('../views/teacher-devEntering/index.vue')
-    },
-    {
-        path: '/creadDocument',
-        name: 'creadDocument',
-        component: () =>
-            import ('../views/teacher-devEntering/creadDocument.vue')
-    },
-    {
-        path: '*',
-        redirect: '/404'
+  path: '/EnterSys',
+  // component: Index,
+  beforeEnter: (to, from, next) => {
+    let loadingInstance = Loading.service({
+      text: '跳转中...'
+    });
+    let token = getToken();
+    if (token) {
+      if (JSON.parse(token).popedom_code_list.indexOf(2000006) != -1) {
+        next("/teacherdevEntering");
+        loadingInstance.close()
+      } else {
+        next({ path: "/" });
+        loadingInstance.close()
+      }
     }
+  }
+},
+{
+  path: '/GoodsDetail',
+  beforeEnter: (to, from, next) => {
+    let loadingInstance = Loading.service({
+      text: '跳转中...'
+    });
+    if (to.query.goods_type == 401) {
+      next({
+        path: "/Preview",
+        query: {
+          id: to.query.goods_id,
+        },
+      })
+      loadingInstance.close()
+    }
+  }
+},
+// 教研中心
+{
+  path: '/',
+  name: 'Index',
+  component: Index
+},
+{
+  path: '/login',
+  name: 'login',
+  component: () =>
+    import('../views/login.vue'),
+},
+{
+  path: '/Preview',
+  name: 'Preview',
+  component: () =>
+    import('../views/teacher-dev/Preview.vue')
+},
+{
+  path: "/Viewmore",
+  name: 'Viewmore',
+  component: () =>
+    import('../views/teacher-dev/Viewmore.vue')
+},
+{
+  path: '/teacherdevEntering',
+  name: 'teacherdevEntering',
+  component: () =>
+    import('../views/teacher-devEntering/index.vue')
+},
+{
+  path: '/creadDocument',
+  name: 'creadDocument',
+  component: () =>
+    import('../views/teacher-devEntering/creadDocument.vue')
+},
+{
+  path: '*',
+  redirect: '/404'
+}
 ]
 
 
 
 const router = new VueRouter({
-    // mode: 'history',
-    base: process.env.BASE_URL,
-    routes
+  // mode: 'history',
+  base: process.env.BASE_URL,
+  routes
 })
 
 //获取原型对象上的push函数
 const originalPush = VueRouter.prototype.push
-    //修改原型对象中的push方法
+//修改原型对象中的push方法
 VueRouter.prototype.push = function push(location) {
-    return originalPush.call(this, location).catch(err => err)
+  return originalPush.call(this, location).catch(err => err)
 }
 
 export default router

+ 79 - 79
src/utils/request.js

@@ -9,93 +9,93 @@ 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;
-        console.log(res)
-        let msg = null
-            // if the custom code is not 20000, it is judged as an error.
-        if (res.status == 0 || res.status == -2) {
-            console.log("执行错误", res);
-            // 执行错误  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("失效", res);
-            // 登录失效
-            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("最后一个else", res);
-            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)
+    const res = response.data;
+    console.log(res)
+    let msg = null
+    // if the custom code is not 20000, it is judged as an error.
+    if (res.status == 0 || res.status == -2) {
+      console.log("执行错误");
+      // 执行错误  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`)
+    }
+    Message({
+      message: '网络错误,请稍后重试',
+      type: 'error',
+      duration: 2 * 1000
+    })
+    return Promise.reject(error)
+  }
 )
 export default service

+ 4 - 2
src/views/teacher-dev/Preview.vue

@@ -292,6 +292,7 @@ export default {
         isSelectForUpdate: this.Ispreview ? true : false,
       })
         .then((res) => {
+          console.log("请求了函数getdetail");
           if (res.data.result) {
             let index = res.data.result.tag.indexOf("downloadable");
             if (index != -1) {
@@ -325,9 +326,11 @@ export default {
         });
     },
   },
-  created() {
+  created() {},
+  mounted() {
     this.materialId = this.$route.query.id;
     this.Ispreview = this.$route.query.type;
+    console.log("materialId" + this.materialIdå);
     if (this.materialId) {
       this.getdetail();
       if (!this.Ispreview) {
@@ -341,7 +344,6 @@ export default {
       }
     }
   },
-  mounted() {},
 };
 </script>