index.vue 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343
  1. <template>
  2. <div class="container">
  3. <div class="content">
  4. <div class="card-border">
  5. <div class="card-box">
  6. <van-image
  7. width="50px"
  8. height="50px"
  9. round
  10. src="https://wallet.accshare.io/storage/images/aaa.jpg"
  11. />
  12. <div class="card-text">
  13. <div>元宝总额</div>
  14. <div class="balance">{{ybbalance}}</div>
  15. </div>
  16. </div>
  17. </div>
  18. <div class="tab-box">
  19. <div class="tab-item lf-bg">
  20. <div>可用元宝</div>
  21. <div class="lf-balance">{{ ybbalance }}</div>
  22. <van-button class="tab-lf-btn" type="primary" @click="changePop(1)">兑换元宝</van-button>
  23. </div>
  24. <div class="tab-item ri-bg">
  25. <div>冻结元宝</div>
  26. <div class="lf-balance">0</div>
  27. <van-button class="tab-ri-btn" type="primary" @click="changePop(2)">取款(转出)</van-button>
  28. </div>
  29. </div>
  30. <div class="list-box">
  31. <div>明细</div>
  32. <div class="list-box-ul">
  33. <van-pull-refresh v-model="loading" @refresh="onRefresh">
  34. <div class="list-box-li" v-for="(item,i) in list" :key="i">
  35. <div>{{item.reason}}</div>
  36. <div class="list-box-li-text">
  37. <div>{{item.CreateTime}}</div>
  38. <div :class="item.amount < 0 ? 'red' : 'green'">{{ item.amount > 0 ? '+' + item.amount : item.amount }}</div>
  39. </div>
  40. </div>
  41. </van-pull-refresh>
  42. </div>
  43. </div>
  44. </div>
  45. <van-popup v-model:show="show" :style="{ borderRadius:'25px' }">
  46. <div class="pop-content">
  47. <div class="pop-title">兑换元宝</div>
  48. <div class="pop-balance">{{selectIndex == 1?`当前WGT钱包余额 ${WGTbalance}`:`当前元宝总额 ${ybbalance}`}}</div>
  49. <van-field v-model="text" class="pop-input" :placeholder="selectIndex == 1?'请输入wgt数量':'请输入元宝数量'"/>
  50. <div class="pop-state">
  51. <div style="margin-bottom: 4px;">说明</div>
  52. <div>{{selectIndex == 1?'兑换的币种数量,将按照当前价值转换成对应元宝实时到账':'取款的元宝数量,按照当前价值转换成兑换的币种实时到账'}}</div>
  53. </div>
  54. <div class="pop-btn">
  55. <van-button type="default" class="btn cancel" @click="cancel">取消</van-button>
  56. <van-button type="default" class="btn confirm" @click="confirm">提交</van-button>
  57. </div>
  58. </div>
  59. </van-popup>
  60. </div>
  61. </template>
  62. <script setup>
  63. import { useWalletStore } from "@/stores/modules/walletStore";
  64. import { syceeBalance,syceeRecords,wgt2sycee,sycee2wgt } from '@/api/path/exchange.api'
  65. import { showToast } from 'vant';
  66. import { AES_CBC_ENCRYPT,generateSign } from '@/utils/crypto';
  67. const walletStore = useWalletStore();
  68. const list = ref([]);
  69. const ybbalance = ref(0);
  70. const text = ref('')
  71. const show = ref(false);
  72. const selectIndex = ref(1);//1:wgt-元宝 2:元宝-wgt
  73. const WGTbalance = ref(0);
  74. const loading = ref(false);
  75. const changePop = (i) => {
  76. selectIndex.value = i;
  77. text.value = '';
  78. show.value = true;
  79. }
  80. const getList = async () => {
  81. const { data } = await syceeRecords({dapp_id:0,game_id:0,address:walletStore.account})
  82. list.value = data.records;
  83. }
  84. const getbalanceInfo = async () => {
  85. const { data } = await syceeBalance({address:walletStore.account})
  86. ybbalance.value = data.balance
  87. }
  88. // 代币数据
  89. const gethotTokens = async () => {
  90. const data = await walletStore.updateTokenVal()
  91. WGTbalance.value = data[2].balance;
  92. }
  93. // 取消
  94. const cancel = () => {
  95. show.value = false;
  96. text.value = ''
  97. }
  98. // 提交
  99. const confirm = () => {
  100. const inputValue = parseFloat(text.value);
  101. if (!text.value || isNaN(inputValue)) {
  102. showToast('请输入有效的数量');
  103. return;
  104. }
  105. if (inputValue <= 0) {
  106. showToast('数量必须大于0');
  107. return;
  108. }
  109. let maxValue = selectIndex.value == 1 ? parseFloat(WGTbalance.value) : parseFloat(ybbalance.value);
  110. let tokenName = selectIndex.value == 1 ? 'WGT' : '元宝';
  111. if (inputValue > maxValue) {
  112. showToast(`输入数量不能大于可用${tokenName}数量`);
  113. return;
  114. }
  115. const { ciphertext, iv } = AES_CBC_ENCRYPT(walletStore.privateKey);
  116. let params = {
  117. address: walletStore.account,
  118. quantity:text.value,
  119. key:ciphertext,
  120. _y:iv
  121. }
  122. params = generateSign(params);
  123. getwgt2sycee(params);
  124. }
  125. const getwgt2sycee = async (params) => {
  126. let res = ''
  127. if(selectIndex.value == 1){
  128. res = await wgt2sycee(params);
  129. }else{
  130. res = await sycee2wgt(params);
  131. }
  132. show.value = false;
  133. }
  134. const onRefresh = () => {
  135. setTimeout(() => {
  136. getList();
  137. getbalanceInfo();
  138. gethotTokens();
  139. loading.value = false;
  140. }, 1000);
  141. };
  142. onMounted(async ()=>{
  143. getList();
  144. getbalanceInfo();
  145. gethotTokens();
  146. })
  147. </script>
  148. <style lang="less" scoped>
  149. .container{
  150. height: calc(100vh - 44px);
  151. display: flex;
  152. flex-direction: column;
  153. padding: 15px 17px;
  154. box-sizing: border-box;
  155. .content{
  156. flex: 1;
  157. display: flex;
  158. flex-direction: column;
  159. overflow: hidden;
  160. }
  161. .card-border {
  162. padding: 2px;
  163. border-radius: 17px;
  164. background: linear-gradient(90deg, rgba(71, 101, 221, 0.5), rgba(64, 164, 251, 0.5));
  165. display: inline-block;
  166. .card-box {
  167. border-radius: 15px;
  168. background-color: #F7F8FA;
  169. display: flex;
  170. align-items: center;
  171. padding: 26px 25px;
  172. .card-text{
  173. margin-left: 8px;
  174. font-family: PingFang SC, PingFang SC;
  175. font-weight: 500;
  176. font-size: 15px;
  177. color: #000000;
  178. .balance{
  179. font-weight: 400;
  180. font-size: 12px;
  181. color: @theme-color1;
  182. margin-top: 3px;
  183. }
  184. }
  185. }
  186. }
  187. .tab-box{
  188. margin: 15px 0 33px;
  189. display: flex;
  190. gap: 17px;
  191. .tab-item{
  192. width: calc(100% / 2);
  193. border-radius: 8px;
  194. font-family: PingFang SC, PingFang SC;
  195. font-weight: 400;
  196. font-size: 15px;
  197. color: #000000;
  198. display: flex;
  199. flex-direction: column;
  200. align-items: center;
  201. padding: 6px 23px 10px;
  202. .lf-balance{
  203. font-weight: 500;
  204. font-size: 17px;
  205. color: @theme-color1;
  206. margin-bottom: 10px;
  207. }
  208. .tab-lf-btn{
  209. background: #6C8AFF;
  210. border-radius: 8px;
  211. width: 100%;
  212. color: #FFFFFF;
  213. padding: 6px 0 !important;
  214. height: 33px !important;
  215. line-height: 33px !important;
  216. border: none !important;
  217. }
  218. .tab-ri-btn{
  219. background: #73BBFF;
  220. border-radius: 8px;
  221. width: 100%;
  222. color: #FFFFFF;
  223. padding: 6px 0 !important;
  224. height: 33px !important;
  225. line-height: 33px !important;
  226. border: none !important;
  227. }
  228. }
  229. .lf-bg{
  230. background: rgba(71,101,221,0.05);
  231. }
  232. .ri-bg{
  233. background: rgba(65,160,249,0.05);
  234. color: #8D8D8D;
  235. }
  236. }
  237. .list-box{
  238. flex: 1;
  239. display: flex;
  240. flex-direction: column;
  241. background: #FFFFFF;
  242. border-radius: 12px;
  243. padding: 16px 17px 4px;
  244. font-family: PingFang SC, PingFang SC;
  245. font-weight: 500;
  246. font-size: 17px;
  247. color: #000000;
  248. overflow: hidden;
  249. .list-box-ul{
  250. margin-top: 20px;
  251. flex: 1;
  252. overflow: auto;
  253. .list-box-li{
  254. font-family: PingFang SC, PingFang SC;
  255. font-weight: 400;
  256. font-size: 15px;
  257. color: #000000;
  258. margin-bottom: 17px;
  259. .list-box-li-text{
  260. font-size: 12px;
  261. color: #8D8D8D;
  262. display: flex;
  263. align-items: center;
  264. justify-content: space-between;
  265. .red{
  266. color: #FF0000;
  267. }
  268. .green{
  269. color: #00B42A;
  270. }
  271. }
  272. }
  273. }
  274. .list-box-ul::-webkit-scrollbar{
  275. width: 0;
  276. }
  277. }
  278. .pop-content{
  279. padding: 24px 20px;
  280. font-family: PingFang SC, PingFang SC;
  281. font-weight: 400;
  282. color: #000000;
  283. font-size: 12px;
  284. .pop-title{
  285. font-weight: 500;
  286. font-size: 17px;
  287. text-align: center;
  288. margin-bottom: 12px;
  289. }
  290. .pop-balance{
  291. text-align: center;
  292. }
  293. .pop-input{
  294. background: #F2F2F2;
  295. border-radius: 8px;
  296. height: 40px;
  297. margin: 8px 0;
  298. }
  299. .pop-state{
  300. color: #4F4F4F;
  301. }
  302. .pop-btn{
  303. display: flex;
  304. justify-content: center;
  305. margin-top: 20px;
  306. .btn{
  307. width: 83px;
  308. height: 29px;
  309. line-height: 29px;
  310. padding: 5px 0 !important;
  311. border-radius: 6px;
  312. font-family: PingFang SC, PingFang SC;
  313. font-weight: 400;
  314. font-size: 15px;
  315. box-sizing:border-box;
  316. }
  317. .cancel{
  318. margin-right: 16px !important;
  319. border: 1px solid #D8D8D8;
  320. color: #000 !important;
  321. }
  322. .confirm{
  323. background: @theme-color1;
  324. color: #FFF;
  325. font-weight: 500;
  326. }
  327. }
  328. }
  329. :deep(.van-popup--center) {
  330. margin: 0 40px !important;
  331. width: auto !important;
  332. }
  333. }
  334. </style>