From bc3a0af9389c5b2c89d9c6f76ebbb71abd0fcfc6 Mon Sep 17 00:00:00 2001 From: yuyongdong Date: Tue, 6 Aug 2024 17:17:35 +0800 Subject: [PATCH] =?UTF-8?q?=E5=AE=8C=E5=96=84=E5=85=85=E5=80=BC=E5=8A=9F?= =?UTF-8?q?=E8=83=BD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/components/assets/assetsHeader.vue | 210 +++++++++++++----- src/components/chain/WalletSelectModel.vue | 2 +- src/components/chain/contract/GameItemMall.js | 10 +- src/utils/marketplace.js | 15 ++ 4 files changed, 177 insertions(+), 60 deletions(-) diff --git a/src/components/assets/assetsHeader.vue b/src/components/assets/assetsHeader.vue index 560e283..8dcfcf2 100644 --- a/src/components/assets/assetsHeader.vue +++ b/src/components/assets/assetsHeader.vue @@ -9,10 +9,10 @@
{{ localWalletStore.showAddress ? localWalletStore.showAddress : 'User Address' }}
-

Player name:   {{ contributionPoint }}

+

Player name:   {{ userInfoData.nickname }}

@@ -20,10 +20,10 @@
- 0 + {{ userInfoData.diamond ? userInfoData.diamond : 0 }}
  • -
    Top up
    +
    Top-Up
  • @@ -65,7 +65,7 @@

    Total Contribution Credits: 

    - {{ contributionPointTotal }} + {{ userInfoData.contribution_point }}
    @@ -339,11 +339,11 @@
    -
    Diamond Top up
    +
    Top-Up
    -

    Diamonds are centralized assets that can be used in the game

    +

    Diamonds: In-game currency for purchasing items and entering the Lucky Draw.

    @@ -362,54 +362,57 @@
    - {{ priceAmount ? priceAmount : 0 }} + {{ priceAmount ? confirmRecharge.price : 0 }} {{ confirmRecharge?.price }} - + +
    -
    Staking Contribution Credits Record
    +
    Transaction History
    - +
  • + Action +
  • Date
  • - Reward + Amount
  • -
    +

    No Data

    -
    - +
    +
  • + Top-Up + Spending +
  • {{ timeFormat(item.date*1000) }}
  • - {{contributionLogs(item.contribution_point)}} - + {{contributionLogs(item.amount)}} +
  • +
    @@ -417,17 +420,20 @@ import { ref, toRaw, watch, computed, onMounted, inject } from "vue" const message = inject("$message"); import ConfirmDialog from "@/components/Dialogs/confirmDialog.vue"; +import LoadingDialog from "@/components/Dialogs/loadingDialog.vue" import {createModal} from "@/utils/model.util"; -import { apiCecInfo, apiExpected, apiUserData, apiContribution, apiRechargeGoods, apiRechargeHistory, apiPreRecharge } from "@/utils/marketplace" +import { apiCecInfo, apiExpected, apiUserData, apiContribution, apiRechargeGoods, apiRechargeHistory, apiDiamondHistory, apiGameLog } from "@/utils/marketplace" import { priceCalculated, timeFormat, contributionLogs } from "@/configs/priceCalculate" import { rechargeImgList } from "@/configs/cenImg" +import { icon_usdc } from "@/configs/configchain" import { useMarketplaceStore } from "@/store/marketplace" import { BlockChain } from "@/components/chain/BlockChain" import {walletStore} from "@/store/wallet"; const marketplaceStore = useMarketplaceStore() const localWalletStore = walletStore() - +// loading 弹窗 +const loadingDialogVisible = ref(false) const bgCor = ref(['#5bbbff', '#ffc35b', '#bb7fff', '#ff6600']) const logDialogVisible = ref(false) @@ -526,13 +532,24 @@ const getExpected = async () => { } const contributionPointTotal = ref(0) +const userInfoData = ref( + { + contribution_point: "0.00", + diamond: "", + email: "", + errcode: 0, + errmsg: "", + gold: "0.00", + nickname: "", + } +) const getUserData = async () => { let address = localWalletStore.address if(address) { - const {errcode, contribution_point, gold} = await apiUserData(address) - if(errcode == 0) { - contributionPointTotal.value = contribution_point - marketplaceStore.userGold = gold + let res = await apiUserData(address) + if(res.errcode == 0) { + marketplaceStore.userGold = res.gold + userInfoData.value = res } } else { return @@ -544,9 +561,21 @@ const rechargeLogDialogVisible = ref(false) const rechargeListDialogVisible = ref(false) const activeIndex = ref(0) const rechargeList = ref() +const rechargeHistoryList = ref() const confirmRecharge = ref() const brickworkAmount = ref(0) const priceAmount = ref(0) + +// 打开充值弹窗 +const rechargeDialogVisible = async () => { + let token = localWalletStore.token + if(token) { + rechargeListDialogVisible.value = true + } else { + await new BlockChain().connect() + } +} + // 列表 const getRechargeGoods = async () => { const { errcode, errmsg, rows} = await apiRechargeGoods() @@ -572,56 +601,115 @@ const selectItem = (data, index) => { } const handleInput = (e) => { - console.log(brickworkAmount.value, e) - toRaw(confirmRecharge.value).price = brickworkAmount.value - priceAmount.value = brickworkAmount.value + // console.log(brickworkAmount.value, e) + if(Number(brickworkAmount.value) >9999) { + brickworkAmount.value = 9999 + toRaw(confirmRecharge.value).price = 9999 + } else { + toRaw(confirmRecharge.value).price = brickworkAmount.value + priceAmount.value = brickworkAmount.value + } + } const rechargeDecrease = async () => { if(brickworkAmount.value == 0) return false brickworkAmount.value-- priceAmount.value-- - toRaw(confirmRecharge.value).price = priceAmount.value + if(confirmRecharge.value.goods_id == 1006) { + toRaw(confirmRecharge.value).price = priceAmount.value + } } const rechargeIncrease = async () => { brickworkAmount.value++ priceAmount.value++ - toRaw(confirmRecharge.value).price = priceAmount.value + if(confirmRecharge.value.goods_id == 1006) { + toRaw(confirmRecharge.value).price = priceAmount.value + } } +// 充值 const conformBtn = async () => { - console.log(toRaw(confirmRecharge.value)) - let address = localWalletStore.address - if(toRaw(confirmRecharge.value).price == 0) { - message.error('Please select the amount of bricks to be recharged.') - } else { - try { - const bc = new BlockChain() - let res = await bc.mall.execBuyItem(Number(toRaw(confirmRecharge.value).goods_id)) - console.log(res) - } catch(e) { - console.log(e) +// debugger + // if(localWalletStore.walletType == 3) { + let address = localWalletStore.address + if(toRaw(confirmRecharge.value).price == 0) { + message.error('Please select the amount of bricks to be recharged.') + } else { + loadingDialogVisible.value = true + // getGameLog() + // return + try { + const bc = new BlockChain() + let res = await bc.mall.execBuyItem(Number(toRaw(confirmRecharge.value).goods_id)) + // console.log(res) + if(res) { + await dataInfo() + loadingDialogVisible.value = false + message.success('Top-Up Successful') + } + } catch(e) { + if(e.message.indexOf('rejected') > -1) { + message.error('Top-Up Cancelled by User') + } else if(e.message.indexOf('Error during transaction') > -1) { + message.error('Top-Up Failed - Insufficient Balance') + } else { + message.error('Top-Up fail.') + } + loadingDialogVisible.value = false + } } - // alert('充值') - // let query = { - // net_id: Number(import.meta.env.VUE_APP_NET_ID), - // goods_id: toRaw(confirmRecharge.value).goods_id, - // account_address: address - // } - // console.log(query) - // let res = await apiPreRecharge(query) - // console.log(res) - } + // } else { + // const confirmResult = await createModal(ConfirmDialog, { + // title: 'Need login to Passport', + // noBtnTitle: '', + // message: 'Please log in with Passport.' + // }).show() + // } } const getRechargeHistory = async () => { let address = localWalletStore.address - let res = await apiRechargeHistory(address) - console.log(res,'-----------------------------') + // let res = await apiRechargeHistory(address) + if(address) { + let res = await apiDiamondHistory(address) + // if(!res.rows) { + // res.rows = [] + // } + // res.rows.forEach(item => { + // item['event'] = 'Top_Up' + // }) + // his.rows.forEach(item => { + // item['event'] = 'Spending' + // }) + rechargeHistoryList.value = res.rows + } + +} + +// 打点 +const getGameLog = async () => { + let data = { + account_id: '', + session_id: '', + gameid: '', + channel: '', + event_name: '', + localuuid: '' + } + try { + let res = await apiGameLog(data) + console.log(res) + } catch(e) { + loadingDialogVisible.value = false + } } // 充值----------------------------------------end - +const isPassprotLogin = ref(false) const dataInfo = async () => { + // const bc = new BlockChain() + // isPassprotLogin.value = bc.passportLogined + // console.log(isPassprotLogin.value) await getCecInfo() await getContribution() await getExpected() @@ -632,7 +720,7 @@ const dataInfo = async () => { watch(localWalletStore,() => { // console.log('localWalletStore.token',localWalletStore.address,localWalletStore.token) - if(!localWalletStore.address) { + if(!localWalletStore.token) { nftList.value = [] cecInfo.value = { total: 0, @@ -1038,7 +1126,7 @@ onMounted(() => { } img { width: 28px; - height: 25px; + height: 28px; margin-left: 15px; } } @@ -1803,6 +1891,12 @@ onMounted(() => { top: -50px; right: -50px; cursor: pointer; + width: 160px; + height: 160px; + img { + width: 100%; + height: 100%; + } } p { font-family: 'Poppins'; diff --git a/src/components/chain/WalletSelectModel.vue b/src/components/chain/WalletSelectModel.vue index 71a2d7c..d7c1a18 100644 --- a/src/components/chain/WalletSelectModel.vue +++ b/src/components/chain/WalletSelectModel.vue @@ -111,7 +111,7 @@ function hideModal(result = null) { left: 0; overflow: auto; margin: 0; - z-index: 10; + z-index: 10001; .modal-bg { position: absolute; top: 0; diff --git a/src/components/chain/contract/GameItemMall.js b/src/components/chain/contract/GameItemMall.js index d0ea2a0..113ddae 100644 --- a/src/components/chain/contract/GameItemMall.js +++ b/src/components/chain/contract/GameItemMall.js @@ -14,7 +14,7 @@ export class GameItemMall { data }] }) - console.log(txHash) + // console.log(txHash) const res = await provider.waitForTransaction(txHash) if (res.status == 0) { throw new Error('transaction failed') @@ -23,6 +23,12 @@ export class GameItemMall { } async execBuyItem(itemId) { + // await this.bc.checkPassportLogin(); + // const chainId = parseInt(import.meta.env.VUE_APP_NET_ID); + // const provider = this.bc.passportProvider + // const address = this.bc.store.passportAddress + // return + await this.bc.checkPassportLogin(); const chainId = parseInt(import.meta.env.VUE_APP_NET_ID); const { provider, address } = await this.bc.selectAddress({targetChainId: chainId}) @@ -30,6 +36,8 @@ export class GameItemMall { net_id: chainId, goods_id: itemId, account_address: address, + // passport: '', + } const { errocode, errmsg, calls } = await apiPreRecharge(preDatas) if (errocode) { diff --git a/src/utils/marketplace.js b/src/utils/marketplace.js index ca486a7..0fd8082 100644 --- a/src/utils/marketplace.js +++ b/src/utils/marketplace.js @@ -178,8 +178,23 @@ export const apiRechargeHistory = async (account_address) => { return httpPost(url, {}) } +// 消耗记录 +export const apiDiamondHistory = async (account_address) => { + const url = `${API_BASE}/api/activity/diamond/history/${account_address}` + return httpGet(url, {}) +} + // 充值-购买 export const apiPreRecharge = async (data) => { const url = `${API_BASE}/api/recharge/buy` return httpPost(url, data) } + + +// 充值打点 +export const apiGameLog = async (data) => { + console.log(data) + // return + const url = `https://gamelog-test.kingsome.cn/webapp/index.php?c=GameLog&a=customReport` + return httpPost(url,data) +}