- 你使用的是哪个包(必填):
"name": "@lucky-canvas/uni",
"version": "0.0.10",
- 你当前插件的版本(必填):
hbuilderX引入的https://ext.dcloud.net.cn/plugin?id=3499
- 详细描述你的bug:
电脑编译器没有问题,移动端体验版偶尔进入页面点击抽奖无任何反应,也不报错
// 代码开始, 别再放歪了行吗
<!-- 九宫格抽奖 -->
<view>
<LuckyGrid ref="myLucky" width="695rpx" height="725rpx" :prizes="prizes" :blocks="blocks" :buttons="buttons"
@start="startCallback" @end="endCallback" />
</view>
<script>
import LuckyGrid from '@/components/@lucky-canvas/uni/lucky-grid'
import {licklist,getTurn,getNum,awardDetail}from '@/api/activity/luckgrid.js'
export default {
components: {
LuckyGrid
},
data() {
return {
background: {
backgroundColor: 'transparent',
},
bkImg: 'https://xht.jxqyl.site/xht/u/cjbk.png',
blocks: [{
padding: '20px',
imgs: [{
src: require('@/static/img/zpbk.png'),
width: '100%',
height: '100%'
}]
}],
prizes: [{
x: 0,
y: 0,
fonts: [{
text: '',
top: '70%',
fontColor: '#9E6600',
fontSize: '28rpx'
}],
imgs: [{
src: require('@/static/img/thanks.png'),
width: '50%',
top: '15%'
}],
background: '#FFF7BF',
borderRadius: '10rpx'
},
{
x: 1,
y: 0,
fonts: [{
text: '',
top: '70%',
fontColor: '#9E6600',
fontSize: '28rpx'
}],
imgs: [{
src: require('@/static/img/thanks.png'),
width: '50%',
top: '15%'
}],
background: '#FFF7BF',
borderRadius: '10rpx'
},
{
x: 2,
y: 0,
fonts: [{
text: '',
top: '70%',
fontColor: '#9E6600',
fontSize: '28rpx'
}],
imgs: [{
src: require('@/static/img/thanks.png'),
width: '50%',
top: '15%'
}],
background: '#FFF7BF',
borderRadius: '10rpx'
},
{
x: 2,
y: 1,
fonts: [{
text: '',
top: '70%',
fontColor: '#9E6600',
fontSize: '28rpx'
}],
imgs: [{
src: require('@/static/img/thanks.png'),
width: '50%',
top: '15%'
}],
background: '#FFF7BF',
borderRadius: '10rpx'
},
{
x: 2,
y: 2,
fonts: [{
text: '',
top: '70%',
fontColor: '#9E6600',
fontSize: '28rpx'
}],
imgs: [{
src: require('@/static/img/thanks.png'),
width: '50%',
top: '15%'
}],
background: '#FFF7BF',
borderRadius: '10rpx'
},
{
x: 1,
y: 2,
fonts: [{
text: '',
top: '70%',
fontColor: '#9E6600',
fontSize: '28rpx'
}],
imgs: [{
src: require('@/static/img/thanks.png'),
width: '50%',
top: '15%'
}],
background: '#FFF7BF',
borderRadius: '10rpx'
},
{
x: 0,
y: 2,
fonts: [{
text: '',
top: '70%',
fontColor: '#9E6600',
fontSize: '28rpx'
}],
imgs: [{
src: require('@/static/img/thanks.png'),
width: '50%',
top: '15%'
}],
background: '#FFF7BF',
borderRadius: '10rpx'
},
{
x: 0,
y: 1,
fonts: [{
text: '',
top: '70%',
fontColor: '#9E6600',
fontSize: '28rpx'
}],
imgs: [{
src: require('@/static/img/thanks.png'),
width: '50%',
top: '15%'
}],
background: '#FFF7BF',
borderRadius: '10rpx'
}
],
buttons: [{
x: 1,
y: 1,
background: '',
imgs: [{
src: require('@/static/img/start.png'),
width: '100%',
top: '0'
}]
}],
}
},
onLoad(options) {
let that = this
console.log('活动编码',options.code)
if(options.code){
that.hdId = options.code;
uni.showLoading({
title: '正在加载中',
mask:true
})
licklist(options.code).then(res => {
if (res.data.code == 200) {
res.data.data.map((item, index) => {
that.prizes[index].fonts[0].text = item.name
that.prizes[index].raffleId = item.id
that.prizes[index].contentType = item.contentType
if(item.contentType == 0){
// that.prizes[index].imgs[0].src = that.imageUrl + item.imgPath
that.prizes[index].imgs[0].src = require('@/static/img/thanks.png')
}else if(item.contentType == 4){
that.prizes[index].imgs[0].src = require('@/static/img/xfj.jpg')
}
})
}
uni.hideLoading();
})
}else{
uni.showToast({
title: '缺少活动编码',
type: 'error',
back:true
})
}
const SystemInfo = wx.getSystemInfoSync();
this.statusBarHeight = SystemInfo.statusBarHeight;
},
methods: {
// 点击抽奖按钮会触发star回调
startCallback() {
let that =this
console.log('点击抽奖')
if(that.isStart){
that.isStart = false
// 模拟调用接口异步抽奖
let user = uni.getStorageSync('user')
let params={'wxUserId':user.id,configCode:that.hdId}
getTurn(params).then(res=>{
console.log('抽奖结果',res)
if(res.data.code == 200){
// 调用抽奖组件的play方法开始游戏
that.$refs.myLucky.play()
let i = 0;
that.pollingTime = setInterval(() => {
if (that.pollingNum < 5) {
that.pollingNum += 1
awardDetail({wxUserId:user.id,configCode:that.hdId}).then(res=>{
if(res.data.code == 200 && res.data.rows.length>0){
clearInterval(that.pollingTime)
that.pollingTime = null
that.prizes.map((item,index)=>{
if(res.data.rows[0].raffleId == item.raffleId){
that.luckName = item.fonts[0].text
i = index
}
})
// 使用定时器来模拟请求接口
setTimeout(() => {
// 调用stop停止旋转并传递中奖索引
that.$refs.myLucky.stop(i)
}, 3000)
}
})
} else {
clearInterval(that.pollingTime)
that.pollingTime = null
}
}, 3000)
}else{
that.isStart = true;
uni.showToast({
title:res.data.msg,
icon:'none'
})
}
})
}
},
// 抽奖结束会触发end回调
endCallback(prize) {
},
}
}
</script>
// 代码结束