This commit is contained in:
2023-08-30 20:51:12 +08:00
parent 2e8d06d5e0
commit 6710347935
7 changed files with 152 additions and 4 deletions

17
src/api/index.ts Normal file
View File

@@ -0,0 +1,17 @@
import request from "@/utils/request";
export const getGameOption = () =>
request({
url: "/betting",
method: "GET",
});
export const getKaiJiangList = () => request({url: "/draw", method: "GET"});
// 用户信息
export const getJfDz = (uid: string) =>
request({url: `/userBettingInfo?uid=${uid}`, method: "GET"});
// 用户投注记录
export const getTzJl = (uid: string) =>
request({url: `/userBettingRecord?uid=${uid}`, method: "GET"});

13
src/config/index.ts Normal file
View File

@@ -0,0 +1,13 @@
// 用于配置项目的一些常量如接口地址、websocket地址等
import Taro from "@tarojs/taro";
export const app = {
API_URL: () =>
process.env.NODE_ENV === "production"
? "https://game.jdt168.com/dice"
: "http://game.jdt168.com/dice",
API_WS: () =>
process.env.NODE_ENV === "production"
? `wss://game.jdt168.com/dice/home?uid=${Taro.getStorageSync('uid')}`
: `ws://game.jdt168.com/dice/home?uid=${Taro.getStorageSync('uid')}`,
};

View File

@@ -21,7 +21,7 @@
margin: 20px auto; margin: 20px auto;
padding: 10px; padding: 10px;
border-radius: 50px; border-radius: 50px;
background-color: #74c0fc; background-color: #7950f2;
color: #fff; color: #fff;
width: 300px; width: 300px;
text-align: center; text-align: center;

View File

@@ -188,6 +188,9 @@
width: 300px; width: 300px;
height: 100px; height: 100px;
margin-bottom: 20px; margin-bottom: 20px;
line-height: 100px;
color: #FBE039;
font-weight: bold;
} }
} }
} }

View File

@@ -54,7 +54,9 @@
</view> </view>
</view> </view>
<view class="base"> <view class="base">
<view class="qz"></view> <view class="qz">
{{ qzTitle }}
</view>
</view> </view>
<view> <view>
<view class="subColor item"> <view class="subColor item">
@@ -85,6 +87,11 @@
<script lang="ts" setup> <script lang="ts" setup>
import {ref} from 'vue' import {ref} from 'vue'
import Taro from '@tarojs/taro'
import {app} from '@/config'
let ws: any = null;
const odds = ref([ const odds = ref([
{ {
@@ -183,6 +190,73 @@ const odd2 = ref([
odds: 1.98 odds: 1.98
} }
]) ])
const qzTitle = ref('请投注')
Taro.useLoad(() => {
init();
})
const init = () => {
ws = new WebSocket(`${app.API_WS()}`);
ws.onopen = async () => {
console.log("连接游戏服务器成功");
Taro.showToast({
title: "连接游戏服务器成功",
mask: true,
icon: "none",
});
};
ws.onmessage = async (e: any) => {
const res = JSON.parse(e.data);
switch (res.code) {
case 200:
let num = Number(res.data);
if (num === 1) {
}
break;
case 401:
Taro.showToast({
title: "未登录",
mask: true,
icon: "none",
});
break;
case 403:
Taro.showToast({
title: "未能操作",
mask: true,
icon: "none",
});
break;
case 400:
Taro.showToast({
title: "豆子不足",
mask: true,
icon: "none",
});
break;
case 5:
Taro.showToast({
title: "投注成功",
mask: true,
icon: "none",
});
break;
}
};
ws.onerror = () => {
console.log("连接游戏服务器失败");
Taro.showToast({
title: "连接游戏服务器失败,请退出重新进入游戏",
mask: true,
icon: "none",
});
};
};
</script> </script>
<style lang="scss" scoped> <style lang="scss" scoped>

View File

@@ -13,8 +13,19 @@ import {ref} from "vue";
import Taro from "@tarojs/taro"; import Taro from "@tarojs/taro";
import "./index.scss"; import "./index.scss";
Taro.useLoad(() => { Taro.useLoad((options) => {
console.log("Taro.useLoad"); if (options.uid) {
Taro.showToast({
title: "登陆成功",
icon: "none",
})
Taro.setStorageSync("uid", options.uid)
} else {
Taro.showToast({
title: "登陆失败,请重新进入游戏大厅",
icon: "none",
})
}
}) })
const list = ref([ const list = ref([

30
src/utils/request.ts Normal file
View File

@@ -0,0 +1,30 @@
import {app} from '@/config';
import Taro from '@tarojs/taro';
export interface RequestParams {
url: string;
method: 'GET' | 'POST' | 'PUT' | 'DELETE';
header?: object;
data?: string | object;
}
const request = (request: RequestParams) => {
return new Promise((resolve, reject) => {
Taro.request({
url: `${app.API_URL()}${request.url}`,
method: request.method,
timeout: 5000,
dataType: 'json',
header: request.header || {},
data: request.data || {},
success: (res) => {
resolve(res.data);
},
fail: (err) => {
reject(err);
},
});
});
};
export default request;