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

447 lines
11 KiB
Vue
Raw Normal View History

2025-04-10 11:11:46 +08:00
<script setup>
2026-01-08 10:30:41 +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-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-12-30 18:10:31 +08:00
2025-07-22 00:01:29 +08:00
import {
getAppConfig,
getRankListAPI,
getHomeData,
getMyDevicesAPI,
2025-12-31 13:39:16 +08:00
getDeviceBatteryAPI,
2025-07-22 00:01:29 +08:00
} from "@/apis";
2025-06-26 23:41:23 +08:00
import { topThreeColors } from "@/constants";
2026-01-04 11:36:31 +08:00
import { canEenter } from "@/util";
2025-12-31 13:39:16 +08:00
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-12-31 13:39:16 +08:00
const {
updateConfig,
updateUser,
updateDevice,
updateRank,
getLvlName,
updateOnline,
} = store;
const { user, device, rankData, online, game } = storeToRefs(store);
2025-12-31 13:39:16 +08:00
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-11-26 17:12:55 +08:00
const toPage = async (path) => {
2025-06-12 00:24:14 +08:00
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-12-31 13:39:16 +08:00
if (path === "/pages/first-try") {
2026-01-04 11:36:31 +08:00
if (canEenter(user.value, device.value, online.value, path)) {
await uni.$checkAudio();
} else {
return;
2025-06-15 22:38:28 +08:00
}
2025-11-26 17:12:55 +08:00
}
2025-12-31 13:39:16 +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);
2025-12-03 17:24:55 +08:00
if ("823,209,293,257".indexOf(homeData.user.id) !== -1) {
2025-12-03 13:56:01 +08:00
const show = uni.getStorageSync("show-the-user");
if (!show) {
showTheUser.value = true;
uni.setStorageSync("show-the-user", true);
}
}
2025-09-18 09:28:14 +08:00
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
);
2026-01-07 15:12:18 +08:00
const data = await getDeviceBatteryAPI();
updateOnline(data.online);
2025-07-22 00:01:29 +08:00
}
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-10-30 09:19:34 +08:00
});
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-12-31 16:42:53 +08:00
<view class="top-theme">
<image
src="https://static.shelingxingqiu.com/attachment/2025-12-31/dfc9dxrq4xn7e6y2pp.png"
mode="widthFix"
/>
</view>
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-12-31 13:39:16 +08:00
v-if="online"
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-12-31 13:39:16 +08:00
<image
v-else
2026-01-05 09:23:26 +08:00
src="https://static.shelingxingqiu.com/attachment/2026-01-04/dffohwtk1gwh0xfa6h.png"
2025-12-31 13:39:16 +08:00
mode="widthFix"
@click="() => toPage('/pages/my-device')"
/>
<block v-if="user.id">
<text v-if="!device.deviceId">绑定我的智能弓</text>
<text v-else-if="!online">设备离线</text>
<text v-else-if="online">设备在线</text>
</block>
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
/>
2026-01-12 10:09:36 +08:00
<BubbleTip v-if="showGuide" :location="{ top: '60%', left: '47%' }">
2025-07-12 16:01:49 +08:00
<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>{{
2025-11-13 16:48:24 +08:00
user.rankLvl ? getLvlName(user.rankLvl) : "暂无"
2025-08-15 15:25:41 +08:00
}}</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>
2025-05-01 16:17:51 +08:00
</view>
</view>
2026-01-09 13:44:29 +08:00
<Signin :show="showModal" :onClose="() => (showModal = false)" />
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%;
2026-01-09 18:12:27 +08:00
height: calc(100% - 120px);
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%;
2026-01-05 09:23:26 +08:00
border-radius: 25rpx;
overflow: hidden;
2025-05-01 16:17:51 +08:00
}
.feature-grid > view > image {
width: 100%;
}
.bow-card > text {
position: absolute;
2026-01-05 09:23:26 +08:00
top: 66%;
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
}
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-12-31 16:42:53 +08:00
.top-theme {
position: absolute;
display: flex;
align-items: center;
justify-content: center;
width: 100%;
height: 60px;
2026-01-05 09:23:26 +08:00
z-index: -1;
2025-12-31 16:42:53 +08:00
}
.top-theme > image {
width: 300rpx;
transform: translate(-4%, -14%);
}
2025-04-10 11:11:46 +08:00
</style>