功能完善
This commit is contained in:
@@ -192,9 +192,11 @@ const onClose = () => {
|
||||
:result="practiseResult"
|
||||
/>
|
||||
</view>
|
||||
<SButton v-if="step !== 4" :onClick="nextStep" :disabled="btnDisabled">{{
|
||||
stepButtonTexts[step]
|
||||
}}</SButton>
|
||||
<view :style="{ marginBottom: '10px' }">
|
||||
<SButton v-if="step !== 4" :onClick="nextStep" :disabled="btnDisabled">{{
|
||||
stepButtonTexts[step]
|
||||
}}</SButton>
|
||||
</view>
|
||||
</Container>
|
||||
</template>
|
||||
|
||||
|
||||
@@ -4,69 +4,15 @@ import AppFooter from "@/components/AppFooter.vue";
|
||||
import AppBackground from "@/components/AppBackground.vue";
|
||||
import UserHeader from "@/components/UserHeader.vue";
|
||||
import SModal from "@/components/SModal.vue";
|
||||
import SButton from "@/components/SButton.vue";
|
||||
import { getAppConfig, getHomeData, getMyDevicesAPI, loginAPI } from "@/apis";
|
||||
import Signin from "@/components/Signin.vue";
|
||||
import { getAppConfig, getHomeData, getMyDevicesAPI } from "@/apis";
|
||||
import useStore from "@/store";
|
||||
|
||||
import { storeToRefs } from "pinia";
|
||||
const store = useStore();
|
||||
const { updateConfig, updateUser, updateDevice } = store;
|
||||
// 使用storeToRefs,用于UI里显示,保持响应性
|
||||
const { user } = storeToRefs(store);
|
||||
const showModal = ref(false);
|
||||
const agree = ref(false);
|
||||
|
||||
const getDevice = async () => {
|
||||
const devices = await getMyDevicesAPI();
|
||||
if (devices.bindings.length) {
|
||||
updateDevice(devices.bindings[0].deviceId, devices.bindings[0].deviceName);
|
||||
}
|
||||
};
|
||||
|
||||
const handleAgree = () => {
|
||||
agree.value = !agree.value;
|
||||
};
|
||||
const handleLogin = () => {
|
||||
if (!agree.value) {
|
||||
return uni.showToast({
|
||||
title: "请先同意协议",
|
||||
icon: "none",
|
||||
});
|
||||
}
|
||||
|
||||
// 先调用wx.getUserProfile获取用户信息
|
||||
wx.getUserProfile({
|
||||
desc: "用于完善用户资料", // 声明获取用户个人信息后的用途
|
||||
success: (res) => {
|
||||
const { nickName, avatarUrl } = res.userInfo;
|
||||
// 再获取登录凭证
|
||||
uni.login({
|
||||
provider: "weixin",
|
||||
success: async (loginRes) => {
|
||||
const { code } = loginRes;
|
||||
const result = await loginAPI(nickName, avatarUrl, code);
|
||||
updateUser({ ...result.user, nickName, avatarUrl });
|
||||
await getDevice();
|
||||
showModal.value = false;
|
||||
},
|
||||
fail: (err) => {
|
||||
uni.showToast({
|
||||
title: "登录失败",
|
||||
icon: "none",
|
||||
});
|
||||
console.error("登录失败:", err);
|
||||
},
|
||||
});
|
||||
},
|
||||
fail: (err) => {
|
||||
console.log("获取用户信息失败:", err);
|
||||
uni.showToast({
|
||||
title: "获取用户信息失败",
|
||||
icon: "none",
|
||||
});
|
||||
},
|
||||
});
|
||||
};
|
||||
|
||||
const toPage = (path) => {
|
||||
if (!user.value.id) {
|
||||
@@ -86,7 +32,13 @@ onMounted(async () => {
|
||||
const result = await getHomeData();
|
||||
if (result.user) {
|
||||
updateUser(result.user);
|
||||
await getDevice();
|
||||
const devices = await getMyDevicesAPI();
|
||||
if (devices.bindings.length) {
|
||||
updateDevice(
|
||||
devices.bindings[0].deviceId,
|
||||
devices.bindings[0].deviceName
|
||||
);
|
||||
}
|
||||
}
|
||||
console.log("首页数据:", result);
|
||||
} catch (error) {
|
||||
@@ -103,14 +55,11 @@ onMounted(async () => {
|
||||
<UserHeader :user="user" showRank />
|
||||
</block>
|
||||
<block v-else>
|
||||
<view
|
||||
@click="() => (showModal = true)"
|
||||
:style="{ marginTop: '20px', paddingLeft: '10px' }"
|
||||
>
|
||||
<text>微信登录</text>
|
||||
<view class="signin-btn" @click="() => (showModal = true)">
|
||||
<text>新来的弓箭手你好呀~</text>
|
||||
<text>微信登录 ></text>
|
||||
</view>
|
||||
</block>
|
||||
|
||||
<view class="container">
|
||||
<view class="feature-grid">
|
||||
<view class="bow-card">
|
||||
@@ -204,38 +153,21 @@ onMounted(async () => {
|
||||
</view>
|
||||
<AppFooter />
|
||||
<SModal :show="showModal" :onClose="() => (showModal = false)">
|
||||
<view class="signin">
|
||||
<SButton :rounded="20" width="80vw" :onClick="handleLogin">
|
||||
<image
|
||||
src="../static/wechat-icon.png"
|
||||
mode="widthFix"
|
||||
class="wechat-icon"
|
||||
/>
|
||||
<text :style="{ color: '#000' }">登录/注册</text>
|
||||
</SButton>
|
||||
<view class="protocol" @click="handleAgree">
|
||||
<view v-if="!agree" />
|
||||
<image v-if="agree" src="../static/checked.png" mode="widthFix" />
|
||||
<text
|
||||
>已同意并阅读<text :style="{ color: '#fff' }">《用户协议》</text
|
||||
>及<text :style="{ color: '#fff' }">《隐私协议》</text>内容</text
|
||||
>
|
||||
</view>
|
||||
</view>
|
||||
<Signin :onClose="() => (showModal = false)" />
|
||||
</SModal>
|
||||
</view>
|
||||
</template>
|
||||
|
||||
<style scoped>
|
||||
.root-container {
|
||||
height: calc(100vh - 45px);
|
||||
height: calc(100vh - 40px);
|
||||
color: white;
|
||||
position: relative;
|
||||
padding-top: 45px;
|
||||
padding-top: 40px;
|
||||
}
|
||||
|
||||
.container {
|
||||
height: calc(100vh - 220px);
|
||||
height: calc(100vh - 210px);
|
||||
padding: 15px 10px;
|
||||
}
|
||||
|
||||
@@ -411,37 +343,16 @@ onMounted(async () => {
|
||||
line-height: 20px;
|
||||
margin-bottom: 5px;
|
||||
}
|
||||
.signin {
|
||||
width: 100%;
|
||||
height: 100%;
|
||||
.signin-btn {
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
justify-content: center;
|
||||
align-items: center;
|
||||
align-items: flex-start;
|
||||
margin-left: 10px;
|
||||
font-size: 14px;
|
||||
}
|
||||
.protocol {
|
||||
display: flex;
|
||||
justify-content: center;
|
||||
align-items: center;
|
||||
font-size: 13px;
|
||||
margin-top: 40px;
|
||||
color: #8a8a8a;
|
||||
}
|
||||
.protocol > image {
|
||||
width: 18px;
|
||||
height: 18px;
|
||||
margin-right: 10px;
|
||||
}
|
||||
.protocol > view:first-child {
|
||||
width: 16px;
|
||||
height: 16px;
|
||||
border-radius: 50%;
|
||||
margin-right: 10px;
|
||||
border: 1px solid #fff;
|
||||
}
|
||||
.wechat-icon {
|
||||
width: 24px;
|
||||
height: 24px;
|
||||
margin-right: 20px;
|
||||
.signin-btn > text:last-child {
|
||||
color: #39a8ff;
|
||||
margin-top: 2px;
|
||||
}
|
||||
</style>
|
||||
|
||||
@@ -115,7 +115,7 @@ onUnmounted(() => {
|
||||
<template>
|
||||
<Container title="大乱斗排位赛" :bgType="1">
|
||||
<view class="container">
|
||||
<BattleHeader v-if="!start" :players="players" />
|
||||
<BattleHeader v-if="!start && players.length" :players="players" />
|
||||
<Guide noBg v-if="!start">
|
||||
<view :style="{ display: 'flex', justifyContent: 'space-between' }">
|
||||
<view :style="{ display: 'flex', flexDirection: 'column' }">
|
||||
@@ -143,10 +143,12 @@ onUnmounted(() => {
|
||||
/>
|
||||
<Timer :seq="timerSeq" :callBack="readyToGo" />
|
||||
</view>
|
||||
<SButton v-if="!battleId" :onClick="matching ? stopMatch : startMatch">{{
|
||||
matching ? "取消匹配" : "开始匹配"
|
||||
}}</SButton>
|
||||
<SButton v-if="battleId && !start" :onClick="readyToGo">准备完毕</SButton>
|
||||
<view :style="{ marginBottom: '10px' }">
|
||||
<SButton v-if="!battleId" :onClick="matching ? stopMatch : startMatch">{{
|
||||
matching ? "取消匹配" : "开始匹配"
|
||||
}}</SButton>
|
||||
<SButton v-if="battleId && !start" :onClick="readyToGo">准备完毕</SButton>
|
||||
</view>
|
||||
</Container>
|
||||
</template>
|
||||
|
||||
|
||||
@@ -2,7 +2,12 @@
|
||||
import { onMounted } from "vue";
|
||||
import Container from "@/components/Container.vue";
|
||||
import Avatar from "@/components/Avatar.vue";
|
||||
import { getBattleListAPI, getPractiseResultListAPI } from "@/apis";
|
||||
import BowData from "@/components/BowData.vue";
|
||||
import {
|
||||
getBattleListAPI,
|
||||
getPractiseResultListAPI,
|
||||
getPractiseAPI,
|
||||
} from "@/apis";
|
||||
|
||||
import { ref } from "vue";
|
||||
|
||||
@@ -12,6 +17,8 @@ const matchList = ref([]);
|
||||
const battlePage = ref(1);
|
||||
const battleList = ref([]);
|
||||
const practiseList = ref([]);
|
||||
const showBowData = ref(false);
|
||||
const arrows = ref([]);
|
||||
|
||||
const handleSelect = async (index) => {
|
||||
if (index === 0 && matchList.value.length === 0) {
|
||||
@@ -36,6 +43,11 @@ const toMatchDetail = (id) => {
|
||||
url: `/pages/match-detail?id=${id}`,
|
||||
});
|
||||
};
|
||||
const getPractiseDetail = async (id) => {
|
||||
const result = await getPractiseAPI(id);
|
||||
arrows.value = JSON.parse(result.UserPracticeRound.arrows);
|
||||
showBowData.value = true;
|
||||
};
|
||||
onMounted(async () => {
|
||||
const result = await getBattleListAPI(matchPage.value, 2);
|
||||
matchList.value = result;
|
||||
@@ -154,12 +166,18 @@ onMounted(async () => {
|
||||
v-for="(item, index) in practiseList"
|
||||
:key="index"
|
||||
class="practice-record"
|
||||
@click="() => getPractiseDetail(item.id)"
|
||||
>
|
||||
<text>单组练习 {{ item.createdAt }}</text>
|
||||
<image src="../static/back.png" mode="widthFix" />
|
||||
</view>
|
||||
</view>
|
||||
</view>
|
||||
<BowData
|
||||
:arrows="arrows"
|
||||
:show="showBowData"
|
||||
:onClose="() => (showBowData = false)"
|
||||
/>
|
||||
</view>
|
||||
</Container>
|
||||
</template>
|
||||
|
||||
@@ -8,6 +8,10 @@ import ScoreResult from "@/components/ScoreResult.vue";
|
||||
import SButton from "@/components/SButton.vue";
|
||||
import { createPractiseAPI } from "@/apis";
|
||||
import { MESSAGETYPES, roundsName } from "@/constants";
|
||||
import useStore from "@/store";
|
||||
import { storeToRefs } from "pinia";
|
||||
const store = useStore();
|
||||
const { user } = storeToRefs(store);
|
||||
const start = ref(false);
|
||||
const showScore = ref(false);
|
||||
const scores = ref([]);
|
||||
@@ -18,12 +22,13 @@ const power = ref(0);
|
||||
const onReady = async () => {
|
||||
await createPractiseAPI(total);
|
||||
start.value = true;
|
||||
scores.value = [];
|
||||
};
|
||||
|
||||
async function onReceiveMessage(content) {
|
||||
const messages = JSON.parse(content).data.updates || [];
|
||||
messages.forEach((msg) => {
|
||||
if (start.value && msg.constructor === MESSAGETYPES.ShootSyncMeArrowID) {
|
||||
if (msg.constructor === MESSAGETYPES.ShootSyncMeArrowID) {
|
||||
scores.value.push(msg.target);
|
||||
power.value = msg.target.battery;
|
||||
if (scores.value.length === total) {
|
||||
@@ -67,8 +72,8 @@ onUnmounted(() => {
|
||||
/>
|
||||
<BowTarget
|
||||
:totalRound="total"
|
||||
:currentRound="scores.length + 1"
|
||||
avatar="../static/avatar.png"
|
||||
:currentRound="start ? scores.length + 1 : 0"
|
||||
:avatar="user.avatarUrl"
|
||||
:power="power"
|
||||
:scores="scores"
|
||||
/>
|
||||
@@ -81,7 +86,9 @@ onUnmounted(() => {
|
||||
:result="practiseResult"
|
||||
/>
|
||||
</view>
|
||||
<SButton v-if="!start" :onClick="onReady">准备好了,直接开始</SButton>
|
||||
<view :style="{ marginBottom: '10px' }">
|
||||
<SButton v-if="!start" :onClick="onReady">准备好了,直接开始</SButton>
|
||||
</view>
|
||||
</Container>
|
||||
</template>
|
||||
|
||||
|
||||
@@ -8,6 +8,10 @@ import ScoreResult from "@/components/ScoreResult.vue";
|
||||
import SButton from "@/components/SButton.vue";
|
||||
import { createPractiseAPI } from "@/apis";
|
||||
import { MESSAGETYPES } from "@/constants";
|
||||
import useStore from "@/store";
|
||||
import { storeToRefs } from "pinia";
|
||||
const store = useStore();
|
||||
const { user } = storeToRefs(store);
|
||||
const start = ref(false);
|
||||
const showScore = ref(false);
|
||||
const scores = ref([]);
|
||||
@@ -59,7 +63,7 @@ onUnmounted(() => {
|
||||
<BowTarget
|
||||
:totalRound="total"
|
||||
:currentRound="scores.length + 1"
|
||||
avatar="../static/avatar.png"
|
||||
:avatar="user.avatarUrl"
|
||||
:power="power"
|
||||
:scores="scores"
|
||||
/>
|
||||
@@ -77,7 +81,9 @@ onUnmounted(() => {
|
||||
:result="practiseResult"
|
||||
/>
|
||||
</view>
|
||||
<SButton v-if="!start" :onClick="onReady">准备好了,直接开始</SButton>
|
||||
<view :style="{ marginBottom: '10px' }">
|
||||
<SButton v-if="!start" :onClick="onReady">准备好了,直接开始</SButton>
|
||||
</view>
|
||||
</Container>
|
||||
</template>
|
||||
|
||||
|
||||
@@ -141,7 +141,11 @@ onUnmounted(() => {
|
||||
<template>
|
||||
<Container title="1V1排位赛" :bgType="1">
|
||||
<view class="container">
|
||||
<BattleHeader v-if="!start" :redTeam="redTeam" :blueTeam="blueTeam" />
|
||||
<BattleHeader
|
||||
v-if="!start && redTeam.length && blueTeam.length"
|
||||
:redTeam="redTeam"
|
||||
:blueTeam="blueTeam"
|
||||
/>
|
||||
<Guide noBg v-if="!start">
|
||||
<view :style="{ display: 'flex', justifyContent: 'space-between' }">
|
||||
<view :style="{ display: 'flex', flexDirection: 'column' }">
|
||||
@@ -180,10 +184,12 @@ onUnmounted(() => {
|
||||
/>
|
||||
<Timer :seq="timerSeq" :callBack="readyToGo" />
|
||||
</view>
|
||||
<SButton v-if="!battleId" :onClick="matching ? stopMatch : startMatch">{{
|
||||
matching ? "取消匹配" : "开始匹配"
|
||||
}}</SButton>
|
||||
<SButton v-if="battleId && !start" :onClick="readyToGo">准备完毕</SButton>
|
||||
<view :style="{ marginBottom: '10px' }">
|
||||
<SButton v-if="!battleId" :onClick="matching ? stopMatch : startMatch">{{
|
||||
matching ? "取消匹配" : "开始匹配"
|
||||
}}</SButton>
|
||||
<SButton v-if="battleId && !start" :onClick="readyToGo">准备完毕</SButton>
|
||||
</view>
|
||||
</Container>
|
||||
</template>
|
||||
|
||||
|
||||
Reference in New Issue
Block a user