杂务:整理文档并收口 YumiNail 修复

This commit is contained in:
xiaowang
2026-05-21 18:43:59 +08:00
parent 3797938616
commit 9227ec6175
362 changed files with 8358 additions and 19928 deletions
+60
View File
@@ -1,8 +1,11 @@
const authApi = require('./api/auth')
const cartApi = require('./api/cart')
const shopApi = require('./api/shop')
const userApi = require('./api/user')
const auth = require('./utils/auth')
const idleSession = require('./utils/idle-session')
const theme = require('./utils/theme')
const file = require('./utils/file')
const { IDLE_TIMEOUT_MS, IDLE_WARNING_MS } = require('./utils/config')
App({
@@ -10,6 +13,7 @@ App({
userInfo: null,
isLoggedIn: false,
cartCount: 0,
shopTheme: theme.DEFAULT_SHOP_THEME,
pendingProductFilter: null,
pendingWechatMiniLogin: null,
wechatMiniAutoLoginState: 'idle'
@@ -41,6 +45,7 @@ App({
const isLoggedIn = auth.isLoggedIn()
this.globalData.userInfo = userInfo
this.globalData.isLoggedIn = isLoggedIn
this.refreshShopTheme(userInfo)
if (userInfo && userInfo.shopId) {
auth.setPreferredMiniLoginShopId(userInfo.shopId)
@@ -161,6 +166,7 @@ App({
auth.setSession(payload)
this.globalData.userInfo = auth.getStoredUserInfo()
this.globalData.isLoggedIn = auth.isLoggedIn()
this.refreshShopTheme(this.globalData.userInfo)
if (this.globalData.userInfo && this.globalData.userInfo.shopId) {
auth.setPreferredMiniLoginShopId(this.globalData.userInfo.shopId)
@@ -173,6 +179,7 @@ App({
auth.updateStoredUserInfo(userInfo)
this.globalData.userInfo = userInfo
this.globalData.isLoggedIn = auth.isLoggedIn()
this.refreshShopTheme(userInfo)
if (userInfo && userInfo.shopId) {
auth.setPreferredMiniLoginShopId(userInfo.shopId)
@@ -183,9 +190,62 @@ App({
auth.clearSession()
this.globalData.userInfo = null
this.globalData.isLoggedIn = false
this.setShopTheme(null)
this.clearCartBadge()
},
setShopTheme(shop) {
const resolvedTheme = theme.resolveShopTheme(shop)
this.globalData.shopTheme = resolvedTheme
this.syncThemeToCurrentPages()
if (resolvedTheme.backgroundImageFileId) {
this.resolveShopThemeBackground(shop, resolvedTheme.backgroundImageFileId)
}
},
async resolveShopThemeBackground(shop, fileId) {
try {
const backgroundImageUrl = await file.getSignedUrl(fileId)
if (
!backgroundImageUrl
|| !this.globalData.shopTheme
|| this.globalData.shopTheme.backgroundImageFileId !== String(fileId)
) {
return
}
this.globalData.shopTheme = theme.resolveShopTheme({
...(shop || {}),
themeBackgroundImageUrl: backgroundImageUrl
})
this.syncThemeToCurrentPages()
} catch (error) {}
},
async refreshShopTheme(userInfo) {
if (!userInfo || !userInfo.shopId) {
this.setShopTheme(null)
return
}
try {
const shop = await shopApi.getShopById(userInfo.shopId)
if (this.globalData.userInfo && String(this.globalData.userInfo.shopId) === String(userInfo.shopId)) {
this.setShopTheme(shop)
}
} catch (error) {
this.setShopTheme(null)
}
},
syncThemeToCurrentPages() {
const pages = typeof getCurrentPages === 'function' ? getCurrentPages() : []
const data = theme.pageThemeData(this.globalData.shopTheme)
pages.forEach(page => {
if (page && typeof page.setData === 'function') {
page.setData(data)
}
})
},
async refreshSessionUserInfo() {
if (!auth.isLoggedIn()) {
return