Commit 443e547d by luyt

feat:处理分享逻辑

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