Bläddra i källkod

转换paramsPath方法为全局属性方法

yellowtaotao 4 år sedan
förälder
incheckning
83a179264f
4 ändrade filer med 39 tillägg och 11 borttagningar
  1. 2 0
      src/main.js
  2. 21 0
      src/utils/common.js
  3. 14 9
      src/views/home/exam/page-exam-item-doing.vue
  4. 2 2
      src/views/home/learn/page-learn.vue

+ 2 - 0
src/main.js

@@ -4,6 +4,7 @@ import store from "./store/index";
 // 路由
 import router from "./router";
 import axios from "@/utils/axios";
+import common from "@/utils/common";
 import API from "@/api";
 // 共通filters
 import * as filters from "./filters";
@@ -19,6 +20,7 @@ window.$_http = axios;
 Vue.prototype.$bus = new Vue();
 Vue.prototype.$_http = axios;
 Vue.prototype.$_API = API;
+Vue.use(common)
 
 Vue.component("VanButton", Button);
 Vue.component("VanImage", Image);

+ 21 - 0
src/utils/common.js

@@ -0,0 +1,21 @@
+exports.install = function(Vue, options) {
+  /**
+   * 路径参数替换
+   * @pathParams {Object} 路径参数
+   */
+  Vue.prototype.$pathParams = function(path, pathParams) {
+    if (path.includes("{") && pathParams) {
+      let keys = Object.keys(pathParams);
+      keys.forEach(it => {
+        path = path.replace("{" + `${it}` + "}", pathParams[it]);
+      });
+    }
+    return path;
+  };
+  // Vue.prototype.$pushH = function() { // 全局函数
+  //     xxx
+  // };
+  // Vue.prototype.$pushHN = function() { // 全局函数
+  //     xxx
+  // };
+};

+ 14 - 9
src/views/home/exam/page-exam-item-doing.vue

@@ -356,6 +356,7 @@ export default {
         if (diffTime <= 0) {
           clearInterval(_self.interval);
           _self.timeDiff = "00:00:00";
+          this.handleSubmitFun(true); // 自动交卷
           return;
         }
         let hours = Math.floor(diffTime / (1000 * 60 * 60));
@@ -457,16 +458,20 @@ export default {
     handleSureFun() {
       this.examQuestionList[this.answerIndex].userAnswer = this.answerValue;
     },
-    // 操作:交卷
-    handleSubmitFun() {
-      Dialog.confirm({
-        title: "温馨提示",
-        message: "确认交卷?"
-      })
-        .then(() => {
-          // TODO...
+    // 操作:交卷 isAuto:true(时间到了的自动交卷)  false(手动交卷)
+    handleSubmitFun(isAuto) {
+      if (isAuto) {
+        console.log("自动交卷");
+      } else {
+        Dialog.confirm({
+          title: "温馨提示",
+          message: "确认交卷?"
         })
-        .catch(() => {});
+          .then(() => {
+            // TODO...
+          })
+          .catch(() => {});
+      }
     }
   }
 };

+ 2 - 2
src/views/home/learn/page-learn.vue

@@ -14,7 +14,6 @@
 </template>
 
 <script>
-import { pathParams } from "@/utils/tools";
 import PageLearnChild from "./page-learn-child";
 export default {
   name: "page-learn",
@@ -53,8 +52,9 @@ export default {
         categoryId: this.learnRootList[this.choosedRootIndex].id
       };
       this.$_http
-        .get(pathParams(this.$_API.JTXT_GET_CATEGORIES_CATEGROYID, path))
+        .get(this.$pathParams(this.$_API.JTXT_GET_CATEGORIES_CATEGROYID, path))
         .then(res => {
+          console.log(res);
           this.learnChildList = res.data;
           //   移除第一个根目录
           this.learnChildList.shift();