// 如果url是tab的页面，使用switchTab，否则使用navigateTo
export function goto(url: string) {
  uni.navigateTo({ url, fail: () => uni.switchTab({ url }) })
}
export function gotoEventToPage(e: any) {
  if (e?.redirect_type === 'InnerPage') {
    //打开小程序页面
    goto(e?.redirect_path)
    return
  }
  if (e?.redirect_type === 'H5') {
    uni.navigateTo({ url: `/pages/web_view/index?web_url=${encodeURIComponent(e?.redirect_path)}` })
    return
  }
  if (e?.redirect_type === 'AnotherMiniProgram') {
    // 打开另一个小程序
    uni.navigateToMiniProgram({
      appId: e?.app_id,
      path: e?.redirect_path || '',
      success(res) {
        // 打开成功
      }
    })
  }
}
export function showToastBack(label?: string, delta = 1, back = true) {
  uni.showToast({
    title: label || '提交成功！',
    duration: 1000,
    icon: 'none',
    success() {
      if (back) {
        setTimeout(() => {
          uni.navigateBack({ delta })
        }, 1000)
      }
    }
  })
}

export function showToast(label?: string, fun?: (res: boolean) => void) {
  uni.showToast({
    title: label || '提交成功！',
    duration: 1000,
    icon: 'none',
    success() {
      setTimeout(() => {
        return fun?.(true)
      }, 1000)
    }
  })
}
