123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685 |
- <template>
- <section element-loading-text="请稍后..." class="content">
- <div class="part-box">
- <el-form
- ref="primaryForm"
- class="part-filter-form"
- inline
- :model="formSearch"
- >
- <el-form-item label="课程名称">
- <el-input v-model="formSearch.name" placeholder="请输入课程名称" />
- </el-form-item>
- <el-form-item label="课程代码">
- <el-input v-model="formSearch.code" placeholder="请输入课程代码" />
- </el-form-item>
- <el-form-item label="层次">
- <el-select v-model="formSearch.level" placeholder="请选择" clearable>
- <el-option
- v-for="item in levelList"
- :key="item.value"
- :label="item.label"
- :value="item.value"
- />
- </el-select>
- </el-form-item>
- <el-form-item>
- <el-button type="primary" @click="handleSearchBtn">查询</el-button>
- <el-button type="danger" plain @click="resetPrimaryForm">
- 重置
- </el-button>
- </el-form-item>
- </el-form>
- <!-- <div class="part-box-action">
- <div>
- <el-button
- type="danger"
- plain
- :disabled="noBatchSelected"
- icon="icon icon-play"
- @click="deleteByIds"
- >删除
- </el-button>
- <el-button
- type="primary"
- plain
- icon="icon icon-import"
- @click="importCourse"
- >导入</el-button
- >
- <el-button
- type="primary"
- plain
- icon="icon icon-export"
- :loading="downloading"
- @click="exportCourse"
- >导出</el-button
- >
- </div>
- <el-button
- v-if="authButtons.includes('index_course-add_course')"
- type="primary"
- icon="icon icon-plus-white"
- @click="insertCourse"
- >新增</el-button
- >
- </div> -->
- </div>
- <div class="part-box">
- <div class="icon-btn-group">
- <svg-btn
- name="xinzeng"
- v-if="authButtons.includes('index_course-add_course')"
- @click="insertCourse"
- >新增</svg-btn
- >
- <svg-btn name="daoru" @click="importCourse">导入</svg-btn>
- <svg-btn name="daochu" @click="exportCourse">导出</svg-btn>
- <svg-btn name="shanchu" :disabled="noBatchSelected" @click="deleteByIds"
- >删除</svg-btn
- >
- </div>
- <!-- 页面列表 -->
- <!-- FIXME: element-ui style bug https://github.com/ElemeFE/element/issues/16167 -->
- <el-table :data="tableData" resizable @selection-change="selectChange">
- <el-table-column type="selection" width="50" align="center" />
- <el-table-column prop="id" label="课程ID" width="80" />
- <el-table-column prop="name" label="课程名称" width="180" />
- <el-table-column prop="code" label="课程代码" />
- <el-table-column label="层次">
- <span slot-scope="scope">{{ getLevel(scope.row.level) }}</span>
- </el-table-column>
- <el-table-column
- sortable
- prop="updateTime"
- label="更新时间"
- width="170"
- />
- <el-table-column label="操作" width="220">
- <div slot-scope="scope">
- <!-- <el-button
- size="mini"
- type="primary"
- plain
- icon="el-icon-share"
- @click="relation(scope.row)"
- >
- 关联专业
- </el-button> -->
- <el-button
- size="medium"
- type="text"
- class="normal"
- @click="editCourse(scope.row)"
- >
- 编辑
- </el-button>
- <el-button
- size="medium"
- type="text"
- class="normal"
- @click="toKnowledge(scope.row)"
- >
- 知识点
- </el-button>
- <el-button
- size="medium"
- type="text"
- class="normal"
- @click="deleteById(scope.row)"
- >
- 删除
- </el-button>
- </div>
- </el-table-column>
- </el-table>
- <div class="part-page">
- <el-pagination
- :current-page="currentPage"
- :page-size="10"
- :page-sizes="[10, 20, 50, 100, 200, 300]"
- layout="total, sizes, prev, pager, next, jumper"
- :total="total"
- @current-change="handleCurrentChange"
- @size-change="handleSizeChange"
- >
- </el-pagination>
- </div>
- </div>
- <!-- 添加或新增课程弹出框 -->
- <el-dialog
- title="课程"
- width="450px"
- :visible.sync="courseDialog"
- :modal="true"
- append-to-body
- custom-class="side-dialog"
- @close="dialogBeforeClose"
- >
- <el-form
- ref="courseForm"
- class="form-tight"
- :model="courseForm"
- :rules="rules"
- label-width="90px"
- >
- <el-form-item label="课程名称" prop="name">
- <el-input
- v-model="courseForm.name"
- auto-complete="off"
- placeholder="请输入课程名称"
- />
- </el-form-item>
- <br />
- <el-form-item label="课程代码" prop="code">
- <el-input
- v-model="courseForm.code"
- auto-complete="off"
- placeholder="请输入课程代码"
- />
- </el-form-item>
- <br />
- <el-form-item label="层次" prop="level">
- <el-select v-model="courseForm.level" placeholder="请选择">
- <el-option
- v-for="item in levelList"
- :key="item.value"
- :label="item.label"
- :value="item.value"
- />
- </el-select>
- </el-form-item>
- </el-form>
- <div slot="footer">
- <el-button type="primary" @click="submitForm">保存</el-button>
- <el-button type="danger" plain @click="courseDialog = false"
- >取消</el-button
- >
- </div>
- </el-dialog>
- <!-- 导入弹窗 -->
- <import-file-dialog
- ref="ImportCourseDialog"
- dialog-title="导入课程"
- :template-url="courseTemplateUrl"
- :upload-url="uploadCourseUrl"
- @uploaded="uploadSuccess"
- ></import-file-dialog>
- <!-- 导入错误信息列表 -->
- <el-dialog title="错误提示" :visible.sync="errDialog" append-to-body>
- <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>
- </section>
- </template>
- <script>
- import { QUESTION_API } from "@/constants/constants.js";
- import { ENABLE_TYPE, LEVEL_TYPE } from "../constants/constants.js";
- import { mapState, mapGetters } from "vuex";
- import { courseExportApi } from "../api";
- import { downloadByApi } from "@/plugins/download";
- import ImportFileDialog from "@/components/ImportFileDialog.vue";
- import SvgBtn from "@/components/SvgBtn.vue";
- export default {
- name: "Course",
- components: { ImportFileDialog, SvgBtn },
- data() {
- return {
- formSearch: {
- name: "",
- code: "",
- enable: "true",
- level: "",
- },
- courseForm: {
- id: null,
- name: "",
- code: "",
- level: "ALL",
- enable: "true",
- },
- statusList: ENABLE_TYPE,
- levelList: LEVEL_TYPE,
- selectedCourseIds: [],
- tableData: [],
- currentPage: 1,
- pageSize: 10,
- total: 10,
- uploadCourseUrl: `${QUESTION_API}/course/import`,
- courseTemplateUrl: `${QUESTION_API}/course/importTemplate`,
- uploadHeaders: {},
- errMessages: [],
- errDialog: false,
- courseDialog: false,
- relationDialog: false,
- downloading: false,
- rules: {
- name: [
- {
- required: true,
- message: "请输入课程名称",
- trigger: "blur",
- },
- {
- max: 30,
- message: "课程名称最多30个字符",
- trigger: "blur",
- },
- ],
- code: [
- {
- required: true,
- message: "请输入课程代码",
- trigger: "blur",
- },
- {
- max: 30,
- message: "课程代码最多30个字符",
- trigger: "blur",
- },
- {
- pattern: new RegExp(`^[a-zA-Z0-9-_\\s\\[\\]\\(\\)\\{\\}]{1,30}$`),
- message: "只能包含字母、数字、括号、空格、下划线和短横线",
- trigger: "blur",
- },
- ],
- level: [
- {
- required: true,
- message: "请选择层次",
- trigger: "change",
- },
- ],
- status: [
- {
- required: true,
- message: "请选择状态",
- trigger: "change",
- },
- ],
- },
- };
- },
- computed: {
- ...mapState({
- user: (state) => state.user,
- }),
- ...mapGetters(["authButtons"]),
- noBatchSelected() {
- return this.selectedCourseIds.length === 0;
- },
- courseIds() {
- var courseIds = "";
- for (let courseId of this.selectedCourseIds) {
- if (!courseIds) {
- courseIds += courseId;
- } else {
- courseIds += "," + courseId;
- }
- }
- return courseIds;
- },
- },
- //初始化查询
- created() {
- this.searchForm();
- this.uploadHeaders = {
- key: this.user.key,
- token: this.user.token,
- };
- },
- methods: {
- handleSizeChange(val) {
- this.pageSize = val;
- this.currentPage = 1;
- this.searchForm();
- },
- dialogBeforeClose() {
- this.$refs.courseForm.clearValidate();
- },
- submitAddRelationForm() {
- this.$refs.addRelationForm.validate((valid) => {
- if (valid) {
- var param = new URLSearchParams(this.addRelationForm);
- var url = QUESTION_API + "/courseSpeciatlyRelation/add?" + param;
- this.$httpWithMsg.post(url, this.speciallyForm).then(() => {
- this.$notify({
- type: "success",
- message: "添加成功!",
- });
- this.addRelationDialog = false;
- });
- } else {
- console.log("error submit!");
- return false;
- }
- });
- },
- getTag(status) {
- if (status == true) {
- return "success";
- } else if (status == false) {
- return "danger";
- }
- return status;
- },
- getLevel(level) {
- if (level == "ZSB") {
- return "专升本";
- } else if (level == "GQZ") {
- return "高起专";
- } else if (level == "GQB") {
- return "高起本";
- } else {
- return "不限";
- }
- },
- handleSearchBtn() {
- this.currentPage = 1;
- this.searchForm();
- },
- searchForm() {
- let searchLock = true;
- setTimeout(() => {
- if (searchLock) {
- this.loading = true;
- }
- }, 500);
- var param = new URLSearchParams(this.formSearch);
- var url =
- QUESTION_API +
- "/course/coursePage/" +
- this.currentPage +
- "/" +
- this.pageSize +
- "?" +
- param;
- this.$httpWithMsg
- .get(url)
- .then((response) => {
- this.tableData = response.data.content;
- this.total = response.data.totalElements;
- })
- .finally(() => {
- searchLock = false;
- this.loading = false;
- });
- },
- handleCurrentChange(val) {
- this.currentPage = val;
- this.searchForm();
- },
- selectChange(row) {
- this.selectedCourseIds = [];
- row.forEach((element) => {
- this.selectedCourseIds.push(element.id);
- });
- console.log(this.selectedCourseIds);
- },
- //新增
- insertCourse() {
- this.courseForm.id = null;
- this.courseForm.name = null;
- this.courseForm.code = null;
- this.courseForm.level = "ALL";
- this.courseForm.enable = "true";
- this.courseDialog = true;
- },
- //修改
- editCourse(row) {
- this.courseForm = Object.assign({}, row);
- this.courseForm.enable = row.enable ? "true" : "false";
- this.courseId = row.id;
- this.courseDialog = true;
- },
- async exportCourse() {
- if (this.downloading) return;
- this.downloading = true;
- const res = await downloadByApi(() => {
- return courseExportApi(this.formSearch);
- }).catch((e) => {
- this.$message.error(e || "下载失败,请重新尝试!");
- });
- this.downloading = false;
- if (!res) return;
- this.$message.success("下载成功!");
- },
- closeCourse() {
- this.courseDialog = false;
- },
- saveRelation() {},
- //保存(新增/修改)
- submitForm() {
- var url = QUESTION_API + "/course";
- if (null != this.courseForm.id) {
- //修改
- this.$refs.courseForm.validate((valid) => {
- if (valid) {
- this.$httpWithMsg.put(url, this.courseForm).then(() => {
- this.$notify({
- type: "success",
- message: "修改成功!",
- });
- this.searchForm();
- this.resetForm();
- this.courseDialog = false;
- });
- } else {
- console.log("error submit!");
- return false;
- }
- });
- } else {
- this.$refs.courseForm.validate((valid) => {
- if (valid) {
- this.$httpWithMsg.post(url, this.courseForm).then(() => {
- this.$notify({
- type: "success",
- message: "添加成功",
- });
- this.searchForm();
- this.resetForm();
- this.courseDialog = false;
- });
- } else {
- console.log("error submit!");
- return false;
- }
- });
- }
- },
- //重置
- resetForm() {
- this.$refs.courseForm.resetFields();
- },
- resetPrimaryForm() {
- this.formSearch = {
- name: "",
- code: "",
- enable: "",
- level: "",
- };
- this.$refs.primaryForm.resetFields();
- },
- //删除单个数据
- deleteById(row) {
- this.$confirm("是否删除该课程?", "系统通知", {
- confirmButtonText: "确定",
- cancelButtonText: "取消",
- type: "warning",
- }).then(() => {
- var url = QUESTION_API + "/course/delete";
- let temCourseIds = [];
- temCourseIds.push(row.id);
- this.$httpWithMsg
- .post(url, new URLSearchParams({ courseIds: temCourseIds }))
- .then(() => {
- this.$notify({
- type: "success",
- message: "删除成功!",
- });
- this.searchForm();
- });
- });
- },
- //知识点
- toKnowledge(row) {
- this.$router.push({
- path: "/questions/property_info/" + row.id,
- });
- },
- //删除多条数据
- deleteByIds() {
- if (this.selectedCourseIds.length === 0) {
- this.$notify({
- type: "warning",
- message: "请选择要删除的课程",
- });
- } else {
- this.$confirm("确定要删除所选课程吗?", "提示", {
- confirmButtonText: "确定",
- cancelButtonText: "取消",
- type: "error",
- }).then(() => {
- var url = QUESTION_API + "/course/delete";
- this.$httpWithMsg
- .post(
- url,
- new URLSearchParams({ courseIds: this.selectedCourseIds })
- )
- .then(() => {
- this.$notify({
- type: "success",
- message: "删除成功!",
- });
- this.searchForm();
- });
- });
- }
- },
- //启用
- enableByIds() {
- if (this.selectedCourseIds.length === 0) {
- this.$notify({
- type: "warning",
- message: "请选择要启用的课程",
- });
- } else {
- this.$confirm("确定要启用所选课程吗?", "系统通知", {
- confirmButtonText: "确定",
- cancelButtonText: "取消",
- type: "warning",
- }).then(() => {
- var url = QUESTION_API + "/course/enable/" + this.courseIds;
- this.$httpWithMsg.put(url, {}).then(() => {
- this.$notify({
- type: "success",
- message: "启用成功!",
- });
- this.searchForm();
- });
- });
- }
- },
- enableById(row) {
- this.$confirm("是否启用该课程?", "系统通知", {
- confirmButtonText: "确定",
- cancelButtonText: "取消",
- type: "warning",
- }).then(() => {
- var url = QUESTION_API + "/course/enable/" + row.id;
- this.$httpWithMsg.put(url, {}).then(() => {
- this.$notify({
- type: "success",
- message: "启用成功!",
- });
- this.searchForm();
- });
- });
- },
- //禁用
- disableByIds() {
- if (this.selectedCourseIds.length === 0) {
- this.$notify({
- type: "warning",
- message: "请选择要禁用的课程",
- });
- } else {
- this.$confirm("确定要禁用所选课程吗?", "系统通知", {
- confirmButtonText: "确定",
- cancelButtonText: "取消",
- type: "error",
- }).then(() => {
- var url = QUESTION_API + "/course/disable/" + this.courseIds;
- this.$httpWithMsg.put(url, {}).then(() => {
- this.$notify({
- type: "success",
- message: "禁用成功!",
- });
- this.searchForm();
- });
- });
- }
- },
- //禁用
- disableById(row) {
- this.$confirm("是否禁用该课程?", "系统通知", {
- confirmButtonText: "确定",
- cancelButtonText: "取消",
- type: "error",
- }).then(() => {
- var url = QUESTION_API + "/course/disable/" + row.id;
- return this.$httpWithMsg.put(url, {}).then(() => {
- this.$notify({
- type: "success",
- message: "禁用成功!",
- });
- return this.searchForm();
- });
- });
- },
- //导入
- importCourse() {
- this.$refs.ImportCourseDialog.open();
- },
- uploadSuccess(response) {
- const { hasError, failRecords } = response.data;
- if (!hasError) {
- this.$notify({
- message: "上传成功",
- type: "success",
- });
- this.searchForm();
- } else {
- this.errMessages = failRecords;
- this.errDialog = true;
- }
- },
- },
- };
- </script>
|