Jelajahi Sumber

网络接口维护;在线考试列表初始化

Michael Wang 7 tahun lalu
induk
melakukan
649d7d7c14
7 mengubah file dengan 198 tambahan dan 88 penghapusan
  1. 1 1
      README.md
  2. 32 0
      http-test/online-exam.http
  3. 66 0
      src/features/OnlineExam/OnlineExamHome.vue
  4. 3 3
      src/main.js
  5. 6 0
      src/router.js
  6. 79 73
      src/utils/axios.js
  7. 11 11
      vue.config.js

+ 1 - 1
README.md

@@ -65,7 +65,7 @@ vue-cli
 | src/styles/     | 全局样式。 局部样式应该放在 src/features/中                                                                                                                                                                                                                                                                        |
 | src/utils/      | 共享的工具类。 跟业务有关的  工具方法放在 src/features/中                                                                                                                                                                                                                                                          |
 | static/         | 不需要 Webpack 处理的静态文件                                                                                                                                                                                                                                                                                      |
-| test/           | 单元测试和 E2E 测试                                                                                                                                                                                                                                                                                                |
+| tests/          | 单元测试和 E2E 测试                                                                                                                                                                                                                                                                                                |
 
 ## 错误处理
 

+ 32 - 0
http-test/online-exam.http

@@ -0,0 +1,32 @@
+POST https://ecs-dev.qmth.com.cn:8878/api/ecs_core/auth/login
+Content-Type: application/json;charset=UTF-8
+
+{"domain":"ecs-dev.qmth.com.cn",
+"accountValue":"20180613",
+"password":"180613",
+"accountType":"STUDENT_CODE"}
+
+
+@token = a19d4ae9e8c04b4cba197c1f966525ff
+@key = U__109_55481
+
+###
+GET https://ecs-dev.qmth.com.cn:8878/api/exam_record/checkExam
+token: {{token}}
+key: {{key}}
+
+###
+GET https://ecs-dev.qmth.com.cn:8878/api/online_exam_course
+token: {{token}}
+key: {{key}}
+
+
+### 
+GET https://ecs-dev.qmth.com.cn:8878/api/online_exam_course/currentTime
+token: {{token}}
+key: {{key}}
+
+
+
+
+

+ 66 - 0
src/features/OnlineExam/OnlineExamHome.vue

@@ -0,0 +1,66 @@
+<template>
+  <div class="home">
+    <Table border :columns="columns" :data="courses"></Table>
+  </div>
+</template>
+
+<script>
+export default {
+  name: "OnlineExamHome",
+  data() {
+    return {
+      columns: [
+        {
+          title: "课程名称",
+          key: "courseName"
+        },
+        {
+          title: "专业",
+          key: "specialtyName"
+        },
+        {
+          title: "考试开放时间",
+          key: "start2end"
+        },
+        {
+          title: "剩余考试次数",
+          key: "times"
+        },
+        {
+          title: "操作",
+          key: "operations"
+        }
+      ],
+      courses: []
+    };
+  },
+  async mounted() {
+    this.$http.defaults.headers.post["Content-Type"] = "application/json";
+    if (!this.$http.defaults.headers.common["token"]) {
+      // let that = this;
+      const response = await this.$http.post("/api/ecs_core/auth/login", {
+        domain: process.env.VUE_APP_LOGIN_DOMAIN,
+        accountValue: process.env.VUE_APP_LOGIN_ACCOUNT_VALUE,
+        password: process.env.VUE_APP_LOGIN_PASSWORD,
+        accountType: process.env.VUE_APP_LOGIN_ACCOUNTTYPE
+      });
+      this.$http.defaults.headers.common["token"] = response.data.token;
+      this.$http.defaults.headers.common["key"] = response.data.key;
+    }
+
+    const res = await this.$http.get("/api/online_exam_course");
+    // console.log(res);
+
+    this.courses = res.data.map(c => ({
+      courseName: c.courseName,
+      specialtyName: c.specialtyName,
+      start2end: c.startTime + " ~ " + c.endTime,
+      times: c.allowExamCount,
+      operations: ""
+    }));
+  }
+};
+</script>
+
+<style scoped>
+</style>

+ 3 - 3
src/main.js

@@ -4,8 +4,8 @@ import router from "./router";
 import store from "./store";
 import "./registerServiceWorker";
 
-import iView from 'iview';
-import 'iview/dist/styles/iview.css';
+import iView from "iview";
+import "iview/dist/styles/iview.css";
 
 import axiosPlugin from "./utils/axios";
 
@@ -19,4 +19,4 @@ new Vue({
   router,
   store,
   render: h => h(App)
-}).$mount("#app");
+}).$mount("#app");

+ 6 - 0
src/router.js

@@ -4,6 +4,7 @@ import Home from "./views/Home.vue";
 import About from "./views/About.vue";
 
 import NotFoundComponent from "./views/NotFoundComponent.vue";
+import OnlineExamHome from "./features/OnlineExam/OnlineExamHome.vue";
 
 Vue.use(Router);
 
@@ -19,6 +20,11 @@ export default new Router({
       name: "about",
       component: About
     },
+    {
+      path: "/online-exam",
+      name: "OnlineExamHome",
+      component: OnlineExamHome
+    },
     {
       path: "*",
       component: NotFoundComponent

+ 79 - 73
src/utils/axios.js

@@ -4,37 +4,41 @@ import Axios from "axios";
 
 //请求拦截
 let $Message;
-Axios.interceptors.request.use(config => {
-        // 在发送请求之前做某件事
+Axios.interceptors.request.use(
+  config => {
+    // 在发送请求之前做某件事
 
-        // 若是有做鉴权token , 就给头部带上token
-        // if (localStorage.token) {
-        // config.headers.Authorization = localStorage.token;
-        // }
-        $Message = config.message;
-        return config;
-    },
-    error => {
-        $Message.error({
-            content: error,
-            duration: 10,
-            closable: true
-        });
-        return Promise.resolve(error);
-    }
+    // 若是有做鉴权token , 就给头部带上token
+    // if (localStorage.token) {
+    // config.headers.Authorization = localStorage.token;
+    // }
+    $Message = config.message;
+    return config;
+  },
+  error => {
+    $Message.error({
+      content: error,
+      duration: 10,
+      closable: true
+    });
+    return Promise.resolve(error);
+  }
 );
 
 //响应拦截
-Axios.interceptors.response.use(response => {
+Axios.interceptors.response.use(
+  response => {
     return response;
-}, error => { // 这里是返回状态码不为200时候的错误处理
+  },
+  error => {
+    // 这里是返回状态码不为200时候的错误处理
     let status = error.response.status;
     // 登录失效 跳转登录页面
     if (status == 403 || status == 401) {
-
     }
     return Promise.resolve(error);
-});
+  }
+);
 
 Axios.defaults.withCredentials = true; //允许跨域携带cookie
 Axios.defaults.timeout = 100000; //超时时间
@@ -46,65 +50,67 @@ Axios.defaults.headers.common["X-Requested-With"] = "XMLHttpRequest"; //标识
   type   json || form
   method get || post
 */
-let ajax = (url, params, type = 'json', method = 'get', thisObj) => {
-    let getData = method === 'get' ? params : {};
-    let postData = method === 'post' ? params : {};
-    let headers = type == 'form' ? {
-        'Content-Type': 'application/x-www-form-urlencoded; charset=UTF-8'
-    } : {
-        "Accept": "application/json",
-        "Content-Type": "application/json; charset=UTF-8"
-    };
-
-    return new Promise(function (resolve, reject) {
-        Axios({
-            method: method,
-            url: url,
-            params: getData,
-            data: postData,
-            headers: headers,
-            withCredentials: true,
-            message: thisObj.$Message
-        }).then((res) => {
-            let status = res.status;
-            if (status >= 200 && status < 300) {
-                resolve(res.data.data || res.data);
-            } else {
-                $Message.error({
-                    content: "服务异常:" + res.message,
-                    duration: 10,
-                    closable: true
-                });
-            }
-        }).catch((response) => {
-            $Message.error({
-                content: "服务异常(catch):" + response.message,
-                duration: 10,
-                closable: true
-            });
-
-        })
+let ajax = (url, params, type = "json", method = "get", thisObj) => {
+  let getData = method === "get" ? params : {};
+  let postData = method === "post" ? params : {};
+  let headers =
+    type == "form"
+      ? {
+          "Content-Type": "application/x-www-form-urlencoded; charset=UTF-8"
+        }
+      : {
+          Accept: "application/json",
+          "Content-Type": "application/json; charset=UTF-8"
+        };
 
+  return new Promise(function(resolve, reject) {
+    Axios({
+      method: method,
+      url: url,
+      params: getData,
+      data: postData,
+      headers: headers,
+      withCredentials: true,
+      message: thisObj.$Message
     })
-}
+      .then(res => {
+        let status = res.status;
+        if (status >= 200 && status < 300) {
+          resolve(res.data.data || res.data);
+        } else {
+          $Message.error({
+            content: "服务异常:" + res.message,
+            duration: 10,
+            closable: true
+          });
+        }
+      })
+      .catch(response => {
+        $Message.error({
+          content: "服务异常(catch):" + response.message,
+          duration: 10,
+          closable: true
+        });
+      });
+  });
+};
 
 Vue.prototype.$http = Axios;
 
 // get请求
-Vue.prototype.$get = function (url, params) {
-    return ajax(url, params, '', 'get', this);
-}
+Vue.prototype.$get = function(url, params) {
+  return ajax(url, params, "", "get", this);
+};
 
 // post请求
-Vue.prototype.$post = function (url, params, type) {
-    return ajax(url, params, type, 'post', this);
-}
-
+Vue.prototype.$post = function(url, params, type) {
+  return ajax(url, params, type, "post", this);
+};
 
 export default {
-    install: function (Vue, Option) {
-        Object.defineProperty(Vue.prototype, "$http", {
-            value: Axios
-        });
-    }
-};
+  install: function(Vue, Option) {
+    Object.defineProperty(Vue.prototype, "$http", {
+      value: Axios
+    });
+  }
+};

+ 11 - 11
vue.config.js

@@ -3,20 +3,20 @@ let proxy = {
     target: " http://ecs-dev.qmth.com.cn:8000", //代理跨域转地址,基础信息
     changeOrigin: true
   },
-  "/api/logic/portal": {
-    target: " http://ecs-dev.qmth.com.cn:8018", //
-    changeOrigin: true
-  },
+  // "/api/logic/portal": {
+  //   target: " http://ecs-dev.qmth.com.cn:8018", //基础信息 门户 王伟
+  //   changeOrigin: true
+  // },
   "/api/ecs_exam_work": {
-    target: " http://ecs-dev.qmth.com.cn:8001",
-    changeOrigin: true
-  },
-  "/api/ecs_outlet": {
-    target: " http://ecs-dev.qmth.com.cn:8007",
+    target: " http://ecs-dev.qmth.com.cn:8001", // 考务 王伟
     changeOrigin: true
   },
+  // "/api/ecs_outlet": {
+  //   target: " http://ecs-dev.qmth.com.cn:8007", //  王伟
+  //   changeOrigin: true
+  // },
   "/facepp_api": {
-    target: " http://ecs-dev.qmth.com.cn:8898",
+    target: " http://ecs-dev.qmth.com.cn:8898", // 陈恳
     changeOrigin: true
   }
 };
@@ -40,7 +40,7 @@ const stu = [
 
 for (const s of stu) {
   proxy[s] = {
-    target: " http://ecs-dev.qmth.com.cn:8003",
+    target: " http://ecs-dev.qmth.com.cn:8003", // 陈恳
     changeOrigin: true
   };
 }