领取水晶增加队列处理,增加批量领取

This commit is contained in:
唐明明
2021-11-17 15:32:21 +08:00
parent 0f9b01274f
commit a5688f6ff8
4 changed files with 298 additions and 147 deletions

View File

@@ -35,6 +35,13 @@
</view>
<view class="text">发权证<uni-icons type="arrowright" color="#FFFFFF" size="12"></uni-icons>
</view>
</view>
<view class="oct-float ore-item-key" @click="getAllThawall" v-if="crystalArr.length > 1">
<view class="oct-icon">
<image src="@/static/icons/crystals-icon.png" mode="widthFix" class="icon" />
</view>
<view class="text">一键领取<uni-icons type="arrowright" color="#FFFFFF" size="12"></uni-icons>
</view>
</view>
</view>
</block>
@@ -120,38 +127,38 @@
</template>
<script>
import { chain, crystals, thawlog } from '@/apis/interfaces/chain'
import { chain, crystals, thawlog, crystalsBefore, allThawall } from '@/apis/interfaces/chain'
import F2 from '@/uni_modules/lime-f2/components/lime-f2/f2.min.js'
import lF2 from '@/uni_modules/lime-f2/components/lime-f2/'
import lF2 from '@/uni_modules/lime-f2/components/lime-f2/'
import Queue from '@/public/queue'
let queue = new Queue()
export default {
components: { lF2 },
data() {
return {
isAuth: false,
chains: { // 区块链统计
balance: 0,
height: 0,
number: 0,
score: 0,
up: 0,
stone: 0
balance : 0,
height : 0,
number : 0,
score : 0,
up : 0,
stone : 0
},
account: { // 账户
coin: 0,
crystal: 0
coin : 0,
crystal : 0
},
crystalArr: [], // 待领取
allIds: [], // 可领取ids
categoryArr: [], // 推荐列表
help: {}, // 帮助信息
userAuth: { // 用户认证状态
crystalArr : [], // 待领取
categoryArr : [], // 推荐列表
help : {}, // 帮助信息
userAuth : { // 用户认证状态
certification: false,
company: false,
vip: false
company : false,
vip : false
},
// 领取贡献值队列
queueData : [],
queueState : false
queueState : false
};
},
onShow() {
@@ -224,37 +231,100 @@
})
},
// 领取贡献值
ledCrystal(index) {
// 播放音频
const innerAudioContext = uni.createInnerAudioContext();
innerAudioContext.autoplay = true;
innerAudioContext.src = require('@/static/mp3/crystal.mp3');
// 请求接口
thawlog({
thaw_id: this.crystalArr[index].log_id,
all_ids: this.allIds
}).then(res => {
uni.showToast({
image: require('@/static/icons/crystal-icon.png'),
title: '+' + this.crystalArr[index].amount,
duration: 2000
})
this.$set(this.account, 'crystal', res.crystal)
this.ids = res.all_ids
if (JSON.stringify(res.last) === '[]') {
this.$set(this.crystalArr, index, {
amount: null
})
return
}
this.$set(this.crystalArr, index, res.last)
}).catch(err => {
uni.showToast({
icon: 'none',
title: err
})
})
},
ledCrystal(index) {
this.playAudio()
// 领取提示信息
uni.showToast({
image: require('@/static/icons/crystal-icon.png'),
title: '+' + this.crystalArr[index].amount,
duration: 2000
})
// 处理领取队列
queue.enqueue(this.crystalArr[index].log_id)
if(!this.queueState){
let queueTime
this.queueState = true
this.startQueue(queueTime)
}
// 移出贡献值数据
this.crystalArr.splice(index, 1)
},
// 领取贡献值队列
startQueue(outTime){
outTime = setInterval(() => {
if(queue.isNull()){
clearInterval(outTime)
this.queueState = false
this.getCrystalsBefore()
return
}
queue.front().then(val => {
thawlog({
thaw_id: val,
}).then(res => {
this.$set(this.account, 'crystal', res.crystal)
}).catch(err => {
uni.showToast({
icon: 'none',
title: err.message
})
})
})
queue.dequeue()
}, 500)
},
// 批量领取贡献值
getAllThawall(){
let ids = []
let amounts = 0
ids = this.crystalArr.map(val => {
amounts += Number(val.amount)
return val.log_id
})
allThawall({
all_ids: ids
}).then(res => {
this.playAudio()
// 领取提示信息
uni.showToast({
image: require('@/static/icons/crystals-icon.png'),
title: '+' + amounts.toFixed(2),
duration: 2000
})
this.crystalArr = []
this.$set(this.account, 'crystal', res.crystal)
this.getCrystalsBefore()
}).catch(err => {
uni.showToast({
icon : 'none',
title: err.message
})
})
},
// 刷新贡献值
getCrystalsBefore(){
if(this.crystalArr.length <= 0){
crystalsBefore().then(res => {
this.crystalArr = res.crystal_array
}).catch(err => {
uni.showToast({
title: err.message,
icon : 'none'
})
})
}
},
// 播放领取提示信息
playAudio(){
const innerAudioContext = uni.createInnerAudioContext();
innerAudioContext.autoplay = true;
innerAudioContext.src = require('@/static/mp3/crystal.mp3');
},
// occ信息
getIndex() {
Promise.all([crystals(), chain()]).then(res => {
@@ -626,6 +696,12 @@
@extend .oct-float-item;
right: $margin;
top: 12%;
}
.ore-item-key{
@extend .oct-float-item;
left: $margin;
top: 20%;
}
.ore-item {