记一次老虎机项目开发

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配合使用,效果最佳

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值