Commit 443e547d by luyt

feat:处理分享逻辑

1 parent 9813a7c9
......@@ -147,6 +147,7 @@ Page({
activeNavIdx,
// apiData,
outshowVideo,
isShow
// origin //跳转来源 home
} = options;
// if(actNum&&activeNavIdx)return
......@@ -172,6 +173,7 @@ Page({
activeNavIdx,
// apiData,
outshowVideo,
isShow
// origin
// isShare
});
......@@ -196,15 +198,56 @@ Page({
// 分享按钮
handleClick(e) {
let { index } = e.currentTarget.dataset;
let _this = this
switch (index) {
case 0:
this.download();
wx.showModal({
content: '确认下载海报?',
success: async (res) => {
if(res.confirm){
// let hasAuth = await _this.toSetting()
// if(hasAuth){
_this.download()
// }
}
},
fail: (res) => {},
complete: (res) => {},
})
// this.download();
break;
case 1:
this.wechatFn();
break;
}
},
//授权添加相册
toSetting(){
return new Promise((resolve,reject)=>{
wx.getSetting({
success: (res)=> {
if(res.authSetting['scope.writePhotosAlbum']){
resolve(true)
}else{
wx.openSetting({
success :(resp)=> {
if(resp.authSetting['scope.writePhotosAlbum']){
resolve(true)
}else{
wx.showToast({
title: "下载海报前需要您授权'添加到相册'权限",
icon: "none",
duration: 2500,
});
}
}
})
}
}
})
})
},
// 微信转发
wechatFn() {
// this.data.onShareAppMessage()
......@@ -214,6 +257,7 @@ Page({
async download() {
let { actNum, activeNavIdx, imgHeightArr ,imgPath} = this.data;
const { appId } = wx.getAccountInfoSync().miniProgram
let { userInfo } = wx.$storage.get()
// let wx_user_info = wx.$storage.get("wx_user_info");
// console.log('wx_user_info: ', wx_user_info.appId);
wx.showLoading({
......@@ -236,22 +280,30 @@ Page({
let _this = this;
wx.getImageInfo({
src: imgPath,
success: async () => {
success: async (respp) => {
let imgW = respp.width/4, imgH =respp.height/4;
let pradH = 288*imgW/1029, qrcodeH = 100;
let drawFun = new Draw({
width: _this.data.imgWidth,
height: _this.data.imgHeight,
width: imgW ,
height: imgH + pradH
});
console.log('actNum',actNum)
let qrcodeH = actNum== 2 ? 100 : 100
let qrcodeY = actNum== 2 ? 20 : 0
let arr = [456, 222, 0, 496];
let imgList = [
{
x: 0,
y: 0,
width: _this.data.imgWidth,
height: _this.data.imgHeight,
width: imgW,
height: pradH,
url: `${IMG_URL}index/canvas/${senceData[actNum].productList[activeNavIdx].img}.png`,
},
{
x: 0,
y: pradH,
width: imgW,
height: imgH,
url: `https://img02.glsx.com.cn/weapp/resource/saas/business-assistant/index/longpic${
actNum + 1
}.png`,
......@@ -261,16 +313,27 @@ Page({
// y: erCodeHeight + 30,
// width: 120 * 2,
// height: 120 * 2,
x: _this.data.imgWidth - qrcodeH + 20,
y: _this.data.imgHeight - qrcodeH + qrcodeY,
width: qrcodeH -20,
height: qrcodeH -20,
x: imgW-qrcodeH,
y: imgH + pradH -qrcodeH -20,
width: qrcodeH,
height: qrcodeH,
url: res.data, //二维码
},
];
let telephone = userInfo.phone?userInfo.phone:''
let textList = [
{
x: 22,
y: imgH + pradH - 25,
text: `联系我:${telephone}`,
color: '#323436',
fontSize: 10
}
]
// console.log(imgList)
let posterUrl = await drawFun.begin({
imageList: imgList,
textList
});
_this.setData({
posterUrl: posterUrl.path,
......@@ -295,13 +358,13 @@ Page({
// this.triggerEvent("modelclose", false);
// },
// 图片加载事件
onloadFn(event) {
// console.log("event.detail", event.detail);
this.setData({
imgHeight: event.detail.height / 5,
imgWidth: event.detail.width / 5,
});
},
// onloadFn(event) {
// // console.log("event.detail", event.detail);
// this.setData({
// imgHeight: event.detail.height / 5,
// imgWidth: event.detail.width / 5,
// });
// },
// 图片视频加载回调拿到url
getImgInfo(actNum){
wx.showLoading({
......@@ -318,7 +381,7 @@ Page({
wx.hideLoading()
wx.nextTick(() => {
_this.setData({
isShow: true,
// isShow: true,
imgPath:res.path
})
})
......
......@@ -6,7 +6,7 @@
</view> -->
<!-- style="padding-top:{{headerHeight}}px" -->
<product stickyTop="{{headerHeight}}" class="productCon" isAuthphone="{{isAuthphone}}" actNum="{{actNum}}" wrapactiveNavIdx="{{activeNavIdx}}" senceData="{{senceData}}" outshowVideo="{{outshowVideo}}" isShare="{{isShare}}" bindauthorized="authorizedFn" />
<product stickyTop="{{headerHeight}}" class="productCon" isAuthphone="{{isAuthphone}}" actNum="{{actNum}}" wrapactiveNavIdx="{{activeNavIdx}}" senceData="{{senceData}}" outshowVideo="{{outshowVideo}}" isShare="{{isShare}}" isShow="{{isShow}}" bindauthorized="authorizedFn" />
<!-- 分享弹框 -->
<!-- <view class="share-wrap" wx:if="{{isShow}}">
<view class="img-wrap">
......@@ -37,7 +37,7 @@
<button></button>
</view> -->
<!-- 用于图片加载事件 -->
<image class="img" src="{{IMG_URL}}index/longpic{{actNum+1}}.png" bindload="onloadFn" />
<!-- <image class="img" src="{{IMG_URL}}index/longpic{{actNum+1}}.png" bindload="onloadFn" /> -->
<view class="btns-wrap" wx:if="{{isShow}}">
<view class="top">
<view class="btn" wx:for="{{btnList}}" wx:key="name" bindtap="handleClick" data-index="{{index}}">
......
......@@ -13,19 +13,23 @@ Component({
properties: {
stickyTop: Number,
actNum: Number,
wrapactiveNavIdx:Number,
wrapactiveNavIdx: Number,
senceData: Object, //本地数据
apiData:Object, //后端接口数据
apiData: Object, //后端接口数据
isShare: {
type: Boolean,
value: false,
},
origin:String, //来源
origin: String, //来源
outshowVideo: {
type: Boolean,
value: true,
}, //显示视频列表
isAuthphone:Boolean
isAuthphone: Boolean,
isShow: {
type: Boolean,
// value: false,
},
},
/**
......@@ -48,26 +52,39 @@ Component({
intoViewId: "to-0",
IMGURL: `${IMG_URL}index/`,
videoBaseUrl,
getMoreBtn:false,
showVideo:true, //显示视频列表
imgTopArr:[]
getMoreBtn: false,
showVideo: true, //显示视频列表
imgTopArr: [],
},
lifetimes: {
ready: function () {
this.init();
this.getImgHeight();
console.log('ready')
//获取当前路径
let currentUrl = this.getCurrentPageUrl()
// console.log('currentUrl: ', currentUrl);
if(currentUrl == '/pages/tab/index/index'){
this.setData({
currentUrl:false
})
}
console.log("ready");
// //获取当前路径
// let currentUrl = this.getCurrentPageUrl()
// // console.log('currentUrl: ', currentUrl);
// if(currentUrl == '/pages/tab/index/index'){
// this.setData({
// currentUrl:false
// })
// }else{
// let {isShare} = this.data
// console.log(isShare,'isShare')
// if(isShare){
// this.setData({
// currentUrl:false
// })
// }else{
// this.setData({
// currentUrl:true
// })
// }
// }
//监听页面滚动的距离
wx.$eventbus.on('evt_page_scroll',async (e)=>{
console.log(e)
wx.$eventbus.on("evt_page_scroll", async (e) => {
// console.log(e)
// let heightTop = this.data.stickyTop// 90 场景高度,8 场景margin-bottom
// let prodArr = await this.getHeight('.prod-wrap')
// // console.log('prodArr: ', prodArr);
......@@ -79,25 +96,23 @@ Component({
// imgHeightArr.push(pre+cur.height)
// return pre+cur.height
// },heightTop)
let imgTopArr = this.data.imgTopArr
console.log('imgTopArr: ', imgTopArr);
if(imgTopArr.length == 0)return
wx.nextTick(()=>{
let idx = imgTopArr.findIndex(item => item > e.scrollTop)
if(idx>-1){
let imgTopArr = this.data.imgTopArr;
// console.log('imgTopArr: ', imgTopArr);
if (imgTopArr.length == 0) return;
wx.nextTick(() => {
let idx = imgTopArr.findIndex((item) => item > e.scrollTop);
if (idx > -1) {
this.setData({
curTabIdx: idx
})
curTabIdx: idx,
});
}
})
})
});
});
if(!this.data.outshowVideo){
if (!this.data.outshowVideo) {
this.setData({
showVideo:false
})
showVideo: false,
});
}
//如果不是分享,初始化的时候调用函数
......@@ -106,7 +121,6 @@ Component({
this.getMoreFn();
}
},
},
observers: {
actNum: function (newval, oldval) {
......@@ -139,8 +153,8 @@ Component({
"360全景导航",
];
break;
case 4:
navList = ["新能源0元换购"];
case 4:
navList = ["新能源0元换购"];
break;
}
......@@ -154,22 +168,30 @@ Component({
// this.getImgHeight();
this.getMoreFn();
// this
if(this.data.wrapactiveNavIdx){
if (this.data.wrapactiveNavIdx) {
this.setData({
activeNavIdx:this.data.wrapactiveNavIdx
})
activeNavIdx: this.data.wrapactiveNavIdx,
});
}
},
// isShow: function (newval) {
// let { isShare } = this.data;
// if (newval && !isShare) {
// this.setData({
// currentUrl: true,
// });
// }
// },
},
/**
* 组件的方法列表
*/
methods: {
getCurrentPageUrl() {
const pages = getCurrentPages()
const currentPage = pages[pages.length - 1]
const url = `/${currentPage.route}`
return url
const pages = getCurrentPages();
const currentPage = pages[pages.length - 1];
const url = `/${currentPage.route}`;
return url;
},
async init() {
try {
......@@ -194,43 +216,42 @@ Component({
});
},
// 视频下载
downVideo(e){
let {url} = e.target.dataset
console.log(url)
wx.$api.showToast('正在下载视频...')
downVideo(e) {
let { url } = e.target.dataset;
console.log(url);
wx.$api.showToast("正在下载视频...");
wx.downloadFile({
url:url,
success (res) {
url: url,
success(res) {
// console.log(res,111)
if (res.statusCode === 200) {
wx.saveVideoToPhotosAlbum({
filePath: res.tempFilePath,
success (res) {
setTimeout(() =>{
wx.$api.showToast('下载成功!')
},2000)
}
})
filePath: res.tempFilePath,
success(res) {
setTimeout(() => {
wx.$api.showToast("下载成功!");
}, 2000);
},
});
}
}
})
},
});
},
saleTextChange(e) {},
changeTab(e) {
let idx = e.detail;
let {imgTopArr,stickyTop} = this.data
console.log('idx: ', imgTopArr[idx],stickyTop);
let { imgTopArr, stickyTop } = this.data;
console.log("idx: ", imgTopArr[idx], stickyTop);
// this.setData({
// intoViewId: `to-${idx}`,
// });
// wx.$eventbus.emit('evt_page_index',idx)
//判断当前路径
let currentUrl = this.getCurrentPageUrl()
if(currentUrl == '/pages/tab/index/index'){
wx.pageScrollTo({ scrollTop: imgTopArr[idx]-stickyTop+88+34})
}else{
wx.pageScrollTo({ scrollTop: (imgTopArr[idx]-stickyTop)})
let currentUrl = this.getCurrentPageUrl();
if (currentUrl == "/pages/tab/index/index") {
wx.pageScrollTo({ scrollTop: imgTopArr[idx] - stickyTop + 88 + 34 });
} else {
wx.pageScrollTo({ scrollTop: imgTopArr[idx] - stickyTop });
}
},
// async changeTab(e){
......@@ -247,16 +268,19 @@ Component({
// }
// wx.pageScrollTo({
// scrollTop: heightTop,
// duration: 0
// duration: 0
// })
// },
getHeight(cla){
return new Promise((resolve,reject)=>{
let query = wx.createSelectorQuery().in(this)
query.selectAll(cla).boundingClientRect((rect) => {
resolve(rect)
}).exec()
})
getHeight(cla) {
return new Promise((resolve, reject) => {
let query = wx.createSelectorQuery().in(this);
query
.selectAll(cla)
.boundingClientRect((rect) => {
resolve(rect);
})
.exec();
});
},
changeNav(event) {
this.setData({
......@@ -278,24 +302,24 @@ Component({
getImgHeight() {
let query = wx.createSelectorQuery().in(this);
let heightArr = [];
let imgTopArr = []
let imgTopArr = [];
let s = 0;
let top
let _this = this
let top;
let _this = this;
query
.selectAll(".img-item")
.boundingClientRect((react) => {
react.forEach((item,index) => {
console.log('item: ', item);
react.forEach((item, index) => {
// console.log('item: ', item);
// if(index == 0){
// console.log('item top: ', item);
// top = item.top
// }
// s = s +item.height;
s = item.top
s = item.top;
// heightArr.push(s);
imgTopArr.push(s)
imgTopArr.push(s);
});
// heightArr = heightArr.map((item)=>{
......@@ -307,8 +331,8 @@ Component({
// this.data.allHeight = heightArr[heightArr.length - 1];
// console.log('imgTopArr',imgTopArr)
_this.setData({
imgTopArr
})
imgTopArr,
});
})
.exec();
},
......@@ -321,25 +345,25 @@ Component({
USERAPI.getUserProfile(this.loginToken, detail)
.then((result) => {
// console.log(result)
let userInfo = wx.$storage.get('wx_user_info')
let userInfo = wx.$storage.get("wx_user_info");
// console.log('userInfo: ', userInfo);
let { phone } = result;
// console.log('phone: ', phone);
wx.$storage.set('wx_user_info', {...userInfo,phone});
wx.$storage.set("wx_user_info", { ...userInfo, phone });
// }
setTimeout(()=>{
setTimeout(() => {
this.triggerEvent("authorized", {
phone,
// isShare: false,
});
},1e3)
}, 1e3);
//隐藏更多按钮,显示视频列表
this.setData({
getMoreBtn:true,
getMoreBtn: true,
isShare: false,
outshowVideo:true
})
this.getMoreFn()
outshowVideo: true,
});
this.getMoreFn();
})
.catch(({ errMsg }) => {
wx.$api.showToast(errMsg || "系统异常");
......@@ -380,12 +404,13 @@ Component({
onShareFn() {
// this.triggerEvent('sharehandle')
// wx.$router.go('apply',1235)
let { actNum, activeNavIdx ,apiData} = this.data;
let { actNum, activeNavIdx, apiData } = this.data;
wx.$router.go("checkProduct", {
actNum,
activeNavIdx,
apiData,
outshowVideo:true
outshowVideo: true,
isShow:true
// origin:'home' //跟首页类似情况
// isShare: true
});
......
......@@ -399,8 +399,10 @@
font-size: 0;
}
.check-prod .video-list{
padding-bottom: 140rpx;
.check-prod .img-item {
&:last-child{
margin-bottom: 148rpx;
}
}
.video-item {
position: relative;
......
......@@ -28,7 +28,7 @@
</view>
</view>
</view>
<view class="project-wrap {{currentUrl == ''? '':'check-prod'}}">
<view class="project-wrap {{isShow ?'check-prod':''}}">
<!-- -->
<view class="stickyTab" style="top:{{isShare ? stickyTop+88 : stickyTop}}rpx">
<tab
......
......@@ -45,6 +45,7 @@
</scroll-view>
</view>
<product
isShow="{{false}}"
stickyTop="{{headerHeight}}"
actNum="{{actNum}}"
senceData="{{senceData}}"
......
Markdown is supported
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!