惯性聚合 高效追踪和阅读你感兴趣的博客、新闻、科技资讯
阅读原文 在惯性聚合中打开

推荐订阅源

WordPress大学
WordPress大学
L
LangChain Blog
酷 壳 – CoolShell
酷 壳 – CoolShell
罗磊的独立博客
J
Java Code Geeks
freeCodeCamp Programming Tutorials: Python, JavaScript, Git & More
博客园 - 叶小钗
小众软件
小众软件
博客园 - Franky
D
Docker
Google DeepMind News
Google DeepMind News
Microsoft Azure Blog
Microsoft Azure Blog
OSCHINA 社区最新新闻
OSCHINA 社区最新新闻
U
Unit 42
宝玉的分享
宝玉的分享
C
Check Point Blog
B
Blog
V
V2EX
博客园 - 三生石上(FineUI控件)
MyScale Blog
MyScale Blog
The Cloudflare Blog
博客园 - 聂微东
博客园_首页
Engineering at Meta
Engineering at Meta

博客园 - 微宇宙

claude-code 接入阿里云百炼(Model Studio)模型 小程序-微信支付和商户接入的流程 弹出框 mp-half-screen-dialog css- around 内容换行 自动贴边显示 echart - 饼图显示数据值 小程序 - 组件内部引入公共 css 样式 git push 错误 js-金额相加 小程序- 字符数据换行 antd-输入框去掉光晕 大屏缩放布局 大屏显示 echarts - 原型的方向盘动画 小程序- 自定义导航栏组件封装 小程序-echart动画git仓库 小程序- 隐私协议完善 小程序- 日期picker样式问题 echart - 折线图显示设置 echart - 移动端提示内容无阴影 echart 柱状图 - 零界点 正负方向展示 小程序 - 导航栏 图标设置 小程序 - 错误问题记录 react项目全屏功能 react-大屏显示antd浮窗 React andt库设置主题色彩 React闭包陷阱 git 操作 小程序 - 订阅消息通知 小程序-分包 mysql安装使用
小程序 - 旧请求 组件计时器
微宇宙 · 2026-09-09 · via 博客园 - 微宇宙

旧的请求 组件计时器的回调。

// ============ 支付结果轮询 ============

/**
 * 查询微信预支付状态入口
 * data == 1 支付处理中(继续轮询)
 * data == 2 支付成功
 * 其他值视为失败
 */
gePrePayStatus: function (prePayId) {
  const that = this;
  this._prePayId = prePayId;
  this.queryPrePayStatus(prePayId);
},

/**
 * 单次状态查询,根据结果决定是否继续轮询
 */
queryPrePayStatus: function (prePayId) {
  const that = this;

  service.gePrePayStatus({
    prePayId: prePayId || that._prePayId,
    callback: (resp, error) => {
      // 先释放"查询中"锁,保证定时器下一轮能继续发请求
      that._prePayQuerying = false;

      if (error) {
        that.stopPrePayTimer();
        wx.showToast({
          title: error,
          duration: 3000,
          icon: 'none',
        });
        return;
      }

      const data = resp.data;
      if (data == 1) {
        // 支付处理中 → 启动/继续轮询
        that.startPrePayTimer(that._prePayId);
      } else if (data == 2) {
        // 支付成功
        that.stopPrePayTimer();
        that.triggerEvent('onBalanceRecharge', null);
      } else {
        // 其他状态都视为失败
        that.stopPrePayTimer();
        wx.showToast({
          title: '启动失败',
          duration: 3000,
          icon: 'none',
        });
      }
    }
  });
},

/**
 * 启动轮询定时器:每 3 秒查一次,已有定时器则复用
 */
startPrePayTimer: function (prePayId) {
  const that = this;
  if (this._prePayTimer) return;

  this._prePayId = prePayId;
  this._prePayTimer = setInterval(function () {
    if (that._prePayQuerying) return;   // 上一次未返回,跳过本轮
    that._prePayQuerying = true;
    that.queryPrePayStatus(that._prePayId);
  }, 3000);
},

/**
 * 停止轮询定时器
 */
stopPrePayTimer: function () {
  if (this._prePayTimer) {
    clearInterval(this._prePayTimer);
    this._prePayTimer = null;
  }
  this._prePayQuerying = false;
  this._prePayId = null;
},