chore(加载主题样式): 只使用异步方式,保留一个函数loadTheme
This commit is contained in:
5
App.vue
5
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');
|
||||
}
|
||||
|
||||
|
||||
@@ -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 - 主题名称
|
||||
|
||||
@@ -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');
|
||||
|
||||
// 底部导航
|
||||
|
||||
Reference in New Issue
Block a user