From ec1918126e5650be3a00e0ea8bb71a735c0078d0 Mon Sep 17 00:00:00 2001 From: huliyong <2783385703@qq.com> Date: Tue, 5 Nov 2024 08:55:36 +0800 Subject: [PATCH] =?UTF-8?q?=E4=B8=8A=E4=BC=A0=E4=BB=A3=E7=A0=81?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- main.js | 8 ++++++++ mixins/share.js | 29 +++++++++++++++++++++++++++++ pages/publish/actorDetail.vue | 14 +++++++++++--- pages/publish/postDetail.vue | 14 +++++++++++--- pages_mine/publish/worksDetail.vue | 8 ++++++++ 5 files changed, 67 insertions(+), 6 deletions(-) create mode 100644 mixins/share.js diff --git a/main.js b/main.js index c85c62d..d4bb01f 100644 --- a/main.js +++ b/main.js @@ -28,6 +28,12 @@ uni.$uv.setConfig({ // //wxe7ae8cbe1673834c + +// 导入并挂载全局的分享方法 +import share from '@/mixins/share.js' +Vue.mixin(share) + + //组件注册 import configPopup from '@/components/config/configPopup.vue' import navbar from '@/components/base/navbar.vue' @@ -35,6 +41,8 @@ import navbar from '@/components/base/navbar.vue' Vue.component('configPopup', configPopup) Vue.component('navbar', navbar) + + const app = new Vue({ ...App, store, diff --git a/mixins/share.js b/mixins/share.js new file mode 100644 index 0000000..568664d --- /dev/null +++ b/mixins/share.js @@ -0,0 +1,29 @@ +export default { + data() { + return { + // 默认的全局分享内容 + share: { + title: '真视界', + path: '/pages/index/index', // 全局分享的路径,比如 首页 + // imageUrl: '/static/image/login/logo.png', // 全局分享的图片(可本地可网络) + } + } + }, + // 定义全局分享 + // 1.发送给朋友 + onShareAppMessage(res) { + return { + title: this.share.title, + path: this.share.path, + imageUrl: this.share.imageUrl, + } + }, + //2.分享到朋友圈 + onShareTimeline(res) { + return { + title: this.share.title, + path: this.share.path, + imageUrl: this.share.imageUrl, + } + }, +} \ No newline at end of file diff --git a/pages/publish/actorDetail.vue b/pages/publish/actorDetail.vue index a20d023..d75a596 100644 --- a/pages/publish/actorDetail.vue +++ b/pages/publish/actorDetail.vue @@ -133,9 +133,17 @@ }, onShareAppMessage(res) { return { - title: this.item.details.title, - desc: this.item.details.content && this.item.details.content.slice(0, 30), - path: '/pages/publish/actorDetail?id=' + this.id + title: this.item.details.title, + desc: this.item.details.content && this.item.details.content.slice(0, 30), + path: '/pages/publish/actorDetail?id=' + this.id + } + }, + //2.分享到朋友圈 + onShareTimeline(res) { + return { + title: this.item.details.title, + desc: this.item.details.content && this.item.details.content.slice(0, 30), + path: '/pages/publish/actorDetail?id=' + this.id } }, onShow() { diff --git a/pages/publish/postDetail.vue b/pages/publish/postDetail.vue index 1e5425f..d21169a 100644 --- a/pages/publish/postDetail.vue +++ b/pages/publish/postDetail.vue @@ -74,9 +74,17 @@ // console.log(res.target) // } return { - title: this.item.title, - desc: this.item.content && this.item.content.slice(0, 30), - path: '/pages/publish/postDetail?id=' + this.id + title: this.item.title, + desc: this.item.content && this.item.content.slice(0, 30), + path: '/pages/publish/postDetail?id=' + this.id + } + }, + //2.分享到朋友圈 + onShareTimeline(res) { + return { + title: this.item.title, + desc: this.item.content && this.item.content.slice(0, 30), + path: '/pages/publish/postDetail?id=' + this.id } }, methods: { diff --git a/pages_mine/publish/worksDetail.vue b/pages_mine/publish/worksDetail.vue index d34e7bb..dee017d 100644 --- a/pages_mine/publish/worksDetail.vue +++ b/pages_mine/publish/worksDetail.vue @@ -113,6 +113,14 @@ path: '/pages_mine/publish/worksDetail?id=' + this.id } }, + //2.分享到朋友圈 + onShareTimeline(res) { + return { + title: this.item.title, + desc: this.item.content && this.item.content.slice(0, 30), + path: '/pages_mine/publish/worksDetail?id=' + this.id + } + }, methods: { leftClick(){ uni.navigateBack(-1)