add 新增
This commit is contained in:
@@ -317,9 +317,13 @@ function CRUD(options) {
|
||||
* 提交新增/编辑
|
||||
*/
|
||||
submitCU(formName) {
|
||||
debugger
|
||||
if (formName instanceof PointerEvent) {
|
||||
formName = 'form'
|
||||
}
|
||||
if (typeof formName !== 'string') {
|
||||
formName = 'form'
|
||||
}
|
||||
if (!callVmHook(crud, CRUD.HOOK.beforeValidateCU)) {
|
||||
return
|
||||
}
|
||||
|
||||
@@ -289,19 +289,61 @@ export default {
|
||||
/**
|
||||
* 提交
|
||||
*/
|
||||
submitMethod() {
|
||||
if (!this.beforeSubmitMethod()) {
|
||||
return
|
||||
}
|
||||
if (this.$refs['form']) {
|
||||
this.$refs['form'].validate((valid) => {
|
||||
if (valid) {
|
||||
this.loading = true
|
||||
if (this.isAdd) {
|
||||
this.addMethod()
|
||||
} else this.editMethod()
|
||||
// 表单提交核心逻辑(带完整异常日志)
|
||||
submitForm() {
|
||||
try {
|
||||
// 1. 先判断表单实例是否存在,打印基础日志
|
||||
if (this.$refs['form']) {
|
||||
console.log('表单实例存在,开始执行校验', {
|
||||
formRef: this.$refs['form'], // 打印表单实例详情
|
||||
isAdd: this.isAdd, // 打印当前是新增/编辑状态
|
||||
formData: this.form // 打印表单数据(排查数据异常)
|
||||
})
|
||||
// 2. 检查validate方法是否存在(核心异常点)
|
||||
if (typeof this.$refs['form'].validate !== 'function') {
|
||||
throw new Error('表单实例存在,但validate方法未找到')
|
||||
}
|
||||
})
|
||||
|
||||
// 3. 执行表单校验
|
||||
this.$refs['form'].validate((valid) => {
|
||||
if (valid) {
|
||||
console.log('表单校验通过,开始执行提交逻辑')
|
||||
this.loading = true
|
||||
try {
|
||||
// 4. 执行新增/编辑方法,捕获接口调用异常
|
||||
if (this.isAdd) {
|
||||
this.addMethod().catch(err => {
|
||||
throw new Error(`新增接口调用失败:${err.message}`)
|
||||
})
|
||||
} else {
|
||||
this.editMethod().catch(err => {
|
||||
throw new Error(`编辑接口调用失败:${err.message}`)
|
||||
})
|
||||
}
|
||||
} catch (submitErr) {
|
||||
// 5. 捕获新增/编辑方法的异常
|
||||
console.error('表单提交逻辑执行失败:', submitErr)
|
||||
this.$message.error(submitErr.message || '操作失败,请重试')
|
||||
this.loading = false // 重置loading状态
|
||||
}
|
||||
} else {
|
||||
console.warn('表单校验未通过:用户输入不符合规则')
|
||||
this.$message.warning('请检查表单填写内容是否符合要求')
|
||||
}
|
||||
})
|
||||
} else {
|
||||
// 6. 表单实例不存在的异常日志
|
||||
console.error('表单校验失败:表单实例未找到', {
|
||||
refs: this.$refs, // 打印所有refs,排查命名错误
|
||||
component: this.$options.name // 打印当前组件名,定位报错组件
|
||||
})
|
||||
this.$message.error('表单初始化失败,请刷新页面重试')
|
||||
}
|
||||
} catch (mainErr) {
|
||||
// 7. 捕获整个流程的未预期异常
|
||||
console.error('表单提交全流程异常:', mainErr)
|
||||
this.$message.error('系统异常,请联系管理员')
|
||||
this.loading = false // 兜底重置loading
|
||||
}
|
||||
},
|
||||
/**
|
||||
|
||||
Reference in New Issue
Block a user