src/views/exam/subject.vue
@@ -1,122 +1,110 @@
/*
 * @Author: Morpheus
 * @Date: 2021-07-05 16:31:54
 * @Last Modified by: liu
 * @Last Modified time: 2021-11-23 14:14:38
 * menu-name 题库查询
 */
/* * @Author: Morpheus * @Date: 2021-07-05 16:31:54 * @Last Modified by: liu *
@Last Modified time: 2021-11-23 14:14:38 * menu-name 题库查询 */
<template>
  <div>
    <el-row class="morpheus-box">
      <el-col :span="24">
        <el-card>
          <div
            :class="[
              'exam-card-body',
              $store.state.control.windowWidth >= 1024 ? 'oneRowSearch' : '',
            ]"
          >
            <avue-crud
              class="company-box"
              :option="questionBankOption"
              :search.sync="questionBankSearch"
              :table-loading="questionBankLoading"
              :data="questionBankData"
              ref="questionBankCrud"
              :permission="permissionList"
              :page.sync="questionBankPage"
              @on-load="questionBankOnLoad"
              @selection-change="questionBankSelectionChange"
              @search-change="questionBankSearchChange"
              @search-reset="questionBankSearchReset"
              @current-change="questionBankCurrentChange"
              @size-change="questionBankSizeChange"
              @row-del="questionBankHandleDel"
            >
              <template slot="menuLeft">
                <el-button
                  type="primary"
                  size="small"
                  icon="el-icon-plus"
                  v-if="permission.subject_add"
                  @click="questionBankHandleAdd"
                  >新 增
                </el-button>
                <el-button
                  type="success"
                  size="small"
                  plain
                  icon="el-icon-upload2"
                  v-if="permission.subject_import"
                  @click="handleImport"
                  >题库导入
                </el-button>
                <el-button
                  type="danger"
                  size="small"
                  icon="el-icon-delete"
                  v-if="permission.subject_delete"
                  @click="questionBankHandleDelete"
                  >删 除
                </el-button>
              </template>
  <basic-container
    :class="[
      'exam-card-body',
      $store.state.control.screenSize == 1366 ? 'smallSize' : 'normalSize',
      $store.state.control.windowWidth >= 1024 ? 'tooRowSearch1' : ''
    ]"
  >
    <avue-crud
      class="company-box tablesss"
      :option="questionBankOption"
      :search.sync="questionBankSearch"
      :table-loading="questionBankLoading"
      :data="questionBankData"
      ref="questionBankCrud"
      :permission="permissionList"
      :page.sync="questionBankPage"
      @on-load="questionBankOnLoad"
      @selection-change="questionBankSelectionChange"
      @search-change="questionBankSearchChange"
      @search-reset="questionBankSearchReset"
      @current-change="questionBankCurrentChange"
      @size-change="questionBankSizeChange"
      @row-del="questionBankHandleDel"
    >
      <template slot="menuLeft">
        <el-button
          type="primary"
          size="small"
          icon="el-icon-plus"
          v-if="permission.subject_add"
          @click="questionBankHandleAdd"
          >新 增
        </el-button>
        <el-button
          type="success"
          size="small"
          plain
          icon="el-icon-upload2"
          v-if="permission.subject_import"
          @click="handleImport"
          >题库导入
        </el-button>
        <el-button
          type="danger"
          size="small"
          icon="el-icon-delete"
          v-if="permission.subject_delete"
          @click="questionBankHandleDelete"
          >删 除
        </el-button>
      </template>
              <template slot-scope="{ row }" slot="menu">
                <el-button
                  type="text"
                  size="mini"
                  icon="el-icon-edit"
                  v-if="permission.subject_edit"
                  @click="questionBankHandleAdd(row)"
                  >编辑
                </el-button>
                <el-button
                  type="text"
                  size="mini"
                  icon="el-icon-delete"
                  v-if="permission.subject_delete"
                  @click="questionBankHandleDel(row)"
                  >删除
                </el-button>
              </template>
            </avue-crud>
      <template slot-scope="{ row }" slot="menu">
        <el-button
          type="text"
          size="mini"
          icon="el-icon-edit"
          v-if="permission.subject_edit"
          @click="questionBankHandleAdd(row)"
          >编辑
        </el-button>
        <el-button
          type="text"
          size="mini"
          icon="el-icon-delete"
          v-if="permission.subject_delete"
          @click="questionBankHandleDel(row)"
          >删除
        </el-button>
      </template>
    </avue-crud>
            <el-dialog
              title="题库导入"
              append-to-body
              :visible.sync="excelBox"
              width="555px"
            >
              <avue-form
                :option="excelOption"
                v-model="excelForm"
                :upload-after="uploadAfter"
              >
                <template slot="excelTemplate">
                  <el-button type="primary" @click="handleTemplate">
                    点击下载<i class="el-icon-download el-icon--right"></i>
                  </el-button>
                </template>
              </avue-form>
            </el-dialog>
          </div>
        </el-card>
      </el-col>
    </el-row>
    <el-dialog
      title="题库导入"
      append-to-body
      :visible.sync="excelBox"
      width="555px"
    >
      <avue-form
        :option="excelOption"
        v-model="excelForm"
        :upload-after="uploadAfter"
      >
        <template slot="excelTemplate">
          <el-button type="primary" @click="handleTemplate">
            点击下载<i class="el-icon-download el-icon--right"></i>
          </el-button>
        </template>
      </avue-form>
    </el-dialog>
    <addsubject ref="addsubject" v-on:refreshPage="refreshPage"></addsubject>
  </div>
  </basic-container>
</template>
<script>
import { getList, remove } from "@/api/examapi/subject";
import addsubject from "./addsubject.vue";
import { mapGetters,mapState } from "vuex";
import { mapGetters, mapState } from "vuex";
import Qs from "qs";
import { getToken } from "@/util/auth";
export default {
  components: {
    addsubject,
    addsubject
  },
  data() {
    return {
@@ -134,18 +122,18 @@
            loadText: "模板上传中,请稍等",
            span: 24,
            propsHttp: {
              res: "data",
              res: "data"
            },
            tip: "请上传 .xls,.xlsx 标准格式文件",
            action: "/api/examSubjectChoices/import-examSubject",
            action: "/api/examSubjectChoices/import-examSubject"
          },
          {
            label: "模板下载",
            prop: "excelTemplate",
            formslot: true,
            span: 24,
          },
        ],
            span: 24
          }
        ]
      },
      questionBankOption: {
        // 操作栏多余按钮去除
@@ -172,13 +160,14 @@
        // 操作栏宽度
        menuWidth: 226,
        ...this.$store.state.control.clearOtherBut,
        ...this.$store.state.control.searchOpen,
        column: [
          {
            label: "题目名称",
            prop: "subjectName",
            searchSpan: 4,
            search: true,
            slot: true,
            slot: true
          },
          {
            label: "题目类型",
@@ -189,61 +178,61 @@
            dicData: [
              {
                label: "单选题",
                value: 0,
                value: 0
              },
              {
                label: "多选题",
                value: 1,
                value: 1
              },
              {
                label: "判断题",
                value: 2,
                value: 2
              },
              {
                label: "实操题",
                value: 3,
              },
                value: 3
              }
            ],
            slot: true,
            width: 96,
            width: 96
          },
          {
            label: "题目分值",
            prop: "score",
            slot: true,
            width: 96,
            width: 96
          },
          {
            label: "参考答案",
            prop: "answer",
            slot: true,
            width: 96,
            width: 96
          },
          {
            label: "创建人",
            prop: "creator",
            slot: true,
            width: 96,
            width: 96
          },
          {
            label: "创建时间",
            prop: "createDate",
            slot: true,
            width: 130,
            width: 130
          },
          {
            label: "修改人",
            prop: "modifier",
            slot: true,
            width: 96,
            width: 96
          },
          {
            label: "修改时间",
            prop: "modifyDate",
            slot: true,
            width: 130,
          },
        ],
            width: 130
          }
        ]
      },
      questionBankSearch: {},
      questionBankLoading: true,
@@ -252,13 +241,15 @@
        pageSize: 10,
        currentPage: 1,
        total: 16,
        ...this.$store.state.control.changePageSize,
        ...this.$store.state.control.changePageSize
      },
      questionBankQuery: {},
      questionBankSelectionList: [],
      questionBankSelectionList: []
    };
  },
  mounted() {},
  mounted() {
    this.$store.commit("setWindowSizeHeightAdd");
  },
  computed: {
    ...mapGetters(["userInfo", "permission"]),
    permissionList() {
@@ -267,20 +258,20 @@
        viewBtn: this.vaildData(this.permission.subject_view, false),
        delBtn: this.vaildData(this.permission.subject_delete, false),
        editBtn: this.vaildData(this.permission.subject_edit, false),
        excelBtn: this.vaildData(this.permission.subject_report, false),
        excelBtn: this.vaildData(this.permission.subject_report, false)
      };
    },
    ids() {
      let ids = [];
      this.questionBankSelectionList.forEach((ele) => {
      this.questionBankSelectionList.forEach(ele => {
        ids.push(ele.id);
      });
      return ids.join(",");
    },
    }
  },
  methods: {
    //触发页面刷新
    refreshPage(){
    refreshPage() {
      this.questionBankOnLoad(this.questionBankPage);
    },
    questionBankHandleAdd(row) {
@@ -293,11 +284,12 @@
        page.currentPage,
        page.pageSize,
        Object.assign(params, this.query)
      ).then((res) => {
      ).then(res => {
        const data = res.data.data;
        this.questionBankPage.total = data.total;
        this.questionBankData = data.records;
        this.questionBankLoading = false;
        this.$store.commit("setWindowSizeHeightAdd");
        this.questionBankSelectionClear();
      });
    },
@@ -329,7 +321,7 @@
      this.$confirm("确定将选择数据删除?", {
        confirmButtonText: "确定",
        cancelButtonText: "取消",
        type: "warning",
        type: "warning"
      })
        .then(() => {
          return remove(row.id);
@@ -338,7 +330,7 @@
          this.questionBankOnLoad(this.questionBankPage);
          this.$message({
            type: "success",
            message: "操作成功!",
            message: "操作成功!"
          });
        });
    },
@@ -351,7 +343,7 @@
      this.$confirm("确定将选择数据删除?", {
        confirmButtonText: "确定",
        cancelButtonText: "取消",
        type: "warning",
        type: "warning"
      })
        .then(() => {
          return remove(this.ids);
@@ -360,7 +352,7 @@
          this.questionBankOnLoad(this.questionBankPage);
          this.$message({
            type: "success",
            message: "操作成功!",
            message: "操作成功!"
          });
          this.$refs.questionBankCrud.toggleSelection();
        });
@@ -371,16 +363,24 @@
      this.$confirm("是否导出清册数据?", "提示", {
        confirmButtonText: "确定",
        cancelButtonText: "取消",
        type: "warning",
        type: "warning"
      }).then(() => {
        window.open(`/api/apply/export-apply?examId=${this.$route.query.id}&${this.website.tokenHeader}=${getToken()}`);
        window.open(
          `/api/apply/export-apply?examId=${this.$route.query.id}&${
            this.website.tokenHeader
          }=${getToken()}`
        );
      });
    },
    handleImport() {
      this.excelBox = true;
    },
    handleTemplate() {
      window.open(`/api/examSubjectChoices/export-template?${this.website.tokenHeader}=${getToken()}`);
      window.open(
        `/api/examSubjectChoices/export-template?${
          this.website.tokenHeader
        }=${getToken()}`
      );
    },
    uploadAfter(res, done, loading, column) {
      window.console.log(column);
@@ -390,10 +390,9 @@
    },
    refreshChange() {
      this.questionBankOnLoad(this.page, this.query);
    },
  },
    }
  }
};
</script>
<style lang="scss" scoped>
</style>
<style lang="scss" scoped></style>