xiatian 4 years ago
parent
commit
0964e1ebaa

+ 2 - 2
src/modules/questions/views/Course.vue

@@ -458,7 +458,7 @@
           />
           <el-table-column label="操作" width="290">
             <div slot-scope="scope">
-              <el-button
+              <!-- <el-button
                 size="mini"
                 type="primary"
                 plain
@@ -466,7 +466,7 @@
                 @click="relation(scope.row)"
               >
                 关联专业
-              </el-button>
+              </el-button> -->
               <el-button
                 size="mini"
                 type="primary"

+ 4 - 2
src/modules/questions/views/data_previllege_add_course.vue

@@ -114,12 +114,14 @@ export default {
       var param = new URLSearchParams(this.form);
       var url =
         QUESTION_API +
-        "/course/coursePage/" +
+        "/course/coursePageForDataRule/" +
         (this.currentPage - 1) +
         "/" +
         this.pageSize +
         "?" +
-        param;
+        param +
+        "&userId=" +
+        this.userId;
       this.loading = true;
       return this.$httpWithMsg.get(url).then((response) => {
         this.tableData = response.data.content;

+ 214 - 5
src/modules/questions/views/user.vue

@@ -108,6 +108,14 @@
             >
               新增
             </el-button>
+            <el-button
+              size="small"
+              type="primary"
+              icon="el-icon-upload2"
+              @click="impUser"
+            >
+              导入
+            </el-button>
           </el-form-item>
         </el-form>
 
@@ -205,6 +213,7 @@
                     :key="item.roleId"
                     :label="item.roleName"
                     :value="item.roleId"
+                    :disabled="roleDis(item.roleCode)"
                   >
                   </el-option>
                 </el-select>
@@ -295,7 +304,7 @@
                     v-for="item in roleList4InsertOrUpdate"
                     :key="item.roleId"
                     :label="item.roleName"
-                    :disabled="item.roleCode == 'SUPER_ADMIN'"
+                    :disabled="roleDis(item.roleCode)"
                     :value="item.roleId"
                   >
                   </el-option>
@@ -320,7 +329,77 @@
             </el-row>
           </el-form>
         </el-dialog>
+        <!-- 导入弹窗 -->
+        <el-dialog title="导入窗口" width="520px" :visible.sync="impDialog">
+          <el-form>
+            <el-row>
+              <el-form-item style="margin-left: 20px">
+                <el-upload
+                  ref="upload"
+                  class="form_left"
+                  accept="application/vnd.openxmlformats-officedocument.spreadsheetml.sheet"
+                  :action="uploadAction"
+                  :headers="uploadHeaders"
+                  :data="uploadData"
+                  :on-success="uploadSuccess"
+                  :on-error="uploadError"
+                  :file-list="fileList"
+                  :auto-upload="false"
+                  :multiple="false"
+                >
+                  <el-button
+                    slot="trigger"
+                    size="small"
+                    type="primary"
+                    icon="el-icon-search"
+                  >
+                    选择文件
+                  </el-button>
+                  &nbsp;
+                  <el-button
+                    size="small"
+                    type="primary"
+                    icon="el-icon-check"
+                    @click="submitUpload"
+                  >
+                    确认上传
+                  </el-button>
+                  <el-button
+                    size="small"
+                    type="primary"
+                    icon="el-icon-refresh"
+                    @click="removeFile"
+                  >
+                    清空文件
+                  </el-button>
+                  <el-button
+                    size="small"
+                    type="primary"
+                    icon="el-icon-download"
+                    @click="exportFile"
+                  >
+                    下载模板
+                  </el-button>
+                  <div slot="tip" class="el-upload__tip">只能上传xlsx文件</div>
+                </el-upload>
+              </el-form-item>
+            </el-row>
+          </el-form>
+        </el-dialog>
 
+        <!-- 导入错误信息列表 -->
+        <el-dialog title="错误提示" :visible.sync="errDialog">
+          <div
+            v-for="errMessage in errMessages"
+            :key="errMessage.lineNum"
+            class="text-danger"
+          >
+            第{{ errMessage.lineNum }}行:{{ errMessage.msg }}
+          </div>
+          <span slot="footer" class="dialog-footer">
+            <el-button @click="errDialog = false">确定</el-button>
+          </span>
+        </el-dialog>
         <!-- 页面列表 -->
         <el-table
           ref="table"
@@ -386,7 +465,7 @@
           </el-table-column>
           <el-table-column width="190" label="操作">
             <div slot-scope="scope">
-              <div v-if="!userIsSuperAdmin(scope.row)">
+              <div v-if="showBtn(scope.row)">
                 <el-button
                   v-if="!scope.row.enable"
                   size="mini"
@@ -501,6 +580,15 @@ export default {
       }
     };
     return {
+      impDialog: false,
+      uploadAction: QUESTION_API + "/user/import",
+      uploadHeaders: {},
+      uploadData: {},
+      errMessages: [],
+      errDialog: false,
+      fileLoading: false,
+      fileList: [],
+
       courseList4Search: [],
       courseLoading4Search: false,
       rolePrivileges: {
@@ -612,9 +700,28 @@ export default {
         (item) => item.roleCode != "SUPER_ADMIN"
       );
     },
+    isSubjectTeacher() {
+      return this.user.roleList.some(
+        (role) => role.roleCode == "SUBJECT_TEACHER"
+      );
+    },
+    onlySubjectTeacher() {
+      if (this.isAdmin) {
+        return false;
+      } else {
+        return this.user.roleList.some(
+          (role) => role.roleCode == "SUBJECT_TEACHER"
+        );
+      }
+    },
     isSuperAdmin() {
       return this.user.roleList.some((role) => role.roleCode == "SUPER_ADMIN");
     },
+    isAdmin() {
+      return this.user.roleList.some(
+        (role) => role.roleCode == "SUPER_ADMIN" || role.roleCode == "ADMIN"
+      );
+    },
     rootSchoolSelect() {
       let rootSchools = [];
       for (let i = 0; i < this.rootOrgList.length; i++) {
@@ -631,8 +738,102 @@ export default {
   created() {
     this.initPrivileges();
     this.init();
+    this.uploadHeaders = {
+      key: this.user.key,
+      token: this.user.token,
+    };
   },
   methods: {
+    roleDis(code) {
+      if (this.onlySubjectTeacher && code != "ASSIGN_TEACHER") {
+        return true;
+      } else {
+        return false;
+      }
+    },
+    impUser() {
+      this.impDialog = true;
+      this.initUpload();
+    },
+    initUpload() {
+      this.fileList = [];
+    },
+    uploadSuccess(response) {
+      if (!response.hasError) {
+        this.$notify({
+          message: "上传成功",
+          type: "success",
+        });
+        this.fileLoading = false;
+        this.impDialog = false;
+        this.searchForm();
+      } else {
+        this.fileLoading = false;
+        this.impDialog = false;
+        this.errMessages = response.failRecords;
+        this.errDialog = true;
+      }
+    },
+    uploadError(response) {
+      var json = JSON.parse(response.message);
+      if (response.status == 500) {
+        this.$notify({
+          message: json.desc,
+          type: "error",
+        });
+      }
+      this.fileLoading = false;
+    },
+    //确定上传
+    submitUpload() {
+      if (!this.checkUpload()) {
+        return false;
+      }
+      this.$refs.upload.submit();
+      this.fileLoading = true;
+    },
+    checkUpload() {
+      var fileList = this.$refs.upload.uploadFiles;
+      if (fileList.length == 0) {
+        this.$notify({
+          message: "上传文件不能为空",
+          type: "error",
+        });
+        return false;
+      }
+      if (fileList.length > 1) {
+        this.$notify({
+          message: "每次只能上传一个文件",
+          type: "error",
+        });
+        return false;
+      }
+      for (let file of fileList) {
+        if (!file.name.endsWith(".xlsx")) {
+          this.$notify({
+            message: "上传文件必须为xlsx格式",
+            type: "error",
+          });
+          this.initUpload();
+          return false;
+        }
+      }
+      return true;
+    },
+    //清空文件
+    removeFile() {
+      // this.fileList = [];
+      this.$refs.upload.clearFiles();
+    },
+    //下载模板
+    exportFile() {
+      window.location.href =
+        QUESTION_API +
+        "/user/importTemplate?$key=" +
+        this.user.key +
+        "&$token=" +
+        this.user.token;
+    },
     getCourses4Search(query) {
       this.courseLoading4Search = true;
       this.$httpWithMsg
@@ -1038,17 +1239,25 @@ export default {
 
       return true;
     },
-    userIsSuperAdmin(row) {
+    showBtn(row) {
       let roleCodes = row.roleCodes;
 
       for (let n = 0; n < roleCodes.length; n++) {
         let roleCode = roleCodes[n];
         if (roleCode == "SUPER_ADMIN") {
-          return true;
+          return false;
+        }
+      }
+      if (this.isSubjectTeacher) {
+        for (let n = 0; n < roleCodes.length; n++) {
+          let roleCode = roleCodes[n];
+          if (roleCode != "ASSIGN_TEACHER") {
+            return false;
+          }
         }
       }
 
-      return false;
+      return true;
     },
   },
 };