|
@@ -8,7 +8,8 @@
|
|
|
import MDialog from '@/components/Dialog'
|
|
|
import MForm from '@/components/MForm'
|
|
|
import {
|
|
|
- createTrainingData
|
|
|
+ createTrainingData,
|
|
|
+ updateTrainingData
|
|
|
} from '@/api/dataChart'
|
|
|
export default {
|
|
|
name: 'modelTrainManage',
|
|
@@ -21,7 +22,9 @@ export default {
|
|
|
visible: false,
|
|
|
readonly: false,
|
|
|
formValues: {
|
|
|
- training_data_type: 'sql'
|
|
|
+ training_data_type: 'sql',
|
|
|
+ question: '',
|
|
|
+ content: ''
|
|
|
},
|
|
|
kinds: {
|
|
|
sql: {
|
|
@@ -59,13 +62,16 @@ export default {
|
|
|
],
|
|
|
rules: [v => this.readonly || !!v || '请选择数据类型'],
|
|
|
change: (val) => {
|
|
|
- this.$refs.form.resetValidation()
|
|
|
+ this.$nextTick(() => {
|
|
|
+ this.$refs.form.resetValidation()
|
|
|
+ })
|
|
|
}
|
|
|
},
|
|
|
{
|
|
|
label: `提问内容 ${isSql ? '*' : ''}`,
|
|
|
key: 'question',
|
|
|
readonly: this.readonly,
|
|
|
+ hide: this.formValues.training_data_type !== 'sql' && this.formValues.training_data_type !== 'error_sql',
|
|
|
type: 'textarea',
|
|
|
rules: [v => !isSql || this.readonly ? true : !!v || '请输入提问内容']
|
|
|
},
|
|
@@ -94,9 +100,12 @@ export default {
|
|
|
return
|
|
|
}
|
|
|
this.formValues = { ...item }
|
|
|
- this.$refs.form.resetValidation()
|
|
|
+ this.$nextTick(() => {
|
|
|
+ this.$refs.form.resetValidation()
|
|
|
+ })
|
|
|
},
|
|
|
async onSubmit () {
|
|
|
+ if (!this.$refs.form.validate()) return
|
|
|
// const a = {
|
|
|
// data: {
|
|
|
// training_data_type: '选择的类型',
|
|
@@ -107,14 +116,21 @@ export default {
|
|
|
// }
|
|
|
// }
|
|
|
const { content, question, training_data_type: type } = this.formValues
|
|
|
+ const query = {
|
|
|
+ id: this.formValues.id,
|
|
|
+ training_data_type: type,
|
|
|
+ [this.kinds[type].key]: content,
|
|
|
+ question: type === 'sql' || type === 'error_sql' ? question : undefined
|
|
|
+ }
|
|
|
try {
|
|
|
- await createTrainingData({
|
|
|
- data: {
|
|
|
- training_data_type: type,
|
|
|
- [this.kinds[type].key]: content,
|
|
|
- question: type === 'sql' || type === 'error_sql' ? question : undefined
|
|
|
- }
|
|
|
- })
|
|
|
+ if (this.formValues.id) {
|
|
|
+ await updateTrainingData(query)
|
|
|
+ } else {
|
|
|
+ await createTrainingData({
|
|
|
+ data: query
|
|
|
+ })
|
|
|
+ }
|
|
|
+
|
|
|
this.$snackbar.success('创建成功')
|
|
|
this.visible = false
|
|
|
this.$emit('success')
|