案例校验、新增

zqqdev
CherrysChang 5 years ago
parent 3607676424
commit 59bfd06560
  1. 2
      src/api/server.js
  2. 47
      src/views/train/case-detail.vue
  3. 2
      src/views/train/case-list.vue

@ -51,7 +51,7 @@ export const Train = new (class {
//添加 //添加
insertCase(params) { insertCase(params) {
return axios return axios
.post(this.insertCaseApi, qs.stringify(params)) .post(this.insertCaseApi, qs.stringify(params,{allowDots: true }))
.then(res => res.data); .then(res => res.data);
} }
//修改 //修改

@ -48,16 +48,15 @@
<template slot-scope="scope"> <template slot-scope="scope">
<el-row> <el-row>
<el-col :span="12"> <el-col :span="12">
<el-form-item :prop="'taskList.'+scope.$index+'.taskOperate'" :rules="dataRule.score" class="score-input" > <el-form-item :prop="'taskList.'+scope.$index+'.taskOperate'" :rules="dataRule.taskOperate" class="score-input" >
<el-select v-model="scope.row.taskOperate" size="small" style="width: 100px;"> <el-select v-model="scope.row.taskOperate" size="small" style="width: 100px;">
<el-option label="大于" value="1"></el-option> <el-option label="大于" value="1"></el-option>
<el-option label="等于" value="2"></el-option> <el-option label="小于" value="2"></el-option>
<el-option label="小于" value="3"></el-option>
</el-select> </el-select>
</el-form-item> </el-form-item>
</el-col> </el-col>
<el-col :span="12"> <el-col :span="12">
<el-form-item :prop="'taskList.'+scope.$index+'.taskRate'" :rules="dataRule.score" class="score-input" > <el-form-item :prop="'taskList.'+scope.$index+'.taskRate'" :rules="dataRule.taskRate" class="score-input" >
<el-input size="small" v-model.trim="scope.row.taskRate" :disabled="formAction == 2" style="width: 100px;"> <el-input size="small" v-model.trim="scope.row.taskRate" :disabled="formAction == 2" style="width: 100px;">
<i slot="suffix">%</i> <i slot="suffix">%</i>
</el-input> </el-input>
@ -66,10 +65,10 @@
</el-row> </el-row>
</template> </template>
</el-table-column> </el-table-column>
<el-table-column prop="score" label="分数" width="120"> <el-table-column prop="taskScore" label="分数" width="120">
<template slot-scope="scope"> <template slot-scope="scope">
<el-form-item :prop="'taskList.'+scope.$index+'.score'" :rules="dataRule.score" class="score-input"> <el-form-item :prop="'taskList.'+scope.$index+'.taskScore'" :rules="dataRule.taskScore" class="score-input">
<el-input size="small" v-model.trim="scope.row.score" :disabled="formAction == 2" style="width: 100px;"><i slot="suffix"></i></el-input> <el-input size="small" v-model.trim="scope.row.taskScore" :disabled="formAction == 2" style="width: 100px;"><i slot="suffix"></i></el-input>
</el-form-item> </el-form-item>
</template> </template>
</el-table-column> </el-table-column>
@ -104,17 +103,17 @@
var validateScore = (rule, value, callback) => { var validateScore = (rule, value, callback) => {
if (!value) { if (!value) {
callback(new Error('请输入分数')); callback(new Error('请输入分数'));
} else if (!(/^(([1-9][0-9]*)|(([0]\.\d{0,2}|[1-9][0-9]*\.\d{0,2})))$/.test(value)) || value > 100) { } else if (!(/^[1-9][0-9]{0,2}$/.test(value)) || value > 100) {
callback(new Error('请输入0-100之间最多两位小数的数字')); callback(new Error('请输入1-100之间的正整数'));
} else { } else {
callback(); callback();
} }
}; };
var validateContent = (rule, value, callback) => { var validateTaskRate = (rule, value, callback) => {
if (!value.trim()) { if (!value) {
callback(new Error('请填写案例描述')); callback(new Error('请输入任务目标'));
} else if (value.length > 3000) { } else if (!(/^(([1-9][0-9]*)|(([0]\.\d|[1-9][0-9]*\.\d)))$/.test(value)) || value > 100) {
callback(new Error('长度在 1 到 3000 个字符')); callback(new Error('请输入100以内最多一位小数的正数'));
} else { } else {
callback(); callback();
} }
@ -137,10 +136,13 @@
type: [ type: [
{ required: true, message: '请选择实训用途', trigger: 'change' } { required: true, message: '请选择实训用途', trigger: 'change' }
], ],
// content: [ taskOperate: [
// {validator: validateContent, trigger: 'blur'} { required: true, message: '请选择设置项', trigger: 'change' }
// ], ],
score: [ taskRate: [
{validator: validateTaskRate, trigger: 'blur'}
],
taskScore: [
{validator: validateScore, trigger: 'blur'} {validator: validateScore, trigger: 'blur'}
], ],
}, },
@ -216,8 +218,8 @@
}, },
methods: { methods: {
goBackList() { goBackList() {
// this.$router.push({name: 'CaseList'}); this.$router.push({name: 'CaseList'});
this.$router.go(-1); // this.$router.go(-1);
}, },
initTargetList(searchObj) { initTargetList(searchObj) {
Train.getTargetList(searchObj).then(res => { Train.getTargetList(searchObj).then(res => {
@ -247,8 +249,7 @@
item=Object.assign({}, item, { item=Object.assign({}, item, {
taskOperate: null, taskOperate: null,
taskRate: null, taskRate: null,
score: null, taskScore: null
taskSeq: null
}) })
// //
this.rightTargetList.push(item); this.rightTargetList.push(item);
@ -303,7 +304,7 @@
return; return;
} }
if (index === 3) { // if (index === 3) { //
values = data.map(item => Number(item['score'])); values = data.map(item => Number(item['taskScore']));
sums[index] = values.reduce((prev, curr) => { sums[index] = values.reduce((prev, curr) => {
const value = Number(curr); const value = Number(curr);
if (!isNaN(value)) { if (!isNaN(value)) {

@ -93,7 +93,7 @@
Train.getCaseList(searchObj).then(res => { Train.getCaseList(searchObj).then(res => {
if (res.code == 200) { if (res.code == 200) {
this.listData = res.data.rows; this.listData = res.data.rows;
this.totalCount = res.totalCount; this.totalCount = res.data.total;
} }
}).catch(error => { }).catch(error => {
console.info(error) console.info(error)

Loading…
Cancel
Save