slim php开发小程序,微信小程序-常用api

(标签)

wx.showToast({

title: '功能暂未开放!',

icon: 'none', success

duration: 2000

})

(选择窗)

wx.showModal({

title: '提示',

content: '这是一个模态弹窗',

success (res) {

if (res.confirm) {

console.log('用户点击确定')

} else if (res.cancel) {

console.log('用户点击取消')

}

}

})

(加载中)

wx.showLoading({

title: '加载中',

})

setTimeout(function () {

wx.hideLoading()

}, 2000)

3.分享

onLoad: function (options) {

this.getDate(options.id)

wx.showShareMenu({

// 要求小程序返回分享目标信息

withShareTicket: true

})

},

/* 转发*/

onShareAppMessage: function (ops) {

if (ops.from === 'button') {

// 来自页面内转发按钮

console.log(ops.target)

}

return {

title: '转发dom',

path: `pages/index/index`,

success: function (res) {

// 转发成功

console.log("转发成功:" + JSON.stringify(res));

var shareTickets = res.shareTickets;

},

fail: function (res) {

// 转发失败

console.log("转发失败:" + JSON.stringify(res));

}

}

}

4.生成canvas图片

var that = this;

var unit = that.data.screenWidth / 375

//2. canvas绘制文字和图片

const ctx = wx.createCanvasContext('share');

var bgImgPath = that.data.shareImgSrc;

ctx.drawImage(bgImgPath, 0, 0, 375, 375); //导入图片

ctx.setFontSize(20)

ctx.setFillStyle('#000')

ctx.fillText('生成文字在图片上', 20, 110)

ctx.stroke()

ctx.draw(false, function () {

// 3. canvas画布转成图片

wx.canvasToTempFilePath({

x: 0,

y: 0,

width: 375,

height: 375,

destWidth: 375,

destHeight: 375,

canvasId: 'share',

success: function (res) {

console.log(res);

that.setData({

shareImgSrc: res.tempFilePath

})

if (!res.tempFilePath) {

wx.showModal({

title: '提示',

content: '图片绘制中,请稍后重试',

showCancel: false

})

}

},

fail: function (res) {

console.log(res)

}

})

});

5.保存图片到相册

click: function () {

let that = this

wx.saveImageToPhotosAlbum({

filePath: that.data.shareImgSrc,

success(res) {

wx.showModal({

title: '图片保存成功',

content: '图片成功保存到相册了,去发圈噻~',

showCancel: false,

confirmText: '好哒',

confirmColor: '#72B9C3',

success: function (res) {

if (res.confirm) {

console.log('用户点击确定');

}

that.setData({

canvasHidden: true

})

}

})

}

})

}

6.数据缓存

wx.setStorageSync('key', 'value')

wx.getStorageSync('key')

7.返回上一页,刷新页面

onShow(){

this.onLoad()

}

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值