• 博客园logo
  • 会员
  • 众包
  • 新闻
  • 博问
  • 闪存
  • 赞助商
  • HarmonyOS
  • Chat2DB
    • 搜索
      所有博客
    • 搜索
      当前博客
  • 写随笔 我的博客 短消息 简洁模式
    用户头像
    我的博客 我的园子 账号设置 会员中心 简洁模式 ... 退出登录
    注册 登录

我的博客我做主

  • 博客园
  • 联系
  • 订阅
  • 管理

公告

View Post

uniapp 开发微信小程序总结(三)mixin - share

share mixin 重要用于 设置分享类容、重定向Url

 1 import {mapState,mapMutations} from 'vuex'
 2 export default {
 3     computed:{
 4         ...mapState('login',['userInfo','redirectUrl']),
 5     },
 6     onUnload() {
 7         if(this.redirectUrl){
 8             if(this.isLogin){
 9                 const token = uni.getStorageSync('token');
10                 const getPhone = uni.getStorageSync('getPhone');
11                 if(token&&!getPhone){
12                     this.clearRedirectUrl()
13                 }
14             }
15         } 
16     },
17     methods:{
18         ...mapMutations('poster',['GETSHAREINFO']),
19         ...mapMutations('login',['GETREDIRECTURL']),
20         setShareInfo(shareTitle,title,shareImg,previewImg,statistics){
21             let inviteUserId = undefined
22             if(this.userInfo){
23                 inviteUserId = this.userInfo.id
24             }
25             var pages = getCurrentPages();
26             var page = pages[pages.length - 1];
27             let path = '/' + page.route + '?code='+this.code+'&inviteUserId='+ inviteUserId
28             this.GETSHAREINFO({shareInfo:{
29                     title: shareTitle || title,
30                     image: shareImg || "",
31                     type: "share",
32                     poster: previewImg,
33                     path: path,
34                     statistics,
35                     code:this.code
36                 }
37             })
38         },
39         // 重定向页面Url
40         getRedirectUrl(){
41             let pages = getCurrentPages();
42             let page = pages[pages.length - 1];
43             // let {scene} = page.options
44             let param = ''
45             for(const key in page.options){
46                 console.log(page.options[key])
47                 param += key+'='+page.options[key]
48             }
49             let path = page.route + (param?'?'+param:'');
50             this.GETREDIRECTURL({redirectUrl:{url:path,type:1}}) //小程序内部页面
51         },
52         // 清除重定向
53         clearRedirectUrl(){
54             this.GETREDIRECTURL({redirectUrl:null})
55         }
56     }
57 }

 

作者:kitty20180903suzhou
出处:https://www.cnblogs.com/kitty-blog/
本文版权归作者和博客园共有,欢迎转载,但必须给出原文链接,并保留此段声明,否则保留追究法律责任的权利。

posted on 2020-12-28 14:14  kitty20180903suzhou  阅读(417)  评论(0)    收藏  举报

刷新页面返回顶部
 
博客园  ©  2004-2025
浙公网安备 33010602011771号 浙ICP备2021040463号-3