1.关于json的基础知识
(1).JSON.parse(plus.runtime.arguments);获取第三方传递的参数,并转化为对象形式
(2).JSON.stringify(cmd)将对象转化为字符串
2.老虎机抽奖动画写法
(1).流程:获取有多少个奖品的照片,然后将三个展示的图片是第几个规定出来。使用 uni.createAnimation创建一个动画实例,动画实例.export()方法导出动画实例。
(2).代码事例
var that = this
//中奖索引
var hou = ''
for (var i = 0; i < that.getGamesInfo.awardlist.length; i++) {
if (that.getGamesInfo.awardlist[i].id == that.award.award_id) {
hou = i
}
}
let animation1 = uni.createAnimation({
duration: that.turn,
timingFunction: 'ease'
})
let infoLength = that.prizesInfo.length
//伪造中奖索引 0就是第一个
//奖品list的length - 中奖的索引
let jiangli = infoLength - hou - that.getGamesInfo.awardlist.length
let infoheight = (infoLength - jiangli) * Number(that.angle)
animation1.translateY(-infoheight + 'rpx').step()
let animation2 = uni.createAnimation({
duration: that.turn,
timingFunction: 'ease',
delay: 250
})
animation2.translateY(-infoheight + 'rpx').step()
let animation3 = uni.createAnimation({
duration: that.turn,
timingFunction: 'ease',
delay: 500
})
animation3.translateY(-infoheight + 'rpx').step()
that.animationData1 = animation1.export()
that.animationData2 = animation2.export()
that.animationData3 = animation3.export()
3.分享
使用uniapp官方文档的API
uni.share({
provider: "weixin",
scene: "WXSceneSession",
type: 2,
imageUrl: that.shareImgUrl,
success: function(res) {
console.log("success:" + JSON.stringify(res));
},
fail: function(err) {
console.log("fail:" + JSON.stringify(err));
}
});
4.保存图片
使用uniapp文档中的API
uni.showActionSheet({
itemList: ['保存到相册'],
success: res => {
if (res.tapIndex == 0) {
uni.showLoading({
title: '保存中...'
});
uni.downloadFile({
url: that.shareImgUrl, //网络路径,下载下来
success: res => {
console.log(res)
if (res.statusCode === 200) {
uni.saveImageToPhotosAlbum({
filePath: res
.tempFilePath, //下载后的临时路径
success: res => {
//下载完成后在相册里压根找不到
uni.hideLoading();
uni.showToast({
title: '保存成功!'
});
}
});
}
}
});
}
}
});
5.手动换行
在uniapp中<br>就够了
在小程序中最好是white-space:pre-wrap;和\n配合使用,效果最佳