tükörképe a:
https://github.com/ialley-workshop-open/uni-halo.git
synced 2026-06-12 13:19:31 +08:00
refactor: 将页面配置通过插件动态化配置(plugin-uni-halo)
This commit is contained in:
@@ -9,85 +9,89 @@
|
||||
* 修改人员:
|
||||
* 修改时间:
|
||||
*/
|
||||
import HaloConfig from '@/config/halo.config.js';
|
||||
import HaloAdConfig from '@/config/ad.config.js';
|
||||
import HaloPluginsConfig from '@/config/plugins.config.js';
|
||||
|
||||
export default {
|
||||
install(Vue) {
|
||||
Vue.mixin({
|
||||
data() {
|
||||
return {
|
||||
author: HaloConfig.author,
|
||||
_isWechat: true,
|
||||
haloConfig: HaloConfig,
|
||||
haloAdConfig: HaloAdConfig,
|
||||
haloPluginsConfig: HaloPluginsConfig,
|
||||
_aniWaitIndex: 0, // 动画索引
|
||||
};
|
||||
},
|
||||
computed: {
|
||||
// 获取全局应用设置
|
||||
globalAppSettings() {
|
||||
return uni.$tm.vx.getters().getSettings;
|
||||
},
|
||||
// 计算动画索引
|
||||
calcAniWait() {
|
||||
return (index) => {
|
||||
if ((index + 1) % 10 == 0) {
|
||||
this._aniWaitIndex = 1;
|
||||
} else {
|
||||
this._aniWaitIndex += 1;
|
||||
}
|
||||
console.log('this._aniWaitIndex', this._aniWaitIndex);
|
||||
return this._aniWaitIndex * 50
|
||||
}
|
||||
}
|
||||
},
|
||||
onLoad() {
|
||||
this.fnResetSetAniWaitIndex()
|
||||
},
|
||||
created() {
|
||||
// #ifdef MP-WEIXIN
|
||||
this._isWechat = true;
|
||||
uni.$tm.vx.commit('setWxShare', HaloConfig.wxShareConfig);
|
||||
// #endif
|
||||
// #ifndef MP-WEIXIN
|
||||
this._isWechat = false;
|
||||
// #endif
|
||||
},
|
||||
onShow() {
|
||||
this.fnResetSetAniWaitIndex()
|
||||
},
|
||||
methods: {
|
||||
/**
|
||||
* 设置页面标题
|
||||
* @param {Object} title 标题
|
||||
*/
|
||||
fnSetPageTitle(title) {
|
||||
uni.setNavigationBarTitle({
|
||||
title: title || HaloConfig.title
|
||||
})
|
||||
},
|
||||
install(Vue) {
|
||||
Vue.mixin({
|
||||
data() {
|
||||
return {
|
||||
_isWechat: true,
|
||||
_aniWaitIndex: 0
|
||||
};
|
||||
},
|
||||
computed: {
|
||||
haloConfig() {
|
||||
return this.$tm.vx.getters().getConfigs;
|
||||
},
|
||||
haloPluginsConfig() {
|
||||
return this.$tm.vx.getters().getConfigs?.pluginConfig;
|
||||
},
|
||||
// 获取全局应用设置
|
||||
globalAppSettings() {
|
||||
return uni.$tm.vx.getters().getSettings;
|
||||
},
|
||||
// 计算动画索引
|
||||
calcAniWait() {
|
||||
return (index) => {
|
||||
if ((index + 1) % 10 === 0) {
|
||||
this._aniWaitIndex = 1;
|
||||
} else {
|
||||
this._aniWaitIndex += 1;
|
||||
}
|
||||
return this._aniWaitIndex * 50
|
||||
}
|
||||
}
|
||||
},
|
||||
watch: {
|
||||
haloConfig: {
|
||||
deep: true,
|
||||
immediate: true,
|
||||
handler(newVal) {
|
||||
if (!newVal) return;
|
||||
// #ifdef MP-WEIXIN
|
||||
uni.$tm.vx.commit('setWxShare', newVal.shareConfig);
|
||||
// #endif
|
||||
}
|
||||
}
|
||||
},
|
||||
onLoad() {
|
||||
this.fnResetSetAniWaitIndex()
|
||||
},
|
||||
created() {
|
||||
// #ifdef MP-WEIXIN
|
||||
this._isWechat = true;
|
||||
// #endif
|
||||
// #ifndef MP-WEIXIN
|
||||
this._isWechat = false;
|
||||
// #endif
|
||||
},
|
||||
onShow() {
|
||||
this.fnResetSetAniWaitIndex()
|
||||
},
|
||||
methods: {
|
||||
// 设置页面标题
|
||||
fnSetPageTitle(title) {
|
||||
uni.setNavigationBarTitle({
|
||||
title: title || (this.haloConfig && this.haloConfig.startConfig.title) || "uni-halo",
|
||||
})
|
||||
},
|
||||
|
||||
/**
|
||||
* 页面返回顶部
|
||||
*/
|
||||
fnToTopPage(duration = 500) {
|
||||
duration = isNaN(duration) ? 500 : duration
|
||||
uni.pageScrollTo({
|
||||
scrollTop: 0,
|
||||
duration: duration,
|
||||
fail: (err) => {
|
||||
console.log('err:', err);
|
||||
},
|
||||
});
|
||||
},
|
||||
// 初始化动画索引值(需要在每个页面调用)
|
||||
fnResetSetAniWaitIndex() {
|
||||
this._aniWaitIndex = 0
|
||||
}
|
||||
},
|
||||
});
|
||||
},
|
||||
// 页面返回顶部
|
||||
fnToTopPage(duration = 500) {
|
||||
duration = isNaN(duration) ? 500 : duration
|
||||
uni.pageScrollTo({
|
||||
scrollTop: 0,
|
||||
duration: duration,
|
||||
fail: (err) => {
|
||||
console.log('err:', err);
|
||||
},
|
||||
});
|
||||
},
|
||||
// 初始化动画索引值(需要在每个页面调用)
|
||||
fnResetSetAniWaitIndex() {
|
||||
this._aniWaitIndex = 0
|
||||
}
|
||||
},
|
||||
});
|
||||
},
|
||||
};
|
||||
|
||||
@@ -1,16 +1,15 @@
|
||||
// 微信分享配置
|
||||
import haloConfig from '@/config/halo.config.js'
|
||||
import HaloTokenConfig from '@/config/token.config.js'
|
||||
import { jsonToUrlParams2 } from '@/utils/url.params.js'
|
||||
import {
|
||||
jsonToUrlParams2
|
||||
} from '@/utils/url.params.js'
|
||||
export const haloWxShareMixin = {
|
||||
data() {
|
||||
return {
|
||||
haloWxShareData: {
|
||||
...haloConfig.wxShareConfig
|
||||
},
|
||||
computed: {
|
||||
haloWxShareData() {
|
||||
const configs = this.$tm.vx.getters().getConfigs;
|
||||
return configs.shareConfig || {}
|
||||
}
|
||||
},
|
||||
|
||||
//#ifdef MP-WEIXIN
|
||||
onShareAppMessage(res) {
|
||||
return {
|
||||
@@ -64,4 +63,4 @@ export const haloWxShareMixin = {
|
||||
this.haloWxShareData = _config;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user