微信分享

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: { watch: {
$route(to, from) { $route(to, from) {
const title = to.meta.title || '' document.title = this.$route.meta.title || this.sysConfig.Base.SiteName || '';
this.updateTitle(title) const recommend = this.$route.query.RecommendCode;
this.updateShare(undefined, undefined, undefined) 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() { mounted() {
this.init()
}, },
methods: { methods: {
init() {
this.$post('/v1/client/HWxinfoClient/share', { url: encodeURIComponent(location.href) }).then(data => {
this.wechatShareInfo = data
}).finally(() => {
this.updateShare()
})
},
updateTitle(title) { updateTitle(title) {
document.title = title document.title = title
if (this.$isWechat()) { if (this.$isWechat()) {
@ -54,34 +69,45 @@ export default {
}, },
updateShare(title, desc, imgUrl) { updateShare(title, desc, imgUrl) {
if (wx && this.$isWechat()) { 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 = { let shareinfo = {
title: title || this.wechatShareInfo.ShareTitle || '泰古润', title: title || data.title || '泰古润',
desc: desc || this.wechatShareInfo.ShareContent || '汇聚平凡梦想,共创美好未来', desc: data.contents || '汇聚平凡梦想,共创美好未来',
imgUrl: this.$file(imgUrl || this.wechatShareInfo.ShareLogo || '/img/logo.png'), imgUrl: imgUrl || data.img,
link: this.$getShareLink(), link: this.$getShareLink(),
}; };
if (this.$isWechatMini()) const jsApiList = data.jsApiList || ['onMenuShareTimeline', 'onMenuShareAppMessage', 'updateAppMessageShareData', 'updateTimelineShareData'];
wx.miniProgram.postMessage({ data: { share: shareinfo } }); const openTagList = data.openTagList || ['wx-open-launch-weapp'];
data.jsApiList.push('wx-open-launch-weapp'); jsApiList.push('wx-open-launch-weapp');
data.openTagList = ['wx-open-launch-weapp'];
wx.config({ wx.config({
debug: false, debug: false,
appId: data.appid, appId: data.appid,
timestamp: data.timestamp, timestamp: Number(data.timestamp) || 0,
nonceStr: data.noncestr, nonceStr: data.noncestr,
signature: data.signature, signature: data.signature,
jsApiList: data.jsApiList, jsApiList: jsApiList,
openTagList: data.openTagList openTagList: openTagList
}); });
wx.ready(() => { wx.ready(() => {
wx.updateAppMessageShareData(shareinfo); wx.updateAppMessageShareData(shareinfo);
wx.updateTimelineShareData(shareinfo); wx.updateTimelineShareData(shareinfo);
}); });
wx.error((e) => { wx.error((e) => {
console.error('wx.error', e);
}); });
}); });
} else {
} }
}, },
} }

View File

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

View File

@ -253,7 +253,7 @@ export default {
this.specCombinations = this.data.specCombinations || []; this.specCombinations = this.data.specCombinations || [];
const recommend = localStorage.getItem('cellphone') || ''; const recommend = localStorage.getItem('cellphone') || '';
this.shareLink = `${location.origin}/#/GoodsDetail?id=${this.data.id}${recommend ? '&RecommendCode=' + recommend : ''}`; 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(); this.initDefaultSku();
}); });
}, },

View File

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

View File

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

View File

@ -34,6 +34,9 @@ export default {
// console.log(data); // console.log(data);
this.articleList = data.data.items; this.articleList = data.data.items;
this.currentColumn.name = data.data.items[0].pidname; 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() { data() {

View File

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

View File

@ -29,6 +29,7 @@
<script> <script>
export default { export default {
name: 'School_Category', name: 'School_Category',
emits: ['updateShare'],
computed: { computed: {
categoryId() { categoryId() {
return Number(this.$route.query.id) || 1 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' } { 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> </script>

View File

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

View File

@ -219,6 +219,7 @@ export default {
deducthuiyuanka: data.deducthuiyuanka || 0, deducthuiyuanka: data.deducthuiyuanka || 0,
mallstate: data.mallstate || 0, mallstate: data.mallstate || 0,
}; };
this.$emit('updateShare', this.product.name, this.product.typename + '订单', this.product.img);
}); });
}, },
loadUserInfo() { 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 || item.state === 4" @click="showLogistics(item)">物流信息</button>
<button v-if="item.state === 3" @click="confirmReceipt(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> <button v-if="item.state === 0" @click="$navigate(`Pay?ordernum=${item.ordernum}`)">立即支付</button>
</div> </div>
</div> </div>
@ -240,6 +241,17 @@ export default {
.catch() .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) { showLogistics(item) {
this.currentLogistics = item this.currentLogistics = item