Files
shoot-miniprograms/src/pages/index.vue

533 lines
13 KiB
Vue
Raw Normal View History

2025-04-10 11:11:46 +08:00
<script setup>
2025-06-12 00:24:14 +08:00
import { ref, onMounted } from "vue";
2025-09-12 10:38:21 +08:00
import { onShow, onShareAppMessage, onShareTimeline } from "@dcloudio/uni-app";
2025-07-02 17:21:44 +08:00
import Container from "@/components/Container.vue";
2025-05-01 16:17:51 +08:00
import AppFooter from "@/components/AppFooter.vue";
import AppBackground from "@/components/AppBackground.vue";
2025-05-01 21:38:35 +08:00
import UserHeader from "@/components/UserHeader.vue";
2025-06-12 00:24:14 +08:00
import SModal from "@/components/SModal.vue";
2025-06-15 15:53:57 +08:00
import Signin from "@/components/Signin.vue";
2025-07-12 16:01:49 +08:00
import BubbleTip from "@/components/BubbleTip.vue";
2025-07-22 00:01:29 +08:00
import {
getAppConfig,
getRankListAPI,
getHomeData,
getMyDevicesAPI,
} from "@/apis";
2025-06-26 23:41:23 +08:00
import { topThreeColors } from "@/constants";
2025-05-26 16:28:13 +08:00
import useStore from "@/store";
2025-05-25 23:51:10 +08:00
import { storeToRefs } from "pinia";
2025-05-26 16:28:13 +08:00
const store = useStore();
2025-07-30 17:38:48 +08:00
const { updateConfig, updateUser, updateDevice, updateRank, getLvlName } =
store;
2025-05-25 23:51:10 +08:00
// 使用storeToRefs用于UI里显示保持响应性
const { user, device, rankData } = storeToRefs(store);
2025-06-12 00:24:14 +08:00
const showModal = ref(false);
2025-07-12 16:01:49 +08:00
const showGuide = ref(false);
2025-05-07 23:34:15 +08:00
2025-06-12 00:24:14 +08:00
const toPage = (path) => {
if (!user.value.id) {
showModal.value = true;
2025-06-15 22:38:28 +08:00
return;
2025-05-30 16:14:17 +08:00
}
2025-06-15 22:38:28 +08:00
if (
"/pages/first-try,/pages/practise,/pages/friend-battle".indexOf(path) !== -1
) {
if (!device.value.deviceId) {
return uni.showToast({
title: "请先绑定设备",
icon: "none",
});
}
2025-07-14 17:57:52 +08:00
if ("/pages/first-try".indexOf(path) === -1 && !user.value.trio) {
2025-07-10 15:34:00 +08:00
return uni.showToast({
title: "请先完成新手试炼",
icon: "none",
});
}
2025-06-15 22:38:28 +08:00
}
uni.navigateTo({
url: path,
});
2025-05-08 22:05:53 +08:00
};
2025-05-10 22:25:06 +08:00
2025-06-17 12:01:44 +08:00
const toRankListPage = () => {
uni.navigateTo({
2025-06-26 13:51:41 +08:00
url: "/pages/rank-list",
2025-06-17 12:01:44 +08:00
});
};
2025-07-19 00:03:12 +08:00
onShow(async () => {
2025-09-12 17:49:26 +08:00
const token = uni.getStorageSync(
`${uni.getAccountInfoSync().miniProgram.envVersion}_token`
);
2025-09-18 09:28:14 +08:00
const promises = [getRankListAPI()];
2025-07-22 09:36:38 +08:00
if (token) {
2025-09-18 09:28:14 +08:00
promises.push(getHomeData());
}
const [rankList, homeData] = await Promise.all(promises);
console.log("排行数据", rankList);
updateRank(rankList);
if (homeData) {
console.log("首页数据:", homeData);
if (homeData.user) {
updateUser(homeData.user);
if (homeData.user.trio <= 0) {
2025-07-22 00:01:29 +08:00
showGuide.value = true;
setTimeout(() => {
showGuide.value = false;
}, 3000);
}
const devices = await getMyDevicesAPI();
if (devices.bindings && devices.bindings.length) {
updateDevice(
devices.bindings[0].deviceId,
devices.bindings[0].deviceName
);
}
2025-07-10 15:34:00 +08:00
}
2025-05-10 22:25:06 +08:00
}
});
2025-06-24 13:18:03 +08:00
2025-07-19 00:03:12 +08:00
onMounted(async () => {
const config = await getAppConfig();
updateConfig(config);
console.log("全局配置:", config);
});
2025-06-24 13:18:03 +08:00
const comingSoon = () => {
uni.showToast({
title: "敬请期待",
icon: "none",
});
};
2025-09-12 10:38:21 +08:00
onShareAppMessage(() => {
return {
2025-09-12 17:49:26 +08:00
title: "智能真弓:实时捕捉+毫秒级同步,弓箭选手全球竞技!", // 分享卡片的标题
2025-09-12 10:38:21 +08:00
path: "/pages/index", // 用户点击分享卡片后跳转的页面路径
2025-09-12 17:49:26 +08:00
imageUrl:
"https://static.shelingxingqiu.com/attachment/2025-09-12/dcqoz26q0268wxmzjg.png", // 分享卡片的配图,可以是本地或网络图片
2025-09-12 10:38:21 +08:00
};
});
onShareTimeline(() => {
return {
2025-09-12 17:49:26 +08:00
title: "智能真弓:实时捕捉+毫秒级同步,弓箭选手全球竞技!", // 分享到朋友圈的标题
2025-09-12 10:38:21 +08:00
query: "from=timeline", // 用户通过朋友圈点击后,在页面 onShow 的 options 中可以获取到的参数
2025-09-12 17:49:26 +08:00
imageUrl:
"https://static.shelingxingqiu.com/attachment/2025-09-12/dcqoz26q0268wxmzjg.png", // 分享到朋友圈的配图
2025-09-12 10:38:21 +08:00
};
});
2025-04-10 11:11:46 +08:00
</script>
<template>
<Container :isHome="true" :showBackToGame="true">
2025-08-07 10:48:05 +08:00
<view class="container">
2025-07-02 17:21:44 +08:00
<UserHeader showRank :onSignin="() => (showModal = true)" />
<view :style="{ padding: '12px 10px' }">
<view class="feature-grid">
<view class="bow-card">
2025-05-01 16:17:51 +08:00
<image
2025-08-07 09:34:47 +08:00
src="https://static.shelingxingqiu.com/attachment/2025-08-07/dbvt1o6dvhr2rop3kn.webp"
2025-05-01 16:17:51 +08:00
mode="widthFix"
2025-07-02 17:21:44 +08:00
@click="() => toPage('/pages/my-device')"
2025-05-01 16:17:51 +08:00
/>
2025-07-02 17:21:44 +08:00
<text v-if="!user.id">我的弓箭</text>
2025-09-03 16:34:54 +08:00
<text v-if="user.id && !device.deviceId">连接智能弓箭</text>
2025-07-07 12:51:02 +08:00
<text
v-if="user.id && device.deviceId"
class="truncate"
:style="{ width: '90%', textAlign: 'center' }"
>{{ device.deviceName }}</text
>
2025-05-01 16:17:51 +08:00
<image
2025-07-30 17:38:48 +08:00
src="../static/first-try.png"
2025-05-01 16:17:51 +08:00
mode="widthFix"
2025-07-02 17:21:44 +08:00
@click="() => toPage('/pages/first-try')"
2025-05-01 16:17:51 +08:00
/>
2025-07-12 16:01:49 +08:00
<BubbleTip
v-if="showGuide"
:location="{ top: '60%', left: '40%', fontSize: '14px' }"
>
<text>新人必刷</text>
<text>快来报到吧~</text>
</BubbleTip>
2025-07-02 17:21:44 +08:00
</view>
2025-07-30 17:38:48 +08:00
<view class="play-card">
<view @click="() => toPage('/pages/practise')">
<image src="../static/my-practise.png" mode="widthFix" />
</view>
<view @click="() => toPage('/pages/friend-battle')">
<image src="../static/friend-battle.png" mode="widthFix" />
</view>
2025-07-02 17:21:44 +08:00
</view>
</view>
<view class="ranking-section">
2025-10-01 12:57:34 +08:00
<image
src="https://static.shelingxingqiu.com/attachment/2025-09-25/dd1p9ci9v7frcrsxhj.png"
mode="widthFix"
/>
2025-07-02 17:21:44 +08:00
<button
class="into-btn"
@click="() => toPage('/pages/ranking')"
hover-class="none"
></button>
<view class="ranking-players" @click="toRankListPage">
<img src="../static/juezhanbang.png" mode="widthFix" />
<view class="divide-line"></view>
2025-10-11 15:37:05 +08:00
<view class="player-avatars">
<view
v-for="i in 6"
:key="i"
class="player-avatar"
:style="{
zIndex: 8 - i,
borderColor: rankData.rank[i - 1]
? topThreeColors[i - 1] || '#000'
: '#000',
}"
>
<image v-if="i === 1" src="../static/champ1.png" />
<image v-if="i === 2" src="../static/champ2.png" />
<image v-if="i === 3" src="../static/champ3.png" />
<view v-if="i > 3">{{ i }}</view>
<image
:src="
rankData.rank[i - 1]
? rankData.rank[i - 1].avatar
: '../static/user-icon-dark.png'
"
mode="aspectFill"
/>
</view>
<view class="more-players">
2025-07-02 17:21:44 +08:00
<text>{{ rankData.rank.length }}</text>
</view>
2025-05-01 16:17:51 +08:00
</view>
</view>
2025-07-30 17:38:48 +08:00
<view class="my-data">
<view @click="() => toPage('/pages/my-growth')">
<image src="../static/my-growth.png" mode="widthFix" />
</view>
2025-08-19 09:44:15 +08:00
<view @click="() => toPage('/pages/ranking')">
2025-07-30 17:38:48 +08:00
<view>
<text>段位</text>
2025-08-15 15:25:41 +08:00
<text>{{
user.scores ? getLvlName(user.scores) : "暂无"
}}</text>
2025-07-30 17:38:48 +08:00
</view>
<view>
<text>赛季平均环数</text>
2025-08-09 11:58:11 +08:00
<text>{{ user.avg_ring ? user.avg_ring + "环" : "暂无" }}</text>
2025-07-30 17:38:48 +08:00
</view>
<view>
<text>赛季胜率</text>
<text>{{
user.avg_win
? Number((user.avg_win * 100).toFixed(2)) + "%"
2025-08-09 11:58:11 +08:00
: "暂无"
2025-07-30 17:38:48 +08:00
}}</text>
</view>
</view>
</view>
<!-- <view class="region-stats">
2025-07-02 17:21:44 +08:00
<view
v-for="(region, index) in [
2025-07-17 13:55:04 +08:00
{ name: '广东', score: 4291 },
{ name: '湖南', score: 3095 },
{ name: '内蒙', score: 2342 },
{ name: '海南', score: 1812 },
{ name: '四川', score: 1293 },
2025-07-02 17:21:44 +08:00
]"
:key="index"
class="region-item"
@click="comingSoon"
>
<image src="../static/region-bg.png" mode="widthFix" />
<image
v-if="index === 0"
src="../static/region-1.png"
mode="widthFix"
/>
<image
v-if="index === 1"
src="../static/region-2.png"
mode="widthFix"
/>
<image
v-if="index === 2"
src="../static/region-3.png"
mode="widthFix"
/>
<image
v-if="index === 3"
src="../static/region-4.png"
mode="widthFix"
/>
<image
v-if="index === 4"
src="../static/region-5.png"
mode="widthFix"
/>
2025-07-17 13:55:04 +08:00
<text>{{ region.name }}</text>
2025-07-02 17:21:44 +08:00
<view>
2025-07-17 13:55:04 +08:00
<text :style="{ color: '#fff', marginRight: '2px' }">{{
region.score
}}</text>
2025-07-02 17:21:44 +08:00
<text></text>
</view>
</view>
<view class="region-more" @click="comingSoon">
<image src="../static/region-more.png" mode="widthFix" />
<text>...</text>
<text>更多</text>
</view>
2025-07-30 17:38:48 +08:00
</view> -->
2025-05-01 16:17:51 +08:00
</view>
</view>
2025-07-02 17:21:44 +08:00
<SModal :show="showModal" :onClose="() => (showModal = false)">
<Signin :onClose="() => (showModal = false)" />
</SModal>
2025-05-01 16:17:51 +08:00
</view>
2025-09-24 21:05:06 +08:00
<AppFooter />
2025-07-02 17:21:44 +08:00
</Container>
2025-04-10 11:11:46 +08:00
</template>
<style scoped>
2025-05-01 16:17:51 +08:00
.container {
2025-07-02 17:21:44 +08:00
width: 100%;
2025-05-01 16:17:51 +08:00
}
.feature-grid {
2025-07-30 17:38:48 +08:00
width: 100%;
display: flex;
margin-bottom: 5px;
2025-05-01 16:17:51 +08:00
}
2025-07-30 17:38:48 +08:00
.feature-grid > view {
2025-05-01 16:17:51 +08:00
position: relative;
2025-07-30 17:38:48 +08:00
display: flex;
flex-direction: column;
}
.bow-card {
width: 50%;
2025-05-01 16:17:51 +08:00
}
.feature-grid > view > image {
width: 100%;
}
.bow-card > text {
position: absolute;
2025-07-15 17:10:56 +08:00
top: 65%;
2025-05-01 16:17:51 +08:00
left: 50%;
transform: translate(-50%, -50%);
2025-06-16 22:43:39 +08:00
white-space: nowrap;
2025-05-01 16:17:51 +08:00
font-size: 13px;
color: #b3b3b3;
}
2025-07-12 16:01:49 +08:00
.bow-card > image:nth-child(3) {
2025-07-15 17:10:56 +08:00
transform: translateY(-1px);
2025-05-01 16:17:51 +08:00
}
2025-07-30 17:38:48 +08:00
.play-card {
width: 48%;
margin-left: 2%;
2025-05-01 16:17:51 +08:00
}
2025-07-30 17:38:48 +08:00
.play-card > view > image {
2025-05-01 16:17:51 +08:00
width: 100%;
}
.ranking-section {
border-radius: 15px;
padding: 15px;
position: relative;
}
.ranking-section > image {
position: absolute;
top: 0;
left: 0;
width: 100%;
z-index: -1;
}
2025-06-19 01:55:40 +08:00
.into-btn {
position: absolute;
top: 40px;
left: calc(50% - 100px);
width: 200px;
height: 100px;
}
2025-05-01 16:17:51 +08:00
.ranking-players {
display: flex;
align-items: center;
padding-bottom: 20px;
2025-05-23 20:58:24 +08:00
margin-top: 42%;
2025-10-11 15:37:05 +08:00
border-bottom: 1rpx solid rgba(255, 255, 255, 0.2);
2025-05-01 16:17:51 +08:00
}
.ranking-players > image:first-child {
width: 28%;
2025-06-26 23:41:23 +08:00
transform: translateX(-10px) translateY(-8px);
2025-05-01 16:17:51 +08:00
}
.player-avatars {
display: flex;
align-items: center;
}
2025-06-25 00:09:53 +08:00
.divide-line {
width: 1px;
height: 35px;
background-color: #80808033;
margin-right: 8px;
}
2025-05-01 16:17:51 +08:00
.player-avatar,
.more-players {
2025-07-15 18:14:59 +08:00
width: 82rpx;
height: 82rpx;
2025-05-01 16:17:51 +08:00
border-radius: 50%;
2025-10-11 15:37:05 +08:00
margin-right: -20rpx;
border: 1rpx solid #312f35;
2025-05-01 16:17:51 +08:00
position: relative;
2025-07-15 18:14:59 +08:00
box-sizing: border-box;
2025-05-01 16:17:51 +08:00
}
.player-avatar > image:first-child,
.player-avatar > view:first-child {
position: absolute;
2025-10-11 15:37:05 +08:00
top: -24rpx;
left: 22rpx;
width: 32rpx;
height: 32rpx;
2025-05-01 16:17:51 +08:00
}
.player-avatar > view:first-child {
border-radius: 50%;
background: #777777;
text-align: center;
2025-06-25 00:09:53 +08:00
font-size: 10px;
line-height: 18px;
width: 18px;
height: 18px;
2025-07-15 17:10:56 +08:00
color: #fff;
2025-05-01 16:17:51 +08:00
}
.player-avatar > image:last-child {
width: 100%;
height: 100%;
border-radius: 50%;
}
.more-players {
background: #3c445a;
2025-06-25 00:09:53 +08:00
font-size: 9px;
2025-06-25 01:46:04 +08:00
line-height: 80rpx;
2025-06-25 00:09:53 +08:00
text-align: center;
2025-06-26 13:51:41 +08:00
z-index: 1;
2025-06-17 12:01:44 +08:00
}
.more-players > text {
2025-06-25 01:46:04 +08:00
margin-left: 2px;
2025-07-02 17:21:44 +08:00
color: #fff;
2025-05-01 16:17:51 +08:00
}
.region-stats {
display: flex;
grid-template-columns: repeat(6, 1fr);
margin-top: 20px;
justify-content: space-between;
}
.region-item,
.region-more {
border-radius: 10px;
2025-04-10 11:11:46 +08:00
text-align: center;
2025-05-01 16:17:51 +08:00
position: relative;
width: 13vw;
height: 13vw;
overflow: hidden;
display: flex;
flex-direction: column;
justify-content: center;
align-items: center;
2025-06-25 01:46:04 +08:00
color: #c5c5c5;
2025-05-01 16:17:51 +08:00
font-size: 12px;
}
.region-item > text {
margin-top: 10px;
}
.region-more {
width: 8vw;
height: 13vw;
}
.region-item > image:first-child,
.region-more > image:first-child {
position: absolute;
top: 0;
left: 0;
width: 100%;
z-index: -1;
}
.region-item > image:nth-of-type(2) {
position: absolute;
top: 0;
left: 0;
width: 18px;
}
.region-item > view:last-child {
display: flex;
justify-content: center;
font-size: 10px;
}
.region-more > text:first-of-type {
font-size: 30px;
line-height: 20px;
margin-bottom: 5px;
2025-04-10 11:11:46 +08:00
}
2025-07-30 17:38:48 +08:00
.my-data {
display: flex;
margin-top: 20px;
justify-content: space-between;
}
.my-data > view:first-child {
width: 28%;
}
.my-data > view:first-child > image {
width: 100%;
transform: translateX(-8px);
}
.my-data > view:nth-child(2) {
width: 68%;
font-size: 12px;
color: #fff6;
display: flex;
justify-content: space-between;
}
.my-data > view:nth-child(2) > view:nth-child(2) {
width: 38%;
}
.my-data > view:nth-child(2) > view {
width: 28%;
border-radius: 10px;
background: linear-gradient(180deg, #303b4c 30%, #2c384a 100%);
display: flex;
flex-direction: column;
align-items: center;
justify-content: center;
}
.my-data > view:nth-child(2) > view > text:last-child {
color: #fff;
line-height: 25px;
2025-08-06 10:56:57 +08:00
font-weight: 500;
2025-07-30 17:38:48 +08:00
}
2025-04-10 11:11:46 +08:00
</style>