123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343 |
- <template>
- <div class="container">
- <div class="content">
- <div class="card-border">
- <div class="card-box">
- <van-image
- width="50px"
- height="50px"
- round
- src="https://wallet.accshare.io/storage/images/aaa.jpg"
- />
- <div class="card-text">
- <div>元宝总额</div>
- <div class="balance">{{ybbalance}}</div>
- </div>
- </div>
- </div>
- <div class="tab-box">
- <div class="tab-item lf-bg">
- <div>可用元宝</div>
- <div class="lf-balance">{{ ybbalance }}</div>
- <van-button class="tab-lf-btn" type="primary" @click="changePop(1)">兑换元宝</van-button>
- </div>
- <div class="tab-item ri-bg">
- <div>冻结元宝</div>
- <div class="lf-balance">0</div>
- <van-button class="tab-ri-btn" type="primary" @click="changePop(2)">取款(转出)</van-button>
- </div>
- </div>
- <div class="list-box">
- <div>明细</div>
- <div class="list-box-ul">
- <van-pull-refresh v-model="loading" @refresh="onRefresh">
- <div class="list-box-li" v-for="(item,i) in list" :key="i">
- <div>{{item.reason}}</div>
- <div class="list-box-li-text">
- <div>{{item.CreateTime}}</div>
- <div :class="item.amount < 0 ? 'red' : 'green'">{{ item.amount > 0 ? '+' + item.amount : item.amount }}</div>
- </div>
- </div>
- </van-pull-refresh>
- </div>
- </div>
- </div>
- <van-popup v-model:show="show" :style="{ borderRadius:'25px' }">
- <div class="pop-content">
- <div class="pop-title">兑换元宝</div>
- <div class="pop-balance">{{selectIndex == 1?`当前WGT钱包余额 ${WGTbalance}`:`当前元宝总额 ${ybbalance}`}}</div>
- <van-field v-model="text" class="pop-input" :placeholder="selectIndex == 1?'请输入wgt数量':'请输入元宝数量'"/>
- <div class="pop-state">
- <div style="margin-bottom: 4px;">说明</div>
- <div>{{selectIndex == 1?'兑换的币种数量,将按照当前价值转换成对应元宝实时到账':'取款的元宝数量,按照当前价值转换成兑换的币种实时到账'}}</div>
- </div>
- <div class="pop-btn">
- <van-button type="default" class="btn cancel" @click="cancel">取消</van-button>
- <van-button type="default" class="btn confirm" @click="confirm">提交</van-button>
- </div>
- </div>
- </van-popup>
- </div>
- </template>
- <script setup>
- import { useWalletStore } from "@/stores/modules/walletStore";
- import { syceeBalance,syceeRecords,wgt2sycee,sycee2wgt } from '@/api/path/exchange.api'
- import { showToast } from 'vant';
- import { AES_CBC_ENCRYPT,generateSign } from '@/utils/crypto';
- const walletStore = useWalletStore();
- const list = ref([]);
- const ybbalance = ref(0);
- const text = ref('')
- const show = ref(false);
- const selectIndex = ref(1);//1:wgt-元宝 2:元宝-wgt
- const WGTbalance = ref(0);
- const loading = ref(false);
- const changePop = (i) => {
- selectIndex.value = i;
- text.value = '';
- show.value = true;
- }
- const getList = async () => {
- const { data } = await syceeRecords({dapp_id:0,game_id:0,address:walletStore.account})
- list.value = data.records;
- }
- const getbalanceInfo = async () => {
- const { data } = await syceeBalance({address:walletStore.account})
- ybbalance.value = data.balance
- }
- // 代币数据
- const gethotTokens = async () => {
- const data = await walletStore.updateTokenVal()
- WGTbalance.value = data[2].balance;
- }
- // 取消
- const cancel = () => {
- show.value = false;
- text.value = ''
- }
- // 提交
- const confirm = () => {
- const inputValue = parseFloat(text.value);
- if (!text.value || isNaN(inputValue)) {
- showToast('请输入有效的数量');
- return;
- }
-
- if (inputValue <= 0) {
- showToast('数量必须大于0');
- return;
- }
-
- let maxValue = selectIndex.value == 1 ? parseFloat(WGTbalance.value) : parseFloat(ybbalance.value);
- let tokenName = selectIndex.value == 1 ? 'WGT' : '元宝';
- if (inputValue > maxValue) {
- showToast(`输入数量不能大于可用${tokenName}数量`);
- return;
- }
- const { ciphertext, iv } = AES_CBC_ENCRYPT(walletStore.privateKey);
- let params = {
- address: walletStore.account,
- quantity:text.value,
- key:ciphertext,
- _y:iv
- }
- params = generateSign(params);
- getwgt2sycee(params);
- }
- const getwgt2sycee = async (params) => {
- let res = ''
- if(selectIndex.value == 1){
- res = await wgt2sycee(params);
- }else{
- res = await sycee2wgt(params);
- }
- show.value = false;
- }
- const onRefresh = () => {
- setTimeout(() => {
- getList();
- getbalanceInfo();
- gethotTokens();
- loading.value = false;
- }, 1000);
- };
- onMounted(async ()=>{
- getList();
- getbalanceInfo();
- gethotTokens();
- })
- </script>
- <style lang="less" scoped>
- .container{
- height: calc(100vh - 44px);
- display: flex;
- flex-direction: column;
- padding: 15px 17px;
- box-sizing: border-box;
- .content{
- flex: 1;
- display: flex;
- flex-direction: column;
- overflow: hidden;
- }
- .card-border {
- padding: 2px;
- border-radius: 17px;
- background: linear-gradient(90deg, rgba(71, 101, 221, 0.5), rgba(64, 164, 251, 0.5));
- display: inline-block;
- .card-box {
- border-radius: 15px;
- background-color: #F7F8FA;
- display: flex;
- align-items: center;
- padding: 26px 25px;
- .card-text{
- margin-left: 8px;
- font-family: PingFang SC, PingFang SC;
- font-weight: 500;
- font-size: 15px;
- color: #000000;
- .balance{
- font-weight: 400;
- font-size: 12px;
- color: @theme-color1;
- margin-top: 3px;
- }
- }
- }
- }
- .tab-box{
- margin: 15px 0 33px;
- display: flex;
- gap: 17px;
- .tab-item{
- width: calc(100% / 2);
- border-radius: 8px;
- font-family: PingFang SC, PingFang SC;
- font-weight: 400;
- font-size: 15px;
- color: #000000;
- display: flex;
- flex-direction: column;
- align-items: center;
- padding: 6px 23px 10px;
- .lf-balance{
- font-weight: 500;
- font-size: 17px;
- color: @theme-color1;
- margin-bottom: 10px;
- }
- .tab-lf-btn{
- background: #6C8AFF;
- border-radius: 8px;
- width: 100%;
- color: #FFFFFF;
- padding: 6px 0 !important;
- height: 33px !important;
- line-height: 33px !important;
- border: none !important;
- }
- .tab-ri-btn{
- background: #73BBFF;
- border-radius: 8px;
- width: 100%;
- color: #FFFFFF;
- padding: 6px 0 !important;
- height: 33px !important;
- line-height: 33px !important;
- border: none !important;
- }
- }
- .lf-bg{
- background: rgba(71,101,221,0.05);
- }
- .ri-bg{
- background: rgba(65,160,249,0.05);
- color: #8D8D8D;
- }
- }
- .list-box{
- flex: 1;
- display: flex;
- flex-direction: column;
- background: #FFFFFF;
- border-radius: 12px;
- padding: 16px 17px 4px;
- font-family: PingFang SC, PingFang SC;
- font-weight: 500;
- font-size: 17px;
- color: #000000;
- overflow: hidden;
- .list-box-ul{
- margin-top: 20px;
- flex: 1;
- overflow: auto;
- .list-box-li{
- font-family: PingFang SC, PingFang SC;
- font-weight: 400;
- font-size: 15px;
- color: #000000;
- margin-bottom: 17px;
- .list-box-li-text{
- font-size: 12px;
- color: #8D8D8D;
- display: flex;
- align-items: center;
- justify-content: space-between;
- .red{
- color: #FF0000;
- }
- .green{
- color: #00B42A;
- }
- }
- }
- }
- .list-box-ul::-webkit-scrollbar{
- width: 0;
- }
- }
- .pop-content{
- padding: 24px 20px;
- font-family: PingFang SC, PingFang SC;
- font-weight: 400;
- color: #000000;
- font-size: 12px;
- .pop-title{
- font-weight: 500;
- font-size: 17px;
- text-align: center;
- margin-bottom: 12px;
- }
- .pop-balance{
- text-align: center;
- }
- .pop-input{
- background: #F2F2F2;
- border-radius: 8px;
- height: 40px;
- margin: 8px 0;
- }
- .pop-state{
- color: #4F4F4F;
- }
- .pop-btn{
- display: flex;
- justify-content: center;
- margin-top: 20px;
- .btn{
- width: 83px;
- height: 29px;
- line-height: 29px;
- padding: 5px 0 !important;
- border-radius: 6px;
- font-family: PingFang SC, PingFang SC;
- font-weight: 400;
- font-size: 15px;
- box-sizing:border-box;
- }
- .cancel{
- margin-right: 16px !important;
- border: 1px solid #D8D8D8;
- color: #000 !important;
- }
- .confirm{
- background: @theme-color1;
- color: #FFF;
- font-weight: 500;
- }
- }
- }
- :deep(.van-popup--center) {
- margin: 0 40px !important;
- width: auto !important;
- }
- }
- </style>
|