From d7b07c974dc7bbc143ca3eac2ca9b62c1bdd1ccd Mon Sep 17 00:00:00 2001 From: ZF sun <34314687@qq.com> Date: Tue, 6 Jan 2026 17:01:03 +0800 Subject: [PATCH] =?UTF-8?q?chore(=E5=8A=A0=E8=BD=BD=E4=B8=BB=E9=A2=98?= =?UTF-8?q?=E6=A0=B7=E5=BC=8F):=20=E5=8F=AA=E4=BD=BF=E7=94=A8=E5=BC=82?= =?UTF-8?q?=E6=AD=A5=E6=96=B9=E5=BC=8F=EF=BC=8C=E4=BF=9D=E7=95=99=E4=B8=80?= =?UTF-8?q?=E4=B8=AA=E5=87=BD=E6=95=B0loadTheme?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- App.vue | 5 +++-- common/js/config-external.js | 22 ---------------------- store/index.js | 7 ++++--- 3 files changed, 7 insertions(+), 27 deletions(-) diff --git a/App.vue b/App.vue index ad9b424..2625d3c 100644 --- a/App.vue +++ b/App.vue @@ -8,7 +8,7 @@ export default { mixins: [auth], - onLaunch: function(options) { + onLaunch: async function(options) { // 方式:支持快应用,从url中query部分获取uniacid,或useragent中获取uniacid if(options.query.uniacid){ uni.setStorageSync('uniacid', options.query.uniacid); @@ -61,7 +61,8 @@ // 主题风格 if (uni.getStorageSync('themeStyle')) { - this.$store.commit('setThemeStyle', configExternal.loadThemeSync(uni.getStorageSync('themeStyle'))); + const themeData = await configExternal.loadTheme(uni.getStorageSync('themeStyle')); + this.$store.commit('setThemeStyle', themeData); this.$store.dispatch('themeColorSet'); } diff --git a/common/js/config-external.js b/common/js/config-external.js index 26cc8f1..02a189d 100644 --- a/common/js/config-external.js +++ b/common/js/config-external.js @@ -98,28 +98,6 @@ class ConfigExternal { return this.loadPromises[key]; } - /** - * 加载主题配置(同步方式) - * @param {string} theme - 主题名称 - * @returns {object} - 主题配置 - */ - loadThemeSync(theme = themeConfig.defaultTheme) { - if (this.loadedConfigs[`theme_${theme}`]) { - return this.loadedConfigs[`theme_${theme}`]; - } - - try { - // 动态加载主题配置 - const themeData = require(`@/common/js/style_color.js`)['default'][theme]; - console.log('sync themeData => ', themeData); - this.loadedConfigs[`theme_${theme}`] = themeData; - return themeData; - } catch (error) { - console.error(`加载主题 ${theme} 失败:`, error); - return {}; - } - } - /** * 加载主题配置(异步方式) * @param {string} theme - 主题名称 diff --git a/store/index.js b/store/index.js index 17b9fad..4339ebd 100644 --- a/store/index.js +++ b/store/index.js @@ -252,13 +252,14 @@ const store = new Vuex.Store({ }, actions: { init() { - return new Promise((resolve, reject) => { + return new Promise(async (resolve, reject) => { Http.sendRequest({ url: '/api/config/init', - success: res => { + success: async res => { var data = res.data; if (data) { - this.commit('setThemeStyle', configExternal.loadThemeSync(data.style_theme?.name)); + const themeData = await configExternal.loadTheme(data.style_theme?.name); + this.commit('setThemeStyle', themeData); this.dispatch('themeColorSet'); // 底部导航