Authored by 李奇

delete snapshot相关代码、后续可能重新添加

let app = getApp();
const windowWidth = app.globalData.systemInfo.windowWidth;
const windowHeight = app.globalData.systemInfo.windowHeight;
const screenHeight = app.globalData.systemInfo.screenHeight;
const scale = windowWidth / 375 ;
Component({
/**
* 组件的属性列表
*/
properties: {
isShow: {
type: Boolean,
value: false,
observer: "_creatSnapshoot"
},
sourceType: {
type: String,
value: ""
},
shareData: {
type: Object,
value: null,
}
},
/**
* 组件的初始数据
*/
data: {
screenHeight,
windowWidth,
windowHeight,
scale,
},
/**
* 组件的方法列表
*/
methods: {
hidden() {
this.triggerEvent("hiddenSheet");
},
saveToAlbum() {
var that = this;
if (wx.getSetting) {
wx.getSetting({
success(res) {
if (!res.authSetting['scope.writePhotosAlbum']) {
wx.authorize({
scope: 'scope.writePhotosAlbum',
success: function (res) {
that.saveSnapShoot();
},
fail: function (error) {
wx.openSetting({
success: function (res) {
}
});
},
})
} else {
that.saveSnapShoot();
}
}
})
} else {
wx.showModal({
title: '提示',
content: '当前微信版本过低,无法使用该功能,请升级到最新微信版本后重试。'
})
}
},
saveSnapShoot() {
var that = this
var source = that.properties.sourceType;
var canvasId = '';
if (source === 'shop') {
canvasId = 'shopCanvas';
} else if (source === 'product') {
canvasId = 'productDetailCanvas';
}
wx.canvasToTempFilePath({
x: 0,
y: 0,
width: windowWidth,
height: screenHeight,
destWidth: windowWidth * 2,
destHeight: screenHeight * 2,
quality: 1.0,
canvasId: canvasId,
success: function (result) {
wx.saveImageToPhotosAlbum({
filePath: result.tempFilePath,
success(res) {
wx.showToast({
title:
'保存成功',
icon:
'success',
duration:
2000
})
that.hidden();
},
fail: function (err) {
that.hidden();
}
}, );
},
fail: function (error) {
that.hidden();
},
complete: function (res) {
that.hidden();
}
}, this);
},
_creatSnapshoot: function(newValue, oldValue) {
if(newValue) {
var that = this;
var type = that.properties.sourceType
if (type === "shop") {
that.createShopSnapShoot();
} else if (type === "product") {
that.creatProductDetailSnapShoot();
}
}
},
createShopSnapShoot() {
var that = this;
var shareData = that.properties.shareData;
if (shareData) {
var sCtx = wx.createCanvasContext("shopCanvas", this);
sCtx.setFillStyle('white');
sCtx.fillRect(0, 0, windowWidth, screenHeight);
// console.log(shareData.bannerUrl)
var bannerUrl = shareData.bannerUrl;
if (bannerUrl.indexOf("https://") == -1) {
bannerUrl = bannerUrl.replace('http://', 'https://');
}
// console.log(bannerUrl)
wx.getImageInfo({
src: bannerUrl,
success: function (res) {
sCtx.drawImage(res.path, 0, 0, windowWidth, 117 * scale);
sCtx.setFillStyle('white');
sCtx.setShadow(-5, -2, 40, 'darkgray');
sCtx.fillRect(27 * scale, 88 * scale, 320 * scale, 320 * scale);
sCtx.setShadow(0, 0, 0, 'white');
wx.getImageInfo({
src: shareData.shop_logo,
success: function (res) {
sCtx.drawImage(res.path, 127 * scale, 107 * scale, 120 * scale, 120 * scale);
sCtx.draw(true);
}
})
sCtx.setFontSize(19);
sCtx.setFillStyle('black');
sCtx.setTextAlign('center');
sCtx.fillText(shareData.shop_name, 187.5 * scale, 259 * scale);
that.drawLongText(shareData.shop_intro_simple, sCtx, 46 * scale, 291 * scale, 'black');
sCtx.draw(true);
}
})
// console.log(shareData.shop_qrCode)
wx.getImageInfo({
src: shareData.shop_qrCode,
success: function (res) {
sCtx.drawImage(res.path, 140.5 * scale, 470 * scale, 90 * scale, 90 * scale);
sCtx.draw(true);
}
});
sCtx.setFillStyle('black');
sCtx.setTextAlign('center');
sCtx.setFontSize(11)
sCtx.fillText('长按扫码查看详情', 187.5 * scale, 596.5 * scale);
sCtx.drawImage("../../../static/images/share-logo@2x.png", 132 * scale, 613 * scale, 111 * scale, 20 * scale);
sCtx.draw();
}
},
creatProductDetailSnapShoot() {
var that = this;
var product = that.properties.shareData;
var pCtx = wx.createCanvasContext("productDetailCanvas", this);
pCtx.setFillStyle('white');
pCtx.fillRect(0, 0, windowWidth, screenHeight);
pCtx.drawImage('../../../static/images/snapshoot_share_bg@2x.png', 0, 0, windowWidth, 186 * scale);
pCtx.setFillStyle('white');
pCtx.setShadow(-5, -2, 40, 'darkgray');
pCtx.fillRect(27 * scale, 60 * scale, 320 * scale, 430 * scale);
// console.log(product.default_image)
var defaultImage = product.default_image;
if (defaultImage.indexOf("https://") == -1) {
defaultImage = defaultImage.replace('http://', 'https://');
}
wx.getImageInfo({
src: defaultImage,
success: function(res) {
pCtx.drawImage(res.path, 27 * scale, 60 * scale, 320 * scale, 430 * scale);
pCtx.setFillStyle("rgba(0,0,0,0.8)");
pCtx.fillRect(27 * scale, 370 * scale, 320 * scale, 120 * scale);
pCtx.setFillStyle('white');
that.drawLongText(product.product_name, pCtx, 73 * scale, 402 * scale, 'white');
pCtx.setTextAlign('center');
pCtx.setFontSize(18 * scale);
pCtx.fillText(product.product_price, 187.5 * scale, 458.5 * scale);
pCtx.draw(true);
}
})
pCtx.setShadow(0, 0, 0, 'white');
pCtx.drawImage("../../../static/images/share-logo@2x.png", 132 * scale, 505 * scale, 111 * scale, 20 * scale);
wx.getImageInfo({
src: product.product_qrCode,
success: function (res) {
pCtx.drawImage(res.path, 148.5 * scale, 539.5 * scale, 78 * scale, 78 * scale);
pCtx.draw(true);
}
});
pCtx.setFillStyle('black');
pCtx.setTextAlign('center');
pCtx.setFontSize(11);
pCtx.fillText('长按扫码查看详情', 187.5 * scale, 632.5 * scale);
pCtx.drawImage("../../../static/images/snapshoot_tip_ic@2x.png", 127 * scale, 645.5 * scale, 9 * scale, 9 * scale);
pCtx.setFillStyle('#b0b0b0');
pCtx.setFontSize(9);
pCtx.fillText('实际价格以页面展示为准', 187.5 * scale, 652.5 * scale);
pCtx.draw();
},
drawLongText(longtext, cxt, begin_width, begin_height, color) {
var linelenght = 20 * scale;//行间距
var numsForLine = 20;
var numberOfLine = 2;
var text = "";
var count = 0;
var lineNumber = 1;
var begin_width = begin_width;
var begin_height = begin_height;
var stringLenght = longtext.length;
var newtext = longtext.split("");
cxt.setFillStyle(color);
cxt.setFontSize(14 * scale);
cxt.setTextAlign('left');
for (var i = 0; i <= stringLenght; i++) {
if (count == numsForLine) {
if (lineNumber === numberOfLine) {
var t = text + '...';
cxt.fillText(t, begin_width, begin_height);
} else {
cxt.fillText(text, begin_width, begin_height);
}
begin_height = begin_height + linelenght;
text = "";
count = 0;
lineNumber ++;
}
if (i == stringLenght) {
cxt.fillText(text, begin_width, begin_height);
}
text = text + newtext[0];
count++;
newtext.shift();
if(lineNumber > numberOfLine){
break;
}
}
}
}
})
{
"component": true
}
\ No newline at end of file
<view class="snapshoot-container" style="display: {{isShow ? 'block' : 'none'}}" >
<view class="snapshoot-container">
<view class="snapshoot-content">
<view class="snapshoot" wx:if="{{sourceType==='shop'}}">
<image class="img-bg" src="{{shareData.bannerUrl}}"></image>
<view class="snapshoot-shopinfo">
<image class="img-logo" mode="aspectFit" src="{{shareData.shop_logo}}"> </image>
<text class="shop-name">{{shareData.shop_name}}</text>
<text class="shop-intro">{{shareData.shop_intro_simple}}</text>
</view>
<view class="shop-miniqr">
<image class="shop-qrcode" src="{{shareData.shop_qrCode}}"></image>
<text class="snapshoot-tips">长按扫码查看详情</text>
<image class="yoho-logo" src="../../../static/images/share-logo@2x.png"></image>
</view>
</view>
<view class="snapshoot" wx:elif="{{sourceType==='product'}}">
<image class="product-img-bg" src="../../../static/images/snapshoot_share_bg@2x.png"></image>
<view class="snapshoot-productinfo">
<image class="product-defaultImage" src="{{shareData.default_image}}"> </image>
<view class="product-info-content">
<text class="product-name">{{shareData.product_name}}</text>
<text class="product-price">{{shareData.product_price}}</text>
</view>
</view>
<view class="product-miniqr">
<image class="yoho-logo" src="../../../static/images/share-logo@2x.png"></image>
<image class="product-qrcode" src="{{shareData.product_qrCode}}"></image>
<text class="snapshoot-tips">长按扫码查看详情</text>
<view class='product-tips'>
<image class="product-tips-img" src="../../../static/images/snapshoot_tip_ic@2x.png"></image>
<text class="product-tips-text">实际价格以页面展示为准</text>
</view>
</view>
</view>
<view wx:else></view>
</view>
<!--底部按钮 -->
<view class="snapshoot-bottom">
<view class="snapshoot-save" bindtap="saveToAlbum">
<text class="text">保存到相册</text>
</view>
<view class="snapshoot-cancel" bindtap="hidden">
<text class="cancel-text">取消</text>
</view>
</view>
</view>
<view class="snapshoot-canvas" style="width: {{windowWidth}}px;height:{{screenHeight}}px; background-color: white; margin-top: {{screenHeight}}px" wx:if="{{sourceType === 'shop'}}">
<canvas canvas-id="shopCanvas" style="width: {{windowWidth}}px;height:{{screenHeight}}px;"></canvas>
</view>
<view class="snapshoot-canvas" style="width: {{windowWidth}}px;height:{{screenHeight}}px; background-color: white; margin-top: {{screenHeight}}px" wx:elif="{{sourceType === 'product'}}">
<canvas canvas-id="productDetailCanvas" style="width: {{windowWidth}}px;height:{{screenHeight}}px;background-color: white"></canvas>
</view>
</view>
.share-bg{
position: fixed;
z-index: 999;
left: 0;
bottom: 0;
width: 100%;
height: 100%;
margin: 0;
border-top: 1px #eee solid;
background-color: rgba(0, 0, 0, 0.4);
}
.share-bg .share-view{
position: fixed;
z-index: 9999;
width:100%;
height: 340rpx;
left:0;
bottom: 0;
background-color: white;
}
.share-bg .share-view .close-view {
display: fixed;
align-items: flex-end;
justify-content: center;
}
.share-bg .share-view .close-view .close-icon{
margin-top: 20rpx;
margin-right: 20rpx;
width: 60rpx;
height: 60rpx;
float:right;
}
.share-bg .share-view .tips-view{
display: fixed;
margin-top: 80rpx;
text-align: center;
}
.share-button{
margin-top: 30rpx;
background-color: white;
}
.share-button::after{
display: none;
}
.share-bg .share-view .tips-view .tips-text-normal {
font-size: 28rpx;
color: #444;
font-family: PingFang SC;
}
.share-bg .share-view .tips-view .tips-text-bold {
font-size: 28rpx;
font-family: PingFang SC;
}
.share-bg .share-view .share-button .share-button-icon{
width: 500rpx;
height: 88rpx;
}
.snapshoot-container {
position: fixed;
left: 0rpx;
top: 0rpx;
width: 750rpx;
height: 1206rpx;
background-color: rgba(0, 0, 0, 0.5);
flex-direction: column;
z-index: 9999;
}
.snapshoot-container .snapshoot-content {
margin-top: 58rpx;
margin-left: 105rpx;
width: 540rpx;
height: 960rpx;
background-color: white;
flex-direction: column;
}
.snapshoot-container .snapshoot-content .snapshoot {
width: 100%;
height: 100%;
display: flex;
flex-direction: column;
align-items: center;
}
.snapshoot-container .snapshoot-content .snapshoot .img-bg {
width: 100%;
height: 168rpx;
}
.snapshoot-container .snapshoot-content .snapshoot .snapshoot-shopinfo {
margin-top: -50rpx;
width: 460rpx;
height: 460rpx;
background-color: white;
box-shadow:5px 5px 3px lightgray;
border: 0.5rpx solid #e5e5e5;
display: flex;
flex-direction: column;
align-items: center;
}
.snapshoot-container .snapshoot-content .snapshoot .snapshoot-shopinfo .img-logo {
margin-top: 30rpx;
width: 172rpx;
height: 172rpx;
}
.snapshoot-container .snapshoot-content .snapshoot .snapshoot-shopinfo .shop-name {
margin-top: 36rpx;
font-size: 28rpx;
font-weight: bold;
text-align: center;
}
.snapshoot-container .snapshoot-content .snapshoot .snapshoot-shopinfo .shop-intro {
margin-top: 61rpx;
font-size: 20rpx;
font-weight: bold;
text-align: left;
width: 401rpx;
height: 60rpx;
line-height:30rpx;
display: -webkit-box;
overflow: hidden;
text-overflow:ellipsis;
white-space: pre-wrap;
-webkit-box-orient: vertical;
-webkit-line-clamp: 2;
}
.snapshoot .shop-miniqr {
display: flex;
flex-direction: column;
align-items: center;
}
.yoho-logo {
width: 160rpx;
height: 29rpx;
margin-top: 21rpx;
}
.snapshoot .shop-miniqr .shop-qrcode {
width: 130rpx;
height: 130rpx;
margin-top: 90rpx;
}
.product-qrcode {
width: 130rpx;
height: 130rpx;
margin-top: 21rpx;
}
.snapshoot-container .snapshoot-save {
width: 260rpx;
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: 20rpx;
width: 260rpx;
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;
}
.text {
font: 28rpx;
color: white;
text-align: center;
}
.cancel-text {
font: 28rpx;
color: black;
text-align: center;
}
.snapshoot-tips {
margin-top: 16rpx;
font-size: 16rpx;
color: #444444;
}
/*商品 */
.product-img-bg {
width: 100%;
height: 268rpx;
}
.snapshoot-productinfo {
margin-top: -220rpx;
width: 460rpx;
height: 620rpx;
background-color: white;
box-shadow:5px 5px 3px lightgray;
border: 0.5rpx solid #e5e5e5;
display: flex;
flex-direction: column;
align-items: center;
}
.product-defaultImage {
width: 100%;
height: 100%
}
.product-info-content {
width: 100%;
height: 172rpx;
margin-top: -172rpx;
background-color: rgba(0, 0, 0, 0.5);
display: flex;
flex-direction: column;
align-items: center;
}
.product-name {
width: 80%;
margin-top: 30rpx;
color: white;
text-align: center;
font-size: 26rpx;
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: 2;
}
.product-price {
color: white;
text-align: center;
font-size: 34rpx;
}
.product-tips {
display: flex;
flex-direction: row;
justify-content: center;
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 {
/* margin-top: -20; */
display: flex;
flex-direction: column;
align-items: center;
}
.snapshoot-bottom {
margin-left: 105rpx;
margin-top: 50rpx;
width: 540rpx;
height: 88rpx;
display: flex;
flex-direction: row;
flex-wrap: wrap;
justify-content: center;
align-items: center;
}
/* .snapshoot-container .snapshoot-content .snapshoot-canvas {
width: 750rpx;
height: 1206rpx;
background-color: white;
} */
\ No newline at end of file
... ... @@ -3,7 +3,6 @@
"usingComponents": {
"product-banner": "/components/product/detail/banner",
"product-list": "/components/product/list",
"snapshot": "/components/product/detail/snapshot",
"view-title": "/components/layout/view-title/view-title",
"copyright": "/components/layout/copyright/copyright",
"quick-navigation": "/components/layout/quick-navigation/quick-navigation"
... ...
... ... @@ -125,6 +125,5 @@
<quick-navigation show-menu="{{true}}" show-back-top="{{showBackTop}}" show="{{true}}"
bindbacktop="backTop" margin-bottom="{{150}}"></quick-navigation>
<snapshot isShow="{{showSnapshootShare}}" sourceType="product" shareData="{{snapshootShareData}}" bind:hiddenSheet="hideSnap"></snapshot>
<template is="Picker" data="{{pickerData, loadingForPayment}}"/>
<template is="zan-actionsheet" data="{{...actionSheet}}"/>
... ...