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 }