fix: 完善报告任务表单的校验
This commit is contained in:
@@ -231,8 +231,8 @@
|
|||||||
</el-select>
|
</el-select>
|
||||||
</el-form-item>
|
</el-form-item>
|
||||||
<!-- 参数 -->
|
<!-- 参数 -->
|
||||||
<el-form-item :label="$t('config.operationlog.params')" prop="params" v-if="categoryParams.length > 0">
|
<el-form-item :label="$t('config.operationlog.params')" prop="categoryParams" v-if="editObject.categoryParams.length > 0">
|
||||||
<el-input v-model="param.value" placeholder=" " v-for="(param, index) in categoryParams" :key="index" size="small" style="vertical-align: unset;" :disabled="!!editObject.id">
|
<el-input v-model="param.value" placeholder=" " v-for="(param, index) in editObject.categoryParams" :key="index" size="small" style="vertical-align: unset;" :disabled="!!editObject.id">
|
||||||
<template #prepend>{{param.key}}</template>
|
<template #prepend>{{param.key}}</template>
|
||||||
</el-input>
|
</el-input>
|
||||||
</el-form-item>
|
</el-form-item>
|
||||||
@@ -258,6 +258,17 @@ import _ from 'lodash'
|
|||||||
import { post, put } from '@/utils/http'
|
import { post, put } from '@/utils/http'
|
||||||
import { dateFormat, getMillisecond } from '@/utils/date-util'
|
import { dateFormat, getMillisecond } from '@/utils/date-util'
|
||||||
|
|
||||||
|
const paramValidator = (rule, value, callback) => {
|
||||||
|
let validate = true
|
||||||
|
if (value && value.length > 0) {
|
||||||
|
const hasEmpty = value.some(v => {
|
||||||
|
return !v.value && v.value !== 0
|
||||||
|
})
|
||||||
|
validate = !hasEmpty
|
||||||
|
}
|
||||||
|
return validate
|
||||||
|
}
|
||||||
|
|
||||||
export default {
|
export default {
|
||||||
name: 'ReportBox',
|
name: 'ReportBox',
|
||||||
mixins: [rightBoxMixin],
|
mixins: [rightBoxMixin],
|
||||||
@@ -292,8 +303,6 @@ export default {
|
|||||||
monthWeekdayCheckedAll: false,
|
monthWeekdayCheckedAll: false,
|
||||||
monthWeekdayIsIndeterminate: false,
|
monthWeekdayIsIndeterminate: false,
|
||||||
|
|
||||||
categoryParams: [],
|
|
||||||
|
|
||||||
rules: { // 表单校验规则
|
rules: { // 表单校验规则
|
||||||
name: [
|
name: [
|
||||||
{ required: true, message: this.$t('validate.required'), trigger: 'blur' }
|
{ required: true, message: this.$t('validate.required'), trigger: 'blur' }
|
||||||
@@ -309,6 +318,10 @@ export default {
|
|||||||
],
|
],
|
||||||
'config.endTime': [
|
'config.endTime': [
|
||||||
{ required: true, message: this.$t('validate.required'), trigger: 'change' }
|
{ required: true, message: this.$t('validate.required'), trigger: 'change' }
|
||||||
|
],
|
||||||
|
categoryParams: [
|
||||||
|
{ required: true, message: this.$t('validate.required'), trigger: 'blur' },
|
||||||
|
{ validator: paramValidator, message: this.$t('validate.required'), trigger: 'blur' }
|
||||||
]
|
]
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -331,6 +344,17 @@ export default {
|
|||||||
this.cleanScheduleConfig()
|
this.cleanScheduleConfig()
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
monthIsCycle (n) {
|
||||||
|
if (!this.editObject.id) {
|
||||||
|
if (n) {
|
||||||
|
this.editObject.config.schedulerConfig.months = []
|
||||||
|
this.monthCheckedAll = false
|
||||||
|
this.monthIsIndeterminate = false
|
||||||
|
} else {
|
||||||
|
this.editObject.config.schedulerConfig.interval = 1
|
||||||
|
}
|
||||||
|
}
|
||||||
|
},
|
||||||
'editObject.config.schedulerConfig.interval': {
|
'editObject.config.schedulerConfig.interval': {
|
||||||
handler (n) {
|
handler (n) {
|
||||||
if (!_.isNumber(n)) {
|
if (!_.isNumber(n)) {
|
||||||
@@ -344,15 +368,30 @@ export default {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
'editObject.config.timeConfig.offset': {
|
||||||
|
handler (n) {
|
||||||
|
if (!_.isNumber(n)) {
|
||||||
|
if (n) {
|
||||||
|
if (!_.isNumber(parseInt(n)) || _.isNaN(parseInt(n))) {
|
||||||
|
this.editObject.config.timeConfig.offset = 1
|
||||||
|
} else {
|
||||||
|
this.editObject.config.timeConfig.offset = parseInt(n)
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
this.editObject.config.timeConfig.offset = 1
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
},
|
||||||
'editObject.categoryId': {
|
'editObject.categoryId': {
|
||||||
handler (n) {
|
handler (n) {
|
||||||
const category = this.categoryList.find(c => c.id === n)
|
const category = this.categoryList.find(c => c.id === n)
|
||||||
if (category && category.config && category.config.queryParam) {
|
if (category && category.config && category.config.queryParam) {
|
||||||
this.categoryParams = Object.keys(category.config.queryParam).map(key => {
|
this.editObject.categoryParams = Object.keys(category.config.queryParam).map(key => {
|
||||||
return { key: key, value: category.config.queryParam[key] }
|
return { key: key, value: category.config.queryParam[key] }
|
||||||
})
|
})
|
||||||
} else {
|
} else {
|
||||||
this.categoryParams = []
|
this.editObject.categoryParams = []
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
@@ -385,7 +424,7 @@ export default {
|
|||||||
}
|
}
|
||||||
if (n.id) {
|
if (n.id) {
|
||||||
if (n.config.queryParam && Object.keys(n.config.queryParam).length > 0) {
|
if (n.config.queryParam && Object.keys(n.config.queryParam).length > 0) {
|
||||||
this.categoryParams = Object.keys(n.config.queryParam).map(key => {
|
this.editObject.categoryParams = Object.keys(n.config.queryParam).map(key => {
|
||||||
return { key: key, value: n.config.queryParam[key] }
|
return { key: key, value: n.config.queryParam[key] }
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
@@ -473,35 +512,41 @@ export default {
|
|||||||
if (schedulerEnd) {
|
if (schedulerEnd) {
|
||||||
copyObject.schedulerEnd = schedulerEnd
|
copyObject.schedulerEnd = schedulerEnd
|
||||||
}
|
}
|
||||||
if (this.categoryParams.length > 0) {
|
if (this.editObject.categoryParams.length > 0) {
|
||||||
const queryParam = {}
|
const queryParam = {}
|
||||||
this.categoryParams.forEach(p => {
|
this.editObject.categoryParams.forEach(p => {
|
||||||
queryParam[p.key] = p.value
|
queryParam[p.key] = p.value
|
||||||
})
|
})
|
||||||
copyObject.config.queryParam = queryParam
|
copyObject.config.queryParam = queryParam
|
||||||
}
|
}
|
||||||
copyObject.config = JSON.stringify(copyObject.config)
|
|
||||||
|
|
||||||
if (copyObject.id) {
|
// 校验scheduleConfig
|
||||||
put(this.url, copyObject).then(res => {
|
if (this.validateScheduleConfig(copyObject)) {
|
||||||
this.blockOperation.save = false
|
copyObject.config = JSON.stringify(copyObject.config)
|
||||||
if (res.code === 200) {
|
if (copyObject.id) {
|
||||||
this.$message({ duration: 2000, type: 'success', message: this.$t('tip.saveSuccess') })
|
put(this.url, copyObject).then(res => {
|
||||||
this.esc(true)
|
this.blockOperation.save = false
|
||||||
} else {
|
if (res.code === 200) {
|
||||||
this.$message.error(res.msg)
|
this.$message({ duration: 2000, type: 'success', message: this.$t('tip.saveSuccess') })
|
||||||
}
|
this.esc(true)
|
||||||
})
|
} else {
|
||||||
|
this.$message.error(res.msg)
|
||||||
|
}
|
||||||
|
})
|
||||||
|
} else {
|
||||||
|
post(this.url, copyObject).then(res => {
|
||||||
|
this.blockOperation.save = false
|
||||||
|
if (res.code === 200) {
|
||||||
|
this.$message({ duration: 2000, type: 'success', message: this.$t('tip.saveSuccess') })
|
||||||
|
this.esc(true)
|
||||||
|
} else {
|
||||||
|
this.$message.error(res.msg)
|
||||||
|
}
|
||||||
|
})
|
||||||
|
}
|
||||||
} else {
|
} else {
|
||||||
post(this.url, copyObject).then(res => {
|
this.blockOperation.save = false
|
||||||
this.blockOperation.save = false
|
this.$message.error('Schedule config is required')
|
||||||
if (res.code === 200) {
|
|
||||||
this.$message({ duration: 2000, type: 'success', message: this.$t('tip.saveSuccess') })
|
|
||||||
this.esc(true)
|
|
||||||
} else {
|
|
||||||
this.$message.error(res.msg)
|
|
||||||
}
|
|
||||||
})
|
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
this.blockOperation.save = false
|
this.blockOperation.save = false
|
||||||
@@ -509,6 +554,45 @@ export default {
|
|||||||
}
|
}
|
||||||
})
|
})
|
||||||
},
|
},
|
||||||
|
validateScheduleConfig (obj) {
|
||||||
|
let validate = true
|
||||||
|
if (obj.config) {
|
||||||
|
if (obj.config.schedulerConfig) {
|
||||||
|
if (obj.config.schedulerConfig.type === 'day') {
|
||||||
|
if (!obj.config.schedulerConfig.interval) {
|
||||||
|
validate = false
|
||||||
|
}
|
||||||
|
} else if (obj.config.schedulerConfig.type === 'week') {
|
||||||
|
if (!obj.config.schedulerConfig.weekDates || obj.config.schedulerConfig.weekDates.length === 0) {
|
||||||
|
validate = false
|
||||||
|
}
|
||||||
|
} else if (obj.config.schedulerConfig.type === 'month') {
|
||||||
|
if (this.monthIsCycle) {
|
||||||
|
if (!obj.config.schedulerConfig.interval) {
|
||||||
|
validate = false
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
if (!obj.config.schedulerConfig.months || obj.config.schedulerConfig.months.length === 0) {
|
||||||
|
validate = false
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if (this.monthScheduleType === 'daily') {
|
||||||
|
if (!obj.config.schedulerConfig.monthDates || obj.config.schedulerConfig.monthDates.length === 0) {
|
||||||
|
validate = false
|
||||||
|
}
|
||||||
|
} else if (this.monthScheduleType === 'weekly') {
|
||||||
|
if (!obj.config.schedulerConfig.weekDates || obj.config.schedulerConfig.weekDates.length === 0) {
|
||||||
|
validate = false
|
||||||
|
}
|
||||||
|
if (!obj.config.schedulerConfig.monthWeekDates || obj.config.schedulerConfig.monthWeekDates.length === 0) {
|
||||||
|
validate = false
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return validate
|
||||||
|
},
|
||||||
dateCheckAllChange (checked) {
|
dateCheckAllChange (checked) {
|
||||||
this.editObject.config.schedulerConfig.monthDates = checked ? this.dateList : []
|
this.editObject.config.schedulerConfig.monthDates = checked ? this.dateList : []
|
||||||
this.dateIsIndeterminate = false
|
this.dateIsIndeterminate = false
|
||||||
|
|||||||
@@ -116,7 +116,8 @@ export default {
|
|||||||
},
|
},
|
||||||
schedulerStart: '',
|
schedulerStart: '',
|
||||||
schedulerEnd: '',
|
schedulerEnd: '',
|
||||||
categoryId: ''
|
categoryId: '',
|
||||||
|
categoryParams: []
|
||||||
},
|
},
|
||||||
checkWeekListData: [
|
checkWeekListData: [
|
||||||
'report.sunday',
|
'report.sunday',
|
||||||
|
|||||||
Reference in New Issue
Block a user