微信小程序 分享海报
const app = getApp();
const template = require('../../template/templates.js');
Page({
/**
* 页面的初始数据
*/
data: {
hidden: true,
dataList: {
img_bg: '../../img/share_picture/shareListPicbg1.jpg',
title: '',
img: '',
qrCodeUrl: '',
plusPrice: null, //PLUS价格
faceValue: null, //代金券面值 },
referrerVOid: null,
saveImgBtnHidden: false,
openSettingBtnHidden: true,
referrerVOidShow: ""
},
getVouchersId: function(vouchersId) {
wx.request({
url: app.data.urls + 'vouchers/detail/id',
data: vouchersId,
method: "POST",
header: {
'content-type': 'application/json' // 默认值
},
success: (res) => {
console.log(res)
let dataList = this.data.dataList,
data = {
status: 1,
customerId: app.data.customerId,
type: 1
}
dataList.name = res.data.data.restaurant.name;
if (dataList.name.length > 10) {
dataList.name = `${dataList.name.substr(0, 9)}...`;
}
let payMoney = res.data.data.deductionPrice / 100,
useDiscountPrice = res.data.data.useDiscountPrice / 100;
//plus价格
let price = res.data.data.vipcardPrice / 100;
//地址 和电话
let address = res.data.data.restaurant.address;
let moblie = `电话:${res.data.data.restaurant.moblie}`;
dataList.address = address
dataList.moblie = moblie dataList.content = `立省${payMoney - price}元`;
dataList.originalCost = `原价:${payMoney}元`;
dataList.realPrice = `${price}元`;
dataList.useDiscountPrice = `( 消费满${useDiscountPrice}元可用 )`;
dataList.deductionPriceShow = `${payMoney}元代金券`;
template.getDistributorMsg(data, res => {
console.log(res)
this.setData({
plusPrice: price,
faceValue: payMoney,
referrerVOidShow: res.data.data.referrerVO.id,
// referrerVOid: res.data.data.referrerVO.id
})
this.referrerGenQRCode(vouchersId, res.data.data.referrerVO.id, res => {
// 获取店铺或者二维码
console.log(res)
let qrCodeUrl = `https://www.yooeepoint.com.cn${res.data.localQrCodeUrl}`; // 小程序二维码
let img = `https://www.yooeepoint.com.cn${res.data.localTitleImageUrl}` // 店铺图片
//背景图片
let vouchers_background = 'https://www.yooeepoint.com.cn/images/vouchers_background.png' this.downLoadImage(qrCodeUrl, res => { // 网络图片下载本地(canvas限制图片使用本地路径)
dataList.qrCodeUrl = res.tempFilePath;
this.downLoadImage(img, res => {
dataList.img = res.tempFilePath;
this.downLoadImage(vouchers_background, res => {
dataList.vouchers_background = res.tempFilePath; //背景图片
this.getSystemInfo(res => {
dataList.windowWidth = res.windowWidth
dataList.windowHeight = res.windowHeight
this.creatCanvas(dataList);
}) }) })
}) })
})
}
})
},
// 绘制分享图片
creatCanvas: function(data) { const ctx = wx.createCanvasContext('shareImg');
//背景图
// ctx.setFillStyle('#fff')
// ctx.fillRect(0, 0, data.windowWidth, data.windowHeight * 0.78)
ctx.drawImage(data.vouchers_background, 0, 0, data.windowWidth, data.windowHeight);
//banner图
//banner图
ctx.drawImage(data.img, 0, 10, data.windowWidth, data.windowHeight * 0.315);
//店铺名称
ctx.setFontSize(data.windowWidth / (750 / 35));
ctx.setTextAlign('center');
ctx.setFillStyle('#000000');
ctx.fillText(data.name, data.windowWidth / 2, data.windowHeight * 0.39 + 6);
//多少元代金券
ctx.setFontSize(data.windowWidth / (750 / 30));
ctx.setTextAlign('center');
ctx.setFillStyle('#000000');
ctx.fillText(data.deductionPriceShow, data.windowWidth / 2, data.windowHeight * 0.39 + 30); // 满减条件
ctx.setFillStyle('#000000');
ctx.setFontSize(data.windowWidth / (750 / 25));
ctx.fillText(data.useDiscountPrice, data.windowWidth / 2, data.windowHeight * 0.39 + 45); //原价
ctx.setFontSize(data.windowWidth / (750 / 22));
ctx.setFillStyle('#666666');
ctx.fillText(data.originalCost, data.windowWidth / 2 + 120, data.windowHeight * 0.50); // 立省
ctx.setFillStyle('#f10c0c');
ctx.setFontSize(data.windowWidth / (750 / 22));
ctx.fillText(data.content, data.windowWidth / 2 + 120, data.windowHeight * 0.50+ 15); // plus价
ctx.setFontSize(data.windowWidth / (750 / 55));
ctx.setFillStyle('#f10c0c');
ctx.fillText(data.realPrice, data.windowWidth / 2, data.windowHeight * 0.60-15 ); // 地址和电话
ctx.setFontSize(data.windowWidth / (750 / 25));
ctx.setFillStyle('#323232');
ctx.fillText(data.address, data.windowWidth / 2, data.windowHeight *0.60+15); ctx.setFontSize(data.windowWidth / (750 / 20));
ctx.setFillStyle('#323232');
ctx.fillText(data.moblie, data.windowWidth / 2, data.windowHeight *0.60+35); // 二维码图
ctx.drawImage(data.qrCodeUrl, data.windowWidth * 0.38-2, data.windowHeight * 0.73, data.windowWidth * 0.25, data.windowWidth * 0.25); // tip
ctx.setTextAlign('center');
ctx.setFillStyle('#fff');
ctx.setFontSize(data.windowWidth / (750 / 22));
ctx.fillText("长按识别图中小程序码购买", data.windowWidth / 2, data.windowHeight * 0.95); // tip
ctx.setTextAlign('center');
ctx.setFillStyle('#fff');
ctx.setFontSize(data.windowWidth / (750 / 18));
ctx.fillText("想要吃点喝点,首选搜城天下", data.windowWidth / 2, data.windowHeight * 0.97); //
// ctx.setTextAlign('right');
// ctx.setFillStyle('#282828');
// ctx.setFontSize(data.windowWidth / (750 / 22));
// ctx.fillText("长按识别二维码", data.windowWidth * 0.89, data.windowHeight * 0.60 + 35);
//结束绘制/展示
ctx.stroke();
ctx.draw(false, () => {
this.toShare();
});
}, // 获取二维码/店铺图片
referrerGenQRCode: function(vouchersId, referrerId, successCallBack) {
let data = {
referrerId: referrerId,
serviceType: 3,
vouchersId: vouchersId
}
wx.request({
url: app.data.urls + `html5/toShareImagePage`,
data: data,
method: 'POST',
success: (res) => {
successCallBack(res)
}
})
},
/**
* 生命周期函数--监听页面加载
*/
onLoad: function(options) {
wx.showLoading({
title: '加载中',
mask: true
});
console.log(options) this.getVouchersId(options.vouchersId)
console.log(options.referrerId)
this.setData({
vouchersId: options.vouchersId,
referrerVOid: options.referrerId,
partnersId: options.partnersId,
isFreeObtain: options.isFreeObtain,
restaurantId: options.restaurantId
})
console.log(this.data.referrerVOid)
// 初始化数据
}, // 动态设置画布宽高
getSystemInfo: function(successCallBack) {
wx.getSystemInfo({
success: (res) => {
successCallBack(res)
}
})
}, // 网络图片下载本地(canvas限制图片使用本地路径)
downLoadImage: function(data, successCallBack) {
wx.downloadFile({
url: data,
success: function(res) {
successCallBack(res)
}
}) },
// 分享图片生成后展示
toShare: function() {
wx.canvasToTempFilePath({
x: 0,
y: 0,
canvasId: 'shareImg',
success: (res) => {
console.log(res)
wx.hideLoading();
this.setData({
prurl: res.tempFilePath,
hidden: false
})
}
})
},
// 分享图片保存到相册
savePic: function() {
let that = this
wx.getSetting({
success: res => {
if (!res.authSetting['scope.writePhotosAlbum']) { //用户同意授权
wx.authorize({
scope: 'scope.writePhotosAlbum',
success: () => {
this.saveImageToPhotosAlbum();
},
fail: () => { //这里是用户拒绝授权后的回调
that.setData({
saveImgBtnHidden: true,
openSettingBtnHidden: false
})
}
})
} else { //用户已经授权过
this.saveImageToPhotosAlbum();
}
}
})
},
saveImageToPhotosAlbum: function() {
wx.saveImageToPhotosAlbum({
filePath: this.data.prurl,
success(res) {
this.onShareAppMessage()
}
})
},
handleSetting: function(e) {
let that = this;
// 对用户的设置进行判断,如果没有授权,即使用户返回到保存页面,显示的也是“去授权”按钮;同意授权之后才显示保存按钮
if (!e.detail.authSetting['scope.writePhotosAlbum']) {
wx.showModal({
title: '提示',
content: '若不打开授权,则无法将图片保存在相册中!',
showCancel: false
})
that.setData({
saveImgBtnHidden: true,
openSettingBtnHidden: false
})
} else {
wx.showModal({
title: '提示',
content: '您已授权,赶紧将图片保存在相册中吧!',
showCancel: false
})
that.setData({
saveImgBtnHidden: false,
openSettingBtnHidden: true
})
}
},
/**
* 用户点击右上角分享
*/
onShareAppMessage: function() {
// return {
// title: '【搜城天下】' + this.data.dataList.name,
// path: '/pages/goinSharePic/goinSharePic?vouchersId=' + this.data.vouchersId + "&referrerVOid=" + this.data.referrerVOid,
// imageUrl: this.data.prurl
// }
console.log("kankan" + this.data.referrerVOidShow)
return {
title: '【' + this.data.plusPrice + '元抢购】' + this.data.faceValue + '元代金券',
path: '/pages/vouchersDetails/vouchersDetails?vouchersId=' + this.data.vouchersId + "&referrerId=" + this.data.referrerVOidShow + '&restaurantId=' + this.data.restaurantId + '&isFreeObtain=' + this.data.isFreeObtain + '&partnersId=' + this.data.partnersId,
imageUrl: this.data.prurl
} },
onReady: function() {
wx.hideLoading();
}
})

微信小程序 分享海报的更多相关文章
- 关于微信小程序分享/转发功能的实现方法
实现微信小程序分享,可以有两个入口: 1. 小程序右上角菜单自带的分享 这个入口是默认关闭的,需要在当前页面中调用showShareMenu方法,开启分享 onLoad: function () { ...
- golang-vue实现微信小程序分享到朋友圈
最近涉及到微信小程序分享到朋友圈,不知道微信为什么不直接接口分享,咱也不敢佛,咱也不敢问,只能百度问度娘,看官方文档,网上的一些分享五花八门,每一个重点的,所以整理了一下到底怎样生成二维码分享图片才是 ...
- 微信小程序分享转发用法大全——自定义分享、全局分享、组合分享
官方提供的自定义分享 使用隐式页面配置函数实现的全局分享-推荐 使用隐式路由实现的全局分享-不推荐,仅供了解隐式路由 前言: 目前微信小程序只开放了页面自定义分享的API,为了能够更灵活的进行分享配置 ...
- 微信小程序分享至朋友圈的方法
最近研究怎么实现微信小程序分享至朋友圈,对就是朋友圈. 微信小程序目前没有直接提供方法来将小程序分享至朋友圈,不过可以采用曲线救国的方式来达到目的. 方法分两步: 1.通过浏览器将希望分享的东西风向至 ...
- 微信小程序--分享功能
微信小程序--分享功能 微信小程序前段时间开放了小程序右上角的分享功能, 可以分享任意一个页面到好友或者群聊, 但是不能分享到朋友圈 这里有微信开发文档链接:点击跳转到微信分享功能API 入口方法: ...
- 微信小程序分享支持自定义封面图
微信小程序又发布更新了,刚好昨天支付宝也发布小程序,不能让它抢了风头的节奏.微信小程序主要更新如下:“小程序分享支持自定义封面图,公众号及小程序客服可发送小程序卡片.同时,我们还开放了获取发票抬头,指 ...
- 微信小程序--分享报错(thirdScriptError Cannot read property 'from' of undefined;at pages/index/index page onShareAppMessage function TypeError: Cannot read property 'from' of undefined)
分享功能: onShareAppMessage: function (res) { if (res.from === 'button') { // 来自页面内转发按钮 console.log(res. ...
- 微信小程序分享朋友圈的实现思路与解决办法
实现思路 那么既然小程序没有分享到朋友圈的api,我们怎么实现分享到朋友圈呢,下面我介绍一下实现思路. 既然没有捷径,那就走复杂一点的路线,那就是需要用户手动分享到朋友圈,问题又来了,用户手动分享的话 ...
- 微信小程序分享功能的path路径
表示被微信小程序坑惨了 糟心的开始写,老板说先不上太复杂,就先显示了两个页面,然后开开心心的发布,测试了几遍,没啥问题呀.结果,一上上去,就被老板批了! 啥呀! 这分享怎么这个鬼样子!明明我看文档都是 ...
随机推荐
- 路飞学城Python-Day29(第四模块-并发编程)
01-进程与程序的概念 并发:多进程和多线程 进程的概念:进程就是正在执行的过程,一个应用程序不是进程,只有应用程序启动以后才能说是进程,进程是一个抽象的概念,起源于操作系统 02-操作系统介绍 应用 ...
- 浅谈自底向上的Shell脚本编程及效率优化
作者:沐星晨 出处:http://blog.csdn.net/sosodream/article/details/6276758 浅谈自底向上的Shell脚本编程及效率优化 小论文,大家多批评指导:) ...
- 六、利用frp穿透连接内网的linx系统和windows系统
服务端的配置 # frps.ini [common] bind_port = 7000 说明:防火墙放行该端口 启动:./frps -c ./frps.ini 后台启动:nohup ./frps -c ...
- 一般树--common tree
参照libyang中的lyd_tree的组织结构,写了一套通用树接口. github 的地址:https://github.com/HellsingAshen/mytc/tree/master/tc_ ...
- PHP中的 Iterator 与 Generator
在讲解生成器之前先介绍一下迭代器: 在 PHP 中,通常情况下遍历数组使用 foreach 来遍历. 如果我们要想让一个对象可以遍历呢? PHP 为我们提供了 Iterator 接口,只要实现了这个接 ...
- python_购物车程序
#需求1.启动程序后,让用户输入工资,然后打印商品列表2.允许用户根据商品编号购买商品3.用户选择商品后,检测余额是否够,够就直接扣款,不够就提醒4.可随时退出,退出时,打印已购买商品和余额 #先定义 ...
- 小学生都能学会的python(运算符 和 while循环)
---恢复内容开始--- 小学生都能学会的python(运算符和编码) 一.格式化输出 #占位:"%s"占位,占得是字符串,"%d"占位,占的是数字. # 让用 ...
- IDEA Maven Web项目 clone到本地导入到Eclipse中,启动服务器的时候会出现这个错误:SEVERE: Exception starting filter [hiddenHttpMethodFilter]
背景(Background): 我将一个IDEA的maven web项目clone到本地,并导入到Eclipse中. I imported a MAVEN WEB project which was ...
- oracle 控制语句
PL输出语句 set serverout on; -- 开启PL的输出语句功能declare n number:=1; -- 声明一个number型的变量n,并赋值为1 v varchar2(20): ...
- Java基础学习总结(57)——Jrebel插件热部署
JavaEE开发环境下,Tomcat对热布署的支持还是比较弱,致使开发过程中浪费大量时间在重启服务上.胖先生讨厌来来回回的折腾,所以想看看有没有实时的编译,发现Jrebel的插件付费软件,它对热布署的 ...