diff --git a/xuan-deduct-uniapp/src/utils/coinUtils.js b/xuan-deduct-uniapp/src/utils/coinUtils.js index 426ec9b..9fd9a36 100644 --- a/xuan-deduct-uniapp/src/utils/coinUtils.js +++ b/xuan-deduct-uniapp/src/utils/coinUtils.js @@ -7,8 +7,12 @@ const checkCoinsAndConsume = () => { } let coins = uni.getStorageSync('userCoins') - if (!coins) coins = 10 - else coins = parseInt(coins) + if (coins === null || coins === undefined || coins === '') { + coins = 10 + uni.setStorageSync('userCoins', coins) + } else { + coins = parseInt(coins) + } if (coins < 1) { uni.showModal({ @@ -18,10 +22,10 @@ const checkCoinsAndConsume = () => { cancelText: '取消', success: (res) => { if (res.confirm) { - uni.navigateTo({ url: '/pages/mine/coins' }) + uni.navigateTo({ url: '/pages/mine/coins' }) + } } - } - }) + }) return { canUse: false, needCoins: true } } @@ -35,8 +39,11 @@ const consumeCoin = async () => { } let coins = uni.getStorageSync('userCoins') - if (!coins) coins = 10 - else coins = parseInt(coins) + if (coins === null || coins === undefined || coins === '') { + coins = 10 + } else { + coins = parseInt(coins) + } coins -= 1 uni.setStorageSync('userCoins', coins)