gaoluyang
3 天以前 92230c9a97dc9ce9df3313d11d26999c04bb6b26
src/plugins/modal.ts
¶Ô±ÈÐÂÎļþ
@@ -0,0 +1,99 @@
export default {
  /**
   * æ¶ˆæ¯æç¤º
   * @param content æ¶ˆæ¯å†…容
   */
  msg(content: string): void {
    uni.showToast({
      title: content,
      icon: 'none'
    })
  },
  /**
   * é”™è¯¯æ¶ˆæ¯
   * @param content æ¶ˆæ¯å†…容
   */
  msgError(content: string): void {
    uni.showToast({
      title: content,
      icon: 'error'
    })
  },
  /**
   * æˆåŠŸæ¶ˆæ¯
   * @param content æ¶ˆæ¯å†…容
   */
  msgSuccess(content: string): void {
    uni.showToast({
      title: content,
      icon: 'success'
    })
  },
  /**
   * éšè—æ¶ˆæ¯
   */
  hideMsg(): void {
    uni.hideToast()
  },
  /**
   * å¼¹å‡ºæç¤º
   * @param content æç¤ºå†…容
   */
  alert(content: string): void {
    uni.showModal({
      title: '提示',
      content: content,
      showCancel: false
    })
  },
  /**
   * ç¡®è®¤çª—体
   * @param content æç¤ºå†…容
   * @returns
   */
  confirm(content: string): Promise<unknown> {
    return new Promise((resolve: Function, reject: Function) => {
      uni.showModal({
        title: '系统提示',
        content: content,
        cancelText: '取消',
        confirmText: '确定',
        success: function (res) {
          if (res.confirm) {
            resolve(res.confirm)
          }
        }
      })
    })
  },
  /**
   * æç¤ºä¿¡æ¯
   * @param option æç¤ºå†…容或者提示框配置
   */
  showToast(option: string | object): void {
    if (typeof option === "object") {
      uni.showToast(option)
    } else {
      uni.showToast({
        title: option,
        icon: "none",
        duration: 2500
      })
    }
  },
  /**
   * æ‰“开遮罩层,需要手动关闭遮罩层
   * @param content é®ç½©å±‚内容
   */
  loading(content: string): void {
    uni.showLoading({
      title: content
    })
  },
  /**
   * å…³é—­é®ç½©å±‚
   */
  closeLoading(): void {
    uni.hideLoading()
  }
}