2 Commits f4c3aa3d22 ... f464a60482

Autor SHA1 Mensagem Data
  jianghaili f464a60482 Merge branch 'master' of https://git.nanodreamtech.com/jianghaili/wallet 3 dias atrás
  jianghaili 0848a4889d feat:竞赛交互页面 3 dias atrás

+ 86 - 17
package-lock.json

@@ -23,6 +23,9 @@
         "@dcloudio/uni-mp-weixin": "3.0.0-4030620241128001",
         "@dcloudio/uni-mp-xhs": "3.0.0-4030620241128001",
         "@dcloudio/uni-quickapp-webview": "3.0.0-4030620241128001",
+        "dayjs": "^1.11.13",
+        "pinia": "^2.0.36",
+        "pinia-plugin-persistedstate": "^2.4.0",
         "uview-plus": "^3.4.19",
         "vue": "^3.4.21",
         "vue-i18n": "^9.1.9",
@@ -7466,23 +7469,6 @@
         "url": "https://github.com/sponsors/ljharb"
       }
     },
-    "node_modules/form-data": {
-      "version": "3.0.3",
-      "resolved": "https://registry.npmjs.org/form-data/-/form-data-3.0.3.tgz",
-      "integrity": "sha512-q5YBMeWy6E2Un0nMGWMgI65MAKtaylxfNJGJxpGh45YDciZB4epbWpaAfImil6CPAPTYB4sh0URQNDRIZG5F2w==",
-      "dev": true,
-      "license": "MIT",
-      "peer": true,
-      "dependencies": {
-        "asynckit": "^0.4.0",
-        "combined-stream": "^1.0.8",
-        "es-set-tostringtag": "^2.1.0",
-        "mime-types": "^2.1.35"
-      },
-      "engines": {
-        "node": ">= 6"
-      }
-    },
     "node_modules/forwarded": {
       "version": "0.2.0",
       "resolved": "https://registry.npmjs.org/forwarded/-/forwarded-0.2.0.tgz",
@@ -9176,6 +9162,23 @@
         }
       }
     },
+    "node_modules/jsdom/node_modules/form-data": {
+      "version": "3.0.3",
+      "resolved": "https://registry.npmjs.org/form-data/-/form-data-3.0.3.tgz",
+      "integrity": "sha512-q5YBMeWy6E2Un0nMGWMgI65MAKtaylxfNJGJxpGh45YDciZB4epbWpaAfImil6CPAPTYB4sh0URQNDRIZG5F2w==",
+      "dev": true,
+      "license": "MIT",
+      "peer": true,
+      "dependencies": {
+        "asynckit": "^0.4.0",
+        "combined-stream": "^1.0.8",
+        "es-set-tostringtag": "^2.1.0",
+        "mime-types": "^2.1.35"
+      },
+      "engines": {
+        "node": ">= 6"
+      }
+    },
     "node_modules/jsdom/node_modules/ws": {
       "version": "7.5.10",
       "resolved": "https://registry.npmjs.org/ws/-/ws-7.5.10.tgz",
@@ -10261,6 +10264,46 @@
         "node": ">=0.10.0"
       }
     },
+    "node_modules/pinia": {
+      "version": "2.0.36",
+      "resolved": "https://registry.npmjs.org/pinia/-/pinia-2.0.36.tgz",
+      "integrity": "sha512-4UKApwjlmJH+VuHKgA+zQMddcCb3ezYnyewQ9NVrsDqZ/j9dMv5+rh+1r48whKNdpFkZAWVxhBp5ewYaYX9JcQ==",
+      "license": "MIT",
+      "dependencies": {
+        "@vue/devtools-api": "^6.5.0",
+        "vue-demi": "*"
+      },
+      "funding": {
+        "url": "https://github.com/sponsors/posva"
+      },
+      "peerDependencies": {
+        "@vue/composition-api": "^1.4.0",
+        "typescript": ">=4.4.4",
+        "vue": "^2.6.14 || ^3.2.0"
+      },
+      "peerDependenciesMeta": {
+        "@vue/composition-api": {
+          "optional": true
+        },
+        "typescript": {
+          "optional": true
+        }
+      }
+    },
+    "node_modules/pinia-plugin-persistedstate": {
+      "version": "2.4.0",
+      "resolved": "https://registry.npmjs.org/pinia-plugin-persistedstate/-/pinia-plugin-persistedstate-2.4.0.tgz",
+      "integrity": "sha512-bQcpv47jk3ISl+InuJWsFaS/K7pRZ97kfoD2WCf/suhnlLy48k3BnFM2tI6YZ1xMsDaPv4yOsaPuPAUuSmEO2Q==",
+      "license": "MIT",
+      "peerDependencies": {
+        "pinia": "^2.0.0"
+      },
+      "peerDependenciesMeta": {
+        "pinia": {
+          "optional": true
+        }
+      }
+    },
     "node_modules/pirates": {
       "version": "4.0.7",
       "resolved": "https://registry.npmjs.org/pirates/-/pirates-4.0.7.tgz",
@@ -12569,6 +12612,32 @@
         }
       }
     },
+    "node_modules/vue-demi": {
+      "version": "0.14.10",
+      "resolved": "https://registry.npmjs.org/vue-demi/-/vue-demi-0.14.10.tgz",
+      "integrity": "sha512-nMZBOwuzabUO0nLgIcc6rycZEebF6eeUfaiQx9+WSk8e29IbLvPU9feI6tqW4kTo3hvoYAJkMh8n8D0fuISphg==",
+      "hasInstallScript": true,
+      "license": "MIT",
+      "bin": {
+        "vue-demi-fix": "bin/vue-demi-fix.js",
+        "vue-demi-switch": "bin/vue-demi-switch.js"
+      },
+      "engines": {
+        "node": ">=12"
+      },
+      "funding": {
+        "url": "https://github.com/sponsors/antfu"
+      },
+      "peerDependencies": {
+        "@vue/composition-api": "^1.0.0-rc.1",
+        "vue": "^3.0.0-0 || ^2.6.0"
+      },
+      "peerDependenciesMeta": {
+        "@vue/composition-api": {
+          "optional": true
+        }
+      }
+    },
     "node_modules/vue-i18n": {
       "version": "9.14.4",
       "resolved": "https://registry.npmjs.org/vue-i18n/-/vue-i18n-9.14.4.tgz",

+ 3 - 0
package.json

@@ -50,6 +50,9 @@
     "@dcloudio/uni-mp-weixin": "3.0.0-4030620241128001",
     "@dcloudio/uni-mp-xhs": "3.0.0-4030620241128001",
     "@dcloudio/uni-quickapp-webview": "3.0.0-4030620241128001",
+    "dayjs": "^1.11.13",
+    "pinia": "^2.0.36",
+    "pinia-plugin-persistedstate": "^2.4.0",
     "uview-plus": "^3.4.19",
     "vue": "^3.4.21",
     "vue-i18n": "^9.1.9",

+ 3 - 0
src/App.vue

@@ -14,4 +14,7 @@ onHide(() => {
 <style lang="scss">
 	/* 注意要写在第一行,同时给style标签加入lang="scss"属性 */
 	@import "uview-plus/index.scss";
+  page{
+    background: #1E1915;
+  }
 </style>

+ 10 - 0
src/api/currency.js

@@ -0,0 +1,10 @@
+// src/services/user.ts
+import { http } from '@/utils/http'
+
+export const getCoinList = (data) => {
+  return http({
+    url: '/api/common/getCoinList',
+    method: 'get',
+    data,
+  })
+}

+ 48 - 0
src/api/game.js

@@ -0,0 +1,48 @@
+import { http } from '@/utils/http'
+// 查询游戏赛事列表
+export const matchList = (data) => {
+  return http({
+    url: '/api/game/match/list',
+    method: 'get',
+    data,
+  })
+}
+// 查询游戏赛事详情
+export const matchInfo = (data) => {
+    return http({
+      url: '/api/game/match/info',
+      method: 'get',
+      data,
+    })
+  }
+  // 查询游戏赛事详情
+export const matchRank = (data) => {
+    return http({
+      url: '/api/game/match/rank',
+      method: 'get',
+      data,
+    })
+  }
+export const matchEnroll = (data) => {
+    return http({
+      url: '/api/game/match/enroll',
+      method: 'post',
+      data,
+    })
+  }
+  // 查询用户奖金信息
+export const userPrize = (data) => {
+    return http({
+      url: '/api/game/user/prize',
+      method: 'post',
+      data,
+    })
+  }
+  // 领取用户奖金
+export const claimPrize = (data) => {
+    return http({
+      url: '/api/game/claim/prize',
+      method: 'post',
+      data,
+    })
+  }

+ 3 - 0
src/main.ts

@@ -1,10 +1,13 @@
 import uviewPlus from 'uview-plus'
 import { createSSRApp } from "vue";
+import * as Pinia from 'pinia'
 import App from "./App.vue";
 export function createApp() {
   const app = createSSRApp(App);
   app.use(uviewPlus);
+  app.use(Pinia.createPinia())
   return {
     app,
+    Pinia
   };
 }

+ 42 - 23
src/pages/home/index.vue

@@ -19,10 +19,7 @@
           <view class="btn">分享链接</view>
         </view>
         <view class="code-img">
-          <image
-            src="@/static/image/test/code-img.png"
-            mode="scaleToFill"
-          />
+          <image src="@/static/image/test/code-img.png" mode="scaleToFill" />
         </view>
       </view>
       <view class="home-title-box">
@@ -64,7 +61,14 @@
                 <view class="name-star">
                   <view class="name">金铲铲之战</view>
                   <view class="star">
-                    <up-rate :count="5" size="14" active-color="#FFD339" inactive-color="#b2b2b2" gutter="0" v-model="star"></up-rate>
+                    <up-rate
+                      :count="5"
+                      size="14"
+                      active-color="#FFD339"
+                      inactive-color="#b2b2b2"
+                      gutter="0"
+                      v-model="star"
+                    ></up-rate>
                   </view>
                 </view>
               </view>
@@ -80,23 +84,39 @@
   <script setup>
 import { ref, onMounted, reactive } from "vue";
 import Header from "@/components/Header";
+import { getCoinList } from "@/api/currency";
+import { matchList } from "@/api/game";
+import { useCounterStore } from "@/stores/counter";
+const Login = async () => {
+  let res = await getCoinList();
+  console.log(res, "测试");
+};
+Login();
+// 获取游戏列表
+const getGameList = async () => {
+  let res = await matchList();
+  console.log(res, "游戏列表");
+};
+getGameList();
+const counter = useCounterStore();
+counter.count++;
+// 自动补全! ✨
+counter.$patch({ count: counter.count + 1 });
+// 或使用 action 代替
+counter.increment();
 const title = ref("Hello");
-import {getWalletAddress} from "@/utils/utils";
+import { getWalletAddress } from "@/utils/utils";
 const star = ref(3);
 const count = ref(0);
-const address = ref('');
-const list5 = reactive([
-  "https://cdn.uviewui.com/uview/swiper/swiper3.png",
-  "https://cdn.uviewui.com/uview/swiper/swiper2.png",
-  "https://cdn.uviewui.com/uview/swiper/swiper1.png",
-]);
+const address = ref("");
+const list5 = reactive([1, 2, 3]);
 onMounted(async () => {
   const addr = await getWalletAddress();
   if (addr) {
-    console.log(addr)
+    console.log(addr);
     address.value = `${addr.slice(0, 4)}...${addr.slice(-4)}`;
   } else {
-    address.value = '未连接钱包';
+    address.value = "未连接钱包";
   }
 });
 </script>
@@ -199,7 +219,7 @@ onMounted(async () => {
       // background: yellow;
       width: 160rpx;
       height: 160rpx;
-      image{
+      image {
         width: 100%;
         height: 100%;
       }
@@ -295,33 +315,32 @@ onMounted(async () => {
           }
           .name-star {
             width: 100%;
-            padding: 0 24rpx ;
+            padding: 0 24rpx;
             box-sizing: border-box;
-            .name{
+            .name {
               color: #fff;
               font-size: 28rpx;
               margin-bottom: 12rpx;
             }
           }
         }
-        .upload-btn{
+        .upload-btn {
           padding: 12rpx 24rpx;
           box-sizing: border-box;
           border-radius: 100rpx;
-          background: linear-gradient(to bottom,#FFF1CA ,#FAC21A);
+          background: linear-gradient(to bottom, #fff1ca, #fac21a);
           font-size: 28rpx;
           color: #4c220f;
         }
       }
-      .game-item-index:last-child(){
+      .game-item-index:last-child() {
         margin-bottom: 0;
       }
     }
   }
 }
-::v-deep .u-swiper{
+::v-deep .u-swiper {
   background: none !important;
 }
-
 </style>
-  
+  @/api/coinMoney

+ 276 - 24
src/pages/trade/index.vue

@@ -3,7 +3,7 @@
     <view class="content">
       <Header>
         <template #title
-          >ACC <text style="padding: 0 12rpx">|</text>{{address}}</template
+          >ACC <text style="padding: 0 12rpx">|</text>{{ address }}</template
         >
       </Header>
       <view></view>
@@ -17,17 +17,39 @@
         </view>
       </view>
       <view class="home-code">
-        <view class="trade-border-box"> $0 </view>
-        <view class="trade-border-num">≈¥0</view>
+        <view class="trade-border-box"> ${{ gameDetail.counts }}</view>
+        <view class="trade-border-num">≈¥{{ gameDetail.bonus }}</view>
       </view>
       <view class="trade-img-box">
         <image src="@/static/image/trade/money-box.png" mode="aspectFit" />
       </view>
-      <view class="trade-process"></view>
+      <view class="trade-process">
+        <view
+          :class="
+            gameCheck == index
+              ? 'trde-process-item-active'
+              : 'trde-process-item'
+          "
+          v-for="(item, index) in gameList"
+          :key="index"
+          @click="selectGame(index, item)"
+        >
+          <view class="trade-game-name">{{ item.title }}</view>
+          <view class="trade-game-time"
+            >{{ dayjs(item.date).format("MM-DD") }}-{{
+              dayjs(item.end_date).format("MM-DD")
+            }}</view
+          >
+        </view>
+      </view>
       <view class="trade-time-box">
-        <view class="time-title"> 距离 <text>赛程 竞赛结束 </text>还有 </view>
+        <view class="time-title">
+          距离 <text>{{ gameDetail.title }}赛程 竞赛结束 </text>还有
+        </view>
         <up-count-down
-          :time="30 * 60 * 60 * 1000"
+          :time="
+            dayjs(gameDetail.end_date).valueOf() - dayjs(new Date()).valueOf()
+          "
           format="DD:HH:mm:ss"
           autoStart
           millisecond
@@ -56,8 +78,10 @@
           </view>
         </up-count-down>
         <view class="start-btn">未报名</view>
-        <view class="num-txt">奖池数量:<text>$0</text> </view>
-        <view class="num-txt-small">≈¥0</view>
+        <view class="num-txt"
+          >奖池数量:<text>${{ gameDetail.counts }}</text>
+        </view>
+        <view class="num-txt-small">≈¥{{ gameDetail.bonus }}</view>
       </view>
       <view class="game-play-name">赛程名次</view>
       <view class="game-list">
@@ -92,20 +116,58 @@
         </view>
       </view>
     </view>
-    <view class="fix-box" @click="awardFun">
-      <view class="fix-item">赛程规则</view>
+    <view class="fix-box">
+      <view class="fix-item" @click="openGamePopup">赛程规则</view>
       <view class="fix-item">赛程名次</view>
     </view>
+    <!-- @click="awardFun" -->
+    <up-popup
+      :show="showGameMsg"
+      :round="10"
+      mode="center"
+      :closeOnClickOverlay="true"
+      @close="showGameMsg = false"
+    >
+      <view class="show-game-msg">
+        <image
+        class="close-img"
+          src="@/static/image/home/alert-pay-close.png"
+          mode="scaleToFill"
+           @click="showGameMsg=false"
+        />
+        <view class="show-game-title">
+          <text>赛程</text>竞赛消息
+        </view>
+        <view class="show-game-content">
+          <view class="game-msg">1:赛程开始时间:</view>
+          <view class="game-msg">2:赛程结束时间:</view>
+          <view class="game-msg">3:参与场次:<text>0场;</text>输:<text>0局;</text>赢:<text>0局;</text></view>
+          <view class="game-msg">4:排名赢局:<text>0局</text></view>
+          <view class="desc-title">注意:</view>
+          <view class="dest-item">①: 当期赛程信息可能存在延迟,仅供参考;</view>
+          <view class="dest-item">②:如当期赛程奖励未在有效期内领取,将视为放弃;</view>
+          <view class="dest-item">③:赢局次数小于等于0的地址参与排名,但没有奖励分配;</view>
+          <view class="dest-item" style="color:red;">④:每场赛程中相同地址频繁对战,场次将不作为有效局数; </view>
+          <view class="dest-item" style="color:red;">⑤:对于恶意刷单地址,平台将永久封禁账号;</view>
+
+        </view>
+        <view class="show-game-bottom">
+          <view class="show-game-btn" @click="showGameMsg=false">关闭</view>
+        </view>
+      </view>
+    </up-popup>
   </view>
 </template>
   
   <script setup>
 import { ref, onMounted, reactive } from "vue";
 import Header from "@/components/Header";
-import {getWalletAddress} from "@/utils/utils";
-import { sendSingleReward } from '@/utils/web.js';
+import { getWalletAddress } from "@/utils/utils";
+import { sendSingleReward } from "@/utils/web.js";
+import { matchList, matchRank, matchInfo } from "@/api/game";
+import dayjs from "dayjs";
 const timeData = ref({});
-const address = ref('');
+const address = ref("");
 // 定义 onChange 方法
 const onChange = (e) => {
   timeData.value = e;
@@ -113,25 +175,78 @@ const onChange = (e) => {
 onMounted(async () => {
   const addr = await getWalletAddress();
   if (addr) {
-    console.log(addr)
+    console.log(addr);
     address.value = `${addr.slice(0, 4)}...${addr.slice(-4)}`;
   } else {
-    address.value = '未连接钱包';
+    address.value = "未连接钱包";
   }
 });
 // 例子  调用合约
-const awardFun = async () =>{
+const awardFun = async () => {
   // const privateKey = window.android.getPrivateKey();//app
-  const privateKey = '0x4553077da5d773773dad0511c6e5d33142ae2c1bd05a3a8a4a7becbc0d23d9b5';//h5
+  const privateKey =
+    "0x4553077da5d773773dad0511c6e5d33142ae2c1bd05a3a8a4a7becbc0d23d9b5"; //h5
   try {
-      const result = await sendSingleReward(privateKey,0.01);
-      if (result.status === "success") {
-        console.log(result)
-      } 
-  } catch (error) {
-    
+    const result = await sendSingleReward(privateKey, 0.01);
+    if (result.status === "success") {
+      console.log(result);
+    }
+  } catch (error) {}
+};
+// 获取各种数据
+const gameList = ref([]);
+const getGameMatchList = async () => {
+  let params = {
+    dapp_id: 15,
+  };
+  // 获取游戏赛事列表
+  let res = await matchList(params);
+  if (res.status == 200) {
+    gameList.value = res.data;
+    getGameInfo(res.data[0].id);
+    getGameRank(res.data[0].id);
   }
-}
+};
+getGameMatchList();
+// 游戏赛事排行
+const gameRankList = ref([]);
+// 查询游戏赛事排名
+const getGameRank = async (id) => {
+  let params = {
+    dapp_id: 15,
+    match_id: id,
+  };
+  // 获取游戏赛事列表
+  let res = await matchRank(params);
+  if (res.status == 200) {
+    gameRankList.value = res.data;
+  }
+};
+// 游戏详情
+const gameDetail = ref("");
+// 获取游戏赛事详情
+const getGameInfo = async (id) => {
+  let params = {
+    dapp_id: 15,
+    match_id: id,
+  };
+  // 获取游戏赛事列表
+  let res = await matchInfo(params);
+  if (res.status == 200) {
+    gameDetail.value = res.data;
+  }
+};
+const gameCheck = ref(1);
+const selectGame = (value, item) => {
+  gameCheck.value = value;
+  getGameInfo(item.id);
+  getGameRank(item.id);
+};
+// 游戏规则弹出框
+const showGameMsg = ref(false);
+const openGamePopup = () => {
+  showGameMsg.value = true;
+};
 </script>
   
   <style lang="scss" scoped>
@@ -259,6 +374,74 @@ const awardFun = async () =>{
     background-position: center center;
     background-size: 100% 100%;
     background-repeat: no-repeat;
+    display: flex;
+    justify-content: space-between;
+    align-items: center;
+    .trde-process-item {
+      width: 100%;
+      height: 100%;
+      color: #d3bdd9;
+      display: flex;
+      flex-direction: column;
+      justify-content: center;
+      align-items: center;
+      .trade-game-name {
+        font-size: 28rpx;
+        font-weight: 600;
+      }
+      .trade-game-time {
+        font-size: 24rpx;
+        margin-top: 12rpx;
+      }
+    }
+    .trde-process-item {
+      width: 100%;
+      height: 100%;
+      display: flex;
+      flex-direction: column;
+      justify-content: center;
+      align-items: center;
+      color: #d3bdd9;
+      overflow: hidden;
+      padding-left: 36rpx;
+      box-sizing: border-box;
+      .trade-game-name {
+        overflow: hidden;
+        text-overflow: ellipsis;
+        white-space: nowrap;
+        width: 100%;
+        font-size: 28rpx;
+        font-weight: 600;
+      }
+      .trade-game-time {
+        font-size: 24rpx;
+        margin-top: 12rpx;
+      }
+    }
+    .trde-process-item-active {
+      width: 100%;
+      height: 100%;
+      display: flex;
+      flex-direction: column;
+      justify-content: center;
+      align-items: center;
+      color: #4c303a;
+      overflow: hidden;
+      padding-left: 36rpx;
+      box-sizing: border-box;
+      .trade-game-name {
+        overflow: hidden;
+        text-overflow: ellipsis;
+        white-space: nowrap;
+        width: 100%;
+        font-size: 28rpx;
+        font-weight: 600;
+      }
+      .trade-game-time {
+        font-size: 24rpx;
+        margin-top: 12rpx;
+      }
+    }
   }
   .trade-time-box {
     margin: 24rpx 0;
@@ -394,5 +577,74 @@ const awardFun = async () =>{
     }
   }
 }
+.show-game-msg {
+  background: #000;
+  border-radius: 25rpx;
+  padding: 30rpx;
+  box-sizing: border-box;
+  width: 80vw;
+  height: 60vh;
+  display: flex;
+  flex-direction: column;
+  position: relative;
+  .close-img{
+    width: 50rpx;
+    height: 50rpx;
+    position: absolute;
+    right: 0;
+    top: 0;
+  }
+  .show-game-title {
+    flex-shrink: 0;
+    font-size: 32rpx;
+    font-weight: 700;
+    margin-bottom: 35rpx;
+    text-align: center;
+    color: #fff;
+    text{
+      color: rgb(255, 214, 0);
+      margin-right: 10rpx;
+    }
+  }
+  .show-game-content {
+    padding-bottom: 24rpx;
+    box-sizing: border-box;
+    overflow-y: auto;
+    flex: 1;
+    font-size: 28rpx;
+    font-weight: 700;
+    color: #fff;
+    .game-msg{
+      color: #f1dc00;
+      font-size: 26rpx;
+      margin-bottom: 6rpx;
+      text{
+        color: #fff;
+        font-weight: 600;
+      }
+    }
+    .desc-title{
+      padding: 12rpx 0;
+      box-sizing: border-box;
+    }
+    .dest-item{
+      font-weight: 400;
+      margin-bottom: 6rpx;
+    }
+  }
+  .show-game-bottom {
+    width: 100%;
+    flex-shrink: 0;
+    .show-game-btn{
+      background: linear-gradient(90deg, rgba(0, 179, 170, .7) 0, #00b3aa);
+      color: #fff;
+      height: 80rpx;
+      border-radius:8rpx ;
+      display: flex;
+      justify-content: center;
+      align-items: center;
+    }
+  }
+}
 </style>
   

BIN
src/static/image/home/alert-pay-close.png


+ 36 - 0
src/stores/counter.js

@@ -0,0 +1,36 @@
+
+import { defineStore } from 'pinia';
+export const useStore = defineStore(
+    'main',
+    () => {
+      const someState = ref('你好 pinia')
+      return { someState }
+    },
+    {
+      persist: {
+        // 调整为兼容多端的API
+        storage: {
+          setItem(key, value) {
+            uni.setStorageSync(key, value) 
+          },
+          getItem(key) {
+            return uni.getStorageSync(key) 
+          },
+        },
+      },
+
+    },
+)
+ 
+export const useCounterStore = defineStore('counter', {
+	state: () => {
+		return { count: 0 };
+	},
+	// 也可以这样定义
+	// state: () => ({ count: 0 })
+	actions: {
+		increment() {
+			this.count++;
+		},
+	},
+});

+ 53 - 0
src/utils/http.js

@@ -0,0 +1,53 @@
+const BASE_URL = import.meta.env.VITE_API_BASE_URL || ''
+
+export const http = (options) => {
+  const {
+    url,
+    method = 'GET',
+    data = {},
+    header = {},
+    showLoading = true
+  } = options
+
+  if (showLoading) {
+    uni.showLoading({
+      title: '加载中...',
+      mask: true
+    })
+  }
+
+  return new Promise((resolve, reject) => {
+    uni.request({
+      url: BASE_URL + url,
+      method,
+      data,
+      header: {
+        'Content-Type': 'application/json',
+        ...header
+      },
+      success: (res) => {
+        if (res.statusCode === 200) {
+          resolve(res.data)
+        } else {
+          uni.showToast({
+            title: '请求失败',
+            icon: 'none'
+          })
+          reject(res)
+        }
+      },
+      fail: (err) => {
+        uni.showToast({
+          title: '网络错误',
+          icon: 'none'
+        })
+        reject(err)
+      },
+      complete: () => {
+        if (showLoading) {
+          uni.hideLoading()
+        }
+      }
+    })
+  })
+}

+ 15 - 0
vite.config.ts

@@ -30,5 +30,20 @@ export default defineConfig({
         rollupNodePolyFill()
       ]
     }
+  },
+  server: {
+    port: 8088,
+    host: '0.0.0.0',
+    open: true,
+    cors: true,
+    hmr: true,
+    proxy: {
+      '/api': {
+        target:'https://wallet.nanodreamtech.com',
+        changeOrigin: true,
+        ws: true,
+        secure: true,
+      },
+    }
   }
 });