build(projects): 增加代码规范

This commit is contained in:
2023-11-03 18:17:27 +08:00
parent 9a0b0505e9
commit 5e64ea27de
38 changed files with 14545 additions and 11926 deletions

View File

@@ -1,3 +1,3 @@
export default definePageConfig({
navigationBarTitleText: '吹气球'
})
export default definePageConfig({
navigationBarTitleText: '吹气球',
})

View File

@@ -1,49 +1,49 @@
.container {
box-sizing: border-box;
height: 100vh;
position: relative;
display: flex;
flex-direction: column;
align-items: center;
.header {
display: flex;
justify-content: space-between;
width: 100%;
padding: 0 10px;
}
.time {
margin: 100px;
}
.balloon-box {
background-image: url("../../../static/balloon.png");
background-size: cover;
width: 200px;
height: 300px;
margin: 100px;
}
.bottom-box {
position: fixed;
bottom: 0;
margin: 10px;
width: 80%;
.input {
padding: 10px;
border-radius: 10px;
border: 1px solid grey;
}
.box {
display: flex;
justify-content: space-between;
.btn {
margin: 10px 0;
width: 45%;
}
}
}
}
.container {
box-sizing: border-box;
height: 100vh;
position: relative;
display: flex;
flex-direction: column;
align-items: center;
.header {
display: flex;
justify-content: space-between;
width: 100%;
padding: 0 10px;
}
.time {
margin: 100px;
}
.balloon-box {
background-image: url('../../../static/balloon.png');
background-size: cover;
width: 200px;
height: 300px;
margin: 100px;
}
.bottom-box {
position: fixed;
bottom: 0;
margin: 10px;
width: 80%;
.input {
padding: 10px;
border-radius: 10px;
border: 1px solid grey;
}
.box {
display: flex;
justify-content: space-between;
.btn {
margin: 10px 0;
width: 45%;
}
}
}
}

View File

@@ -1,192 +1,181 @@
<script setup lang="ts">
import { ref } from "vue";
import Taro from "@tarojs/taro";
import utils from "@/utils";
const val = ref("");
const timeStr = ref("0");
const betVal = ref(100);
const count = ref(1);
const zoom = ref(1);
const isBalloon = ref(true);
const ws = new WebSocket(
`${process.env.TARO_APP_BALLOON_WS}?uid=${Taro.getStorageSync(
"uid"
)}&game_id=${Taro.getStorageSync("gameItem").ID}`
);
ws.onopen = () => {
Taro.showToast({
title: "连接游戏服务器成功",
mask: true,
icon: "none",
});
};
ws.onmessage = (message) => {
const res = JSON.parse(message.data);
switch (res.code) {
case 200:
timeStr.value = res.data;
break;
case 5:
Taro.showToast({
title: res.msg,
icon: "none",
});
break;
case 400:
Taro.showToast({
title: res.msg,
icon: "none",
});
break;
case 100:
Taro.showToast({
title: res.msg,
icon: "none",
});
break;
default:
startFun(res.name);
break;
}
};
const changeBet = () => {
switch (betVal.value) {
case 100:
betVal.value = 1000;
break;
case 1000:
betVal.value = 10000;
break;
case 10000:
betVal.value = 100;
break;
}
};
const startBet = () => {
if (!val.value)
return Taro.showToast({
title: "请输入秒数",
icon: "none",
});
if (Number(val.value) > 13) {
val.value = "13";
Taro.showToast({
title: "秒数不能超过13",
icon: "none",
});
}
ws.send(
JSON.stringify({
type: 1,
data: {
number: betVal.value * count.value,
second: Number(val.value),
},
})
);
setTimeout(() => {
getUserInfo();
}, 1000);
};
const clear = () => {
count.value = 1;
val.value = "";
};
const startFun = (num: number) => {
let count = 1;
for (let i = 0; i < num; i++) {
setTimeout(() => {
count++;
zoom.value += 0.1;
if (count === num) {
isBalloon.value = false;
setTimeout(() => {
isBalloon.value = true;
zoom.value = 1;
}, 1000);
}
}, 1000 * i);
}
};
Taro.useDidShow(() => {
getUserInfo();
});
const douzi = ref(0);
const getUserInfo = async () => {
Taro.request({
url: `${
process.env.TARO_APP_BALLOON_API
}/userBalloonInfo?uid=${Taro.getStorageSync("uid")}`,
method: "GET",
success: ({ data: res }) => {
douzi.value = res.data.data.pulse;
},
});
};
const toPage = (type: number) => {
Taro.navigateTo({
url: `/pages/balloon/records/index?type=${type}`,
});
};
</script>
<template>
<view class="container">
<view class="header">
<view>豆子:{{ douzi }}</view>
<view @click="utils.vibrateShort(() => toPage(1))">开奖记录</view>
<view @click="utils.vibrateShort(() => toPage(2))">投注记录</view>
</view>
<view class="time">开奖倒计时{{ timeStr }}</view>
<view
v-if="isBalloon"
class="balloon-box"
:style="{
transform: `scale(${zoom})`,
transition: 'transform 0.5s',
}"
></view>
<view v-else>气球爆炸了</view>
<view class="bottom-box">
<input
class="input"
type="number"
v-model="val"
placeholder="请输入秒数,秒数不能超过13"
/>
<view class="box">
<button class="btn" type="primary" @click="count++">
X{{ count }}
</button>
<button class="btn" type="primary" @click="changeBet">
X{{ betVal }}
</button>
</view>
<view class="box">
<button class="btn" type="primary" @click="clear">重置</button>
<button class="btn" type="primary" @click="startBet"></button>
</view>
</view>
</view>
</template>
<style lang="scss">
@import "./index.scss";
</style>
<script setup lang="ts">
import { ref } from 'vue'
import Taro from '@tarojs/taro'
import utils from '@/utils'
const val = ref('')
const timeStr = ref('0')
const betVal = ref(100)
const count = ref(1)
const zoom = ref(1)
const isBalloon = ref(true)
const ws = new WebSocket(
`${process.env.TARO_APP_BALLOON_WS}?uid=${Taro.getStorageSync('uid')}&game_id=${
Taro.getStorageSync('gameItem').ID
}`
)
ws.onopen = () => {
Taro.showToast({
title: '连接游戏服务器成功',
mask: true,
icon: 'none',
})
}
ws.onmessage = (message) => {
const res = JSON.parse(message.data)
switch (res.code) {
case 200:
timeStr.value = res.data
break
case 5:
Taro.showToast({
title: res.msg,
icon: 'none',
})
break
case 400:
Taro.showToast({
title: res.msg,
icon: 'none',
})
break
case 100:
Taro.showToast({
title: res.msg,
icon: 'none',
})
break
default:
startFun(res.name)
break
}
}
const changeBet = () => {
switch (betVal.value) {
case 100:
betVal.value = 1000
break
case 1000:
betVal.value = 10000
break
case 10000:
betVal.value = 100
break
}
}
const startBet = () => {
if (!val.value)
return Taro.showToast({
title: '请输入秒数',
icon: 'none',
})
if (Number(val.value) > 13) {
val.value = '13'
Taro.showToast({
title: '秒数不能超过13',
icon: 'none',
})
}
ws.send(
JSON.stringify({
type: 1,
data: {
number: betVal.value * count.value,
second: Number(val.value),
},
})
)
setTimeout(() => {
getUserInfo()
}, 1000)
}
const clear = () => {
count.value = 1
val.value = ''
}
const startFun = (num: number) => {
let count = 1
for (let i = 0; i < num; i++) {
setTimeout(() => {
count++
zoom.value += 0.1
if (count === num) {
isBalloon.value = false
setTimeout(() => {
isBalloon.value = true
zoom.value = 1
}, 1000)
}
}, 1000 * i)
}
}
Taro.useDidShow(() => {
getUserInfo()
})
const douzi = ref(0)
const getUserInfo = async () => {
Taro.request({
url: `${process.env.TARO_APP_BALLOON_API}/userBalloonInfo?uid=${Taro.getStorageSync('uid')}`,
method: 'GET',
success: ({ data: res }) => {
douzi.value = res.data.data.pulse
},
})
}
const toPage = (type: number) => {
Taro.navigateTo({
url: `/pages/balloon/records/index?type=${type}`,
})
}
</script>
<template>
<view class="container">
<view class="header">
<view>豆子:{{ douzi }}</view>
<view @click="utils.vibrateShort(() => toPage(1))">开奖记录</view>
<view @click="utils.vibrateShort(() => toPage(2))">投注记录</view>
</view>
<view class="time">开奖倒计时{{ timeStr }}</view>
<view
v-if="isBalloon"
class="balloon-box"
:style="{
transform: `scale(${zoom})`,
transition: 'transform 0.5s',
}"
></view>
<view v-else>气球爆炸了</view>
<view class="bottom-box">
<input class="input" type="number" v-model="val" placeholder="请输入秒数,秒数不能超过13" />
<view class="box">
<button class="btn" type="primary" @click="count++">X{{ count }}</button>
<button class="btn" type="primary" @click="changeBet">X{{ betVal }}</button>
</view>
<view class="box">
<button class="btn" type="primary" @click="clear">重置</button>
<button class="btn" type="primary" @click="startBet"></button>
</view>
</view>
</view>
</template>
<style lang="scss">
@import './index.scss';
</style>

View File

@@ -1,4 +1,4 @@
export default definePageConfig({
navigationBarBackgroundColor: '#23684B',
enablePullDownRefresh: true
enablePullDownRefresh: true,
})

View File

@@ -3,8 +3,8 @@
<template v-if="typeNum === 1">
<view class="card" v-for="(item,index) in list as any[]" :key="index">
<view>
<view
>{{ item.Periods }}期开奖:
<view>
{{ item.Periods }}期开奖:
<text>{{ item.Name }}</text>
</view>
</view>
@@ -12,19 +12,17 @@
</template>
<template v-else>
<view v-if="list.length > 0">
<view
class="card desc"
v-for="(item,index) in list as any[]"
:key="index"
>
<view class="card desc" v-for="(item,index) in list as any[]" :key="index">
<view>
<view>{{ item.Periods }}期投注:</view>
<view
>时间:<text style="color: red">{{ item.Name }}</text></view
>
<view class="sub"
>投注时间:<text>{{ item.DrawTime }}</text></view
>
<view>
时间:
<text style="color: red">{{ item.Name }}</text>
</view>
<view class="sub">
投注时间:
<text>{{ item.DrawTime }}</text>
</view>
</view>
<view style="text-align: right">
<view style="color: red">+{{ item.DrawNum }}积分</view>
@@ -40,45 +38,47 @@
</template>
<script lang="ts" setup>
import { ref } from "vue";
import Taro from "@tarojs/taro";
import { ref } from 'vue'
import Taro from '@tarojs/taro'
const list = ref<any[]>([]);
const list = ref<any[]>([])
const typeNum = ref(0);
const typeNum = ref(0)
Taro.useLoad((options) => {
typeNum.value = Number(options.type);
typeNum.value = Number(options.type)
Taro.setNavigationBarTitle({
title: options.type === "1" ? "开奖记录" : "投注记录",
});
getData();
});
title: options.type === '1' ? '开奖记录' : '投注记录',
})
getData()
})
Taro.usePullDownRefresh(() => {
getData();
});
getData()
})
const getData = async () => {
if (typeNum.value === 1) {
Taro.request({
url: `${process.env.TARO_APP_BALLOON_API}/draw`,
method: "GET",
method: 'GET',
success: ({ data: res }) => {
list.value = res.data.data || [];
list.value = res.data.data || []
},
});
})
} else {
Taro.request({
url: `${process.env.TARO_APP_BALLOON_API}/userBalloonRecord?uid=${Taro.getStorageSync('uid')}`,
method: "GET",
url: `${process.env.TARO_APP_BALLOON_API}/userBalloonRecord?uid=${Taro.getStorageSync(
'uid'
)}`,
method: 'GET',
success: ({ data: res }) => {
list.value = res.data.data || [];
list.value = res.data.data || []
},
});
})
}
Taro.stopPullDownRefresh();
};
Taro.stopPullDownRefresh()
}
</script>
<style lang="scss" scoped>