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'); // 底部导航