import {
  ElMessage,
  type FormInstance,
} from 'element-plus'
import type { R } from '@/common/utils/http-util.ts'

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