diff --git a/src/App.vue b/src/App.vue index c236804..6a2a2d4 100644 --- a/src/App.vue +++ b/src/App.vue @@ -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 { } }, } diff --git a/src/styles/public.less b/src/styles/public.less index 9720b31..d884d0c 100644 --- a/src/styles/public.less +++ b/src/styles/public.less @@ -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; } diff --git a/src/views/Goods/GoodsDetail.vue b/src/views/Goods/GoodsDetail.vue index ed6faad..b70b27a 100644 --- a/src/views/Goods/GoodsDetail.vue +++ b/src/views/Goods/GoodsDetail.vue @@ -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(); }); }, diff --git a/src/views/Index.vue b/src/views/Index.vue index 47aea01..c2f10ec 100644 --- a/src/views/Index.vue +++ b/src/views/Index.vue @@ -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 }) } diff --git a/src/views/Platform/Business_School.vue b/src/views/Platform/Business_School.vue index ac24b58..2d4d8c4 100644 --- a/src/views/Platform/Business_School.vue +++ b/src/views/Platform/Business_School.vue @@ -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() { diff --git a/src/views/Platform/Column.vue b/src/views/Platform/Column.vue index 8265d08..3df4d5e 100644 --- a/src/views/Platform/Column.vue +++ b/src/views/Platform/Column.vue @@ -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() { diff --git a/src/views/Platform/ColumnDetail.vue b/src/views/Platform/ColumnDetail.vue index a4e6f5f..c0ce0fc 100644 --- a/src/views/Platform/ColumnDetail.vue +++ b/src/views/Platform/ColumnDetail.vue @@ -22,6 +22,7 @@ diff --git a/src/views/Platform/School_Detail.vue b/src/views/Platform/School_Detail.vue index 358843a..37cc4c6 100644 --- a/src/views/Platform/School_Detail.vue +++ b/src/views/Platform/School_Detail.vue @@ -17,6 +17,7 @@