123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102 |
- // compontents/share/share.js
- Component({
- /**
- * 组件的属性列表
- * 分享弹窗 没怎么用
- */
- properties: {
- },
- /**
- * 组件的初始数据
- */
- data: {
- flag: true,
- postId: '',
- imgUrl: []
- },
- /**
- * 组件的方法列表
- */
- methods: {
- //隐藏分享框
- hidePopup: function () {
- this.setData({
- flag: !this.data.flag
- })
- },
- //展示分享框
- showPopup (postId, imgUrl) {
- this.setData({
- flag: !this.data.flag,
- postId,
- imgUrl
- })
- },
- //保存图片
- saveImage (e) {
- const imgUrl = this.data.imgUrl;
- //先绘制图片
- for (let item of imgUrl) {
- // wx.downloadFile({
- // url: item,
- // success: function (res) {
- // console.log(res);
- // }
- // })
- //canvas绘制文字和图片
- const ctx = wx.createCanvasContext('myCanvas');
- var imgPath = item;
- ctx.setFillStyle('white')
- //获取屏幕宽度
- const windowWidth = wx.getSystemInfoSync().windowWidth;
- ctx.fillRect(0, 0, windowWidth, 1.6 * windowWidth)
- ctx.drawImage(imgPath, 30, 10, 300, 100);
- ctx.setFontSize(18)
- ctx.setFillStyle('black')
- ctx.fillText('我画的图片', 50, 140)
- ctx.draw();
- }
- //canvas生成图片
- wx.canvasToTempFilePath({
- x: 0,
- y: 0,
- width: wx.getSystemInfoSync().windowWidth,
- height: 0.6 * wx.getSystemInfoSync().windowWidth,
- destWidth: wx.getSystemInfoSync().windowWidth,
- destHeight:0.6 * wx.getSystemInfoSync().windowWidth,
- canvasId: 'myCanvas',
- success: (res) => {
- console.log('canvas'+res.tempFilePath);
- //保存图片到本地
- wx.saveImageToPhotosAlbum({
- filePath: res.tempFilePath,
- success(res) {
- wx.showModal({
- title: '存图成功',
- content: '图片成功保存到相册了,去发朋友圈',
- showCancel:false,
- confirmText:'好哒',
- confirmColor:'#72B9C3',
- success: function(res) {
- if (res.confirm) {
- console.log('用户点击确定');
- }
- //that.hideShareImg()
- }
- })
- }
- })
- },
- fail:function (res) {
- console.log(res)
- }
- })
- }
- }
- })
|