From d2c122897d5277a1498b3e5a2ec7865297167d69 Mon Sep 17 00:00:00 2001 From: kola-web Date: Wed, 24 Dec 2025 11:51:59 +0800 Subject: [PATCH] =?UTF-8?q?=E5=A2=9E=E5=8A=A0=E7=89=88=E6=9C=AC=E6=9B=B4?= =?UTF-8?q?=E6=96=B0=E6=8F=90=E7=A4=BA?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- project.config.json | 2 +- src/app.ts | 32 ++++++++++++++++++++++++++++++++ src/config.ts | 12 ++++++++++++ 3 files changed, 45 insertions(+), 1 deletion(-) create mode 100644 src/config.ts diff --git a/project.config.json b/project.config.json index 1d8faf4..625d498 100644 --- a/project.config.json +++ b/project.config.json @@ -71,5 +71,5 @@ } ] }, - "appid": "wx71ac9c27c3c3e3f4" + "appid": "wxf9ce8010f1ad24aa" } \ No newline at end of file diff --git a/src/app.ts b/src/app.ts index 01445c8..eb8052a 100644 --- a/src/app.ts +++ b/src/app.ts @@ -4,6 +4,7 @@ import component from '@/utils/component' import relativeTime from '@/utils/dayjs/relativeTime.js' import page from '@/utils/page' import { request } from '@/utils/request' +import config from './config' import { parseScene } from './utils/util' require('/utils/dayjs/day-zh-cn.js') @@ -104,6 +105,9 @@ App({ }, }, onLaunch() { + const appid = wx.getAccountInfoSync().miniProgram.appId + Object.assign(this.globalData, config[appid] || {}) + Page = page as WechatMiniprogram.Page.Constructor Component = component as WechatMiniprogram.Component.Constructor @@ -115,6 +119,8 @@ App({ obeyMuteSwitch: false, mixWithOther: false, }) + + this.handleUpdateMiniprogram() }, onShow(options) { if (options.query.scene) { @@ -550,4 +556,30 @@ App({ wx.removeTabBarBadge({ index: 2 }) }) }, + handleUpdateMiniprogram() { + const updateManager = wx.getUpdateManager() + + updateManager.onCheckForUpdate((res) => { + // 请求完新版本信息的回调 + // eslint-disable-next-line no-console + console.log(res.hasUpdate) + }) + + updateManager.onUpdateReady(() => { + wx.showModal({ + title: '更新提示', + content: '新版本已经准备好,是否重启应用?', + success(res) { + if (res.confirm) { + // 新的版本已经下载好,调用 applyUpdate 应用新版本并重启 + updateManager.applyUpdate() + } + }, + }) + }) + + updateManager.onUpdateFailed(() => { + // 新版本下载失败 + }) + }, }) diff --git a/src/config.ts b/src/config.ts new file mode 100644 index 0000000..7b12359 --- /dev/null +++ b/src/config.ts @@ -0,0 +1,12 @@ +export default { + wxf9ce8010f1ad24aa: { + url: 'https://m.xd.hbraas.com', + upFileUrl: 'https://m.xd.hbraas.com/', + imageUrl: 'https://m.xd.hbraas.com/xd/', + }, + wx71ac9c27c3c3e3f4: { + url: 'https://m.xd.hbsaas.com', + upFileUrl: 'https://m.xd.hbsaas.com/', + imageUrl: 'https://m.xd.hbsaas.com/api/xd/', + }, +}