增加商品详情页的分享功能

youmengting-dev
游梦婷 1 year ago
parent 08ef214596
commit c5aa40893e
  1. 2
      App.vue
  2. 3
      common/share.js
  3. 274
      components/cc-shareMenu/cc-shareMenu.vue
  4. 7
      pages.json
  5. 2
      pages/goods/goods.vue
  6. 181
      physical-merchants/classify/goodsDetail/goodsDetail.vue
  7. 693
      physical-merchants/classify/poster/poster.vue
  8. 1123
      physical-merchants/classify/poster/weapp-qrcode.js
  9. BIN
      physical-merchants/static/img/ic_weixin.png
  10. BIN
      physical-merchants/static/img/icon_download.png
  11. BIN
      physical-merchants/static/img/link.png
  12. BIN
      physical-merchants/static/img/placard.png
  13. BIN
      physical-merchants/static/img/rightTop.png
  14. BIN
      physical-merchants/static/img/share_wechat.png
  15. 24
      static/iconfont/cart.scss

@ -87,6 +87,7 @@
this.globalData.imgUrl = 'https://hsgcs.dctpay.com/filesystem/'; this.globalData.imgUrl = 'https://hsgcs.dctpay.com/filesystem/';
this.globalData.imageWxImg = 'https://hsgcs.dctpay.com/filesystem/wxApplets/'; this.globalData.imageWxImg = 'https://hsgcs.dctpay.com/filesystem/wxApplets/';
this.globalData.imageqrImg = 'https://hsgcs.dctpay.com/filesystem/temporary/'; this.globalData.imageqrImg = 'https://hsgcs.dctpay.com/filesystem/temporary/';
this.globalData.h5url = "https://hsgcs.dctpay.com/hsgH5";
} }
if (accountInfo.miniProgram.envVersion == 'release') { if (accountInfo.miniProgram.envVersion == 'release') {
this.globalData.url = 'https://hsg.dctpay.com/crest'; this.globalData.url = 'https://hsg.dctpay.com/crest';
@ -98,6 +99,7 @@
this.globalData.imgUrl = 'https://hsg.dctpay.com/filesystem/'; this.globalData.imgUrl = 'https://hsg.dctpay.com/filesystem/';
this.globalData.imageWxImg = 'https://hsg.dctpay.com/filesystem/wxApplets/'; this.globalData.imageWxImg = 'https://hsg.dctpay.com/filesystem/wxApplets/';
this.globalData.imageqrImg = 'https://hsg.dctpay.com/filesystem/temporary/'; this.globalData.imageqrImg = 'https://hsg.dctpay.com/filesystem/temporary/';
this.globalData.h5url = "https://hsg.dctpay.com/hsgH5" /* 分享需要用到*/
} }
// #endif // #endif
// #ifdef H5 // #ifdef H5

@ -36,7 +36,7 @@ export default {
/* https://hsg.dctpay.com/hsgH5/index.html?code=081Zb4ml2gamsb4L3nnl2UArrO1Zb4mc&state=1#/physical-merchants/classify/goods-search/goods-search?goodsLabel=%E9%9B%B6%E5%85%83%E8%B4%AD */ /* https://hsg.dctpay.com/hsgH5/index.html?code=081Zb4ml2gamsb4L3nnl2UArrO1Zb4mc&state=1#/physical-merchants/classify/goods-search/goods-search?goodsLabel=%E9%9B%B6%E5%85%83%E8%B4%AD */
let api = require('../Utils/Api'); let api = require('../Utils/Api');
that.resVerifyWx = await api.verifyWx(datas); that.resVerifyWx = await api.verifyWx(datas);
// console.log(that.resVerifyWx,"doshare");
that.h5ShareMethod(); that.h5ShareMethod();
}, },
@ -101,6 +101,7 @@ export default {
"/physical-merchants/classify/order/pay",//收银台页 "/physical-merchants/classify/order/pay",//收银台页
"/physical-merchants/classify/order/paymentResult",//支付结果 "/physical-merchants/classify/order/paymentResult",//支付结果
"/physical-merchants/address/addNewAddress/addNewAddress",//添加地址 "/physical-merchants/address/addNewAddress/addNewAddress",//添加地址
"/physical-merchants/classify/poster/poster",//生成海报
]; ];
// #ifdef H5 // #ifdef H5

@ -0,0 +1,274 @@
<template>
<view v-if="show" class="mask" @click="toggleMask" @touchmove.stop.prevent="stopPrevent"
:style="{backgroundColor: backgroundColor}">
<view class="mask-content" @click.stop.prevent="stopPrevent" :style="[{
height: config.height,
transform: transform
}]">
<!---->
<view class="view-content ">
<view class="share-header">
分享内容
</view>
<view class="share-list">
<view v-for="(item, index) in shareList" :key="index" class="share-item"
@click="shareToFriend(item)">
<template v-if="item.type==3">
<!-- #ifdef MP-WEIXIN -->
<button open-type="share">
<image :src="item.icon" mode=""></image>
<text>{{item.text}}</text>
</button>
<!-- #endif -->
<!-- #ifdef H5 -->
<image :src="item.icon" mode=""></image>
<text>{{item.text}}</text>
<!-- #endif -->
</template>
<template v-else>
<image :src="item.icon" mode=""></image>
<text>{{item.text}}</text>
</template>
</view>
</view>
</view>
<view style="height: 92rpx;">
</view>
<view class="bottom border-t" @click="toggleMask">取消</view>
</view>
</view>
</template>
<script>
export default {
data() {
return {
transform: 'translateY(50vh)',
timer: 0,
backgroundColor: 'rgba(0,0,0,0)',
show: false,
config: {},
};
},
props: {
contentHeight: {
type: Number,
default: 0
},
//tabbar
hasTabbar: {
type: Boolean,
default: false
},
shareList: {
type: Array,
default: function() {
return [];
}
}
},
created() {
const height = uni.upx2px(this.contentHeight) + 'px';
this.config = {
height: height,
transform: `translateY(${height})`,
backgroundColor: 'rgba(0,0,0,.4)',
}
this.transform = this.config.transform;
},
methods: {
toggleMask() {
//
if (this.timer == 1) {
return;
}
this.timer = 1;
setTimeout(() => {
this.timer = 0;
}, 500)
if (this.show) {
this.transform = this.config.transform;
this.backgroundColor = 'rgba(0,0,0,0)';
setTimeout(() => {
this.show = false;
this.hasTabbar && uni.showTabBar();
}, 200)
return;
}
this.show = true;
//mask
if (this.hasTabbar) {
uni.hideTabBar({
success: () => {
setTimeout(() => {
this.backgroundColor = this.config.backgroundColor;
this.transform = 'translateY(0px)';
}, 10)
}
});
} else {
setTimeout(() => {
this.backgroundColor = this.config.backgroundColor;
this.transform = 'translateY(0px)';
}, 10)
}
},
//穿
stopPrevent() {},
//
shareToFriend(type) {
this.$emit("click", type);
this.toggleMask();
},
}
}
</script>
<style lang='scss'>
/* 文字尺寸 */
$font-base: 28upx;
/*文字颜色*/
$font-color-dark: #303133;
$font-color-base: #606266;
/* 边框颜色 */
/* $border-color-dark: #DCDFE6; */
$border-color-base: #E4E7ED;
/* $border-color-light: #EBEEF5; */
/* 图片加载中颜色 */
/* $image-bg-color: #eee; */
/* 行为相关颜色 */
/* $uni-color-primary:#fa436a;
$uni-color-success: #4cd964;
$uni-color-warning: #f0ad4e;
$uni-color-error: #dd524d; */
.mask {
position: fixed;
left: 0;
top: 0;
right: 0;
bottom: 0;
display: flex;
justify-content: center;
align-items: flex-end;
z-index: 998;
transition: .3s;
.bottom {
position: absolute;
left: 0;
bottom: 0;
display: flex;
justify-content: center;
align-items: center;
width: 100%;
height: 90upx;
background: #fff;
z-index: 9;
font-size: $font-base + 2upx;
color: $font-color-dark;
}
}
.mask-content {
width: 100%;
/* height: 580upx; */
transition: .3s;
background: #fff;
&.has-bottom {
padding-bottom: 90upx;
}
.view-content {
/* height: 100%; */
}
}
.share-header {
height: 110upx;
font-size: $font-base+2upx;
color: font-color-dark;
display: flex;
align-items: center;
justify-content: center;
padding-top: 10upx;
&:before,
&:after {
content: '';
width: 240upx;
heighg: 0;
border-top: 1px solid $border-color-base;
transform: scaleY(.5);
margin-right: 30upx;
}
&:after {
margin-left: 30upx;
margin-right: 0;
}
}
.share-list {
display: flex;
flex-wrap: wrap;
}
.share-list button {
min-width: 25%;
display: flex;
flex-direction: column;
justify-content: center;
align-items: center;
height: 180rpx;
background-color: #fff;
padding: 0;
line-height: inherit;
margin: 0;
width: 100%;
font-weight: normal;
border-radius: none;
border: none;
}
.share-list button::after {
border: none !important;
padding: 0 !important;
margin: 0 !important;
}
.share-item {
min-width: 25%;
display: flex;
flex-direction: column;
justify-content: center;
align-items: center;
height: 180upx;
image {
width: 80upx;
height: 80upx;
margin-bottom: 16upx;
}
text {
font-size: $font-base;
color: $font-color-base;
}
}
</style>

@ -1108,6 +1108,13 @@
} }
}, },
{
"path": "classify/poster/poster",
"style": {
"navigationBarTitleText": "生成海报",
"enablePullDownRefresh": false
}
},
// { // {
// "path": "classify/goods-comment/goods-comment", // "path": "classify/goods-comment/goods-comment",
// "style": { // "style": {

@ -81,7 +81,7 @@
<view style="height: 48px;"> <view style="height: 48px;">
</view> </view>
</view> </view>
<wybPopup ref="popup" type="bottom" width="500" scrollY="true" radius="6" :showCloseIcon="true"> <wybPopup ref="popup" type="bottom" width="500" :scrollY="true" radius="6" :showCloseIcon="true">
<view class="fotct font18 fontwig6 fcor333 mart10 height30">赠送卡券</view> <view class="fotct font18 fontwig6 fcor333 mart10 height30">赠送卡券</view>
<view class="width92 height110 tccs mart10" v-for="product in goodsData[0].handselCouponList" <view class="width92 height110 tccs mart10" v-for="product in goodsData[0].handselCouponList"
:key="product.id"> :key="product.id">

@ -4,7 +4,8 @@
<view class="swiper-box" v-if="goodsDetail.bannerImg"> <view class="swiper-box" v-if="goodsDetail.bannerImg">
<swiper circular="true" :autoplay="false" style="height: 288px;" @change="swiperChange"> <swiper circular="true" :autoplay="false" style="height: 288px;" @change="swiperChange">
<swiper-item class="fotct" v-for="(swiper,index) in goodsDetail.bannerImg" :key="index"> <swiper-item class="fotct" v-for="(swiper,index) in goodsDetail.bannerImg" :key="index">
<image mode="heightFix" style="height: 100%;" :src="swiper" @click="perImage(index,goodsDetail.bannerImg)"></image> <image mode="heightFix" style="height: 100%;" :src="swiper"
@click="perImage(index,goodsDetail.bannerImg)"></image>
</swiper-item> </swiper-item>
</swiper> </swiper>
<view class="indicator">{{currentSwiper+1}}/{{goodsDetail.bannerImg.length}}</view> <view class="indicator">{{currentSwiper+1}}/{{goodsDetail.bannerImg.length}}</view>
@ -63,7 +64,7 @@
<view class="font13 goods-desc-img br tc colorccc"> <view class="font13 goods-desc-img br tc colorccc">
商品详情 商品详情
</view> </view>
<view style="font-size: 0;" > <view style="font-size: 0;">
<image mode="widthFix" class="width100" v-for="(item,index) in goodsDetail.detailImg" :key="index" <image mode="widthFix" class="width100" v-for="(item,index) in goodsDetail.detailImg" :key="index"
:src="item" @click="perImage(index,goodsDetail.detailImg)"> :src="item" @click="perImage(index,goodsDetail.detailImg)">
</image> </image>
@ -82,14 +83,17 @@
<view class="h5_press_save" v-if="rightTopSrc" @click="rightTopSrc = ''">
<image :src="rightTopSrc" class="my_xing" mode="aspectFit"></image>
</view>
<ccShareMenu ref="share" :contentHeight="400" :shareList="shareList" @click="shareMenuClick"></ccShareMenu>
<!-- 选择类别 --> <!-- 选择类别 -->
<wybPopup ref="popup" zIndex="999" height="500" type="bottom" width="500" :scrollY="true" radius="6" :showCloseIcon="true"> <wybPopup ref="popup" zIndex="999" height="500" type="bottom" width="500" :scrollY="true" radius="6"
:showCloseIcon="true">
<cart-choose :goodsDetail="goodsDetail" :status="status" @refreshCartNum="refreshCartNum" <cart-choose :goodsDetail="goodsDetail" :status="status" @refreshCartNum="refreshCartNum"
:specificationList="specificationList" @close="close"></cart-choose> :specificationList="specificationList" @close="close"></cart-choose>
@ -149,7 +153,7 @@
import cartChoose from '@/components/cart-choose/cart-choose.vue' import cartChoose from '@/components/cart-choose/cart-choose.vue'
import uniGoodsNav from '@/components/uni-goods-nav/components/uni-goods-nav/uni-goods-nav.vue' import uniGoodsNav from '@/components/uni-goods-nav/components/uni-goods-nav/uni-goods-nav.vue'
import ccShareMenu from '@/components/cc-shareMenu/cc-shareMenu.vue'
import { import {
findGoodsDetailById, findGoodsDetailById,
@ -158,6 +162,8 @@
findGoodsSkuByGoodsId findGoodsSkuByGoodsId
} from '@/Utils/physicalObject.js'; } from '@/Utils/physicalObject.js';
const app = getApp(); const app = getApp();
export default { export default {
data() { data() {
return { return {
@ -183,7 +189,28 @@
text: '购物车', text: '购物车',
info: 0, info: 0,
color: "#646566" color: "#646566"
} },
{
icon: 'icon-y share',
text: '分享',
},
],
rightTopSrc:'',
shareList: [{
type: 1,
icon: '/physical-merchants/static/img/link.png',
text: '复制链接'
},
{
type: 2,
icon: '/physical-merchants/static/img/placard.png',
text: '生成海报'
},
{
type: 3,
icon: '/physical-merchants/static/img/share_wechat.png',
text: '分享给好友'
},
], ],
buttonGroup: [{ buttonGroup: [{
text: '加入购物车', text: '加入购物车',
@ -222,7 +249,7 @@
} }
return return
} }
}, },
onLoad(options) { onLoad(options) {
this.goodsId = options.goodsId; this.goodsId = options.goodsId;
@ -233,7 +260,8 @@
wybPopup, wybPopup,
cartChoose, cartChoose,
uniGoodsNav, uniGoodsNav,
noMore noMore,
ccShareMenu,
}, },
onShow() { onShow() {
this.refreshCartNum(); this.refreshCartNum();
@ -283,16 +311,18 @@
findGoodsDetailById(params).then(res => { findGoodsDetailById(params).then(res => {
setTimeout(()=>{ setTimeout(() => {
uni.hideLoading(); uni.hideLoading();
if (res.return_code == '000000') { if (res.return_code == '000000') {
this.goodsDetail = res.return_data; this.goodsDetail = res.return_data;
this.goodsDetail.bannerImg = res.return_data.bannerImg.split(",").map(temp => this this.goodsDetail.bannerImg = res.return_data.bannerImg.split(",").map(temp =>
this
.imageUrl + temp); .imageUrl + temp);
this.goodsDetail.detailImg = res.return_data.detailImg.split(",").map(temp => this this.goodsDetail.detailImg = res.return_data.detailImg.split(",").map(temp =>
this
.imageUrl + temp); .imageUrl + temp);
// console.log(this.goodsDetail, ) // console.log(this.goodsDetail, )
@ -306,7 +336,7 @@
}) })
} }
},100) }, 100)
}) })
@ -351,6 +381,72 @@
// }) // })
}, },
//
shareMenuClick(item) {
let currentRoutes = getCurrentPages(); //
let route = currentRoutes[currentRoutes.length - 1];
let str = app.globalData.h5url + '?accountId=0000016&key=&code=' + decodeURIComponent(route.$page
.fullPath);
if (item.type == 1) {
/* 复制链接*/
this.copyText(str);
} else if (item.type == 2) {
/* 生成海报*/
let obj = {
priceShop: '¥' + this.goodsDetail.originalPrice, //
headImgs: this.goodsDetail.bannerImg,
goodsName: this.goodsDetail.name,
goodsPrice: '¥' + this.goodsDetail.price, //
goLink: str,
recommendCodeGoods: '', //
}
// console.log(obj,"obj");
uni.navigateTo({
url: "/physical-merchants/classify/poster/poster?obj=" + encodeURIComponent(JSON.stringify(
obj))
})
} else if (item.type == 3) {
/* 分享给好友 */
// #ifdef H5
console.log("点击了分享好友")
this.rightTopSrc="../../static/img/rightTop.png"
setTimeout(()=>{
this.rightTopSrc = ""
},3000)
// #endif
}
},
//
copyText(text) {
// #ifdef H5
this.$copyText(text).then(
res => {
uni.showToast({
title: '复制成功'
})
}
)
// #endif
// #ifndef H5
uni.setClipboardData({
data: text,
success: () => {
uni.showToast({
title: '复制成功'
})
}
})
// #endif
},
// //
onClick(e) { onClick(e) {
@ -365,6 +461,16 @@
return return
} }
if (e.index == 1) {
console.log("点击分享")
this.$refs.share.toggleMask();
return
}
// //
// if(e.index == 1){ // if(e.index == 1){
// this.isShowCang = !this.isShowCang; // this.isShowCang = !this.isShowCang;
@ -469,6 +575,51 @@
</script> </script>
<style lang="scss" scoped> <style lang="scss" scoped>
.h5_press_save {
background-color: #000;
opacity: 0.5;
position: fixed;
top: 0;
left: 0;
width: 100%;
height: 100%;
display: flex;
align-items: center;
z-index: 100;
image {
width:80px;
height: 80px;
object-fit: contain;
position:absolute;
top: 100px;
right: 60px;
}
}
@keyframes xing {
0% {
transform: scale(1);
}
25% {
transform: scale(1.4);
}
50% {
transform: scale(1);
}
75% {
transform: scale(1.4);
}
}
.my_xing {
-webkit-animation-name: xing;
-webkit-animation-timing-function: ease-in-out;
-webkit-animation-iteration-count: infinite;
-webkit-animation-duration: 2s;
}
// uni-goods-nav // uni-goods-nav
@ -603,9 +754,9 @@
// //
&.baozhang-detail { &.baozhang-detail {
padding:30px 10px 10px; padding: 30px 10px 10px;
box-sizing: border-box; box-sizing: border-box;
height:calc(100% - 100rpx); height: calc(100% - 100rpx);
.baozhangTitle {} .baozhangTitle {}

@ -0,0 +1,693 @@
<template>
<view>
<canvas canvas-id="poster" class="poster_canvas"></canvas>
<canvas canvas-id="qrImg" class="poster_qr"></canvas>
<swiper v-if="dataInfo.recommendCodeGoods" class="poster_swiper" previous-margin="110rpx" :current="swiperIndex"
next-margin="110rpx" @change="onSwiperChange">
<swiper-item v-for="(item, index) of dataInfo.headImgs" :key="index">
<view class="goods_info_box" :class="{ active: swiperIndex == index }">
<image class="goods_image" :src="item" mode="aspectFit"></image>
<view class="goods_info">
<view class="goods_name">{{dataInfo.goodsName}}</view>
<view class="price_box">
<view class="price">{{dataInfo.goodsPrice}}</view>
<view class="store_price">{{dataInfo.priceShop}}</view>
</view>
<view class="poster_info">
<view class="info">
<view>长按识别二维码访问</view>
<text>{{platformName}}</text>
</view>
<image class="poster_code_image" :src="dataInfo.recommendCodeGoods" mode="aspectFit">
</image>
</view>
</view>
</view>
</swiper-item>
</swiper>
<view class="share_save_box" v-if="dataInfo.recommendCodeGoods">
<view class="b-con" @click="onSaveImg">
<!-- <button class="onSave" > -->
<image src="/physical-merchants/static/img/ic_weixin.png" mode="aspectFit"></image>
<text class="mart5">保存图片</text>
<!-- </button> -->
</view>
</view>
<!-- #ifdef H5 -->
<!-- -->
<view class="h5_press_save" v-if="h5SaveImg" @click="h5SaveImg = ''">
<image :src="h5SaveImg" mode="widthFix"></image>
<button class="download">长按图片保存图片</button>
</view>
<!-- #endif -->
</view>
</template>
<script>
const qrCode = require('./weapp-qrcode.js');
export default {
data() {
return {
swiperIndex: 0,
posterImgs: [],
dataInfo: {
// priceShop: "¥699.0", //
// headImgs: [
// "http://qn.kemean.cn/file/upload/202005/21/1590043402088i2jxb79n.jpg?imageView2/0/w/800",
// "http://qn.kemean.cn/file/upload/202005/21/1590043404759qml3zmlm.jpg?imageView2/0/w/800",
// ],
// goodsName: "50ml",
// goodsPrice: "¥299.0", //
recommendCodeGoods: "", //
},
platformName: "嗨森逛",
h5SaveImg: "",
settingWritePhotosAlbum: false
};
},
//
onLoad(e) {
if (e.obj) {
this.dataInfo = JSON.parse(decodeURIComponent(e.obj));
}
},
mounted() {
this.couponQrCode()
},
//
methods: {
//
onSwiperChange(e) {
this.swiperIndex = e.detail.current;
},
async couponQrCode() {
uni.showLoading({
title: '加载中...'
});
var that = this;
/* if (this.quality == 'L') {
this.level = qrCode.CorrectLevel.L
} else if (this.quality == 'M') {
this.level = qrCode.CorrectLevel.M
} else if (this.quality == 'Q') {
this.level = qrCode.CorrectLevel.Q
} else if (this.quality == 'H') {
this.level = qrCode.CorrectLevel.H
} else {
this.level = qrCode.CorrectLevel.L
} */
console.log(that.dataInfo, " that.dataInfo")
let qrcode = await new qrCode('qrImg', {
text: that.dataInfo.goLink,
width: 100,
height: 100,
showLoading: true, // loading
loadingText: '二维码生成中', // loading
colorDark: '#000000', //
colorLight: '#ffffff', //
correctLevel: qrCode.CorrectLevel.L, //L/M/Q/H
// usingIn: this //this
})
//
uni.canvasToTempFilePath({
canvasId: 'qrImg',
success: (res) => {
uni.hideLoading()
// H5tempFilePath base64
// console.log('yz-qr:', res)
this.dataInfo.recommendCodeGoods = res.tempFilePath;
qrcode = null;
/* uni.getFileSystemManager().readFile({
filePath: res.tempFilePath, //
encoding: 'base64', //
success: res => {
//
let base64 = 'data:image/jpeg;base64,' + res.data;
this.dataInfo.recommendCodeGoods = base64;
}
}); */
},
fail: (err) => {
uni.hideLoading();
qrcode = null;
console.log(err)
}
}, this);
// console.log('');
},
//
createPoster() {
let that = this;
return new Promise((resolve, reject) => {
uni.showLoading({
title: '海报生成中'
});
const ctx = uni.createCanvasContext('poster');
ctx.fillRect(0, 0, 375, 673);
ctx.setFillStyle("#FFF");
ctx.fillRect(0, 0, 375, 673);
uni.downloadFile({
url: this.dataInfo.headImgs[this.swiperIndex],
success: (res) => {
if (res.statusCode === 200) {
ctx.drawImage(res.tempFilePath, 0, 0, 375, 375);
if (res.statusCode === 200) {
//
ctx.setFontSize(21);
ctx.setFillStyle('#333');
let drawtextList = that.drawtext(this.dataInfo
.goodsName, 341);
let textTop = 0;
drawtextList.forEach((item, index) => {
if (index < 2) {
textTop = 380 + (index + 1) *
28;
ctx.fillText(item.content, 17,
textTop);
}
});
//
ctx.setFontSize(26);
ctx.setFillStyle('#f00');
ctx.fillText(this.dataInfo.goodsPrice, 17,
textTop + 47);
//
ctx.setFontSize(18);
ctx.setFillStyle('#999');
let textLeft = 38 + (this.dataInfo.goodsPrice
.length * 13)
ctx.fillText(this.dataInfo.priceShop, textLeft,
textTop + 45);
// 线
ctx.beginPath();
ctx.setLineWidth(1);
ctx.moveTo(textLeft - 1, textTop + 38);
ctx.lineTo((textLeft + 5 + this.dataInfo
.priceShop.length * 9), textTop +
38);
ctx.setStrokeStyle('#999');
ctx.stroke();
// 线
ctx.beginPath();
ctx.setLineWidth(1);
ctx.moveTo(17, textTop + 70);
ctx.lineTo(358, textTop + 70);
ctx.setStrokeStyle('#eee');
ctx.stroke();
// 访
ctx.setFontSize(19);
ctx.setFillStyle('#333');
ctx.fillText("长按识别二维码访问", 17, textTop + 136);
//
ctx.setFontSize(16);
ctx.setFillStyle('#999');
ctx.fillText(this.platformName, 17, textTop +
170);
//
ctx.drawImage(this.dataInfo.recommendCodeGoods, 238, textTop +
88, 120, 120);
ctx.draw(true, () => {
// canvas
uni.canvasToTempFilePath({
canvasId: 'poster',
width: 375,
height: 673,
success: (res) => {
/* if (this.posterImgs[this.swiperIndex]){
this.posterImgs[this.swiperIndex].temporary=res.tempFilePath;
} else {
this.posterImgs[this.swiperIndex] = {temporary: res.tempFilePath};
} */
// console.log(
// ""
// );
resolve(res
.tempFilePath
);
},
fail: () => {
uni.hideLoading();
reject();
}
})
});
} else {
uni.hideLoading();
uni.showToast({
title: '海报制作失败,图片下载失败',
icon: 'none'
});
}
} else {
uni.hideLoading();
uni.showToast({
title: '海报制作失败,图片下载失败',
icon: 'none'
});
}
},
fail: err => {
console.log(err, "err")
uni.hideLoading();
uni.showToast({
title: '海报制作失败,图片下载失败',
icon: 'none'
});
}
});
});
},
//
async onSaveImg() {
let imgUrl = await this.createPoster();
/* if (this.posterImgs[this.swiperIndex] && this.posterImgs[this.swiperIndex].temporary) {
imgUrl = await this.posterImgs[this.swiperIndex].temporary;
} else {
imgUrl = await this.createPoster();
} */
// console.log(imgUrl, "imgUrl")
// #ifdef H5
this.h5SaveImg = imgUrl;
uni.hideLoading();
// #endif
// #ifdef MP-WEIXIN
uni.showLoading({
title: '海报下载中'
});
// if (this.settingWritePhotosAlbum) {
uni.getSetting({
success: res => {
if (res.authSetting['scope.writePhotosAlbum']) {
uni.saveImageToPhotosAlbum({
filePath: imgUrl,
success: () => {
uni.hideLoading();
uni.showToast({
title: '保存成功'
});
},
fail() {
uni.hideLoading();
}
});
} else {
uni.showModal({
title: '提示',
content: '请先在设置页面打开“保存相册”使用权限',
confirmText: '去设置',
cancelText: '算了',
success: data => {
if (data.confirm) {
uni.openSetting();
}
uni.hideLoading();
},
fail() {
uni.hideLoading();
}
});
}
},
fail() {
uni.hideLoading();
}
});
// } else {
// this.settingWritePhotosAlbum = true;
// uni.authorize({
// scope: 'scope.writePhotosAlbum',
// success: () => {
// uni.saveImageToPhotosAlbum({
// filePath: imgUrl,
// success: () => {
// uni.hideLoading();
// uni.showToast({
// title: ''
// });
// },
// fail(){
// uni.hideLoading();
// }
// });
// },
// fail(){
// uni.hideLoading();
// }
// });
// }
// #endif
},
//
drawtext(text, maxWidth) {
let textArr = text.split("");
let len = textArr.length;
//
let previousNode = 0;
//
let nodeWidth = 0;
//
let rowText = [];
//
let letterWidth = 0;
//
let chineseWidth = 21;
// otherFont
let otherWidth = 10.5;
for (let i = 0; i < len; i++) {
if (/[\u4e00-\u9fa5]|[\uFE30-\uFFA0]/g.test(textArr[i])) {
if (letterWidth > 0) {
if (nodeWidth + chineseWidth + letterWidth * otherWidth > maxWidth) {
rowText.push({
type: "text",
content: text.substring(previousNode, i)
});
previousNode = i;
nodeWidth = chineseWidth;
letterWidth = 0;
} else {
nodeWidth += chineseWidth + letterWidth * otherWidth;
letterWidth = 0;
}
} else {
if (nodeWidth + chineseWidth > maxWidth) {
rowText.push({
type: "text",
content: text.substring(previousNode, i)
});
previousNode = i;
nodeWidth = chineseWidth;
} else {
nodeWidth += chineseWidth;
}
}
} else {
if (/\n/g.test(textArr[i])) {
rowText.push({
type: "break",
content: text.substring(previousNode, i)
});
previousNode = i + 1;
nodeWidth = 0;
letterWidth = 0;
} else if (textArr[i] == "\\" && textArr[i + 1] == "n") {
rowText.push({
type: "break",
content: text.substring(previousNode, i)
});
previousNode = i + 2;
nodeWidth = 0;
letterWidth = 0;
} else if (/[a-zA-Z0-9]/g.test(textArr[i])) {
letterWidth += 1;
if (nodeWidth + letterWidth * otherWidth > maxWidth) {
rowText.push({
type: "text",
content: text.substring(previousNode, i + 1 - letterWidth)
});
previousNode = i + 1 - letterWidth;
nodeWidth = letterWidth * otherWidth;
letterWidth = 0;
}
} else {
if (nodeWidth + otherWidth > maxWidth) {
rowText.push({
type: "text",
content: text.substring(previousNode, i)
});
previousNode = i;
nodeWidth = otherWidth;
} else {
nodeWidth += otherWidth;
}
}
}
}
if (previousNode < len) {
rowText.push({
type: "text",
content: text.substring(previousNode, len)
});
}
return rowText;
},
savePic(Url) {
Url = this.dialogImgUrl //
var triggerEvent = "touchstart"; //
var blob = new Blob([''], {
type: 'application/octet-stream'
}); //blob
var url = URL.createObjectURL(blob); //
var a = document.createElement('a'); // a
a.href = Url; //ahref
//a.download,使
a.download = Url.replace(/(.*\/)*([^.]+.*)/ig, "$2").split("?")[0];
/* var e = document.createEvent('MouseEvents'); //创建事件MouseEvents鼠标事件
e.initMouseEvent('click', true, false, window, 0, 0, 0, 0, 0, false, false, false, false, 0, null); //initMouseEvent*/
// https://developer.mozilla.org/en-US/docs/Web/API/MouseEvent/MouseEvent
var e = new MouseEvent('click', (true, false, window, 0, 0, 0, 0, 0, false, false, false, false, 0, null));
//
a.dispatchEvent(e);
//createObjectURLrevokeObjectURL
URL.revokeObjectURL(url);
/*
//
var imgs = document.getElementsByTagName("img");
for(var i = 0,o;o = imgs[i];i++){
o.addEventListener(triggerEvent,function(){
var newurl = this.getAttribute("src");
saveAs(newurl);
},false);
} */
},
},
//
// onShareAppMessage(e) {
// let dataInfo = this.dataInfo;
// let shareInfo = {
// path: "/pages/home/shop/goodsDetail?objId="+dataInfo.objId,
// title: dataInfo.share.shareTitle,
// imageUrl: dataInfo.share.shareImg
// };
// if(this.userInfo.token){
// shareInfo.path += "&recommendCode=" + this.userInfo.uid;
// }
// return shareInfo;
// }
};
</script>
<style lang="scss" scoped>
//
@mixin bis($url, $size: cover) {
background-image: url($url);
background-repeat: no-repeat;
background-position: center center;
background-size: $size;
}
//
@mixin bov($num: 2) {
overflow: hidden;
text-overflow: ellipsis;
display: -webkit-box;
-webkit-line-clamp: $num;
-webkit-box-orient: vertical;
}
.poster_qr {
width: 100px;
height: 100px;
position: absolute;
top: -999px;
left: -999px;
}
.poster_page {
min-height: 100vh;
background-color: #f5f5f5;
display: flex;
align-items: center;
}
.poster_canvas {
width: 750rpx;
height: 1334rpx;
position: fixed;
top: -10000rpx;
left: 0rpx;
}
.poster_swiper {
height: 950rpx;
width: 100%;
swiper-item {
box-sizing: border-box;
display: flex;
align-items: center;
.goods_info_box {
width: 100%;
height: 100%;
transform: scale(0.88);
transition: all 0.4s;
position: relative;
overflow: hidden;
background-color: #FFFFFF;
&.active {
transform: scale(1);
}
.goods_image {
width: 100%;
height: calc(100vw - 220rpx);
}
.goods_info {
padding: 24rpx;
.goods_name {
color: #333;
font-size: 30rpx;
// @include bov(2);
}
.price_box {
margin-top: 24rpx;
display: flex;
align-items: center;
.price {
font-size: 38rpx;
color: red;
}
.store_price {
margin-left: 30rpx;
font-size: 26rpx;
color: #999;
text-decoration: line-through;
}
}
.poster_info {
border-top: 2rpx solid #f1f1f1;
padding-top: 24rpx;
margin-top: 24rpx;
display: flex;
align-items: center;
justify-content: space-between;
.info {
display: flex;
flex-direction: column;
view {
color: #333;
font-size: 28rpx;
}
text {
color: #999;
font-size: 24rpx;
margin-top: 20rpx;
}
}
.poster_code_image {
width: 170upx;
height: 170upx;
flex-shrink: 0;
}
}
}
}
}
}
.share_save_box {
position: fixed;
// bottom: calc((100vh - 950rpx - 240rpx) / 4);
bottom: 10px;
left: 0;
z-index: 6;
width: 100%;
display: flex;
justify-content: space-around;
.b-con {
display: flex;
flex-direction: column;
align-items: center;
background-color: transparent;
image {
width: 60rpx;
height: 60rpx;
}
text {
font-size: 24rpx;
color: #333333;
}
}
}
.h5_press_save {
background-color: #000;
position: fixed;
top: 0;
left: 0;
width: 100%;
height: 100%;
display: flex;
align-items: center;
z-index: 100;
image {
width: 100%;
}
.download {
font-size: 24rpx;
color: #ffffff;
background-color: rgba(0, 0, 0, 0.5);
display: flex;
align-items: center;
flex-direction: row;
justify-content: center;
position: absolute;
padding: 5rpx 30rpx;
border-radius: 40rpx;
bottom: 30rpx;
left: 50%;
transform: translateX(-50%);
&:before {
content: '';
@include bis('../../static/img/icon_download.png');
width: 24rpx;
height: 24rpx;
margin-right: 15rpx;
}
}
}
</style>

File diff suppressed because it is too large Load Diff

Binary file not shown.

After

Width:  |  Height:  |  Size: 2.2 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.1 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 2.6 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 3.0 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 4.6 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 11 KiB

@ -84,3 +84,27 @@
} }
@font-face {
font-family: 'iconf';
src: url('data:font/woff2;charset=utf-8;base64,d09GMgABAAAAAALgAA0AAAAABsgAAAKLAAEAAAAAAAAAAAAAAAAAAAAAAAAAAAAAP0ZGVE0cGh4GYACCQhEICoE0gUoLCgABNgIkAxAEIAWFAgczG+wFEZWbI8l+Jth03Bb6pBpE8ZhEKpuUPnWnZ66pxmLSb+Lhaaz2/sys6J2nw7yRzZpLkgT14l7EJIqHSrNKIolIhbz37dfmXRLL18S0HRaK2ux+k1nMEjQvidCoVB7pJJH/+ioB8D+X41vi8/sNlzkBD4+PmnaWjgkUWNbLo7mfT7AssALzgKhBd0vQ1WXNhYDn97J1wKcH3/OXDrQxjiRkWShIKEVcVCGdSr9cAK+Pv0vDS1LJ+JwtRxdP4MmPAeyJcq/fk9/1EACYKZCRMSHAMllgQjETRRH8GOjT/uuJ/hNAVAlAJCQAQICvJPoggQLqSFiBfYACgDR74up+Mmm2T7+YRb75ct5qRfO0jyP1nk9bnTNxRHM/Fu2YSCS0pnbPFwi0ro7uyK9/PbQrt/rZOvKTz44XsjmeH1PxOM+9HskcmH8oTrX2NBvrLd6CJUjGnXXPsR4LETtxKY1wOMSRdFkwu3vt7e32Xtc00k0h/oV4WnkWxHxxE0AgeLb2b7gfWfa/3ioa7Hin5TyZC+oSCBpZvwMF5EmiDJTCFKNwWvyqFRJIaGqiDzDsgwCMWChAqNskQFJzTICsbkqAou6aABUtDwWoqnsrQNOSGAnQMhIvsigNzIeCMGgZJF27IRt0EinEaagYdx+qBj2Fpl2+LdAyPyRrGQ4eEp7Eji54sXxsGqyJ4OhcGcKUIbYCZDDDR8I25EI7dOCHtKzps0PiXei4cnmsXqnB2qr7eqWWF9nY20Cnjtu4p7xBxGLMMfXYUhmfQE0zY5ZjKnhMFTiWT7unvEHEVmPKHVRlSWT81vs+gONE1qBaZRWXV45NHZbKPsutjDbmYFaNJp4UIsOw8HgZGufyocEBAA==') format('woff2'),
url('data:font/woff;charset=utf-8;base64,d09GRgABAAAAAASoAA0AAAAABsgAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAABGRlRNAAAEjAAAABoAAAAclxGc/UdERUYAAARsAAAAHgAAAB4AKQAKT1MvMgAAAaAAAABGAAAAYDxESN5jbWFwAAAB+AAAAD4AAAFCAA/pumdhc3AAAARkAAAACAAAAAj//wADZ2x5ZgAAAkQAAACyAAAAtLVlW59oZWFkAAABMAAAAC8AAAA2JI25+GhoZWEAAAFgAAAAHQAAACQHVgOFaG10eAAAAegAAAAPAAAAEAwAAIpsb2NhAAACOAAAAAoAAAAKAFoAAG1heHAAAAGAAAAAHgAAACABEABKbmFtZQAAAvgAAAFGAAACgl6CAQJwb3N0AAAEQAAAACEAAAAzx+/n0njaY2BkYGAA4vvOJ/3j+W2+MnCzMIDAg227fsHpLgZm5gpmkAQHAxNIFABYLwuYAHjaY2BkYGBu+N/AEMPCAALMFQyMDKiABQBP3gLkAAAAeNpjYGRgYGBhsGNgYgABEMkFhAwM/8F8BgAO8gFbAAB42mNgYWFgnMDAysDA1Ml0hoGBoR9CM75mMGLkAIoysDIzYAUBaa4pDAee8T/jZ27438DAwHyHAUgyMCIpUWBgBABmJAydAAB42mNhgAAWCO4CAAEKAJcAeNpjYGBgZoBgGQZGBhCwAfIYwXwWBgUgzQKEQP4z/v//IaTkF6hKBkY2BhiTgZEJSDAxoAJGhmEPAEy2B68AAAAAAAAAAAAAAFoAAHjaY2Bi6GJgZq5gZmFQZLBlYFAV4WNUVlTSYzQVtGOyZjRVVuJjFBUUkWM0VjSyY7RlVBZWVmJnY2cTNTYxNzM3s2Zk42cUNzcz0WdkFxdjdtNw1fg3U9NFk1HDRbOx0STS2DjShDHdJMJYiymvKjPNxlbLwiwmPj+PmaVMrkxSEkiwHNZ00QCqZkwH0tomESb/ZgIJIGpiVLS1Scusyo+PMbNgA6v3kCoFamAAAD/SI/oAAHjafZDNSsNAFIXP9E9tQcSC61kVQUh/lqW7Qt25cFHXbTpJW5JMmEwLXbp15QO49TF8AJ9BcOWDeBqvCBWakMs3595zZiYALvEJhZ+njWthhVPcCVdwgli4Sv1RuEZ+Ea6jhTfhBvUP4SZu1Ei4hbZ6ZoKqnXHVKdP2rHCBkXAF53gQrlK3wjXyk3AdV3gVblB/F25iii/hFjpqiTEcDGbwrAtozLFjXSFkboaorB4YOzPzZqHnO70KbRbZjOK/qb/WPeNibJAw2nFp4k0yc0ctR1pTpjkUHNm3NPoI0KNsXLGyme4HvaP2W9qzMuLwngW2POaAqqdR83O0p6SJxBheISFr5GVvTSWkHjDWZMb9/pViGw+8j3TkbKon3NYkidW5s2sTeg4vyz1yDNHlGx2kB+XhU455nw+73UgCgtCm+AYPanCHAAB42mNgYoAALjDJyIAOWMCiTIxMHGmpeRWZiXnpABIdA3AAAAAAAAAB//8AAgABAAAADAAAABYAAAACAAEAAwADAAEABAAAAAIAAAAAeNpjYGBgZACCq0vUOUD0g227fsFoAEq7CD4AAA==') format('woff'),
// url('iconfont.ttf') format('truetype')
;
font-weight: normal;
font-style: normal;
font-display: swap;
}
.icon-y{
font-family: 'iconf' !important;
font-size: 40upx;
font-style: normal;
color: #646566;
&.share:before {
// &#xe60f;
content: '\e60f';
}
}
Loading…
Cancel
Save