zhangjie 4 年之前
父节点
当前提交
964d3ed912
共有 5 个文件被更改,包括 191 次插入25 次删除
  1. 38 0
      src/assets/styles/mark.less
  2. 35 0
      src/constants/authority.js
  3. 20 19
      src/main.js
  4. 94 5
      src/modules/grading/GradingStandardPaperManage.vue
  5. 4 1
      src/routers/index.js

+ 38 - 0
src/assets/styles/mark.less

@@ -879,3 +879,41 @@
     color: @dark-color-lighter;
   }
 }
+.change-standard-paper-dialog {
+  .level-list {
+    font-size: 0;
+    padding-bottom: 50px;
+  }
+  .level-item {
+    display: inline-block;
+    vertical-align: top;
+    height: 32px;
+    width: 40px;
+    line-height: 32px;
+    text-align: center;
+    border-radius: @box-border-radius-small;
+    color: @dark-color-lighter;
+    border: 1px solid @dark-color-lighter;
+    font-size: 16px;
+    margin: 10px;
+    cursor: pointer;
+
+    &:hover {
+      color: @main-color;
+      border-color: @main-color;
+    }
+
+    &-act {
+      border-color: rgba(34, 192, 255, 0.4) !important;
+      background-color: @info-color;
+      color: @white!important;
+      box-shadow: 0px 10px 10px 0px rgba(34, 192, 255, 0.4);
+    }
+
+    &-disabled {
+      border-color: @disabled-color !important;
+      color: @disabled-color!important;
+      cursor: not-allowed;
+    }
+  }
+}

+ 35 - 0
src/constants/authority.js

@@ -180,3 +180,38 @@ export const inspection = [
     icon: "ivu-icon-score"
   }
 ];
+
+const getLeadRouter = () => {
+  let leadGrade = grading.map(item => item.name);
+  leadGrade.splice(2, 2);
+  let leadMark = mark.map(item => item.name);
+  leadMark.splice(1, 1);
+  leadMark.splice(2, 1);
+  return [...leadGrade, ...leadMark];
+};
+
+const getAdminRouter = () => {
+  let leadGrade = grading.map(item => item.name).slice(0, -2);
+  let leadMark = mark.map(item => item.name).slice(0, -1);
+  return [
+    ...leadGrade,
+    ...leadMark,
+    ...main.map(item => item.name),
+    ...clientSet.map(item => item.name),
+    ...gradingSet.map(item => item.name),
+    ...markSet.map(item => item.name)
+  ];
+};
+
+export const checkRouterValid = (roleCode, routerName) => {
+  const func = {
+    ADMIN: getAdminRouter,
+    MARKER: () => ["GradingOperation", "MarkOperation"],
+    MARK_LEADER: getLeadRouter,
+    INSPECTION: () => inspection.map(item => item.name),
+    QC: () => ["Quality"]
+  };
+
+  const validList = func[roleCode]();
+  return validList.includes(routerName);
+};

+ 20 - 19
src/main.js

@@ -15,6 +15,8 @@ import "./assets/styles/index.less";
 // regist v-chart
 import "./plugins/VueCharts";
 
+import { checkRouterValid } from "./constants/authority";
+
 Vue.use(ViewUI);
 ViewUI.Message.config({
   duration: 3
@@ -30,24 +32,23 @@ Vue.prototype.GLOBAL = GLOBAL;
 Vue.config.productionTip = false;
 
 // route interceptor
-// router.beforeEach((to, from, next) => {
-//   const token = Vue.ls.get("token");
-//   if (to.meta.noRequire) {
-//     // 不需要登录的页面
-//     next();
-//   } else {
-//     // 需要登录的路由
-//     if (token) {
-//       next();
-//     } else {
-//       // 登录失效的处理
-//       Vue.ls.clear();
-//       // Vue.ls.remove("token");
-//       // Vue.ls.remove("user");
-//       next({ name: "Login" });
-//     }
-//   }
-// });
+router.beforeEach((to, from, next) => {
+  const user = Vue.ls.get("user");
+  if (to.meta.noRequire) {
+    // 不需要登录的页面
+    next();
+  } else {
+    // 需要登录的路由
+    if (user && checkRouterValid(user["role"], to.name)) {
+      next();
+    } else {
+      ViewUI.Notice.error({ title: "错误提示", desc: "权限失效!" });
+      // 登录失效的处理
+      Vue.ls.clear();
+      next({ name: "Login" });
+    }
+  }
+});
 
 // axios interceptors
 var load = "";
@@ -82,7 +83,7 @@ axios.interceptors.request.use(
   },
   error => {
     // 关闭loading提示
-    // 串联并发请求,延时处理是为防止多个loading实例闪屏
+    // 继发请求,延时处理是为防止出现多个loading实例
     setTimeout(() => {
       queue.shift();
       if (!queue.length) load();

+ 94 - 5
src/modules/grading/GradingStandardPaperManage.vue

@@ -22,7 +22,7 @@
             size="small"
             class="btn-form-search"
             type="primary"
-            @click="getList"
+            @click="search"
             >查询</Button
           >
         </FormItem>
@@ -62,13 +62,17 @@
               @click="toReview(index)"
             />
           </div>
-          <div class="image-view-actions" v-if="canCancel">
+          <div class="image-view-actions">
             <Button
               type="error"
               size="small"
               @click="cancelPaper(image)"
               :disabled="image.loading"
-              >取消标准卷</Button
+              v-if="canCancel"
+              >取消</Button
+            >
+            <Button type="primary" size="small" @click="toChangePaper(image)"
+              >修改</Button
             >
           </div>
         </div>
@@ -85,6 +89,41 @@
       @on-next="toNextPaper"
       ref="SimpleImagePreview"
     ></simple-image-preview>
+    <!-- change-standard-paper-dialog -->
+    <Modal
+      class="change-standard-paper-dialog"
+      v-model="modalIsShow"
+      title="修改标准卷"
+      :mask-closable="false"
+    >
+      <div class="level-list">
+        <p
+          v-for="level in levels"
+          :key="level"
+          :class="[
+            'level-item',
+            {
+              'level-item-act': level === curSelectLevel,
+              'level-item-disabled': level === curChangePaper.level
+            }
+          ]"
+          @click="selectLevel(level)"
+        >
+          {{ level }}
+        </p>
+      </div>
+
+      <div slot="footer">
+        <Button
+          shape="circle"
+          type="primary"
+          :disabled="isSubmit || !curSelectLevel"
+          @click="confirmChange"
+          >确认</Button
+        >
+        <Button shape="circle" @click="cancelChange">取消</Button>
+      </div>
+    </Modal>
   </div>
 </template>
 
@@ -94,7 +133,8 @@ import {
   subjectDetail,
   sampleAreaList,
   workLevelList,
-  cancelStandardPaper
+  cancelStandardPaper,
+  leaderGradingPaper
 } from "@/api";
 import SimpleImagePreview from "@/components/SimpleImagePreview";
 
@@ -108,6 +148,7 @@ export default {
       subject: "",
       canCancel: false,
       questionId: "",
+      lastQuestionId: "",
       curLevel: "",
       curLevelIndex: 0,
       levels: [],
@@ -115,7 +156,12 @@ export default {
       paperMap: {},
       papers: [],
       curPaper: {},
-      curPaperIndex: 0
+      curPaperIndex: 0,
+      // change standard
+      modalIsShow: false,
+      curChangePaper: {},
+      curSelectLevel: null,
+      isSubmit: false
     };
   },
   mounted() {
@@ -153,6 +199,11 @@ export default {
         };
       });
     },
+    search() {
+      if (this.lastQuestionId !== this.questionId) this.paperMap = {};
+      this.lastQuestionId = this.questionId;
+      this.getList();
+    },
     async getList() {
       if (this.paperMap[this.curLevel] && this.paperMap[this.curLevel].length) {
         this.papers = this.paperMap[this.curLevel];
@@ -195,6 +246,44 @@ export default {
         }
       });
     },
+    // change standard paper
+    toChangePaper(paper) {
+      this.curChangePaper = paper;
+      this.modalIsShow = true;
+    },
+    selectLevel(level) {
+      if (level === this.curChangePaper.level) return;
+      this.curSelectLevel = level;
+    },
+    async confirmChange() {
+      if (!this.curSelectLevel) return;
+      if (this.isSubmit) return;
+
+      this.isSubmit = true;
+      const datas = {
+        action: "sampling",
+        level: this.curSelectLevel,
+        originLevel: this.curChangePaper.level,
+        paperIds: this.curChangePaper.id
+      };
+      let result = true;
+      await leaderGradingPaper(datas).catch(() => {
+        result = false;
+      });
+      this.isSubmit = false;
+
+      if (!result) return;
+
+      this.$Message.success("操作成功!");
+      this.paperMap[datas.level] = [];
+      this.paperMap[this.curLevel] = [];
+      this.cancelChange();
+      this.getList();
+    },
+    cancelChange() {
+      this.curSelectLevel = null;
+      this.modalIsShow = false;
+    },
     // to review
     toReview(index) {
       this.selectPaper(index);

+ 4 - 1
src/routers/index.js

@@ -22,7 +22,10 @@ export default new Router({
     {
       path: "/login",
       name: "Login",
-      component: Login
+      component: Login,
+      meta: {
+        noRequire: true
+      }
     },
     ...main,
     ...grading,