Commit 89906d8a by zhangquan

分享

1 parent 11cbfab2
......@@ -10,7 +10,8 @@
"pages/authentication/registerSuccess/registerSuccess",
"pages/authentication/registerInfo/registerInfo",
"pages/authentication/accountItems/accountItems",
"pages/authentication/customerService/customerService"
"pages/authentication/customerService/customerService",
"pages/checkProduct/checkProduct"
],
"requiredPrivateInfos": [
"getLocation"
......
// pages/checkProduct/checkProduct.js
// const navStyle = "background-color: transparent;";
import { IMG_URL } from "~/utils/constantData.js";
const navStyle = "background-color: #fff";
import { senceData } from "~/pages/tab/discovery/constant/data";
Page({
/**
* 页面的初始数据
*/
data: {
navStyle,
headerHeight: 0,
senceData,
// 模态框
isShow: true,
},
navbarReady(e) {
let {
height
} = e.detail;
this.setData({
headerHeight: height,
});
},
onPageScroll({
scrollTop
}) {
let opacity = scrollTop / 100
let color = `rgba(255,255,255${opacity > 1 ? 1 : opacity})`
this.setData({
navStyle: scrollTop == 0 ? navStyle : `background-color:${color};`
})
},
modelcloseFn(e) {
this.setData({
isShow: e.detail,
});
},
// 分享按钮
sharehandle() {
this.setData({
isShow: true,
});
},
onRouter(options) {
console.log("options: ", options);
},
/**
* 生命周期函数--监听页面加载
*/
onLoad(options) {
// actNum,activeNavIdx
},
/**
* 生命周期函数--监听页面初次渲染完成
*/
onReady() {},
/**
* 生命周期函数--监听页面显示
*/
onShow(options) {},
/**
* 生命周期函数--监听页面隐藏
*/
onHide() {},
/**
* 生命周期函数--监听页面卸载
*/
onUnload() {},
/**
* 页面相关事件处理函数--监听用户下拉动作
*/
onPullDownRefresh() {},
/**
* 页面上拉触底事件的处理函数
*/
onReachBottom() {},
/**
* 用户点击右上角分享
*/
onShareAppMessage() {},
});
{
"usingComponents": {
"product": "../tab/discovery/components/product/product",
"shareModel":"../tab/discovery/components/shareModel/shareModel"
},
"navigationBarTitleText": "特色产品",
"onReachBottomDistance": 10,
"backgroundColor": "#FC5B32",
"enablePullDownRefresh": true
}
/* pages/checkProduct/checkProduct.wxss */
page{
background-color: #fff;
}
\ No newline at end of file
<!--pages/checkProduct/checkProduct.wxml-->
<!-- <navigation-bar showBack="{{true}}" bindnavbarReady="navbarReady" navStyle="{{navStyle}}">特色产品</navigation-bar>
<view style="height:{{headerHeight}}px">
</view> -->
<product actNum="{{actNum}}" senceData="{{senceData}}" isShare="{{true}}"/>
<!-- 分享弹框 -->
<shareModel actNum="{{actNum}}" isShow="{{isShow}}" bindmodelclose="modelcloseFn" />
// pages/tab/discovery/components/product/product.js
import {imgUrlMixin} from '~/mixins/index'
const videoBaseUrl = 'https://img02.glsx.com.cn/weapp/resource/miniprogram/ai-card/'
Component({
behaviors: [imgUrlMixin],
/**
* 组件的属性列表
*/
properties: {
headerHeight: Number,
senceData:Object,
actNum: Number,
isShare:{
type: Boolean,
value: false
}
},
/**
* 组件的初始数据
*/
data: {
videoBaseUrl,
// senceData:['scene_talk.png','scene_delivery.png','scene_within_12mth.png','scene_more_12mth.png'],
navList:['数字无忧权益卡'],
activeNavIdx: 0, //特色产品
tab:['适用场景','营销链路','项目亮点','转化漏斗','合作流程','合作案例'],
......@@ -31,16 +29,12 @@ Component({
},
},
/**
* 组件的方法列表
*/
methods: {
changeSwiper(e){
console.log(e)
let actNum = e.detail.current
observers: {
actNum: function () {
let num = this.data.actNum;
let navList = []
let tab = ['适用场景','营销链路','项目亮点','转化漏斗','合作流程']
switch (actNum) {
switch (num) {
case 0:
navList = ["数字无忧权益卡"];
tab.push("合作案例");
......@@ -65,13 +59,15 @@ Component({
}
this.setData({
navList,
actNum,
intoViewId: `to-0`,
activeNavIdx: 0,
tab
})
this.getImgHeight();
},
},
methods: {
changeTab(e){
let idx = e.detail
this.setData({
......@@ -88,7 +84,6 @@ Component({
this.setData({
curTabIdx: idx
})
console.log(this.data.curTabIdx1)
},
getImgHeight(){
let query = wx.createSelectorQuery().in(this)
......@@ -115,10 +110,13 @@ Component({
heightArr.push(s);
});
this.data.heightArr = heightArr;
// console.log(heightArr[heightArr.length-1])
this.data.allHeight = heightArr[heightArr.length - 1];
})
.exec();
}
},
onShareFn() {
let { actNum, activeNavIdx ,senceData} = this.data;
wx.$router.go("checkProduct", { actNum, activeNavIdx ,senceData});
},
}
})
.scene-wrap {
white-space: nowrap;
height: 180rpx;
margin-bottom: 16rpx;
.scene-img {
width: 100%;
}
}
// 特色产品
.prod-wrap .big-title {
......
<view class="header">
<swiper bindchange="changeSwiper" class="scene-wrap" circular="{{true}}" previousMargin="40rpx" nextMargin="40rpx">
<block wx:for="{{senceData}}" wx:key="index">
<swiper-item>
<image class="scene-img" src="{{IMGURL}}{{item.img}}"></image>
</swiper-item>
</block>
</swiper>
</view>
<view class="prod-wrap">
<text class="big-title">特色产品</text>
<scroll-view enhanced="{{true}}" show-scrollbar="{{false}}" class="nav-wrap" scroll-x="{{true}}">
......@@ -29,7 +20,7 @@
</text>
</view>
<view class="share-btn">
<view class="share-btn" wx:if="{{!isShare}}" bindtap="onShareFn">
<image class="icon" src="{{IMGURL}}share.png"></image>
<text>分享</text>
</view>
......@@ -37,7 +28,7 @@
</view>
</view>
<view class="project-wrap">
<view style="position: sticky;top: {{headerHeight}}px ;z-index: 1;">
<view style="position: sticky;top: {{headerHeight}}px ;z-index: 1;background-color: #F5F7FB;">
<tab openScroll="{{true}}" tab="{{tab}}" index="{{curTabIdx}}" bindclick="changeTab"></tab>
</view>
<scroll-view class="project-img" scroll-into-view="{{intoViewId}}" bindscroll="scrolltoupper" scroll-y="{{true}}">
......@@ -52,7 +43,6 @@
<view class="video-text">{{item.name}}</view>
</view>
</block>
<!-- <view class="video-tips">- 如需开通请咨询客服 -</view> -->
</view>
</view>
</view>
......
// pages/tab/index/components/shareModel/shareModel.js
import { IMG_URL } from "~/utils/constantData.js";
const IMGURL = IMG_URL
import Draw from "~/utils/Draw.js";
import {imgUrlMixin} from '~/mixins/index'
Component({
behaviors: [imgUrlMixin],
/**
* 组件的属性列表
*/
properties: {
actNum: Number, //场景选择
isShow: Boolean,
// //分享方法
// onShareAppMessage:Function,
// onShareTimeline:Function,
},
/**
* 组件的初始数据
*/
data: {
btnList: [
{
src: `${IMGURL}wechat.png`,
name: "微信转发",
},
// {
// src: `${IMGURL}index/moments.png`,
// name: "朋友圈分享",
// },
{
src: `${IMGURL}down.png`,
name: "下载为海报",
},
],
// 4种场景下图片所有的高 (单位 rpx)
imgHeightArr: [
[1110, 1290, 596, 744, 490, 1532],
[2168, 1290, 596, 830, 490, 752],
[1110, 1290, 596, 984, 490],
[678, 1266, 1398, 830, 490, 1666],
],
posterUrl: "", //海报url
// imgList
// imgList:[
// {
// src:`${IMGURL}index/scene${actNum}1.png`,
// },
// ]
},
observers: {
actNum: function (actNum) {
let imgList = [
`${IMGURL}index/scene${actNum + 1}1.png`,
`${IMGURL}index/scene${actNum + 1}2.png`,
`${IMGURL}index/scene${actNum + 1}3.png`,
`${IMGURL}index/scene${actNum + 1}4.png`,
`${IMGURL}index/scene${actNum + 1}5.png`,
];
if (actNum != 2) {
imgList.push(`${IMGURL}index/scene${actNum + 1}6.png`);
}
this.setData({
imgList,
});
},
},
/**
* 组件的方法列表
*/
methods: {
// 分享按钮
handleClick(e) {
let { index } = e.currentTarget.dataset;
switch (index) {
case 0:
this.wechatFn();
break;
case 1:
this.download();
break;
}
},
// 微信转发
wechatFn() {
// this.data.onShareAppMessage()
this.modelClose();
},
// 下载海报
async download() {
let { actNum, imgHeightArr } = this.data;
//所有的长度
let imgAllHeight = imgHeightArr[actNum].reduce((total, current) => {
return total + current;
});
// 缺少视频的长度(前4张)+二维码的长度 (单位rpx)
let erCodeHeight =
imgHeightArr[actNum].slice(0, 4).reduce((total, current) => {
return total + current;
}) +
98 * 2;
// console.log("imgAllHeight: ", imgAllHeight);
let drawFun = new Draw({
width: 750,
height: imgAllHeight,
});
let imgList = [
{
x: 0,
y: 0,
width: 750,
height: imgAllHeight,
url: `${IMGURL}scene/longpic${
actNum + 1
}.png`,
},
{
x: 245*2,
y: erCodeHeight-11,
width: 120*2,
height: 120*2,
url: `https://img02.glsx.com.cn/weapp/resource/saas/business-assistant/index/discovery_prod1.png`, //二维码
},
];
let posterUrl = await drawFun.begin({
imageList: imgList,
});
this.setData({
posterUrl: posterUrl.path,
});
console.log('posterUrl.path',posterUrl.path,wx.pro)
if(this.data.posterUrl){
wx.downloadFile({
url: this.data.posterUrl, //仅为示例,并非真实的资源
success (res) {
console.log('res: ', res);
}
})
}
this.modelClose();
},
//模态框关闭
modelClose() {
this.triggerEvent("modelclose", false);
},
// 图片加载事件
onloadFn(event) {
// console.log('event.detail',event.detail)
this.setData({
imgHeight: (event.detail.height * 0.2).toFixed(0),
});
},
},
});
{
"component": true,
"usingComponents": {}
}
\ No newline at end of file
/* pages/tab/index/components/shareModel/shareModel.wxss */
.share-wrap {
position: fixed;
top: 0;
left: 0;
bottom: 0;
right: 0;
background: rgba(0, 0, 0, 0.5);
z-index: 1;
.img-wrap {
position: absolute;
top: 20%;
left: 50%;
transform: translateX(-50%);
width: 225px;
height: 311px;
// background-color: red;
overflow: auto;
.img {
width: 100%;
// height: auto;
height: 60%;
background-color: #fff;
}
}
.btns {
position: absolute;
left: 0;
bottom: 0;
width: 100%;
height: 154px;
background: #ffffff;
border-radius: 8px 8px 0 0;
.top {
display: flex;
justify-content: space-around;
.btn {
padding-top: 16px;
}
.img {
display: block;
margin: 0 auto 8px;
width: 40px;
height: 40px;
}
.name {
font-size: 12px;
color: #323436;
text-align: center;
line-height: 32rpx;
}
.btn-wechat{
width: auto;
margin: 0;
padding: 0;
background-color: #fff;
&::after{
border:none;
}
}
}
.btom {
margin: 18px auto 0;
width: 343px;
height: 44px;
line-height: 44px;
border: 1px solid #eeeeee;
border-radius: 4px;
text-align: center;
}
}
}
<!-- pages/tab/index/components/shareModel/shareModel.wxml -->
<view class="share-wrap" wx:if="{{isShow}}">
<view class="img-wrap">
<image class="img" style="height:{{imgHeight}}px" src="{{IMGURL}}scene/longpic{{actNum+1}}.png" bindload="onloadFn" />
<!-- <block wx:for="{{imgList}}" wx:key="*this">
<image class="img" src="{{item}}"/>
</block> -->
</view>
<button></button>
<view class="btns">
<view class="top">
<view class="btn" wx:for="{{btnList}}" wx:key="name" bindtap="handleClick" data-index="{{index}}">
<block wx:if="{{index == 0}}">
<button open-type="share" class="btn-wechat">
<image class="img" src="{{item.src}}" />
<view class="name">{{item.name}}</view>
</button>
</block>
<block wx:else>
<image class="img" src="{{item.src}}" />
<view class="name">{{item.name}}</view>
</block>
</view>
</view>
<view class="btom" bindtap="modelClose">取消</view>
</view>
</view>
\ No newline at end of file
......@@ -9,6 +9,7 @@ Page({
data: {
senceData,
headerHeight: 0,
actNum: 0,
navStyle,
// 预估弹框
visible: false,
......@@ -22,8 +23,7 @@ Page({
flow: 10000,
},
isFirst: true,
// tabList: pageData.tabList,
changeSale: 0, //每次改变的销量
changeSale: 0,
},
navbarReady(e) {
let {
......@@ -43,6 +43,12 @@ Page({
})
},
changeSwiper(e){
this.setData({
actNum:e.detail.current,
});
},
// 跳转咨询页面
goConsult() {
wx.pro.openCustomerServiceChat({
......
......@@ -2,6 +2,15 @@
.container{
position: relative;
.scene-wrap {
white-space: nowrap;
height: 180rpx;
margin-bottom: 16rpx;
.scene-img {
width: 100%;
}
}
.bg-img{
position: absolute;
top: 0;
......
......@@ -5,7 +5,16 @@
</navigation-bar>
<view style="padding-top: {{headerHeight}}px;">
<product senceData="{{senceData}}" headerHeight="{{headerHeight}}"></product>
<view class="header">
<swiper bindchange="changeSwiper" class="scene-wrap" circular="{{true}}" previousMargin="40rpx" nextMargin="40rpx">
<block wx:for="{{senceData}}" wx:key="index">
<swiper-item>
<image class="scene-img" src="{{IMGURL}}{{item.img}}"></image>
</swiper-item>
</block>
</swiper>
</view>
<product senceData="{{senceData}}" actNum="{{actNum}}" headerHeight="{{headerHeight}}"></product>
</view>
</view>
......
......@@ -134,8 +134,29 @@
"scene": null
},
{
"name": "",
"pathName": "packageActivity/pages/order/order",
"name": "发现页",
"pathName": "pages/tab/discovery/discovery",
"query": "",
"launchMode": "default",
"scene": null
},
{
"name": "模拟分享",
"pathName": "pages/authentication/loading/loading",
"query": "url=%2Fpages%2Ftab%2Fdiscovery%2Fdiscovery",
"launchMode": "default",
"scene": null
},
{
"name": "申请活动",
"pathName": "packageActivity/pages/applyActivity/applyActivity",
"query": "",
"launchMode": "default",
"scene": null
},
{
"name": "分享页",
"pathName": "pages/checkProduct/checkProduct",
"query": "",
"launchMode": "default",
"scene": null
......
......@@ -7,36 +7,41 @@ class Draw {
[_pixelRatio_] = null;
[_canvasObject_] = null;
[_canvas_] = null
constructor(canvasObject) {
wx.getSystemInfo().then(({ pixelRatio }) => {
// console.log(pixelRatio)
this[_canvasObject_] = canvasObject
this[_pixelRatio_] = canvasObject.pixelRatio || pixelRatio || 2
const height = this.toRpx(canvasObject.height),
width = this.toRpx(canvasObject.width),
canvas = wx.createOffscreenCanvas({
type: '2d',
width,
height
}),
ctx = canvas.getContext('2d')
this[_canvas_] = canvas
this[_ctx_] = ctx
this[_ctx_].clearRect(0, 0, width, height)
this.drawFill({
x: 0,
y: 0,
constructor(canvasObject, isCompInst) {
this[_canvasObject_] = canvasObject
this[_pixelRatio_] = canvasObject.pixelRatio || 2
const height = this.toRpx(canvasObject.height),
width = this.toRpx(canvasObject.width),
canvas = wx.createOffscreenCanvas({
type: '2d',
width,
height,
color: canvasObject.backgroundColor || 'rgb(255, 255, 255)'
})
this[_ctx_].save()
compInst:isCompInst
}),
ctx = canvas.getContext('2d')
this[_canvas_] = canvas
this[_ctx_] = ctx
this[_ctx_].clearRect(0, 0, width, height)
this.drawFill({
x: 0,
y: 0,
width,
height,
color: canvasObject.backgroundColor || 'rgb(255, 255, 255)'
})
this[_ctx_].save()
}
drawImages(imageParams, callback) {
async drawImages(imageParams, callback) {
this[_ctx_].beginPath()
this[_ctx_].save()
let { borderRadius, height, width, url, x, y } = imageParams
let {
borderRadius,
height,
width,
url,
x,
y
} = imageParams
height = this.toRpx(height)
width = this.toRpx(width)
x = this.toRpx(x)
......@@ -52,13 +57,14 @@ class Draw {
this[_ctx_].clip()
}
let image = this[_canvas_].createImage()
new Promise(resolve => {
image.onload = resolve
image.src = `${url}?v=${Date.now()}`
}).then(() => {
this[_ctx_].drawImage(image, x, y, width, height)
this[_ctx_].restore()
if (callback) callback()
image.src = `${url}?v=${Date.now()}`
return new Promise(resolve => {
image.onload = () => {
this[_ctx_].drawImage(image, x, y, width, height)
this[_ctx_].restore()
if (callback) callback()
resolve(imageParams)
}
})
}
toRpx(val) {
......@@ -69,7 +75,13 @@ class Draw {
if (fontSize) this[_ctx_].font = `${fontSize}px${font}`
return this[_ctx_].measureText(text).width
}
drawFill({ x, y, width, height, color }) {
drawFill({
x,
y,
width,
height,
color
}) {
height = this.toRpx(height)
width = this.toRpx(width)
x = this.toRpx(x)
......@@ -82,8 +94,25 @@ class Draw {
this[_ctx_].save()
}
drawText(textParams) {
let { textDecoration, textBaseline, lineHeight, fontWeight, textAlign, textWidth, maxWidth, fontSize, lastFont, opacity, lineNum, width, color, text, x, y } = textParams,
font = this[_ctx_].font.split('px')[1]
let {
textDecoration,
textBaseline,
lineHeight,
fontWeight,
textAlign,
textWidth,
maxWidth,
fontSize,
lastFont,
opacity,
lineNum,
width,
color,
text,
x,
y
} = textParams,
font = this[_ctx_].font.split('px')[1]
textAlign = textAlign || 'left'
textBaseline = textBaseline || 'normal'
opacity = typeof opacity === 'number' ? opacity : 1
......@@ -140,6 +169,7 @@ class Draw {
height: boxHeight,
color: textParams.background
})
}
const drawOneLineText = () => {
let textArr = text.toString().split(''),
......@@ -218,15 +248,20 @@ class Draw {
} else {
drawOneLineText()
}
} else {
drawOneLineText()
}
} else drawOneLineText()
this[_ctx_].stroke()
}
drawLine(lineParams, callback) {
this[_ctx_].beginPath()
let { opacity, startX, startY, width, color, endX, endY } = lineParams
let {
opacity,
startX,
startY,
width,
color,
endX,
endY
} = lineParams
startX = this.toRpx(startX)
startY = this.toRpx(startY)
width = this.toRpx(width)
......@@ -243,7 +278,12 @@ class Draw {
if (callback) callback()
}
setLineY = params => {
let { textDecoration, textBaseline, fontSize, y } = params
let {
textDecoration,
textBaseline,
fontSize,
y
} = params
let type = {
underline: {
top: y + fontSize,
......@@ -266,8 +306,11 @@ class Draw {
}
return type[textDecoration][textBaseline]
}
setLineX({ textAlign, text, x }) {
setLineX({
textAlign,
text,
x
}) {
let textWidth = this.getTextWidth(text)
let type = {
left: x,
......@@ -276,8 +319,13 @@ class Draw {
}
return type[textAlign]
}
drawRadiusRect({ borderRadius, height, width, x, y }, callBack) {
drawRadiusRect({
borderRadius,
height,
width,
x,
y
}, callBack) {
let radius = typeof borderRadius === 'string' ? ((Number(borderRadius.split('%')[0]) / 100) * width) / 2 : borderRadius / 2
radius = radius || 0
this[_ctx_].beginPath()
......@@ -288,7 +336,12 @@ class Draw {
}
if (callBack) callBack()
}
getFontWidth({ textAlign, fontSize, text, x }) {
getFontWidth({
textAlign,
fontSize,
text,
x
}) {
let type = {
left: x,
center: x - (fontSize * text.length) / 2,
......@@ -298,7 +351,12 @@ class Draw {
}
drawDecoration(params) {
let { newText, opacity, y, x } = params
let {
newText,
opacity,
y,
x
} = params
let lineX = x
let lineY = y
lineX = this.setLineX(params)
......@@ -329,10 +387,33 @@ class Draw {
})
}
base64src(url).then(img => {
console.log('img', img)
createLocalImg(img, callBack)
})
}
async begin(data = {}) {
return new Promise(async (resolve, reject) => {
const drawFun = () => {
data.textList && data.textList.length && data.textList.map(e => {
this.drawText(e)
})
data.lineList && data.lineList.length && data.lineList.map(e => {
this.drawLine(e)
})
wx.nextTick(() => {
this.toDataURL(res => resolve(res))
})
}
if (data.imageList && data.imageList.length) {
await this.drawImages(data.imageList[0])
if (data.imageList.length > 1)
for (let index = 1; index < data.imageList.length; index++) {
await this.drawImages(data.imageList[index])
if (index == data.imageList.length - 1) drawFun()
}
else drawFun()
}
})
}
}
const checkTextDecoration = textDecoration => {
return textDecoration && (textDecoration === 'underline' || textDecoration === 'overline' || textDecoration === 'line-through')
......@@ -355,4 +436,4 @@ const createLocalImg = (url, callBack) => {
}
})
}
export default Draw
export default Draw
\ No newline at end of file
Markdown is supported
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!