feat: uniapp 读取分类页设置配置(缓存+默认值兜底)

This commit is contained in:
pikachu1995@126.com
2026-10-22 09:17:58 +08:00
parent 0a47f84c32
commit 1032b6e34d
4 changed files with 106 additions and 1 deletions

24
App.vue
View File

@@ -3,13 +3,18 @@ import config from '@/config/config'
import { getClipboardData } from '@/js_sdk/h5-copy/h5-copy.js'
import APPUpdate from '@/plugins/APPUpdate'
import storage from '@/utils/storage'
import { getThemeSetting } from '@/api/common.js'
import { getThemeSetting, getCategoryPageSetting } from '@/api/common.js'
import {
applyTabBarStyle,
cacheTheme,
loadCachedTheme,
normalizeTheme,
} from '@/utils/theme'
import {
cacheCategoryPageSetting,
loadCachedCategoryPageSetting,
normalizeCategoryPageSetting,
} from '@/utils/categoryPageSetting'
import { onLaunch, onShow } from '@dcloudio/uni-app'
import { useStore } from '@/store'
import { handleAppLaunchScene } from '@/utils/distributionBind.js'
@@ -24,6 +29,7 @@ wx.onAppRoute((res) => {
onLaunch((val) => {
initTheme()
initCategoryPageSetting()
handleAppLaunchScene(val)
if (val?.query?.inviter) {
storage.setInviter(val.query.inviter)
@@ -81,6 +87,22 @@ function initTheme() {
.catch(() => {})
}
function initCategoryPageSetting() {
const cached = loadCachedCategoryPageSetting()
if (cached) {
store.commit('SET_CATEGORY_PAGE_SETTING', cached)
}
getCategoryPageSetting()
.then((res) => {
if (res.data?.success) {
const setting = normalizeCategoryPageSetting(res.data.result)
store.commit('SET_CATEGORY_PAGE_SETTING', setting)
cacheCategoryPageSetting(setting)
}
})
.catch(() => {})
}
function applyUpdateWeChat() {
const updateManager = uni.getUpdateManager()