riku
2022-10-28 b45a01a8bee4a9bff5f9c248ead301b8675d1099
base/behaviors/b_loadingToast.js
@@ -1,5 +1,3 @@
const { clearTimeout } = require("timers");
/**
 * 数据加载弹窗
 * 根据加载状态,展示对应的弹窗
@@ -8,20 +6,16 @@
module.exports = Behavior({
  data: {
    loadingText: '加载中',
    loadCompleteText: '加载完成'
    loadCompleteText: '加载完成',
    timeoutText: '加载超时'
  },
  timeoutId: '',
  methods: {
    // 加载开始toast
    loadStart() {
      clearTimeout(this.timeoutId)
      wx.showLoading({
        title: this.data.loadingText,
        mask: true,
      })
      this.timeoutId = setTimeout(() => {
        wx.hideLoading()
      }, 20000);
    },
    // 加载中toast
    loading() {
@@ -29,13 +23,12 @@
    },
    // 加载完成toast
    loadComplete() {
      clearTimeout(this.timeoutId)
      wx.hideLoading({
        success: (res) => {
          wx.showToast({
            title: this.data.loadCompleteText,
            title: this.data.timeout ? this.data.timeoutText : this.data.loadCompleteText,
            duration: 1000,
            icon: 'success',
            icon: this.data.timeout ? 'error' : 'success',
            mask: true,
          })
        },