Authored by 肖亚东

快照分享功能以及保存快照画布功能提交 — review by 李其昌

/* eslint-disable no-undef */
import Taro from '@tarojs/taro'
import event from '../../../utils/event.js'
import {getImgUrl} from '../../../utils';
import {globalData} from '../../../actions/globalData.js';
// 获取系统信息
let systemInfo = Taro.getSystemInfoSync();
... ... @@ -38,7 +40,8 @@ Component({
windowWidth: systemInfo.windowWidth,
windowHeight: systemInfo.windowHeight,
scale,
ratio:2
ratio:2,
userInfo: {}
},
/**
... ... @@ -149,7 +152,7 @@ Component({
var that = this;
var product = that.properties.shareData;
console.log('====================================');
console.log(product);
console.log('====================================');
... ... @@ -161,89 +164,112 @@ Component({
let snapWidth = this.data.windowWidth * ratio
let snapHeight = this.data.screenHeight * ratio
let middle = snapWidth / 2
scale = snapWidth / 262.5
scale = snapWidth / 375
HScale = scale
// console.log(windowWidth,screenHeight,snapWidth,snapHeight,scale)
let logoHeight = 15.4 * HScale;
let logoWidth = 78.4 * scale;
let logoTop = 25.2 * HScale;
let logoMarginBottom = 21 * HScale;
let logoLeft = (snapWidth - logoWidth) / 2 //logo左边坐标
let imgContainerWidth = 227.5 * scale;
let imgContainerHeight = 303.1 * HScale
let logoHeight = 50 * HScale;
let logoWidth = 50 * scale;
let logoTop = 40 * HScale;
let logoMarginBottom = 25 * HScale;
let logoLeft = 30 * scale //logo左边坐标
let nameTop = 60 * HScale;
let nameLeft = logoLeft + logoWidth + 15 * scale;
let tipsTop = nameTop + 20 * scale;
let imgtextContainerHeight = 393 * HScale
let imgContainerWidth = 315 * scale;
let imgContainerHeight = 315 * scale;
let imgContainerLeft = (snapWidth - imgContainerWidth) / 2 //图片容器左边位置
let imgContainerTop = logoHeight + logoTop + logoMarginBottom //图片容器顶部位置
let namePriceBgHeight = 56 * HScale
let namePriceBgTop = imgContainerTop + (imgContainerHeight - namePriceBgHeight)
let x = 10 * scale
let nameTop = imgContainerTop + 255*scale + x
let priceTop = imgContainerTop + 280* scale + x
let productNameTop = imgContainerTop + imgContainerHeight + 20 * scale
//以下为小程序码相关
let qrImgMarginTop = 21 * HScale
let qrCodeTop = imgContainerTop + imgContainerHeight + qrImgMarginTop
let qrImgWH = 56 * scale
let qrImgMarginTop = 20 * HScale
let qrCodeTop = imgContainerTop + imgtextContainerHeight + qrImgMarginTop
let qrImgWH = 70 * scale
let qrCodeLeft = (snapWidth - qrImgWH)/2
let tipX = 10 * scale
let tipLeft = imgContainerLeft + qrImgWH + 13.7 * scale
let tip1Top = imgContainerTop + imgContainerHeight + 34.2*scale + tipX
let tip2Top = imgContainerTop + imgContainerHeight + 52.5 * scale + tipX
let tipLeft = (snapWidth - 180 * scale)/2
let tipTop = qrCodeTop + qrImgWH + 20 * scale
const app = getApp() || {};
let userInfo = app.props.globalData.userInfo;
var pCtx = wx.createCanvasContext("productDetailCanvas", this);
pCtx.setFillStyle('white');
pCtx.fillRect(0, 0, snapWidth, snapHeight);
/*---------开始新的作画-----------*/
pCtx.drawImage('../../../assets/images/share-logo@2x.png',logoLeft , logoTop, logoWidth, logoHeight)//画logo
pCtx.setFillStyle('white');
//头像
pCtx.drawImage(userInfo.avatarUrl, logoLeft , logoTop, logoWidth, logoHeight)//画logo
pCtx.setFillStyle('#ffffff');
pCtx.setStrokeStyle('#e0e0e0')
// pCtx.fillRect(imgContainerLeft,imgContainerTop,320*scale,430*scale)//图片容器
pCtx.strokeRect(imgContainerLeft, imgContainerTop, imgContainerWidth , imgContainerHeight)//图片容器
// pCtx.arc(logoLeft+logoWidth/2, logoTop+logoHeight/2, logoWidth/2, 0, 2*Math.PI)
// this.circleImg(pCtx, userInfo.avatarUrl, logoLeft, logoTop, logoWidth)
//昵称
pCtx.setFillStyle('#000')
pCtx.setFontSize(20*scale)
pCtx.fillText(userInfo.nickName, nameLeft, nameTop)
pCtx.setFillStyle('#000')
pCtx.setFontSize(12*scale)
pCtx.fillText('发现一件超棒的潮流好物分享给你!', nameLeft, tipsTop)
pCtx.strokeRect(imgContainerLeft, imgContainerTop, imgContainerWidth , imgtextContainerHeight)//图片容器
var defaultImage = getImgUrl(product.default_image, imgContainerWidth, imgContainerHeight);
if (defaultImage && defaultImage.indexOf("https://") == -1) {
defaultImage = defaultImage.replace('http://', 'https://');
}
product.default_image = defaultImage;
that.setData({
shareData: product
shareData: product,
userInfo
})
wx.getImageInfo({
src: defaultImage,
success:function(res){
pCtx.drawImage(res.path, imgContainerLeft, imgContainerTop, imgContainerWidth, imgContainerHeight)
pCtx.setFillStyle("rgba(34,34,34,0.8)");//画名称价格背景
pCtx.fillRect(imgContainerLeft, namePriceBgTop, imgContainerWidth, namePriceBgHeight)
pCtx.setFillStyle('white');
that.drawLongText(product.product_name, pCtx, middle, nameTop, 'white', 9.8, 30,1);
that.drawLongText(product.product_name, pCtx, middle, productNameTop, 'black', 20, 25, 2);
pCtx.setTextAlign('center');
pCtx.setFontSize(16.8 * scale);
pCtx.fillText(product.product_price, middle, priceTop);
pCtx.setFontSize(20 * scale);
pCtx.draw(true)
}
})
})
wx.getImageInfo({
src: product.product_qrCode,
success:function(res){
pCtx.drawImage(res.path, imgContainerLeft, qrCodeTop, qrImgWH, qrImgWH);//画小程序码
pCtx.drawImage(res.path, qrCodeLeft, qrCodeTop, qrImgWH, qrImgWH);//画小程序码
pCtx.draw(true)
}
})
pCtx.setFillStyle('#444444')
pCtx.setFontSize(9.8*scale)
pCtx.fillText('长按扫码查看详情',tipLeft,tip1Top)
pCtx.setFillStyle('#b0b0b0')
pCtx.setFontSize(8.4*scale)
pCtx.fillText('实际价格以页面展示为准', tipLeft, tip2Top)
pCtx.setFillStyle('#999999')
pCtx.setFontSize(12*scale)
pCtx.setTextAlign('center')
pCtx.fillText('扫一扫,发现你中意的潮流好物!', middle, tipTop)
pCtx.draw()
/*---------结束新的作画-----------*/
},
circleImg(ctx, img, x, y, r) {
ctx.save();
var d = 2 * r;
var cx = x + r;
var cy = y + r;
ctx.beginPath();
ctx.arc(cx, cy, r, 0, 2 * Math.PI);
ctx.clip();
ctx.drawImage(img, x, y, d, d);
},
drawLongText(longtext, cxt, begin_width, begin_height, color, fontSize, numsForLine,numberOfLine,
isCenter = true,lineL = 0) {
let linelenght = lineL;//行间距
... ...
... ... @@ -5,33 +5,32 @@
<!--商品详情开始 -->
<view class="snapshoot">
<image class="yoho-logo" style='margin-top:50.4rpx' src="../../../assets/images/share-logo@2x.png"></image>
<view class="snapshoot-productinfo">
<image class="product-defaultImage" src="{{shareData.default_image}}"> </image>
<view class="product-info-content">
<view wx:if="{{userInfo}}" class="user-header">
<image class="user-portrait" src="{{userInfo.avatarUrl}}"> </image>
<view class="user-info">
<text class="user-name">{{userInfo.nickName}}</text>
<text class="tips">发现一件超棒的潮流好物分享给你!</text>
</view>
</view>
<view class="snapshoot-productinfo">
<image class="product-defaultImage" src="{{shareData.default_image}}"> </image>
<text class="product-name">{{shareData.product_name}}</text>
<text class="product-price">{{shareData.product_price}}</text>
</view>
</view>
<view class='product-miniqr-new'>
<image class="product-qrcode" src="{{shareData.product_qrCode}}"></image>
<view class='product-tips-new'>
<text class="snapshoot-tips-new">长按扫码查看详情</text>
<text class="product-tips-text-new" style='margin-top:10.4rpx;margin-left:0rpx'>实际价格以页面展示为准</text>
</view>
</view>
</view>
<view class='product-miniqr-new'>
<image class="product-qrcode" src="{{shareData.product_qrCode}}"></image>
<text class="product-tips-text-new">扫一扫,发现你中意的潮流好物!</text>
</view>
</view>
</view>
<!--底部按钮 -->
<view class="snapshoot-bottom">
<view class="snapshoot-save" bindtap="saveToAlbum">
<!-- <image class="img" src="./images/down@2x.png"></image> -->
<text class="text">保存到相册</text>
</view>
<view class="snapshoot-cancel" bindtap="hidden">
<text class="cancel-text">取消</text>
</view>
<view class="snapshoot-cancel" bindtap="hidden">
<text class="cancel-text">取消</text>
</view>
<view class="snapshoot-save" bindtap="saveToAlbum">
<text class="save-text">保存到相册</text>
</view>
</view>
</view>
</view>
... ...
.snapshoot-container {
position: fixed;
left: 0rpx;
... ... @@ -12,13 +11,11 @@
.snapshoot-container .snapshoot-content {
margin-top: 40rpx;
margin-left: 112.5rpx;
width: 525rpx;
height:auto;
margin-left: 112rpx;
width: 526rpx;
background-color: white;
flex-direction: column;
padding-bottom: 36rpx;
/* height:960rpx */
}
.snapshoot-container .snapshoot-content .snapshoot {
... ... @@ -26,108 +23,53 @@
height: 100%;
display: flex;
flex-direction: column;
align-items: center;
}
.snapshoot-container .snapshoot-content .snapshoot .img-bg {
width: 100%;
height: 142rpx;
}
.snapshoot-container .snapshoot-content .snapshoot .snapshoot-shopinfo {
margin-top: 30rpx;
width: 460rpx;
height: wrap;
background-color: white;
border: 0.5rpx solid #e5e5e5;
display: flex;
flex-direction: column;
align-items: center;
/* box-shadow:5px 5px 3px lightgray; */
}
.snapshoot-container .snapshoot-content .snapshoot .snapshoot-shopinfo .img-logo {
.snapshoot-bottom {
margin-top: 30rpx;
width: 200rpx;
height: 168rpx;
}
.snapshoot-container .snapshoot-content .snapshoot .snapshoot-shopinfo .shop-name {
margin-top: 35.8rpx;
font-size: 25.2rpx;
font-weight: bold;
text-align: center;
font-family: PingFang-SC-Semibold;
color: #444444
}
.snapshoot-container .snapshoot-content .snapshoot .snapshoot-shopinfo .shop-intro {
/* margin-top: 61rpx; */
font-size: 19.6rpx;
/* font-weight: bold; */
text-align: center;
width: 399rpx;
height: wrap;
line-height:33.6rpx;
display: -webkit-box;
overflow: hidden;
text-overflow:ellipsis;
white-space: pre-wrap;
-webkit-box-orient: vertical;
-webkit-line-clamp: 5;
}
.yoho-logo {
width: 156.8rpx;
height: 30rpx;
margin-top: 21rpx;
}
.product-qrcode {
width: 112rpx;
height: 112rpx;
}
.snapshoot-container .snapshoot-save {
width: 250rpx;
margin-left: 112rpx;
margin-right: 112rpx;
height: 88rpx;
background-color: red;
border-radius: 10rpx;
display: flex;
flex-direction: row;
flex-wrap: wrap;
justify-content: center;
align-items: center;
}
.snapshoot-container .snapshoot-cancel {
margin-left: 25rpx;
width: 250rpx;
width: 252rpx;
height: 88rpx;
background-color: white;
border-radius: 10rpx;
display: flex;
flex-direction: row;
flex-wrap: wrap;
justify-content: center;
align-items: center
}
}
.img {
width: 41rpx;
height: 38rpx;
.snapshoot-container .snapshoot-save {
margin-left: 22rpx;
width: 250rpx;
height: 88rpx;
background-color: #002B47;
display: flex;
flex-direction: row;
justify-content: center;
align-items: center;
}
.text {
font: 28rpx;
color: white;
.save-text {
font-family: PingFang-SC-Regular;
font-size: 32rpx;
color: #FFFFFF;
letter-spacing: 0;
text-align: center;
}
.cancel-text {
font: 28rpx;
color: black;
text-align: center;
font-family: PingFang-SC-Regular;
font-size: 32rpx;
color: #000000;
letter-spacing: 0;
}
.snapshoot-tips {
... ... @@ -135,114 +77,81 @@
font-size: 16rpx;
color: #444444;
}
.snapshoot-tips-new{
.user-header {
margin-left: 42rpx;
margin-top: 56rpx;
display: flex;
align-items: center;
}
.user-header .user-portrait {
width: 70rpx;
height: 70rpx;
border-radius: 35rpx;
}
.user-header .user-info {
margin-left: 21rpx;
display: flex;
flex-direction: column;
}
.user-header .user-info .user-name {
font-family: SFProText-Medium;
font-size: 28rpx;
color: #000000;
letter-spacing: 0;
}
.user-header .user-info .tips {
margin-top: 6rpx;
font-family: PingFang-SC-Regular;
font-size: 20rpx;
color: #444444;
font-size: 17rpx;
color: #000000;
letter-spacing: 0;
text-align: center;
}
.snapshoot-productinfo {
margin-top: 42rpx;
width: 455rpx;
height: 606.2rpx;
margin-top: 35rpx;
margin-left: 42rpx;
width: 441rpx;
height: 550rpx;
background-color: white;
display: flex;
flex-direction: column;
align-items: center;
border: 0rpx solid #e0e0e0;
border: 1rpx solid #EEEEEE;
}
.product-defaultImage {
width: 100%;
height: 100%
}
.product-info-content {
width: 100%;
height: 112rpx;
margin-top: -112rpx;
background-color: rgba(0, 0, 0, 0.5);
display: flex;
flex-direction: column;
align-items: center;
height: 441rpx;
}
.product-name {
width: 90%;
margin-top: 16.8rpx;
color: #FFFFFF;
.snapshoot-productinfo .product-name {
margin-left: 40rpx;
margin-right: 40rpx;
color: #000000;
text-align: center;
font-size: 20rpx;
/* margin-bottom: 20rpx; */
line-height: 32rpx;
display: -webkit-box;
overflow: hidden;
text-overflow:ellipsis;
white-space: pre-wrap;
-webkit-box-orient: vertical;
-webkit-line-clamp: 1;
font-size: 28rpx;
font-family: DINAlternate-Bold;
line-height: 48rpx;
}
.product-price {
color: #FFFFFF;
text-align: center;
font-size: 30rpx;
margin-top: 10rpx;
}
.product-tips {
.product-miniqr-new {
display: flex;
flex-direction: row;
justify-content: center;
flex-direction: column;
align-items: center;
margin-top: 10rpx;
}
.product-tips-img {
width: 18rpx;
height: 18rpx;
}
.product-tips-text {
font-size: 16rpx;
color: #b0b0b0;
margin-left: 10rpx;
.product-miniqr-new .product-qrcode {
margin-top: 28rpx;
width: 98rpx;
height: 98rpx;
}
.product-tips-text-new {
margin-top: 14rpx;
font-family: PingFang-SC-Regular;
font-size: 16rpx;
color: #B0B0B0;
letter-spacing: 0;
}
.snapshoot-bottom {
margin-left: 112.5rpx;
margin-top: 25rpx;
width: 525rpx;
height: 88rpx;
display: flex;
flex-direction: row;
flex-wrap: wrap;
justify-content: center;
align-items: center;
font-size: 17rpx;
color: #999999;
letter-spacing: 0;
text-align: center;
}
.product-miniqr-new{
height:112rpx;
margin-top:42rpx;
display: flex;
flex-direction: row;
align-items: center;
width:455rpx;
/* margin-left:112.5rpx; */
}
.product-tips-new {
margin-left:27.4rpx;
width:wrap;
display: flex;
flex-direction: column;
align-items: flex-start
}
 
\ No newline at end of file
... ...
... ... @@ -117,7 +117,14 @@ export default class ProductDetail extends Component {
// } else {
// product_qrCode = config.domains.api + '/wechat/miniapp/img-check.jpg?param=' + productInfo.product_id;
// }
product_qrCode = config.domains.yohoApi + '/wechat/miniapp/img-check.jpg?param=' + productInfo.product_id;
let param = {
id: productInfo.product_id
}
product_qrCode = config.domains.yohoApi + '/wechat/miniapp/img-check.jpg?param=' + encodeURIComponent(JSON.stringify(param)) + '&miniQrType=23&miniapp_type=63';
console.log('====================================');
console.log(product_qrCode);
console.log('====================================');
var shareData = {
product_name : productInfo.product_name,
... ...