微信分享

This commit is contained in:
chenhao 2026-05-29 10:27:56 +08:00
parent 606c3dd7a2
commit 7fb0266abe
11 changed files with 85 additions and 26 deletions

View File

@ -22,22 +22,37 @@ export default {
},
watch: {
$route(to, from) {
const title = to.meta.title || ''
this.updateTitle(title)
this.updateShare(undefined, undefined, undefined)
document.title = this.$route.meta.title || this.sysConfig.Base.SiteName || '';
const recommend = this.$route.query.RecommendCode;
if (recommend && !['null', 'undefined'].includes(recommend)) {
const curRecommend = this.$ls.get('recommend');
if (Array.isArray(recommend)) {
this.$ls.set('recommend', recommend[recommend.length - 1]);
}
else {
this.$ls.set('recommend', recommend);
}
if (this.$route.query.url == 'Invite' && this.$isLogin()) {
location.replace('#/');
}
}
if (this.$route.query.openid)
this.$ls.set('openid', this.$route.query.openid);
if (this.$route.query.miniopenid)
this.$ls.set('miniopenid', this.$route.query.miniopenid);
if (!this.$route.meta.noLogin && !this.$isLogin()) {
location.replace('#/Login');
}
// if (this.$isLogin()) {
// this.getTip();
// }
// updateShare emit
this.updateShare(undefined, undefined, undefined);
}
},
mounted() {
this.init()
},
methods: {
init() {
this.$post('/v1/client/HWxinfoClient/share', { url: encodeURIComponent(location.href) }).then(data => {
this.wechatShareInfo = data
}).finally(() => {
this.updateShare()
})
},
updateTitle(title) {
document.title = title
if (this.$isWechat()) {
@ -54,34 +69,45 @@ export default {
},
updateShare(title, desc, imgUrl) {
if (wx && this.$isWechat()) {
this.$post('/v1/client/HWxinfoClient/share', { url: encodeURIComponent(location.href) }).then(data => {
const url = location.href;
const token = localStorage.getItem('member_token') || '';
fetch(`${import.meta.env.VITE_API_URL}/v1/client/HWxinfoClient/share`, {
method: 'POST',
headers: {
'Content-Type': 'application/json',
'Authorization': `Bearer ${token}`,
},
body: JSON.stringify(url)
}).then(res => {
return res.json();
}).then(res => {
const data = res.data || {};
let shareinfo = {
title: title || this.wechatShareInfo.ShareTitle || '泰古润',
desc: desc || this.wechatShareInfo.ShareContent || '汇聚平凡梦想,共创美好未来',
imgUrl: this.$file(imgUrl || this.wechatShareInfo.ShareLogo || '/img/logo.png'),
title: title || data.title || '泰古润',
desc: data.contents || '汇聚平凡梦想,共创美好未来',
imgUrl: imgUrl || data.img,
link: this.$getShareLink(),
};
if (this.$isWechatMini())
wx.miniProgram.postMessage({ data: { share: shareinfo } });
data.jsApiList.push('wx-open-launch-weapp');
data.openTagList = ['wx-open-launch-weapp'];
const jsApiList = data.jsApiList || ['onMenuShareTimeline', 'onMenuShareAppMessage', 'updateAppMessageShareData', 'updateTimelineShareData'];
const openTagList = data.openTagList || ['wx-open-launch-weapp'];
jsApiList.push('wx-open-launch-weapp');
wx.config({
debug: false,
appId: data.appid,
timestamp: data.timestamp,
timestamp: Number(data.timestamp) || 0,
nonceStr: data.noncestr,
signature: data.signature,
jsApiList: data.jsApiList,
openTagList: data.openTagList
jsApiList: jsApiList,
openTagList: openTagList
});
wx.ready(() => {
wx.updateAppMessageShareData(shareinfo);
wx.updateTimelineShareData(shareinfo);
});
wx.error((e) => {
console.error('wx.error', e);
});
});
} else {
}
},
}

View File

@ -1008,6 +1008,7 @@ img {
.box;
.box-align-center;
margin-top: 3.33vw;
white-space: nowrap;
.b0 {
color: #ea3e23;
@ -1032,7 +1033,7 @@ img {
border: none;
height: 6.93vw;
padding: 0 2.4vw;
margin-left: 2.4vw;
margin-left: 2vw;
background-color: #efefef;
border-radius: 1.33vw;
}

View File

@ -253,7 +253,7 @@ export default {
this.specCombinations = this.data.specCombinations || [];
const recommend = localStorage.getItem('cellphone') || '';
this.shareLink = `${location.origin}/#/GoodsDetail?id=${this.data.id}${recommend ? '&RecommendCode=' + recommend : ''}`;
this.$emit('updateShare', { title: this.data.name, imageUrl: this.data.img, link: this.shareLink });
this.$emit('updateShare', this.data.name, this.data.description, this.data.img);
this.initDefaultSku();
});
},

View File

@ -94,7 +94,8 @@ export default {
if (this.$route.name === name) {
//
// this.$router.replace({ name })
location.reload()
location.reload();
window.scrollTo(0, 0)
} else {
this.$router.push({ name })
}

View File

@ -75,6 +75,7 @@ import BaseList from '../../components/BaseList.vue';
export default {
name: 'Business_School',
emits: ['updateShare'],
data() {
return {
activeTab: 1,
@ -92,6 +93,7 @@ export default {
},
mounted() {
this.getList()
this.$emit('updateShare', '泰古润商学院', '学习知识,提升能力', '/img/bs-icon.png');
},
methods: {
getList() {

View File

@ -34,6 +34,9 @@ export default {
// console.log(data);
this.articleList = data.data.items;
this.currentColumn.name = data.data.items[0].pidname;
if (this.articleList.length > 0) {
this.$emit('updateShare', this.articleList[0].name, this.articleList[0].description, this.articleList[0].img);
}
})
},
data() {

View File

@ -22,6 +22,7 @@
<script>
export default {
name: 'ColumnDetail',
emits: ['updateShare'],
computed: {
},
data() {
@ -41,6 +42,7 @@ export default {
if (id === '1') {
this.$get('/v1/client/CNewscatesClient/1').then(res => {
this.article = res.data;
this.$emit('updateShare', this.article.name, this.article.description, this.article.img);
}).catch(err => {
this.$showFailToast(err.message);
});
@ -48,6 +50,7 @@ export default {
}
this.$get(`/v1/client/CNewsClient/${id}`).then(data => {
this.article = data.data;
this.$emit('updateShare', this.article.name, this.article.description, this.article.img);
}).catch(err => {
this.$showFailToast(err.message);
});

View File

@ -29,6 +29,7 @@
<script>
export default {
name: 'School_Category',
emits: ['updateShare'],
computed: {
categoryId() {
return Number(this.$route.query.id) || 1
@ -58,6 +59,13 @@ export default {
{ id: 8, CategoryId: 3, Title: '品牌建设策略', SubTitle: '农产品品牌打造', CTime: '2023-12-28', ReadCount: 156, Icon: '/img/school-8.png' }
]
}
},
mounted() {
// 使
if (this.articleList.length > 0) {
const first = this.articleList[0];
this.$emit('updateShare', first.Title, first.SubTitle, first.Icon);
}
}
}
</script>

View File

@ -17,6 +17,7 @@
<script>
export default {
name: 'School_detail',
emits: ['updateShare'],
data() {
return {
article: {},
@ -27,6 +28,7 @@ export default {
const id = this.$route.query.id
this.$get(`/v1/client/CBusinessschoolsClient/${id}`).then(res => {
this.article = res.data;
this.$emit('updateShare', res.data.name, res.data.description, res.data.img);
// sessionStorage.setItem(cacheKey, JSON.stringify(res.data))
})
},

View File

@ -219,6 +219,7 @@ export default {
deducthuiyuanka: data.deducthuiyuanka || 0,
mallstate: data.mallstate || 0,
};
this.$emit('updateShare', this.product.name, this.product.typename + '订单', this.product.img);
});
},
loadUserInfo() {

View File

@ -55,6 +55,7 @@
<button v-if="item.state === 3 || item.state === 4" @click="showLogistics(item)">物流信息</button>
<button v-if="item.state === 3" @click="confirmReceipt(item)">确认收货</button>
<!-- <button v-if="item.state === 3" @click="refundTrade(item)">退款</button> -->
<button v-if="item.state === 0" @click="$navigate(`Pay?ordernum=${item.ordernum}`)">立即支付</button>
</div>
</div>
@ -240,6 +241,17 @@ export default {
.catch()
},
// 退
// refundTrade(item) {
// this.$showConfirmDialog({ title: '退' })
// .then(() => this.$get(`/v1/client/FOrdersClient/${item.ordernum}/refund`))
// .then(() => {
// this.$showSuccessToast('退')
// this.$refs.baseList?.refresh()
// })
// .catch()
// },
//
showLogistics(item) {
this.currentLogistics = item