1.先准备一个https地址,用于在微信公众平台/小程序中/开发管理/开发设置/业务域名 中设置
主要是后续要用到 web-view 组件
2.在小程序中设置跳转信息 task/index.vue
this.graceJS.navigate(“/pagesA/task/sharePage?path=yes&houseName=”+houseName+“&typeName=”+typeName)
?path=yes&houseName=“+houseName+”&typeName="+typeName 这个是我个人要传的值,可根据实际情况填写
3.在小程序中创建一个分享页面,task/sharePage.vue
export default {data() {return {web_src:'https:xxxxxxx',//这个是在小程序中配置的业务域名 <!-- 第一步 -->//下面参数是我需要传的值,用于分享标题 (动态)name: '', //登录人houseName: '', //站房名称typeName: '' //任务类型}},onLoad(options) {let that = thislet type = uni.getStorageSync('taskType');let id = uni.getStorageSync('taskNodeId')let typeTaskId = uni.getStorageSync('taskAllType');that.name = this.$store.state.userInfo.name//从本程序页面点击过来的也是从卡片点击过来的参数if (options.houseName) { //从task/index页面传值过来的 站房名称 用于分享this.houseName = decodeURIComponent(options.houseName)}//从本程序页面点击过来的也是从卡片点击过来的参数if (options.typeName) { //从task/index页面传值过来的 任务类型 用于分享this.typeName = decodeURIComponent(options.typeName)}//从本程序页面点击过来的//因为我要传值 判断,所以对this.web_src 进行了拼接,不需要传值的直接用data里面的web_srcif (options.path) { this.web_src += '?id=' + id +'&houseName=' + this.houseName + '&typeName=' + this.typeName+ '&type=' + type + '&typeTaskId=' + typeTaskId+'&name='+this.name +'&erweilma=yes' }//从卡片页面点击过来的 <!-- 第三步 -->//分享出去后,其他人点击分享的卡片,进入小程序页面if (options.name) { //decodeURIComponent 解码this.name = decodeURIComponent(options.name)}//从分享卡片 H5点击过来的 <!-- 第三步 -->if (options.shareUrl) { //decodeURIComponent 解码that.web_src = decodeURIComponent(options.shareUrl)+'&houseName=' + this.houseName + '&typeName=' + this.typeName+'&name='+this.name;}},/*** 用户点击右上角分享 第二步 */onShareAppMessage(options) {let that = thislet return_url=this.web_src+'&erweilma=no'//分享出去的路径,当其他人从卡片点击进入时,就可以进入小程序pagesA/task/sharePage这个页面//'pagesA/task/sharePage?shareUrl=' + encodeURIComponent(return_url)这句与上方onload方法里面的if (options.shareUrl) {}对应var path = 'pagesA/task/sharePage?shareUrl=' + encodeURIComponent(return_url)+'&houseName=' + encodeURIComponent(this.houseName)+'&typeName='+ encodeURIComponent(this.typeName)+'&name='+encodeURIComponent(this.name) ; //此处加密,onload里面就要解密var titles = ''//动态titleif (that.houseName != null && that.houseName != '' && that.houseName != 'null') {titles = that.name + '/' + that.houseName + '/' + that.typeName} else {titles = that.name + '/' + that.typeName}return {title: titles,path: path,success: function(res) {// 转发成功uni.showToast({title: "转发成功",icon: 'success',duration: 2000})},fail: function(res) {// 转发失败}}},
}
4.准备一个H5页面,放在服务器https:xxx里面
//因为我这次需要传参,所以H5里面的参数解析为
onLoad(option) {let that = this// 获取参数 必须这样获取 h5打包 后才有效 而且需相对路径 ./var url = window.location.search;// var url = 'https:/xxxx/?id=47&type=2&typeTaskId=1&erweilma=no'//为了本地测试var theRequest = new Object();if (url.indexOf("?") != -1) {var index = url.indexOf("?");var str = url.substr(index + 1, url.length); //04var strs = str.split("&");for (var i = 0; i < strs.length; i++) {theRequest[strs[i].split("=")[0]] = (strs[i].split("=")[1]);}}that.ids=theRequest['id']that.typeTaskId=theRequest['typeTaskId']that.type=theRequest['type']that.erweilma=theRequest['erweilma']},
/此文章 只是用于记录/