试卷管理代码备用

This commit is contained in:
joylink_zhaoerwei 2024-02-21 10:53:44 +08:00
parent 757f661a22
commit e48289b953
3 changed files with 311 additions and 5 deletions

View File

@ -1,5 +1,55 @@
import request from '@/utils/request';
/**
* 获取竞赛试卷分页列表
* @param {Object} data
* @param {String} data.name 试卷名称
*/
export function getPaperList(data) {
return request({
url: '/api/exercise/race/pager/page',
method: 'GET',
data
});
}
/**
* 创建试卷
* @param {Object} data
* @param {String} data.name 试卷名称
* @param {String} data.desc 基础描述
* @param {Number} data.seasonId 所属赛季id
*/
export function createPaper(data) {
return request({
url: '/api/exercise/race/paper',
method: 'POST',
data
});
}
/**
* @param {Object} data 同创建试卷
* @param {Number} id 试卷id
*/
export function editPaper(id, data) {
return request({
url: `/api/exercise/race/paper/${id}`,
method: 'POST',
data
});
}
/**
* @param {Number} id 任务id
*/
export function deletePaper(id) {
return request({
url: `/api/exercise/race/paper/${id}`,
method: 'DELETE'
});
}
/** 查看所有任务数据 */
export function getTaskTreeDatas() {
return request({
@ -27,11 +77,11 @@ export function createTask(data) {
/**
* @param {Object} data 同创建任务
* @param {Number} data.id 任务id
* @param {Number} id 任务id
*/
export function editTask(data) {
export function editTask(id, data) {
return request({
url: `/api/exercise/race/task/${data.id}`,
url: `/api/exercise/race/task/${id}`,
method: 'POST',
data
});
@ -59,7 +109,7 @@ export function getchildrenTaskDatas(id) {
/**
* @param {Object} data
* @param {Number} data.taskId 任务名称
* @param {Number} data.taskId 任务id
* @param {Number} data.bindId 绑定id根据bindtype来区分对应的id
* @param {String} data.bindType rule =评分规则;scene=场景
*/

View File

@ -0,0 +1,131 @@
<template>
<el-dialog v-dialogDrag :title="title" :visible.sync="dialogVisible" width="500px" :before-close="handleClose" center :close-on-click-modal="false">
<el-form ref="ruleForm" :model="formModel" :rules="rules" label-width="100px">
<el-form-item label="试卷名称:" prop="name">
<el-input v-model="formModel.name" style="width: 350px;" />
</el-form-item>
<el-form-item label="试卷描述:" prop="desc">
<el-input v-model="formModel.desc" type="textarea" style="width:350px;" />
</el-form-item>
<el-form-item label="所属赛季:" prop="seasonId">
<el-select v-model="formModel.seasonId" placeholder="请选择" style="width:350px;">
<el-option
v-for="item in seasonOptions"
:key="item.value"
:label="item.label"
:value="item.value"
/>
</el-select>
</el-form-item>
</el-form>
<span slot="footer" class="dialog-footer">
<el-button v-loading="loading" type="primary" @click="doSave">{{ $t('global.confirm') }}</el-button>
<el-button @click="handleClose">{{ $t('global.cancel') }}</el-button>
</span>
</el-dialog>
</template>
<script>
import { createPaper, editPaper} from '@/api/contest';
export default {
name: 'AddContestTask',
data() {
return {
dialogVisible: false,
formModel: {
id: '',
name: '', //
desc: '', //
seasonId: 0 // id
},
seasonOptions:[{
value: 1,
label: '赛季1'
}, {
value: 2,
label: '赛季2'
}],
loading: false
};
},
computed: {
rules() {
const crules = {
name: [
{ required: true, message: '请输入试卷名称', trigger: 'blur' }
],
desc: [
{ required: true, message: '请输入试卷描述', trigger: 'blur' }
],
seasonId: [
{ required: true, message: '请选择试卷所属赛季', trigger: 'blur' }
]
};
return crules;
},
title() {
return this.formModel.id ? '修改试卷' : '创建试卷';
}
},
methods:{
doShow(row) {
this.dialogVisible = true;
if (row) {
this.formModel.id = row.id;
this.formModel.name = row.name;
this.formModel.desc = row.desc;
this.formModel.seasonId = row.seasonId;
} else {
this.formModel = {
id: '',
name: '',
desc: '',
seasonId: ''
};
this.$nextTick(() => {
this.$refs.ruleForm.resetFields();
});
}
},
handleClose() {
this.formModel = {
id: '',
name: '',
desc: '',
seasonId: ''
};
this.$refs.ruleForm.resetFields();
this.dialogVisible = false;
this.loading = false;
},
doSave() {
this.$refs.ruleForm.validate((valid) => {
if (valid) {
this.loading = true;
const data = Object.assign({}, this.formModel);
delete data.id;
if (this.formModel.id) {
editPaper(data).then(() => {
this.$message.success('修改试卷成功!');
this.handleClose();
this.$emit('paperListRefresh');
}).catch(error => {
this.$message.error(error.message);
this.loading = false;
});
} else {
createPaper(data).then(() => {
this.$message.success('创建试卷成功!');
this.handleClose();
this.$emit('paperListRefresh');
}).catch(error => {
this.$message.error(error.message);
this.loading = false;
});
}
}
});
}
}
};
</script>

View File

@ -1,3 +1,128 @@
<template>
<div>竞赛题目管理</div>
<div style="width: 100%;">
<QueryListPage
ref="examQueryListPage"
:card-padding="10"
:query-form="examQueryForm"
:pager-config="pagerConfig"
:query-list="examQueryList"
/>
<add-edit-paper ref="addEditPaper" @paperListRefresh="paperListRefresh" />
</div>
</template>
<script>
import { getPaperList, deletePaper } from '@/api/contest';
import AddEditPaper from './AddEditPaper.vue';
export default {
name: 'SubjectManage',
components: { AddEditPaper },
data() {
return {
pagerConfig: {
pageSize: 'pageSize',
pageIndex: 'pageNum'
},
seasonlist: [],
examQueryForm: {
leftSpan: 14,
textAlign: 'right',
labelWidth: '90px',
reset: true,
columnNum: 3,
queryObject: {
name: {
type: 'text',
label: '试卷名称:'
}
}
},
examQueryList: {
query: obj => this.getListApi(obj),
selectCheckShow: false,
indexShow: false,
columns: [
{
title: '试卷名称',
prop: 'name'
},
{
title: '试卷描述',
prop: 'desc'
},
{
title: '所属赛季',
prop: 'seasonId'
},
{
type: 'button',
title: this.$t('global.operate'),
width: '350',
buttons: [
{
name: '编辑',
handleClick: this.editPaper,
type: 'primary'
},
{
name: '删除',
handleClick: this.handleDelete,
type: 'danger'
}
]
}
],
actions: [{ text: '新建试卷', handler: this.creatPaper }]
}
};
},
computed: {
userId() {
return this.$store.state.user.id;
}
},
created() {
this.seasonlist = [];
},
methods: {
getListApi(obj) {
return getPaperList({ ...obj });
},
editPaper(row) {
this.$refs.addEditPaper.doShow(row);
},
creatPaper() {
this.$refs.addEditPaper.doShow();
},
handleDelete(data) {
this.$confirm('确定删除该试卷吗?', this.$t('global.tips'), {
confirmButtonText: this.$t('global.confirm'),
cancelButtonText: this.$t('global.cancel'),
type: 'warning'
})
.then(() => deletePaper(data.id))
.then(() => {
this.paperListRefresh();
this.$message({
type: 'success',
message: '删除成功!'
});
})
.catch(res => {
if (res.code && res.code !== 200) {
this.$message({ type: 'error', message: res.message });
}
});
},
paperListRefresh() {
this.$nextTick(() => {
this.$refs.examQueryListPage.refresh(true);
});
}
}
};
</script>
<style scoped></style>