Commit 09b6e959 by 李嘉林

分享

parent 2a417b4e
......@@ -3,7 +3,7 @@
-->
<template>
<div v-if="showPage">
<web-view :src="pageUrl" @error="handleError"></web-view>
<web-view :src="pageUrl" @error="handleError" @message="getMessage"></web-view>
<div style="width: 100%;height: 90vh;display: flex;justify-content: center;align-items: center;"
>
<van-loading size="40px" type="spinner"></van-loading>
......@@ -17,7 +17,9 @@ import {
checkTabbarPage,
getUrlofQuery
} from "../utils/mayi.js";
import { serialize} from "@/utils/index";
import { serialize, DFSImg} from "@/utils/index";
const app = getApp();
const { log } = app;
export default {
props: {
......@@ -118,6 +120,10 @@ export default {
title: "网页加载失败 请右上角刷新",
});
},
//右上角分享时触发
getMessage(res) {
this.$emit("getMessage",res);
},
},
};
</script>
\ No newline at end of file
......@@ -499,14 +499,16 @@ export default {
getMessage(res) {
let len = res.target.data.length - 1;
log.info('右上角分享触发',res, res.target.data[len]);
console.log('右上角分享触发',res, res.target.data[len]);
this.shareShopName = res.target.data[len].shareShopName || "";
this.shareLogoUrl = DFSImg(res.target.data[len].shareLogoUrl, 500, 400);
this.shareLogoUrl = res.target.data[len].shareLogoUrl?DFSImg(res.target.data[len].shareLogoUrl, 500, 400): "";
//分享内容中有订单信息为送礼活动
this.shareOrderSn = res.target.data[len].orderSn;
this.shareTid = res.target.data[len].shareTid;
this.newWindowHref = res.target.data[len].shareImgUrl + '&verifyShare=1';// + '&fromVisitorOpenId=' + wx.getStorageSync("openid")
log.info("getMessage-分享信息:", this.shareLogoUrl, this.shareShopName,1111111,this.newWindowHref);
console.log("getMessage-分享信息:", this.shareLogoUrl, this.shareShopName,1111111,this.newWindowHref);
//文章详情分享埋点
if(this.newWindowHref.indexOf('articleId')!=-1) {
var articleId = ''
......
<template>
<tabbarPage :index="1"></tabbarPage>
<tabbarPage :index="1" @getMessage="getMessage"></tabbarPage>
</template>
<script>
import tabbarPage from "../../components/tabbarPage.vue";
import { concatUrl } from "../../utils/index.js"
import indexApi from "@/api/index.js";
import spokesman from "@/api/spokesman.js";
import { concatUrl, DFSImg } from "../../utils/index.js";
const app = getApp();
const { log } = app;
export default {
......@@ -17,22 +17,28 @@ export default {
return {
pageInfo: {},
pageData: {},
}
newHref: "",
shareShopName: "",
shareLogoUrl: "",
shareOrderSn: "",
shareTid: "",
newWindowHref: "",
};
},
onLoad(options) {
wx.showShareMenu({
withShareTicket: true,
menus: ['shareAppMessage', 'shareTimeline']
})
menus: ["shareAppMessage", "shareTimeline"],
});
console.log(this.mpApp.globalData.pageList, 'llll');
console.log(this.mpApp.globalData.pageList, "llll");
this.init()
this.init();
if (options.userId || options.spokesmanRelId) {
wx.setStorage({
key: "becomeInfo",
data: JSON.stringify(options)
data: JSON.stringify(options),
});
}
......@@ -45,50 +51,55 @@ export default {
// });
//获取分销信息
this.getSpokesmanInit(wx.getStorageSync("becomeInfo") ? JSON.parse(wx.getStorageSync("becomeInfo")) : '')
this.getSpokesmanInit(
wx.getStorageSync("becomeInfo")
? JSON.parse(wx.getStorageSync("becomeInfo"))
: ""
);
}
},
async onShareAppMessage(res) {
log.info(res)
let newHref = '/pages/tabBar1/main';
let title = app.globalData.shopInfo.shopName;
let hasInvitationStatus = 0;
if (wx.getStorageSync("sessionid")) {
await app.fenxiaoModel.getSpokesmanidByShare().then(data => {
hasInvitationStatus = data.hasInvitationStatus;
})
await app.fenxiaoModel.getSpokesmanInfo().then(data => {
let newData = {}
if (data != null) {
if (hasInvitationStatus == 1) {
newData = {
spokesmanGroupId: data.groupId,
spokesmanShopId: data.shopId,
spokesmanRelId: data.id,
userId: data.userId
}
} else {
newData = {
userId: data.userId
}
}
}
newHref = concatUrl(newHref, newData)
})
log.info("onShareAppMessage", res);
await this.getSpokesman();
let url = "";
log.info(this.newWindowHref + "this.newWindowHref");
//分享路径
if (this.newWindowHref) {
url = this.newWindowHref;
} else {
url = res.webViewUrl;
}
let imageUrl = '';
//多主题自定义分享标题和图片
if (this.pageInfo.pageSettingData && JSON.parse(this.pageInfo.pageSettingData).shareTitle) {
title = JSON.parse(this.pageInfo.pageSettingData).shareTitle
//分享页面去掉登录态
if (url.indexOf("sessionid") > -1) {
// url = url.split("?")[0] + "?mixid=" + this.shopId;
url = this.delParam(this.newWindowHref, "sessionid");
url = this.delParam(url, "open_id");
}
if (this.pageInfo.pageSettingData && JSON.parse(this.pageInfo.pageSettingData).shareImg) {
imageUrl = JSON.parse(this.pageInfo.pageSettingData).shareImg
//分销员推广页面 默认分享分销员中心页面
if (url.indexOf("/personalCenter/spokesmanCenter/mine/popularize") > -1) {
url = `${this.baseUrl}/personalCenter/spokesmanCenter?mixid=${this.shopId}`;
}
log.info(newHref, 3333555666, title, res)
log.info("shareUrl---------------" + url);
//增加分销员信息
if (
this.hasInvitationStatus == 1 &&
url.indexOf("spokesmanGroupId") == -1
) {
this.shareUrl = url + this.newHref;
} else {
this.shareUrl = url;
}
log.info("onShareAppMessage-shareUrl", this.shareUrl);
log.info(
`/pages/index/main?share=${encodeURIComponent(this.shareUrl)}`,
"测试直播分享相关"
);
return {
title: title, // 默认是小程序的名称
path: newHref, // 默认是当前页面
imageUrl: imageUrl,
title: this.shareShopName, // 默认是小程序的名称
path: `/pages/index/main?share=${encodeURIComponent(this.shareUrl)}`, // 默认是当前页面
imageUrl: this.shareLogoUrl,
success: function (res) {
// 转发成功之后的回调
if (res.errMsg == "shareAppMessage:ok") {
......@@ -106,11 +117,11 @@ export default {
},
complete: function () {
// 转发结束之后的回调(转发成不成功都会执行)
}
},
};
},
onShareTimeline(res) {
log.info(res, '-----onShareTimeline')
log.info(res, "-----onShareTimeline");
},
methods: {
init() {
......@@ -122,18 +133,102 @@ export default {
async setVisible(pageList, cb) {
// 首页显示条件
let pageInfo = pageList.filter((item) => item.pageCode == 1)[0];
cb(pageInfo)
cb(pageInfo);
},
getSpokesmanInit(extConfig) {
//绑定上下级关系
app.fenxiaoModel.becomeRelation(extConfig).then(res => {
app.fenxiaoModel.becomeRelation(extConfig).then((res) => {
if (res) {
wx.removeStorage({
key: "becomeInfo"
key: "becomeInfo",
});
}
})
});
},
}
//右上角分享时触发
getMessage(res) {
let len = res.target.data.length - 1;
log.info("右上角分享触发", res, res.target.data[len]);
console.log("右上角分享触发", res, res.target.data[len]);
this.shareShopName = res.target.data[len].shareShopName || "";
this.shareLogoUrl = res.target.data[len].shareLogoUrl
? DFSImg(res.target.data[len].shareLogoUrl, 500, 400)
: "";
//分享内容中有订单信息为送礼活动
this.shareOrderSn = res.target.data[len].orderSn;
this.shareTid = res.target.data[len].shareTid;
this.newWindowHref = res.target.data[len].shareImgUrl + "&verifyShare=1"; // + '&fromVisitorOpenId=' + wx.getStorageSync("openid")
log.info(
"getMessage-分享信息:",
this.shareLogoUrl,
this.shareShopName,
1111111,
this.newWindowHref
);
console.log(
"getMessage-分享信息:",
this.shareLogoUrl,
this.shareShopName,
1111111,
this.newWindowHref
);
//文章详情分享埋点
if (this.newWindowHref.indexOf("articleId") != -1) {
var articleId = "";
var vars = this.newWindowHref.split("&");
for (var i = 0; i < vars.length; i++) {
var pair = vars[i].split("=");
log.info(pair, 2222);
if (pair[0] == "articleId") {
articleId = pair[1];
}
}
indexApi.forward({ articleId: articleId }).then((res) => {});
}
},
async getSpokesman() {
await spokesman.getSpokesmanidByShare().then((res) => {
log.info("onShareAppMessage-getSpokesmanidByShare", res);
if (res.data.code == 200) {
if (res.data.data.hasInvitationStatus == 1) {
this.hasInvitationStatus = 1;
this.spokesmanGroupId = res.data.data.groupId;
this.spokesmanShopId = res.data.data.shopId;
this.spokesmanRelId = res.data.data.spokesmanId;
this.newHref = `&spokesmanGroupId=${this.spokesmanGroupId}&spokesmanShopId=${this.spokesmanShopId}&spokesmanRelId=${this.spokesmanRelId}`;
} else {
this.newHref = "";
}
log.info("onShareAppMessage-getSpokesmanidByShare", this.newHref);
}
});
},
delParam(oldUrl,paramKey) {
var url = oldUrl; //页面url
var urlParam = oldUrl.split("?")[1]; //页面参数
var beforeUrl = url.substr(0, url.indexOf("?")); //页面主地址(参数之前地址)
var nextUrl = "";
var arr = new Array();
if (urlParam != "") {
var urlParamArr = urlParam.split("&"); //将参数按照&符分成数组
for (var i = 0; i < urlParamArr.length; i++) {
var paramArr = urlParamArr[i].split("="); //将参数键,值拆开
//如果键雨要删除的不一致,则加入到参数中
if (paramArr[0] != paramKey) {
arr.push(urlParamArr[i]);
}
}
}
if (arr.length > 0) {
nextUrl = "?" + arr.join("&");
}
url = beforeUrl + nextUrl;
return url;
},
},
};
</script>
<template>
<tabbarPage :index="2"></tabbarPage>
<tabbarPage :index="2" @getMessage="getMessage"></tabbarPage>
</template>
<script>
import tabbarPage from "../../components/tabbarPage.vue";
import indexApi from "@/api/index.js";
import spokesman from "@/api/spokesman.js";
import { concatUrl, DFSImg } from "../../utils/index.js";
const app = getApp();
const { log } = app;
export default {
components: {
tabbarPage,
},
data() {
return {
pageInfo: {},
pageData: {},
newHref: "",
shareShopName: "",
shareLogoUrl: "",
shareOrderSn: "",
shareTid: "",
newWindowHref: "",
};
},
onLoad(options) {
wx.showShareMenu({
withShareTicket: true,
menus: ["shareAppMessage", "shareTimeline"],
});
console.log(this.mpApp.globalData.pageList, "llll");
this.init();
if (options.userId || options.spokesmanRelId) {
wx.setStorage({
key: "becomeInfo",
data: JSON.stringify(options),
});
}
if (wx.getStorageSync("sessionid")) {
// wx.showToast({
// title: JSON.stringify(wx.getStorageSync("sessionid")),
// icon: 'none',
// image: '',
// duration: 1500,
// });
//获取分销信息
this.getSpokesmanInit(
wx.getStorageSync("becomeInfo")
? JSON.parse(wx.getStorageSync("becomeInfo"))
: ""
);
}
},
async onShareAppMessage(res) {
log.info("onShareAppMessage", res);
await this.getSpokesman();
let url = "";
log.info(this.newWindowHref + "this.newWindowHref");
//分享路径
if (this.newWindowHref) {
url = this.newWindowHref;
} else {
url = res.webViewUrl;
}
//分享页面去掉登录态
if (url.indexOf("sessionid") > -1) {
// url = url.split("?")[0] + "?mixid=" + this.shopId;
url = this.delParam(this.newWindowHref, "sessionid");
url = this.delParam(url, "open_id");
}
//分销员推广页面 默认分享分销员中心页面
if (url.indexOf("/personalCenter/spokesmanCenter/mine/popularize") > -1) {
url = `${this.baseUrl}/personalCenter/spokesmanCenter?mixid=${this.shopId}`;
}
log.info("shareUrl---------------" + url);
//增加分销员信息
if (
this.hasInvitationStatus == 1 &&
url.indexOf("spokesmanGroupId") == -1
) {
this.shareUrl = url + this.newHref;
} else {
this.shareUrl = url;
}
log.info("onShareAppMessage-shareUrl", this.shareUrl);
log.info(
`/pages/index/main?share=${encodeURIComponent(this.shareUrl)}`,
"测试直播分享相关"
);
return {
title: this.shareShopName, // 默认是小程序的名称
path: `/pages/index/main?share=${encodeURIComponent(this.shareUrl)}`, // 默认是当前页面
imageUrl: this.shareLogoUrl,
success: function (res) {
// 转发成功之后的回调
if (res.errMsg == "shareAppMessage:ok") {
log.info(res, "分享成功");
}
},
fail: function () {
// 转发失败之后的回调
if (res.errMsg == "shareAppMessage:fail cancel") {
// 用户取消转发
log.info(res, "分享失败");
} else if (res.errMsg == "shareAppMessage:fail") {
// 转发失败,其中 detail message 为详细失败信息
}
},
complete: function () {
// 转发结束之后的回调(转发成不成功都会执行)
},
};
},
onShareTimeline(res) {
log.info(res, "-----onShareTimeline");
},
methods: {
init() {
this.setVisible(this.mpApp.globalData.pageList, (res) => {
this.pageInfo = res;
this.pageData = JSON.parse(this.pageInfo.pageData);
});
},
async setVisible(pageList, cb) {
// 首页显示条件
let pageInfo = pageList.filter((item) => item.pageCode == 1)[0];
cb(pageInfo);
},
getSpokesmanInit(extConfig) {
//绑定上下级关系
app.fenxiaoModel.becomeRelation(extConfig).then((res) => {
if (res) {
wx.removeStorage({
key: "becomeInfo",
});
}
});
},
//右上角分享时触发
getMessage(res) {
let len = res.target.data.length - 1;
log.info("右上角分享触发", res, res.target.data[len]);
console.log("右上角分享触发", res, res.target.data[len]);
this.shareShopName = res.target.data[len].shareShopName || "";
this.shareLogoUrl = res.target.data[len].shareLogoUrl
? DFSImg(res.target.data[len].shareLogoUrl, 500, 400)
: "";
//分享内容中有订单信息为送礼活动
this.shareOrderSn = res.target.data[len].orderSn;
this.shareTid = res.target.data[len].shareTid;
this.newWindowHref = res.target.data[len].shareImgUrl + "&verifyShare=1"; // + '&fromVisitorOpenId=' + wx.getStorageSync("openid")
log.info(
"getMessage-分享信息:",
this.shareLogoUrl,
this.shareShopName,
1111111,
this.newWindowHref
);
console.log(
"getMessage-分享信息:",
this.shareLogoUrl,
this.shareShopName,
1111111,
this.newWindowHref
);
//文章详情分享埋点
if (this.newWindowHref.indexOf("articleId") != -1) {
var articleId = "";
var vars = this.newWindowHref.split("&");
for (var i = 0; i < vars.length; i++) {
var pair = vars[i].split("=");
log.info(pair, 2222);
if (pair[0] == "articleId") {
articleId = pair[1];
}
}
indexApi.forward({ articleId: articleId }).then((res) => {});
}
},
async getSpokesman() {
await spokesman.getSpokesmanidByShare().then((res) => {
log.info("onShareAppMessage-getSpokesmanidByShare", res);
if (res.data.code == 200) {
if (res.data.data.hasInvitationStatus == 1) {
this.hasInvitationStatus = 1;
this.spokesmanGroupId = res.data.data.groupId;
this.spokesmanShopId = res.data.data.shopId;
this.spokesmanRelId = res.data.data.spokesmanId;
this.newHref = `&spokesmanGroupId=${this.spokesmanGroupId}&spokesmanShopId=${this.spokesmanShopId}&spokesmanRelId=${this.spokesmanRelId}`;
} else {
this.newHref = "";
}
log.info("onShareAppMessage-getSpokesmanidByShare", this.newHref);
}
});
},
delParam(oldUrl,paramKey) {
var url = oldUrl; //页面url
var urlParam = oldUrl.split("?")[1]; //页面参数
var beforeUrl = url.substr(0, url.indexOf("?")); //页面主地址(参数之前地址)
var nextUrl = "";
var arr = new Array();
if (urlParam != "") {
var urlParamArr = urlParam.split("&"); //将参数按照&符分成数组
for (var i = 0; i < urlParamArr.length; i++) {
var paramArr = urlParamArr[i].split("="); //将参数键,值拆开
//如果键雨要删除的不一致,则加入到参数中
if (paramArr[0] != paramKey) {
arr.push(urlParamArr[i]);
}
}
}
if (arr.length > 0) {
nextUrl = "?" + arr.join("&");
}
url = beforeUrl + nextUrl;
return url;
},
},
};
</script>
<template>
<tabbarPage :index="3"></tabbarPage>
<tabbarPage :index="3" @getMessage="getMessage"></tabbarPage>
</template>
<script>
import tabbarPage from "../../components/tabbarPage.vue";
import indexApi from "@/api/index.js";
import spokesman from "@/api/spokesman.js";
import { concatUrl, DFSImg } from "../../utils/index.js";
const app = getApp();
const { log } = app;
export default {
components: {
tabbarPage,
},
data() {
return {
pageInfo: {},
pageData: {},
newHref: "",
shareShopName: "",
shareLogoUrl: "",
shareOrderSn: "",
shareTid: "",
newWindowHref: "",
};
},
onLoad(options) {
wx.showShareMenu({
withShareTicket: true,
menus: ["shareAppMessage", "shareTimeline"],
});
console.log(this.mpApp.globalData.pageList, "llll");
this.init();
if (options.userId || options.spokesmanRelId) {
wx.setStorage({
key: "becomeInfo",
data: JSON.stringify(options),
});
}
if (wx.getStorageSync("sessionid")) {
// wx.showToast({
// title: JSON.stringify(wx.getStorageSync("sessionid")),
// icon: 'none',
// image: '',
// duration: 1500,
// });
//获取分销信息
this.getSpokesmanInit(
wx.getStorageSync("becomeInfo")
? JSON.parse(wx.getStorageSync("becomeInfo"))
: ""
);
}
},
async onShareAppMessage(res) {
log.info("onShareAppMessage", res);
await this.getSpokesman();
let url = "";
log.info(this.newWindowHref + "this.newWindowHref");
//分享路径
if (this.newWindowHref) {
url = this.newWindowHref;
} else {
url = res.webViewUrl;
}
//分享页面去掉登录态
if (url.indexOf("sessionid") > -1) {
// url = url.split("?")[0] + "?mixid=" + this.shopId;
url = this.delParam(this.newWindowHref, "sessionid");
url = this.delParam(url, "open_id");
}
//分销员推广页面 默认分享分销员中心页面
if (url.indexOf("/personalCenter/spokesmanCenter/mine/popularize") > -1) {
url = `${this.baseUrl}/personalCenter/spokesmanCenter?mixid=${this.shopId}`;
}
log.info("shareUrl---------------" + url);
//增加分销员信息
if (
this.hasInvitationStatus == 1 &&
url.indexOf("spokesmanGroupId") == -1
) {
this.shareUrl = url + this.newHref;
} else {
this.shareUrl = url;
}
log.info("onShareAppMessage-shareUrl", this.shareUrl);
log.info(
`/pages/index/main?share=${encodeURIComponent(this.shareUrl)}`,
"测试直播分享相关"
);
return {
title: this.shareShopName, // 默认是小程序的名称
path: `/pages/index/main?share=${encodeURIComponent(this.shareUrl)}`, // 默认是当前页面
imageUrl: this.shareLogoUrl,
success: function (res) {
// 转发成功之后的回调
if (res.errMsg == "shareAppMessage:ok") {
log.info(res, "分享成功");
}
},
fail: function () {
// 转发失败之后的回调
if (res.errMsg == "shareAppMessage:fail cancel") {
// 用户取消转发
log.info(res, "分享失败");
} else if (res.errMsg == "shareAppMessage:fail") {
// 转发失败,其中 detail message 为详细失败信息
}
},
complete: function () {
// 转发结束之后的回调(转发成不成功都会执行)
},
};
},
onShareTimeline(res) {
log.info(res, "-----onShareTimeline");
},
methods: {
init() {
this.setVisible(this.mpApp.globalData.pageList, (res) => {
this.pageInfo = res;
this.pageData = JSON.parse(this.pageInfo.pageData);
});
},
async setVisible(pageList, cb) {
// 首页显示条件
let pageInfo = pageList.filter((item) => item.pageCode == 1)[0];
cb(pageInfo);
},
getSpokesmanInit(extConfig) {
//绑定上下级关系
app.fenxiaoModel.becomeRelation(extConfig).then((res) => {
if (res) {
wx.removeStorage({
key: "becomeInfo",
});
}
});
},
//右上角分享时触发
getMessage(res) {
let len = res.target.data.length - 1;
log.info("右上角分享触发", res, res.target.data[len]);
console.log("右上角分享触发", res, res.target.data[len]);
this.shareShopName = res.target.data[len].shareShopName || "";
this.shareLogoUrl = res.target.data[len].shareLogoUrl
? DFSImg(res.target.data[len].shareLogoUrl, 500, 400)
: "";
//分享内容中有订单信息为送礼活动
this.shareOrderSn = res.target.data[len].orderSn;
this.shareTid = res.target.data[len].shareTid;
this.newWindowHref = res.target.data[len].shareImgUrl + "&verifyShare=1"; // + '&fromVisitorOpenId=' + wx.getStorageSync("openid")
log.info(
"getMessage-分享信息:",
this.shareLogoUrl,
this.shareShopName,
1111111,
this.newWindowHref
);
console.log(
"getMessage-分享信息:",
this.shareLogoUrl,
this.shareShopName,
1111111,
this.newWindowHref
);
//文章详情分享埋点
if (this.newWindowHref.indexOf("articleId") != -1) {
var articleId = "";
var vars = this.newWindowHref.split("&");
for (var i = 0; i < vars.length; i++) {
var pair = vars[i].split("=");
log.info(pair, 2222);
if (pair[0] == "articleId") {
articleId = pair[1];
}
}
indexApi.forward({ articleId: articleId }).then((res) => {});
}
},
async getSpokesman() {
await spokesman.getSpokesmanidByShare().then((res) => {
log.info("onShareAppMessage-getSpokesmanidByShare", res);
if (res.data.code == 200) {
if (res.data.data.hasInvitationStatus == 1) {
this.hasInvitationStatus = 1;
this.spokesmanGroupId = res.data.data.groupId;
this.spokesmanShopId = res.data.data.shopId;
this.spokesmanRelId = res.data.data.spokesmanId;
this.newHref = `&spokesmanGroupId=${this.spokesmanGroupId}&spokesmanShopId=${this.spokesmanShopId}&spokesmanRelId=${this.spokesmanRelId}`;
} else {
this.newHref = "";
}
log.info("onShareAppMessage-getSpokesmanidByShare", this.newHref);
}
});
},
delParam(oldUrl,paramKey) {
var url = oldUrl; //页面url
var urlParam = oldUrl.split("?")[1]; //页面参数
var beforeUrl = url.substr(0, url.indexOf("?")); //页面主地址(参数之前地址)
var nextUrl = "";
var arr = new Array();
if (urlParam != "") {
var urlParamArr = urlParam.split("&"); //将参数按照&符分成数组
for (var i = 0; i < urlParamArr.length; i++) {
var paramArr = urlParamArr[i].split("="); //将参数键,值拆开
//如果键雨要删除的不一致,则加入到参数中
if (paramArr[0] != paramKey) {
arr.push(urlParamArr[i]);
}
}
}
if (arr.length > 0) {
nextUrl = "?" + arr.join("&");
}
url = beforeUrl + nextUrl;
return url;
},
},
};
</script>
<template>
<tabbarPage :index="4"></tabbarPage>
<tabbarPage :index="4" @getMessage="getMessage"></tabbarPage>
</template>
<script>
import tabbarPage from "../../components/tabbarPage.vue";
import indexApi from "@/api/index.js";
import spokesman from "@/api/spokesman.js";
import { concatUrl, DFSImg } from "../../utils/index.js";
const app = getApp();
const { log } = app;
export default {
components: {
tabbarPage,
},
data() {
return {
pageInfo: {},
pageData: {},
newHref: "",
shareShopName: "",
shareLogoUrl: "",
shareOrderSn: "",
shareTid: "",
newWindowHref: "",
};
},
onLoad(options) {
wx.showShareMenu({
withShareTicket: true,
menus: ["shareAppMessage", "shareTimeline"],
});
console.log(this.mpApp.globalData.pageList, "llll");
this.init();
if (options.userId || options.spokesmanRelId) {
wx.setStorage({
key: "becomeInfo",
data: JSON.stringify(options),
});
}
if (wx.getStorageSync("sessionid")) {
// wx.showToast({
// title: JSON.stringify(wx.getStorageSync("sessionid")),
// icon: 'none',
// image: '',
// duration: 1500,
// });
//获取分销信息
this.getSpokesmanInit(
wx.getStorageSync("becomeInfo")
? JSON.parse(wx.getStorageSync("becomeInfo"))
: ""
);
}
},
async onShareAppMessage(res) {
log.info("onShareAppMessage", res);
await this.getSpokesman();
let url = "";
log.info(this.newWindowHref + "this.newWindowHref");
//分享路径
if (this.newWindowHref) {
url = this.newWindowHref;
} else {
url = res.webViewUrl;
}
//分享页面去掉登录态
if (url.indexOf("sessionid") > -1) {
// url = url.split("?")[0] + "?mixid=" + this.shopId;
url = this.delParam(this.newWindowHref, "sessionid");
url = this.delParam(url, "open_id");
}
//分销员推广页面 默认分享分销员中心页面
if (url.indexOf("/personalCenter/spokesmanCenter/mine/popularize") > -1) {
url = `${this.baseUrl}/personalCenter/spokesmanCenter?mixid=${this.shopId}`;
}
log.info("shareUrl---------------" + url);
//增加分销员信息
if (
this.hasInvitationStatus == 1 &&
url.indexOf("spokesmanGroupId") == -1
) {
this.shareUrl = url + this.newHref;
} else {
this.shareUrl = url;
}
log.info("onShareAppMessage-shareUrl", this.shareUrl);
log.info(
`/pages/index/main?share=${encodeURIComponent(this.shareUrl)}`,
"测试直播分享相关"
);
return {
title: this.shareShopName, // 默认是小程序的名称
path: `/pages/index/main?share=${encodeURIComponent(this.shareUrl)}`, // 默认是当前页面
imageUrl: this.shareLogoUrl,
success: function (res) {
// 转发成功之后的回调
if (res.errMsg == "shareAppMessage:ok") {
log.info(res, "分享成功");
}
},
fail: function () {
// 转发失败之后的回调
if (res.errMsg == "shareAppMessage:fail cancel") {
// 用户取消转发
log.info(res, "分享失败");
} else if (res.errMsg == "shareAppMessage:fail") {
// 转发失败,其中 detail message 为详细失败信息
}
},
complete: function () {
// 转发结束之后的回调(转发成不成功都会执行)
},
};
},
onShareTimeline(res) {
log.info(res, "-----onShareTimeline");
},
methods: {
init() {
this.setVisible(this.mpApp.globalData.pageList, (res) => {
this.pageInfo = res;
this.pageData = JSON.parse(this.pageInfo.pageData);
});
},
async setVisible(pageList, cb) {
// 首页显示条件
let pageInfo = pageList.filter((item) => item.pageCode == 1)[0];
cb(pageInfo);
},
getSpokesmanInit(extConfig) {
//绑定上下级关系
app.fenxiaoModel.becomeRelation(extConfig).then((res) => {
if (res) {
wx.removeStorage({
key: "becomeInfo",
});
}
});
},
//右上角分享时触发
getMessage(res) {
let len = res.target.data.length - 1;
log.info("右上角分享触发", res, res.target.data[len]);
console.log("右上角分享触发", res, res.target.data[len]);
this.shareShopName = res.target.data[len].shareShopName || "";
this.shareLogoUrl = res.target.data[len].shareLogoUrl
? DFSImg(res.target.data[len].shareLogoUrl, 500, 400)
: "";
//分享内容中有订单信息为送礼活动
this.shareOrderSn = res.target.data[len].orderSn;
this.shareTid = res.target.data[len].shareTid;
this.newWindowHref = res.target.data[len].shareImgUrl + "&verifyShare=1"; // + '&fromVisitorOpenId=' + wx.getStorageSync("openid")
log.info(
"getMessage-分享信息:",
this.shareLogoUrl,
this.shareShopName,
1111111,
this.newWindowHref
);
console.log(
"getMessage-分享信息:",
this.shareLogoUrl,
this.shareShopName,
1111111,
this.newWindowHref
);
//文章详情分享埋点
if (this.newWindowHref.indexOf("articleId") != -1) {
var articleId = "";
var vars = this.newWindowHref.split("&");
for (var i = 0; i < vars.length; i++) {
var pair = vars[i].split("=");
log.info(pair, 2222);
if (pair[0] == "articleId") {
articleId = pair[1];
}
}
indexApi.forward({ articleId: articleId }).then((res) => {});
}
},
async getSpokesman() {
await spokesman.getSpokesmanidByShare().then((res) => {
log.info("onShareAppMessage-getSpokesmanidByShare", res);
if (res.data.code == 200) {
if (res.data.data.hasInvitationStatus == 1) {
this.hasInvitationStatus = 1;
this.spokesmanGroupId = res.data.data.groupId;
this.spokesmanShopId = res.data.data.shopId;
this.spokesmanRelId = res.data.data.spokesmanId;
this.newHref = `&spokesmanGroupId=${this.spokesmanGroupId}&spokesmanShopId=${this.spokesmanShopId}&spokesmanRelId=${this.spokesmanRelId}`;
} else {
this.newHref = "";
}
log.info("onShareAppMessage-getSpokesmanidByShare", this.newHref);
}
});
},
delParam(oldUrl,paramKey) {
var url = oldUrl; //页面url
var urlParam = oldUrl.split("?")[1]; //页面参数
var beforeUrl = url.substr(0, url.indexOf("?")); //页面主地址(参数之前地址)
var nextUrl = "";
var arr = new Array();
if (urlParam != "") {
var urlParamArr = urlParam.split("&"); //将参数按照&符分成数组
for (var i = 0; i < urlParamArr.length; i++) {
var paramArr = urlParamArr[i].split("="); //将参数键,值拆开
//如果键雨要删除的不一致,则加入到参数中
if (paramArr[0] != paramKey) {
arr.push(urlParamArr[i]);
}
}
}
if (arr.length > 0) {
nextUrl = "?" + arr.join("&");
}
url = beforeUrl + nextUrl;
return url;
},
},
};
</script>
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment