功能:同步小程序流程

This commit is contained in:
xiaowang
2026-05-23 18:45:41 +08:00
parent 844516988b
commit 30ae763e18
117 changed files with 8823 additions and 76 deletions
+142
View File
@@ -1,10 +1,47 @@
/**
* Purpose: authApi supports app.js by holding or executing the auth api page or API role.
* Usage: import, call, read, or update this const from the owning page/module while preserving the surrounding loading and permission flow.
*/
const authApi = require('./api/auth')
/**
* Purpose: cartApi supports app.js by holding or executing the cart api page or API role.
* Usage: import, call, read, or update this const from the owning page/module while preserving the surrounding loading and permission flow.
*/
const cartApi = require('./api/cart')
/**
* Purpose: shopApi supports app.js by holding or executing the shop api page or API role.
* Usage: import, call, read, or update this const from the owning page/module while preserving the surrounding loading and permission flow.
*/
const shopApi = require('./api/shop')
/**
* Purpose: userApi supports app.js by holding or executing the user api page or API role.
* Usage: import, call, read, or update this const from the owning page/module while preserving the surrounding loading and permission flow.
*/
const userApi = require('./api/user')
/**
* Purpose: auth supports app.js by holding or executing the auth page or API role.
* Usage: import, call, read, or update this const from the owning page/module while preserving the surrounding loading and permission flow.
*/
const auth = require('./utils/auth')
/**
* Purpose: idleSession supports app.js by holding or executing the idle session page or API role.
* Usage: import, call, read, or update this const from the owning page/module while preserving the surrounding loading and permission flow.
*/
const idleSession = require('./utils/idle-session')
/**
* Purpose: theme supports app.js by holding or executing the theme page or API role.
* Usage: import, call, read, or update this const from the owning page/module while preserving the surrounding loading and permission flow.
*/
const theme = require('./utils/theme')
/**
* Purpose: navigation opens popup-message action paths from the global App lifecycle.
* Usage: call openSystemMessage after marking a popup message as shown.
*/
const navigation = require('./utils/navigation')
/**
* Purpose: file supports app.js by holding or executing the file page or API role.
* Usage: import, call, read, or update this const from the owning page/module while preserving the surrounding loading and permission flow.
*/
const file = require('./utils/file')
const { IDLE_TIMEOUT_MS, IDLE_WARNING_MS } = require('./utils/config')
@@ -19,6 +56,44 @@ App({
wechatMiniAutoLoginState: 'idle'
},
/**
* Purpose: checkPopupMessages globally mirrors Web popup-message behavior across mini-program pages.
* Usage: call it from onShow after login so pending popup messages are shown even outside the profile page.
*/
async checkPopupMessages() {
if (!auth.isLoggedIn() || this._checkingPopupMessages || !this._appShownOnce) {
return
}
this._checkingPopupMessages = true
try {
const messages = await userApi.listMyPopupMessages()
for (const item of messages || []) {
await new Promise(resolve => {
wx.showModal({
title: item.title || '消息通知',
content: item.content || '',
showCancel: false,
confirmText: navigation.buildMessageActionPath(item) ? '去查看' : '我知道了',
complete: resolve
})
})
await userApi.markMessagePopupShown(item.id)
const opened = await navigation.openSystemMessage(item)
if (opened) {
break
}
}
} catch (error) {
console.error('加载待弹窗消息失败', error)
} finally {
this._checkingPopupMessages = false
}
},
/**
* Purpose: onLaunch supports app.js by holding or executing the on launch page or API role.
* Usage: import, call, read, or update this method from the owning page/module while preserving the surrounding loading and permission flow.
*/
onLaunch() {
idleSession.init({
timeoutMs: IDLE_TIMEOUT_MS,
@@ -32,14 +107,28 @@ App({
}
},
/**
* Purpose: onShow supports app.js by holding or executing the on show page or API role.
* Usage: import, call, read, or update this method from the owning page/module while preserving the surrounding loading and permission flow.
*/
onShow() {
idleSession.onAppShow()
this._appShownOnce = true
this.checkPopupMessages()
},
/**
* Purpose: onHide supports app.js by holding or executing the on hide page or API role.
* Usage: import, call, read, or update this method from the owning page/module while preserving the surrounding loading and permission flow.
*/
onHide() {
idleSession.onAppHide()
},
/**
* Purpose: bootstrapSession supports app.js by holding or executing the bootstrap session page or API role.
* Usage: import, call, read, or update this method from the owning page/module while preserving the surrounding loading and permission flow.
*/
bootstrapSession() {
const userInfo = auth.getStoredUserInfo()
const isLoggedIn = auth.isLoggedIn()
@@ -91,6 +180,10 @@ App({
return this._wechatMiniAutoLoginPromise
},
/**
* Purpose: handleWechatMiniLoginResult supports app.js by holding or executing the handle wechat mini login result page or API role.
* Usage: import, call, read, or update this method from the owning page/module while preserving the surrounding loading and permission flow.
*/
handleWechatMiniLoginResult(result, options) {
const config = options || {}
const status = result && result.status ? result.status : ''
@@ -125,6 +218,10 @@ App({
return false
},
/**
* Purpose: requestWechatMiniCode supports app.js by holding or executing the request wechat mini code page or API role.
* Usage: import, call, read, or update this method from the owning page/module while preserving the surrounding loading and permission flow.
*/
requestWechatMiniCode() {
return new Promise((resolve, reject) => {
wx.login({
@@ -140,28 +237,52 @@ App({
})
},
/**
* Purpose: isWechatMiniAutoLoginPending supports app.js by holding or executing the is wechat mini auto login pending page or API role.
* Usage: import, call, read, or update this method from the owning page/module while preserving the surrounding loading and permission flow.
*/
isWechatMiniAutoLoginPending() {
return this.globalData.wechatMiniAutoLoginState === 'pending'
},
/**
* Purpose: waitForWechatMiniAutoLogin supports app.js by holding or executing the wait for wechat mini auto login page or API role.
* Usage: import, call, read, or update this method from the owning page/module while preserving the surrounding loading and permission flow.
*/
waitForWechatMiniAutoLogin() {
return this._wechatMiniAutoLoginPromise || Promise.resolve(auth.isLoggedIn())
},
/**
* Purpose: setPendingWechatMiniLogin supports app.js by holding or executing the set pending wechat mini login page or API role.
* Usage: import, call, read, or update this method from the owning page/module while preserving the surrounding loading and permission flow.
*/
setPendingWechatMiniLogin(payload) {
this.globalData.pendingWechatMiniLogin = payload || null
},
/**
* Purpose: consumePendingWechatMiniLogin supports app.js by holding or executing the consume pending wechat mini login page or API role.
* Usage: import, call, read, or update this method from the owning page/module while preserving the surrounding loading and permission flow.
*/
consumePendingWechatMiniLogin() {
const pending = this.globalData.pendingWechatMiniLogin
this.globalData.pendingWechatMiniLogin = null
return pending
},
/**
* Purpose: clearPendingWechatMiniLogin supports app.js by holding or executing the clear pending wechat mini login page or API role.
* Usage: import, call, read, or update this method from the owning page/module while preserving the surrounding loading and permission flow.
*/
clearPendingWechatMiniLogin() {
this.globalData.pendingWechatMiniLogin = null
},
/**
* Purpose: setUserSession supports app.js by holding or executing the set user session page or API role.
* Usage: import, call, read, or update this method from the owning page/module while preserving the surrounding loading and permission flow.
*/
setUserSession(payload) {
auth.setSession(payload)
this.globalData.userInfo = auth.getStoredUserInfo()
@@ -173,8 +294,13 @@ App({
}
this.updateCartBadge()
this.checkPopupMessages()
},
/**
* Purpose: refreshUserInfo supports app.js by holding or executing the refresh user info page or API role.
* Usage: import, call, read, or update this method from the owning page/module while preserving the surrounding loading and permission flow.
*/
refreshUserInfo(userInfo) {
auth.updateStoredUserInfo(userInfo)
this.globalData.userInfo = userInfo
@@ -186,6 +312,10 @@ App({
}
},
/**
* Purpose: clearUserSession supports app.js by holding or executing the clear user session page or API role.
* Usage: import, call, read, or update this method from the owning page/module while preserving the surrounding loading and permission flow.
*/
clearUserSession() {
auth.clearSession()
this.globalData.userInfo = null
@@ -194,6 +324,10 @@ App({
this.clearCartBadge()
},
/**
* Purpose: setShopTheme supports app.js by holding or executing the set shop theme page or API role.
* Usage: import, call, read, or update this method from the owning page/module while preserving the surrounding loading and permission flow.
*/
setShopTheme(shop) {
const resolvedTheme = theme.resolveShopTheme(shop)
this.globalData.shopTheme = resolvedTheme
@@ -236,6 +370,10 @@ App({
}
},
/**
* Purpose: syncThemeToCurrentPages supports app.js by holding or executing the sync theme to current pages page or API role.
* Usage: import, call, read, or update this method from the owning page/module while preserving the surrounding loading and permission flow.
*/
syncThemeToCurrentPages() {
const pages = typeof getCurrentPages === 'function' ? getCurrentPages() : []
const data = theme.pageThemeData(this.globalData.shopTheme)
@@ -305,6 +443,10 @@ App({
}
},
/**
* Purpose: clearCartBadge supports app.js by holding or executing the clear cart badge page or API role.
* Usage: import, call, read, or update this method from the owning page/module while preserving the surrounding loading and permission flow.
*/
clearCartBadge() {
this.globalData.cartCount = 0
wx.removeTabBarBadge({