import {
  ElMessage,
  type FormInstance,
} from 'element-plus'

export default {
  submit<T>(form: ShallowRef<FormInstance | null>, then: () => Promise<T>) {
    return form.value!.validate()
      .then(
        then,
        () => {
          ElMessage.error('请检查表单')
          return Promise.reject({code: 5555, success: false, msg: '表单校验失败', message: '表单校验失败', data: null})
        })
  },
}
