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

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

@@ -28,11 +28,29 @@ const thawlog = (data) => {
url: 'user/account/thawlog', url: 'user/account/thawlog',
method: 'POST', method: 'POST',
data data
}, true)
}
// 获取新的一批水晶
const crystalsBefore = (data) => {
return request({
url: 'user/account/crystals/before',
})
}
// 批量领取水晶
const allThawall = (data) => {
return request({
url: 'user/account/thawall',
method: 'POST',
data
}) })
} }
export { export {
chain, chain,
crystals, crystals,
thawlog thawlog,
crystalsBefore,
allThawall
} }

View File

@@ -36,6 +36,13 @@
<view class="text">发权证<uni-icons type="arrowright" color="#FFFFFF" size="12"></uni-icons> <view class="text">发权证<uni-icons type="arrowright" color="#FFFFFF" size="12"></uni-icons>
</view> </view>
</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> </view>
</block> </block>
<block v-else> <block v-else>
@@ -120,37 +127,37 @@
</template> </template>
<script> <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 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 { export default {
components: { lF2 }, components: { lF2 },
data() { data() {
return { return {
isAuth: false, isAuth: false,
chains: { // 区块链统计 chains: { // 区块链统计
balance: 0, balance : 0,
height: 0, height : 0,
number: 0, number : 0,
score: 0, score : 0,
up: 0, up : 0,
stone: 0 stone : 0
}, },
account: { // 账户 account: { // 账户
coin: 0, coin : 0,
crystal: 0 crystal : 0
}, },
crystalArr: [], // 待领取 crystalArr : [], // 待领取
allIds: [], // 可领取ids categoryArr : [], // 推荐列表
categoryArr: [], // 推荐列表 help : {}, // 帮助信息
help: {}, // 帮助信息 userAuth : { // 用户认证状态
userAuth: { // 用户认证状态
certification: false, certification: false,
company: false, company : false,
vip: false vip : false
}, },
// 领取贡献值队列 // 领取贡献值队列
queueData : [],
queueState : false queueState : false
}; };
}, },
@@ -225,35 +232,98 @@
}, },
// 领取贡献值 // 领取贡献值
ledCrystal(index) { 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(); const innerAudioContext = uni.createInnerAudioContext();
innerAudioContext.autoplay = true; innerAudioContext.autoplay = true;
innerAudioContext.src = require('@/static/mp3/crystal.mp3'); 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
})
})
}, },
// occ信息 // occ信息
getIndex() { getIndex() {
@@ -628,6 +698,12 @@
top: 12%; top: 12%;
} }
.ore-item-key{
@extend .oct-float-item;
left: $margin;
top: 20%;
}
.ore-item { .ore-item {
@extend .oct-float-item; @extend .oct-float-item;
} }

Binary file not shown.

After

Width:  |  Height:  |  Size: 5.8 KiB

File diff suppressed because one or more lines are too long