import { isFunction, isString } from 'lodash-es'
import { ElMessage } from 'element-plus'
export const checkResult = (res, okText, errText) => {
  const { errcode = 0, errmsg } = res || {}
  if (errcode === 0) {
    if (isFunction(okText)) {
      return okText()
    }
    if (isString(okText)) ElMessage.success(okText)
    else if (okText) ElMessage.success('操作成功')
    return true
  }
  if (isFunction(errText)) {
    return errText()
  }
  ElMessage.error(errText || errmsg)
  // Message({ message: _errText || errmsg, duration: 60000 });
  return false
}

export const InitCheckResult = (app) => {
  app.provide('$checkRes', checkResult)
}
