update: 删除分享配置,使用微信默认的分享机制

This commit is contained in:
小莫唐尼 2024-06-26 23:41:00 +08:00
parent 66a39dd723
commit 4d0901b650
5 changed files with 49 additions and 147 deletions

10
App.vue
View File

@ -3,15 +3,13 @@
// apphttps://ext.dcloud.net.cn/plugin?id=4470 // apphttps://ext.dcloud.net.cn/plugin?id=4470
import CheckAppUpdate from '@/uni_modules/uni-upgrade-center-app/utils/check-update'; import CheckAppUpdate from '@/uni_modules/uni-upgrade-center-app/utils/check-update';
import { import {CheckWxUpdate} from '@/utils/update.js';
CheckWxUpdate
} from '@/utils/update.js';
export default { export default {
globalData: { globalData: {
baseApiUrl: HaloTokenConfig.BASE_API baseApiUrl: HaloTokenConfig.BASE_API
}, },
onLaunch: function () { onLaunch: function () {
console.log('App Launch');
// #ifdef APP-PLUS // #ifdef APP-PLUS
CheckAppUpdate(); CheckAppUpdate();
@ -22,10 +20,6 @@
// #endif // #endif
uni.$tm.vx.actions('config/fetchConfigs').then((res) => { uni.$tm.vx.actions('config/fetchConfigs').then((res) => {
console.log('正常:', res)
// #ifdef MP-WEIXIN
uni.$tm.vx.commit('setWxShare', res.shareConfig);
// #endif
}) })
// app // app
uni.$tm.vx.actions('setting/checkAndSetDefaultAppSettings'); uni.$tm.vx.actions('setting/checkAndSetDefaultAppSettings');

View File

@ -42,18 +42,6 @@ export default {
} }
} }
}, },
watch: {
haloConfig: {
deep: true,
immediate: true,
handler(newVal) {
if (!newVal) return;
// #ifdef MP-WEIXIN
uni.$tm.vx.commit('setWxShare', newVal.shareConfig);
// #endif
}
}
},
onLoad() { onLoad() {
this.fnResetSetAniWaitIndex() this.fnResetSetAniWaitIndex()
}, },

View File

@ -1,68 +0,0 @@
// 微信分享配置
import HaloTokenConfig from '@/config/token.config.js'
import {jsonToUrlParams2} from '@/utils/url.params.js'
import utils from '@/utils/index.js'
export const haloWxShareMixin = {
computed: {
haloWxShareData() {
const configs = this.$tm.vx.getters().getConfigs?.shareConfig;
if(!configs) return {};
configs.imageUrl = utils.checkImageUrl(configs.imageUrl)
return configs
}
},
//#ifdef MP-WEIXIN
onShareAppMessage(res) {
return {
...this.haloWxShareData,
success: res => {
}
}
},
//#endif
/* 分享到微信好友 */
onShareAppMessage(res) {
const promise = new Promise(resolve => {
setTimeout(() => {
resolve({
title: this.haloWxShareData.title,
path: this.haloWxShareData.path,
})
}, 2000)
})
return {
title: this.haloWxShareData.title,
path: '',
promise
}
},
// 分享到朋友圈-这里封装不够,在页面还要声明一次,否则是拿不到参数的,被分享者在朋友圈打开链接是空的
onShareTimeline: function () {
return {
title: this.haloWxShareData.title,
query: {},
imageUrl: this.haloWxShareData.imageUrl,
}
},
methods: {
// 设置分享信息(需要在页面调用)
fnSetWxShareConfig(config = {}) {
let currentRoutes = getCurrentPages(); // 获取当前打开过的页面路由数组
let currentRoute = currentRoutes[currentRoutes.length - 1].route; //获取当前页面路由(分销思路分享者点开使用的小程序将获取到分享者的id)
let sharePath = currentRoutes
if (config.params) {
const URLParams = config.params ? jsonToUrlParams2(config.params) : {};
sharePath += URLParams
}
let _config = Object.assign({}, {
path: sharePath,
copyLink: HaloTokenConfig.BASE_API,
query: {}
}, config)
uni.$tm.vx.commit('setWxShare', _config);
}
}
}

View File

@ -14,7 +14,7 @@ export default {
onLoad() { onLoad() {
uni.$tm.vx.actions('config/fetchConfigs').then((res) => { uni.$tm.vx.actions('config/fetchConfigs').then((res) => {
// #ifdef MP-WEIXIN // #ifdef MP-WEIXIN
uni.$tm.vx.commit('setWxShare', res.shareConfig); // uni.$tm.vx.commit('setWxShare', res.shareConfig);
// #endif // #endif
this.fnCheckShowStarted(); this.fnCheckShowStarted();
}).catch((err) => { }).catch((err) => {

View File

@ -233,8 +233,6 @@ import commentModal from '@/components/comment-modal/comment-modal.vue';
import rCanvas from '@/components/r-canvas/r-canvas.vue'; import rCanvas from '@/components/r-canvas/r-canvas.vue';
import barrage from '@/components/barrage/barrage.vue'; import barrage from '@/components/barrage/barrage.vue';
import {haloWxShareMixin} from '@/common/mixins/wxshare.mixin.js';
export default { export default {
components: { components: {
tmSkeleton, tmSkeleton,
@ -251,7 +249,6 @@ export default {
barrage, barrage,
commentModal commentModal
}, },
mixins: [haloWxShareMixin],
data() { data() {
return { return {
loading: 'loading', loading: 'loading',
@ -394,15 +391,6 @@ export default {
this.fnSetPageTitle('文章详情'); this.fnSetPageTitle('文章详情');
this.loading = 'success'; this.loading = 'success';
this.fnSetWxShareConfig({
title: this.result.spec.title,
desc: this.result.content.raw,
imageUrl: this.$utils.checkThumbnailUrl(this.result.spec.cover),
path: `/pagesA/article-detail/article-detail?name=${this.result.metadata.name}`,
copyLink: this.$baseApiUrl,
query: {}
});
}) })
.catch(err => { .catch(err => {
console.log("错误", err) console.log("错误", err)