竞赛任务备用

This commit is contained in:
joylink_zhaoerwei 2024-02-22 17:14:55 +08:00
parent d77e872858
commit 9d2420920c
5 changed files with 436 additions and 8 deletions

View File

@ -175,6 +175,16 @@ export function deleteTask(id) {
});
}
/**
* @param {Number} id 任务id
*/
export function getTaskDetail(id) {
return request({
url: `/api/exercise/race/task/${id}`,
method: 'GET'
});
}
/**
* @param {Number} id 任务id
*/
@ -186,14 +196,15 @@ export function getchildrenTaskDatas(id) {
}
/**
* @param {Object} data
* @param {Number} data.taskId 任务id
* @param {Number} data.bindId 绑定id根据bindtype来区分对应的id
* @param {String} data.bindType rule =评分规则;scene=场景
* @param {Array} data
* @param {Number} taskId 任务id
* @param {Number} data[i].bindId 绑定id根据bindtype来区分对应的id
* @param {String} data[i].bindType rule =0评分规则;scene=1场景
* @param {Number} data[i].status 0=绑定 1=解绑
*/
export function bindTask(data) {
export function bindTask(taskId, data) {
return request({
url: '/api/exercise/race/task/bind',
url: `/api/exercise/race/task/${taskId}/bind`,
method: 'POST',
data
});

View File

@ -141,7 +141,7 @@ export default {
this.$refs.addEditModule.doShow();
},
handleDelete(data) {
this.$confirm('确定删除该试卷吗?', this.$t('global.tips'), {
this.$confirm('确定删除该模块吗?', this.$t('global.tips'), {
confirmButtonText: this.$t('global.confirm'),
cancelButtonText: this.$t('global.cancel'),
type: 'warning'

View File

@ -0,0 +1,142 @@
<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="contest">
<el-input v-model="formModel.contest" type="textarea" style="width: 350px;" />
</el-form-item>
<el-form-item label="评价标准:" prop="standards">
<el-input v-model="formModel.standards" type="textarea" style="width: 350px;" />
</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 { createTask, editTask} from '@/api/contest';
export default {
name: 'AddContestTask',
data() {
return {
dialogVisible: false,
formModel: {
id: '',
name: '', //
desc: '', //
contest: '', //
standards: '', //
parentId:''
},
creatSonTask:false,
loading: false
};
},
computed: {
rules() {
const crules = {
name: [
{ required: true, message: '请输入任务名称', trigger: 'blur' }
],
desc: [
{ required: true, message: '请输入任务描述', trigger: 'blur' }
],
contest: [
{ required: true, message: '请输入考核内容', trigger: 'blur' }
],
standards: [
{ required: true, message: '请输入评价标准', trigger: 'blur' }
]
};
return crules;
},
title() {
if (this.creatSonTask) return '添加子任务';
return this.formModel.id ? '修改任务' : '新建任务';
}
},
methods:{
doShow(row, creatSonTask) {
this.dialogVisible = true;
if (creatSonTask) {
this.creatSonTask = true;
}
if (!creatSonTask && row) {
this.formModel.id = row.id;
this.formModel.name = row.label;
this.formModel.contest = row.contest;
this.formModel.standards = row.standards;
} else {
this.formModel = {
id: '',
name: '',
desc: '',
contest: '',
standards:'',
parentId:''
};
if (creatSonTask) {
this.formModel.parentId = row.parentId;
}
this.$nextTick(() => {
this.$refs.ruleForm.resetFields();
});
}
},
handleClose() {
this.formModel = {
id: '',
name: '',
desc: '',
contest: '',
standards:'',
parentId:''
};
this.$refs.ruleForm.resetFields();
this.creatSonTask = false;
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.parentId == '') {
delete data.parentId;
}
if (this.formModel.id) {
editTask(data).then(() => {
this.$message.success('修改任务成功!');
this.handleClose();
this.$emit('paperListRefresh');
}).catch(error => {
this.$message.error(error.message);
this.loading = false;
});
} else {
createTask(data).then(() => {
this.$message.success('创建任务成功!');
this.handleClose();
this.$emit('paperListRefresh');
}).catch(error => {
this.$message.error(error.message);
this.loading = false;
});
}
}
});
}
}
};
</script>

View File

@ -0,0 +1,97 @@
<template>
<el-dialog v-dialogDrag title="任务绑定" :visible.sync="dialogVisible" width="500px" :before-close="handleClose" center :close-on-click-modal="false">
<el-form ref="ruleForm" :model="formModel" label-width="120px">
<el-form-item label="任务名称:" prop="name">
<el-input v-model="formModel.name" style="width: 320px;" />
</el-form-item>
<el-form-item label="绑定场景:" prop="sceneId">
<el-select v-model="formModel.sceneId" placeholder="请选择" style="width:320px;">
<el-option
v-for="item in bindSceneOptions"
:key="item.value"
:label="item.label"
:value="item.value"
/>
</el-select>
</el-form-item>
<el-form-item label="绑定评分规则:" prop="ruleId">
<el-select v-model="formModel.ruleId" placeholder="请选择" style="width:320px;">
<el-option
v-for="item in bindRuleOptions"
: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 { bindTask} from '@/api/contest';
export default {
name: 'AddContestTask',
data() {
return {
dialogVisible: false,
formModel: {
taskId: '',
name:'',
sceneId: '', // id
ruleId: '' // id
},
bindSceneOptions: [],
bindRuleOptions:[],
loading: false
};
},
methods:{
doShow(row) {
this.dialogVisible = true;
this.formModel.taskId = row.id;
this.formModel.name = row.label;
this.formModel.sceneId = row.sceneId;
this.formModel.ruleId = row.ruleId;
},
handleClose() {
this.formModel = {
taskId: '',
name: '',
sceneId: '',
ruleId: ''
};
this.$refs.ruleForm.resetFields();
this.dialogVisible = false;
this.loading = false;
},
doSave() {
this.$refs.ruleForm.validate((valid) => {
if (valid) {
this.loading = true;
const data = [];
if ( this.formModel.ruleId) {
data.push({bindType:0, bindId:this.formModel.ruleId, status:0});
}
if (this.formModel.sceneId) {
data.push({bindType:1, bindId:this.formModel.sceneId, status:0});
}
bindTask(this.formModel.taskId, 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,181 @@
<template>
<div>竞赛任务管理</div>
<div class="taskContainer">
<div style="margin-bottom: 10px;">
<el-card>
<div class="taskTitle">
<div>竞赛任务管理</div>
<div>
<el-button
type="primary"
size="small"
@click="creatTask"
>
新建任务
</el-button>
</div>
</div>
</el-card>
</div>
<el-card>
<el-tree
:data="taskDta"
node-key="id"
default-expand-all
:expand-on-click-node="false"
>
<span slot-scope="{ node, data }" class="custom-tree-node">
<span>{{ node.label }}</span>
<span>
<el-button
type="text"
size="mini"
@click="() => editTask(data)"
>
修改任务
</el-button>
<el-button
type="text"
style="color: red;"
size="mini"
@click="() => deleteTaskById(data)"
>
删除任务
</el-button>
<el-button
type="text"
size="mini"
@click="() => creatChildrenTask(data)"
>
添加子任务
</el-button>
<el-button
type="text"
size="mini"
@click="() => bindTask(data)"
>
任务绑定
</el-button>
</span>
</span>
</el-tree>
</el-card>
<add-edit-task ref="addEditTask" @reloadTaskTree="getTreeData" />
<bind-task ref="bindTask" />
</div>
</template>
<script>
import axios from 'axios';
import AddEditTask from './AddEditTask';
import BindTask from './BindTask';
import { getTaskTreeDatas, getTaskDetail, deleteTask} from '@/api/contest';
export default {
name:'ContestTaskManage',
components: {
AddEditTask, BindTask
},
data() {
return {
taskDta:[]
};
},
created() {
axios
.get(
'http://127.0.0.1:4523/m1/1531717-0-default/api/exercise/race/task/tree'
)
.then((response) => {
this.taskDta = this.transformTree(response.data);
})
.catch((error) => {
console.log(error);
});
},
methods: {
getTreeData() {
getTaskTreeDatas().then((res) => {
this.taskDta = this.transformTree(res.data);
}).catch(error => {
this.$message.error(error.message);
});
},
queryChildrenTask() {
console.log(111);
},
creatTask() {
this.$refs.addEditTask.doShow();
},
creatChildrenTask(data) {
this.$refs.addEditTask.doShow(data, true);
},
editTask(data) {
getTaskDetail(data.id).then((res) => {
this.$refs.addEditTask.doShow(res.data);
});
},
bindTask(data) {
this.$refs.bindTask.doShow(data);
},
deleteTaskById(data) {
this.$confirm('确定删除该任务吗?', this.$t('global.tips'), {
confirmButtonText: this.$t('global.confirm'),
cancelButtonText: this.$t('global.cancel'),
type: 'warning'
})
.then(() => deleteTask(data.id))
.then(() => {
this.getTreeData();
this.$message({
type: 'success',
message: '删除成功!'
});
})
.catch(res => {
if (res.code && res.code !== 200) {
this.$message({ type: 'error', message: res.message });
}
});
},
transformTree(data) {
const result = [];
for (let i = 0; i < data.length; i++) {
const node = data[i];
const item = {
id: node.id,
label: node.name,
parentId:node.parentId
};
if (node.children) {
item.children = this.transformTree(node.children);
}
result.push(item);
}
return result;
}
}
};
</script>
<style lang="scss" scoped>
.taskContainer{
width: 50%;
margin: 0 auto;
.taskTitle {
display: flex;
align-items: center;
justify-content: space-between;
padding: 10px;
}
.custom-tree-node {
flex: 1;
display: flex;
align-items: center;
justify-content: space-between;
font-size: 16px;
padding-right: 20px;
}
}
</style>