完成首页3个tab页的移动端改造

This commit is contained in:
kron
2025-11-26 15:09:31 +08:00
parent aecd2cea61
commit 6830136957
21 changed files with 716 additions and 695 deletions

View File

@@ -4,3 +4,8 @@
</App> </App>
</template> </template>
<style>
* {
font-family: "PingFang SC";
}
</style>

View File

@@ -10,56 +10,31 @@ const props = defineProps({
default: "#050b19", default: "#050b19",
}, },
}); });
const capsuleHeight = ref(0);
// onMounted(() => {
// const menuBtnInfo = uni.getMenuButtonBoundingClientRect();
// capsuleHeight.value = menuBtnInfo.top + 50 - 9;
// });
</script> </script>
<template> <template>
<view class="background" :style="{ backgroundColor: bgColor }"> <view class="background" :style="{ backgroundColor: bgColor }">
<image <image class="bg-image" v-if="type === 2" src="../static/app-bg3.png" />
class="bg-image"
v-if="type === 2"
src="../static/app-bg3.png"
:style="{ height: capsuleHeight + 'px' }"
/>
<image <image
class="bg-image" class="bg-image"
v-if="type === 4" v-if="type === 4"
src="../static/app-bg5.png" src="../static/app-bg5.png"
mode="widthFix" mode="widthFix"
/> />
<view class="bg-overlay" v-if="type === 0"></view>
</view> </view>
</template> </template>
<style scoped> <style scoped>
.background { .background {
position: fixed;
width: 100%; width: 100%;
height: 100%; height: 100%;
position: fixed;
left: 0; left: 0;
top: 0; top: 0;
z-index: -1; z-index: -1;
} }
.bg-image { .bg-image {
width: 100%; width: 100%;
height: 100%; height: 100%;
} }
.bg-overlay {
position: absolute;
width: 100%;
height: 100%;
left: 0;
top: 0;
background: linear-gradient(
to bottom,
rgba(26, 26, 26, 0.2),
rgba(0, 0, 0, 0.2)
);
}
</style> </style>

View File

@@ -9,7 +9,7 @@ const props = defineProps({
}, },
bgType: { bgType: {
type: Number, type: Number,
default: 0, default: 2,
}, },
onBack: { onBack: {
type: Function, type: Function,
@@ -25,18 +25,13 @@ const props = defineProps({
}, },
bgColor: { bgColor: {
type: String, type: String,
default: "#050b19", default: "#F5F5F5",
}, },
}); });
const showHint = ref(false); const showHint = ref(false);
const hintType = ref(0); const hintType = ref(0);
const capsuleHeight = ref(0);
const isLoading = ref(false); const isLoading = ref(false);
const statusBarHeight = uni.getSystemInfoSync().statusBarHeight;
onMounted(() => {
// const menuBtnInfo = uni.getMenuButtonBoundingClientRect();
// capsuleHeight.value = menuBtnInfo.top - 9;
});
const goBack = () => { const goBack = () => {
uni.navigateBack(); uni.navigateBack();
@@ -44,13 +39,13 @@ const goBack = () => {
</script> </script>
<template> <template>
<view :style="{ paddingTop: capsuleHeight + 'px' }"> <view :style="{ paddingTop: statusBarHeight + 'px' }">
<AppBackground :type="bgType" :bgColor="bgColor" /> <AppBackground :type="bgType" :bgColor="bgColor" />
<Header v-if="!isHome" :title="title" :onBack="onBack" /> <Header v-if="!isHome" :title="title" :onBack="onBack" />
<view <view
class="content" class="content"
:style="{ :style="{
height: `calc(100vh - ${capsuleHeight + (isHome ? 0 : 50)}px)`, height: `calc(100vh - ${statusBarHeight + (isHome ? 0 : 50)}px)`,
overflow, overflow,
}" }"
> >

View File

@@ -1,17 +1,7 @@
<script setup> <script setup>
import { ref, computed, onMounted, onBeforeUnmount } from "vue"; import { ref, computed, onMounted } from "vue";
import Avatar from "@/components/Avatar.vue"; import Avatar from "@/components/Avatar.vue";
import useStore from "@/store";
import { storeToRefs } from "pinia";
const store = useStore();
const { user } = storeToRefs(store);
const currentPage = computed(() => {
const pages = getCurrentPages();
return pages[pages.length - 1].route;
});
const props = defineProps({ const props = defineProps({
title: { title: {
type: String, type: String,
@@ -38,37 +28,14 @@ const onClick = () => {
} }
}; };
const toUserPage = () => {
uni.navigateTo({
url: "/pages/profile",
});
};
const signin = () => {
if (!user.value.id) {
uni.navigateTo({
url: "/pages/signin",
});
}
};
const pointBook = ref(null); const pointBook = ref(null);
const heat = ref(0);
const updateHot = (value) => {
heat.value = value;
};
onMounted(() => { onMounted(() => {
const pages = getCurrentPages(); const pages = getCurrentPages();
const currentPage = pages[pages.length - 1]; const currentPage = pages[pages.length - 1].route;
if (currentPage.route === "pages/edit") { if (currentPage === "pages/edit") {
pointBook.value = uni.getStorageSync("point-book"); pointBook.value = uni.getStorageSync("point-book");
} }
uni.$on("update-hot", updateHot);
});
onBeforeUnmount(() => {
uni.$off("update-hot", updateHot);
}); });
</script> </script>
@@ -77,32 +44,6 @@ onBeforeUnmount(() => {
<view class="back-btn" @click="onClick"> <view class="back-btn" @click="onClick">
<image src="../static/back-black.png" mode="widthFix" /> <image src="../static/back-black.png" mode="widthFix" />
</view> </view>
<view :style="{ color: '#000' }">
<view
v-if="currentPage === 'pages/index'"
class="user-header"
@click="signin"
>
<block v-if="user.id">
<Avatar
:src="user.avatar"
:onClick="toUserPage"
:size="40"
borderColor="#333"
/>
<text class="truncate">{{ user.nickName }}</text>
<image
v-if="heat"
:src="`../static/hot${heat}.png`"
mode="widthFix"
/>
</block>
<block v-else>
<image src="../static/user-icon.png" mode="widthFix" />
<text>新来的弓箭手你好呀~</text>
</block>
</view>
</view>
<view v-if="pointBook" class="point-book-info"> <view v-if="pointBook" class="point-book-info">
<text>{{ pointBook.bowType.name }}</text> <text>{{ pointBook.bowType.name }}</text>
<text>{{ pointBook.distance }} </text> <text>{{ pointBook.distance }} </text>
@@ -129,8 +70,7 @@ onBeforeUnmount(() => {
justify-content: flex-start; justify-content: flex-start;
align-items: center; align-items: center;
width: 72vw; width: 72vw;
height: 50px; height: 100rpx;
/* margin-top: var(--status-bar-height); */
padding-left: 15px; padding-left: 15px;
} }
.container > view:nth-child(2) { .container > view:nth-child(2) {
@@ -146,23 +86,6 @@ onBeforeUnmount(() => {
height: 22px; height: 22px;
margin-right: 10px; margin-right: 10px;
} }
.first-try-steps {
display: flex;
align-items: center;
color: #fff6;
font-size: 14px;
}
.first-try-steps > text {
transition: all 0.3s ease;
}
.first-try-steps > text:nth-child(2),
.first-try-steps > text:nth-child(4) {
margin: 0 5px;
}
.current-step {
font-size: 16px;
color: #fff;
}
.point-book-info { .point-book-info {
color: #333; color: #333;
position: fixed; position: fixed;
@@ -178,25 +101,4 @@ onBeforeUnmount(() => {
padding: 5px 10px; padding: 5px 10px;
margin: 3px; margin: 3px;
} }
.user-header {
display: flex;
align-items: center;
justify-content: flex-start;
}
.user-header > image:first-child {
width: 40px;
height: 40px;
border-radius: 50%;
border: 2rpx solid #333;
}
.user-header > image:last-child {
width: 36rpx;
}
.user-header > text:nth-child(2) {
font-weight: 500;
font-size: 30rpx;
color: #333333;
margin: 0 20rpx;
max-width: 300rpx;
}
</style> </style>

70
src/components/Tabbar.vue Normal file
View File

@@ -0,0 +1,70 @@
<script setup>
import { ref, computed } from "vue";
const props = defineProps({
selected: {
type: Number,
default: 0,
},
onClick: {
type: Function,
default: (index) => {},
},
});
const isIOS = computed(() => {
const systemInfo = uni.getDeviceInfo();
return systemInfo.osName === "ios";
});
</script>
<template>
<view class="tabbar" :style="{ paddingBottom: isIOS ? '30rpx' : '0rpx' }">
<view @click="onClick(0)">
<image
:src="`../static/tab-score${selected === 0 ? '-s' : ''}.png`"
mode="widthFix"
/>
<text :style="{ color: selected === 0 ? '#333' : '#999999' }">Score</text>
</view>
<view @click="onClick(1)">
<image
:src="`../static/tab-history${selected === 1 ? '-s' : ''}.png`"
mode="widthFix"
/>
<text :style="{ color: selected === 1 ? '#333' : '#999999' }"
>History</text
>
</view>
<view @click="onClick(2)">
<image
:src="`../static/tab-user${selected === 2 ? '-s' : ''}.png`"
mode="widthFix"
/>
<text :style="{ color: selected === 2 ? '#333' : '#999999' }"
>Profile</text
>
</view>
</view>
</template>
<style scoped>
.tabbar {
background: #fff;
display: flex;
align-items: center;
justify-content: space-around;
width: 100vw;
height: 100rpx;
}
.tabbar > view {
margin-top: 20rpx;
display: flex;
flex-direction: column;
align-items: center;
justify-content: center;
font-size: 20rpx;
}
.tabbar > view > image {
width: 56rpx;
height: 56rpx;
margin-bottom: 5rpx;
}
</style>

View File

@@ -3,6 +3,12 @@
{ {
"path": "pages/index" "path": "pages/index"
}, },
{
"path": "pages/signin"
},
{
"path": "pages/signup"
},
{ {
"path": "pages/create" "path": "pages/create"
}, },
@@ -12,21 +18,9 @@
{ {
"path": "pages/edit" "path": "pages/edit"
}, },
{
"path": "pages/list"
},
{
"path": "pages/profile"
},
{ {
"path": "pages/reset-pwd" "path": "pages/reset-pwd"
}, },
{
"path": "pages/signin"
},
{
"path": "pages/signup"
},
{ {
"path": "pages/edit-profile" "path": "pages/edit-profile"
} }

View File

@@ -70,7 +70,7 @@ onMounted(async () => {
</script> </script>
<template> <template>
<Container :bgType="2" bgColor="#F5F5F5" title="选择参数"> <Container title="选择参数">
<view class="container"> <view class="container">
<view> <view>
<EditOption <EditOption

View File

@@ -111,7 +111,7 @@ onLoad(async (options) => {
</script> </script>
<template> <template>
<Container :bgType="2" bgColor="#F5F5F5" title="" :onBack="goBack"> <Container title="" :onBack="goBack">
<view class="container"> <view class="container">
<!-- <canvas <!-- <canvas
class="share-canvas" class="share-canvas"

View File

@@ -18,7 +18,7 @@ onLoad((options) => {
</script> </script>
<template> <template>
<Container :bgType="2" bgColor="#F5F5F5" :title="`Edit ${type}`"> <Container :title="`Edit ${type}`">
<view v-if="type === 'Name'" class="input-view input-row"> <view v-if="type === 'Name'" class="input-view input-row">
<input <input
v-model="formData.name" v-model="formData.name"

View File

@@ -96,7 +96,7 @@ onMounted(() => {
</script> </script>
<template> <template>
<Container :bgType="2" bgColor="#F5F5F5" :onBack="() => (showTip = true)"> <Container :onBack="() => (showTip = true)">
<view class="container"> <view class="container">
<BowTargetEdit <BowTargetEdit
:onChange="onEditDone" :onChange="onEditDone"

View File

@@ -1,401 +1,111 @@
<script setup> <script setup>
import { ref, computed, onMounted, watch } from "vue"; import { ref, computed, onMounted, watch } from "vue";
import { onShow } from "@dcloudio/uni-app"; import Score from "@/pages/score.vue";
import Container from "@/components/Container.vue"; import History from "@/pages/list.vue";
import PointRecord from "@/components/PointRecord.vue"; import Profile from "@/pages/profile.vue";
import RingBarChart from "@/components/RingBarChart.vue"; import Tabbar from "@/components/Tabbar.vue";
import {
getHomeData,
getPointBookConfigAPI,
getPointBookStatisticsAPI,
} from "@/api";
import { getElementRect } from "@/util";
// import { generateKDEHeatmapImage } from "@/kde-heatmap";
import useStore from "@/store"; import useStore from "@/store";
import { storeToRefs } from "pinia"; import { storeToRefs } from "pinia";
const store = useStore(); const { user } = storeToRefs(useStore());
const { updateUser } = store;
const { user } = storeToRefs(store);
const isIOS = computed(() => { const isIOS = computed(() => {
const systemInfo = uni.getDeviceInfo(); const systemInfo = uni.getDeviceInfo();
return systemInfo.osName === "ios"; return systemInfo.osName === "ios";
}); });
const loadImage = ref(false); const tabIndex = ref(0);
const data = ref({ const onTabChnage = (index) => {
weeksCheckIn: [], tabIndex.value = index;
});
const bowTargetSrc = ref("");
const heatMapImageSrc = ref(""); // 存储热力图图片地址
const toListPage = () => {
uni.navigateTo({
url: "/pages/list",
});
}; };
const editAvatar = ref(false);
const startScoring = () => {
if (user.value.id)
return uni.navigateTo({
url: "/pages/create",
});
uni.navigateTo({
url: "/pages/signin",
});
};
const loadData = async () => {
data.value = await getPointBookStatisticsAPI();
// const rect = await getElementRect(".heat-map");
// let hot = 0;
// if (result2.checkInCount > -3 && result2.checkInCount < 3) hot = 1;
// else if (result2.checkInCount >= 3) hot = 2;
// else if (result2.checkInCount >= 5) hot = 3;
// else if (result2.checkInCount === 7) hot = 4;
// uni.$emit("update-hot", hot);
// loadImage.value = true;
// const generateHeatmapAsync = async () => {
// const weekArrows = result2.weekArrows
// .filter((item) => item.x && item.y)
// .map((item) => [item.x, item.y]);
// try {
// // 渐进式渲染:数据量大时先快速渲染粗略版本
// if (weekArrows.length > 1000) {
// const quickPath = await generateKDEHeatmapImage(
// "heatMapCanvas",
// rect.width,
// rect.height,
// weekArrows
// );
// heatMapImageSrc.value = quickPath;
// // 延迟后再渲染精细版本
// await new Promise((resolve) => setTimeout(resolve, 500));
// }
// // 渲染最终精细版本
// const finalPath = await generateKDEHeatmapImage(
// "heatMapCanvas",
// rect.width,
// rect.height,
// weekArrows,
// {
// range: [0, 1],
// gridSize: 120, // 更高的网格密度,减少锯齿
// bandwidth: 0.15, // 稍小的带宽,让热力图更细腻
// showPoints: false,
// }
// );
// heatMapImageSrc.value = finalPath;
// loadImage.value = false;
// console.log("Heatmap image path:", finalPath);
// } catch (error) {
// console.error("Failed to generate heatmap image:", error);
// loadImage.value = false;
// }
// };
// // 异步生成热力图不阻塞UI
// generateHeatmapAsync();
};
watch(
() => user.value.id,
(id) => {
if (id) loadData();
}
);
onShow(async () => {
uni.removeStorageSync("point-book");
if (user.value.id) loadData();
});
onMounted(async () => {
const token = uni.getStorageSync("token");
if (!user.value.id && token) {
const data = await getHomeData();
if (data.user) updateUser(data.user);
}
const config = await getPointBookConfigAPI();
uni.setStorageSync("point-book-config", config);
if (config.targetOption && config.targetOption[0]) {
bowTargetSrc.value = config.targetOption[0].icon;
}
});
</script> </script>
<template> <template>
<Container :bgType="4" bgColor="#F5F5F5" title="">
<view class="container"> <view class="container">
<view class="daily-signin"> <swiper
:current="tabIndex"
@change="(e) => (tabIndex = e.detail.current)"
:style="{
height: `calc(100vh - 100rpx - ${isIOS ? '30rpx' : '0rpx'})`,
background: '#f5f5f5',
}"
>
<swiper-item>
<Score />
</swiper-item>
<swiper-item>
<History />
</swiper-item>
<swiper-item>
<Profile :editAvatar="() => (editAvatar = true)" />
</swiper-item>
</swiper>
<view
class="edit-avatar"
:style="{ height: editAvatar ? '100vh' : '0' }"
@click="editAvatar = false"
>
<image :src="user.avatar" mode="widthFix" />
<view> <view>
<image src="../static/week-check.png" />
</view>
<view :class="data.weeksCheckIn[0] ? 'checked' : ''">
<image
v-if="data.weeksCheckIn[0]"
src="../static/checked-green2.png"
mode="widthFix"
/>
<view v-else></view>
<text>Mon</text>
</view>
<view :class="data.weeksCheckIn[1] ? 'checked' : ''">
<image
v-if="data.weeksCheckIn[1]"
src="../static/checked-green2.png"
mode="widthFix"
/>
<view v-else></view>
<text>Tue</text>
</view>
<view :class="data.weeksCheckIn[2] ? 'checked' : ''">
<image
v-if="data.weeksCheckIn[2]"
src="../static/checked-green2.png"
mode="widthFix"
/>
<view v-else></view>
<text>Wed</text>
</view>
<view :class="data.weeksCheckIn[3] ? 'checked' : ''">
<image
v-if="data.weeksCheckIn[3]"
src="../static/checked-green2.png"
mode="widthFix"
/>
<view v-else></view>
<text>Thu</text>
</view>
<view :class="data.weeksCheckIn[4] ? 'checked' : ''">
<image
v-if="data.weeksCheckIn[4]"
src="../static/checked-green2.png"
mode="widthFix"
/>
<view v-else></view>
<text>Fri</text>
</view>
<view :class="data.weeksCheckIn[5] ? 'checked' : ''">
<image
v-if="data.weeksCheckIn[5]"
src="../static/checked-green2.png"
mode="widthFix"
/>
<view v-else></view>
<text>Sat</text>
</view>
<view :class="data.weeksCheckIn[6] ? 'checked' : ''">
<image
v-if="data.weeksCheckIn[6]"
src="../static/checked-green2.png"
mode="widthFix"
/>
<view v-else></view>
<text>Sun</text>
</view>
</view>
<view class="statistics">
<view> <view>
<text>{{ data.todayTotalArrow || "-" }}</text> <text>Take a photo</text>
<text>Arrows Today</text> <image src="../static/back-grey.png" mode="widthFix" />
</view> </view>
<view> <view>
<text>{{ data.totalArrow || "-" }}</text> <text>Choose photo</text>
<text>Total Arrows</text> <image src="../static/back-grey.png" mode="widthFix" />
</view>
<view>
<text>{{ data.totalDay || "-" }}</text>
<text>Training Days</text>
</view>
<view>
<text>{{ data.averageRing || "-" }}</text>
<text>Average Rings</text>
</view>
<view>
<text>{{
data.yellowRate !== undefined
? Number((data.yellowRate * 100).toFixed(2)) + "%"
: "-"
}}</text>
<text>Gold Rate</text>
</view>
<view>
<button hover-class="none" @click="startScoring">
<image src="../static/start-scoring.png" mode="widthFix" />
</button>
</view> </view>
</view> </view>
<view class="title" :style="{ marginBottom: 0 }">
<image src="../static/point-book-title1.png" mode="widthFix" />
</view> </view>
<view class="heat-map"> <Tabbar :selected="tabIndex" :onClick="onTabChnage" />
<image
:src="bowTargetSrc || '../static/bow-target.png'"
mode="widthFix"
/>
<image
v-if="heatMapImageSrc"
:src="heatMapImageSrc"
mode="aspectFill"
/>
<view v-if="loadImage" class="load-image">
<text>Generating...</text>
</view> </view>
<canvas
id="heatMapCanvas"
canvas-id="heatMapCanvas"
type="2d"
style="
width: 100%;
height: 100%;
position: absolute;
top: -1000px;
left: 0;
z-index: 2;
"
/>
</view>
<RingBarChart :data="data.ringRate" v-if="user.id" />
</view>
</Container>
</template> </template>
<style scoped> <style scoped>
.container { .container {
width: calc(100% - 50rpx); width: 100vw;
padding: 25rpx; height: 100vw;
background: #f5f5f5;
} }
.statistics { .edit-avatar {
border-radius: 25rpx; position: fixed;
border-bottom-left-radius: 50rpx;
border-bottom-right-radius: 50rpx;
border: 4rpx solid #fed848;
background: #fff;
font-size: 22rpx;
display: flex;
flex-wrap: wrap;
padding: 25rpx 0;
margin-bottom: 10rpx;
}
.statistics > view {
width: 33.33%;
display: flex;
flex-direction: column;
align-items: center;
justify-content: center;
}
.statistics > view:nth-child(-n + 3) {
margin-bottom: 25rpx;
}
.statistics > view:nth-child(2),
.statistics > view:nth-child(5) {
border-left: 1rpx solid #eeeeee;
border-right: 1rpx solid #eeeeee;
box-sizing: border-box;
}
.statistics > view > text {
text-align: center;
font-size: 22rpx;
color: #333333;
}
.statistics > view > text:first-child {
font-weight: 500;
font-size: 40rpx;
margin-bottom: 10rpx;
}
.statistics > view:last-child > button > image {
width: 164rpx;
}
.daily-signin {
display: grid;
grid-template-columns: repeat(8, 1fr);
gap: 10rpx;
border-radius: 20rpx;
margin-bottom: 25rpx;
}
.daily-signin > view {
display: flex;
flex-direction: column;
align-items: center;
justify-content: center;
border-radius: 12rpx;
box-sizing: border-box;
}
.daily-signin > view:not(:first-child) {
background: #f8f8f8;
box-sizing: border-box;
width: 78rpx;
height: 94rpx;
padding-top: 10rpx;
}
.daily-signin > view:not(:first-child) > image {
width: 32rpx;
height: 32rpx;
}
.daily-signin > view:not(:first-child) > view {
width: 32rpx;
height: 32rpx;
border-radius: 50%;
box-sizing: border-box;
border: 2rpx solid #333;
}
.daily-signin > view > text {
font-size: 20rpx;
color: #999999;
font-weight: 500;
text-align: center;
margin-top: 10rpx;
}
.daily-signin > view:first-child > image {
width: 72rpx;
height: 94rpx;
}
.checked {
border: 2rpx solid #000;
}
.checked > text {
color: #333 !important;
}
.title {
width: 100%;
display: flex;
justify-content: center;
margin: 25rpx 0;
}
.title > image {
width: 566rpx;
}
.heat-map {
position: relative;
margin: 0 auto;
width: calc(100vw - 70rpx);
height: calc(100vw - 70rpx);
transform: scale(0.9);
}
.heat-map > image {
width: 100%;
height: 100%;
position: absolute;
top: 0; top: 0;
left: 0; right: 0;
} width: 100vw;
.load-image { background: rgba(0, 0, 0, 0.8);
position: absolute;
width: 160rpx;
top: calc(50% - 65rpx);
left: calc(50% - 75rpx);
color: #525252;
font-size: 20rpx;
display: flex; display: flex;
flex-direction: column; flex-direction: column;
align-items: center; align-items: center;
justify-content: center;
overflow: hidden;
z-index: 999;
}
.edit-avatar > image {
width: 85vw;
height: 85vw;
border-radius: 50%;
}
.edit-avatar > view {
border-radius: 25rpx;
margin-top: 100rpx;
width: calc(100% - 150rpx);
padding: 0 40rpx;
background: #404040;
}
.edit-avatar > view > view {
display: flex;
align-items: center;
justify-content: space-between;
font-size: 30rpx;
color: #ffffff;
padding: 40rpx 0;
}
.edit-avatar > view > view:not(:last-child) {
border-bottom: 1rpx solid #fff3;
border-radius: 0;
}
.edit-avatar > view > view > image {
width: 28rpx;
} }
</style> </style>

View File

@@ -1,6 +1,5 @@
<script setup> <script setup>
import { ref, onMounted } from "vue"; import { ref, onMounted } from "vue";
import Container from "@/components/Container.vue";
import SModal from "@/components/SModal.vue"; import SModal from "@/components/SModal.vue";
import EditOption from "@/components/EditOption.vue"; import EditOption from "@/components/EditOption.vue";
import PointRecord from "@/components/PointRecord.vue"; import PointRecord from "@/components/PointRecord.vue";
@@ -8,6 +7,7 @@ import ScrollList from "@/components/ScrollList.vue";
import ScreenHint from "@/components/ScreenHint.vue"; import ScreenHint from "@/components/ScreenHint.vue";
import { getPointBookListAPI, removePointRecord } from "@/api"; import { getPointBookListAPI, removePointRecord } from "@/api";
const statusBarHeight = uni.getSystemInfoSync().statusBarHeight;
const showTip = ref(false); const showTip = ref(false);
const bowType = ref({}); const bowType = ref({});
const distance = ref(0); const distance = ref(0);
@@ -67,8 +67,16 @@ const onSelectOption = (itemIndex, value) => {
</script> </script>
<template> <template>
<Container :bgType="2" bgColor="#F5F5F5" title="Point Records"> <view
<view class="container"> class="list"
:style="{
paddingTop: statusBarHeight + 'px',
backgroundSize: `100% ${statusBarHeight + 50}px`,
}"
>
<view class="list-header">
<text>History</text>
</view>
<view class="selectors"> <view class="selectors">
<view @click="() => openSelector(0)"> <view @click="() => openSelector(0)">
<text :style="{ color: bowType.name ? '#000' : '#999' }">{{ <text :style="{ color: bowType.name ? '#000' : '#999' }">{{
@@ -147,20 +155,28 @@ const onSelectOption = (itemIndex, value) => {
</view> </view>
</ScreenHint> </ScreenHint>
</view> </view>
</Container>
</template> </template>
<style scoped> <style scoped>
.container { .list {
width: 100%; background: url("../static/app-bg3.png") no-repeat top/contain;
height: 100%; }
.list-header {
height: 40px;
margin-bottom: 10px;
display: flex;
align-items: center;
justify-content: center;
font-weight: 500;
font-size: 30rpx;
color: #333333;
} }
.selectors { .selectors {
display: flex; display: flex;
align-items: center; align-items: center;
justify-content: space-between; justify-content: space-between;
padding: 0 15px; padding: 0 15px;
margin-top: 10px; margin-top: 40rpx;
} }
.selectors > view { .selectors > view {
display: flex; display: flex;

View File

@@ -7,7 +7,14 @@ import { storeToRefs } from "pinia";
const store = useStore(); const store = useStore();
const { user } = storeToRefs(store); const { user } = storeToRefs(store);
const editAvatar = ref(false); const props = defineProps({
editAvatar: {
type: String,
default: "",
},
});
const statusBarHeight = uni.getSystemInfoSync().statusBarHeight;
const toEditPage = (type) => { const toEditPage = (type) => {
uni.navigateTo({ uni.navigateTo({
@@ -23,90 +30,79 @@ const toSignInPage = () => {
</script> </script>
<template> <template>
<view class="container"> <view
class="profile"
:style="{
paddingTop: statusBarHeight + 'px',
}"
>
<view class="header"> <view class="header">
<image :src="user.avatar" mode="widthFix" /> <image :src="user.avatar" mode="widthFix" />
<button hover-class="none" @click="editAvatar = true"> <view @click="editAvatar">
<image src="../static/pen-yellow.png" mode="widthFix" /> <image src="../static/pen-yellow.png" mode="widthFix" />
</button> </view>
</view> </view>
<view class="body"> <view class="body">
<view> <view>
<button hover-class="none" @click="toEditPage('Name')"> <view @click="toEditPage('Name')">
<image src="../static/user-yellow.png" mode="widthFix" /> <image src="../static/user-yellow.png" mode="widthFix" />
<text>Name</text> <text>Name</text>
<image src="../static/back-grey.png" mode="widthFix" /> <image src="../static/back-grey.png" mode="widthFix" />
</button> </view>
<button hover-class="none" @click="toEditPage('Email')"> <view @click="toEditPage('Email')">
<image src="../static/email-yellow.png" mode="widthFix" /> <image src="../static/email-yellow.png" mode="widthFix" />
<text>Email</text> <text>Email</text>
<image src="../static/back-grey.png" mode="widthFix" /> <image src="../static/back-grey.png" mode="widthFix" />
</button> </view>
<button hover-class="none" @click="toEditPage('Password')"> <view @click="toEditPage('Password')">
<image src="../static/password-yellow.png" mode="widthFix" /> <image src="../static/password-yellow.png" mode="widthFix" />
<text>Password</text> <text>Password</text>
<image src="../static/back-grey.png" mode="widthFix" /> <image src="../static/back-grey.png" mode="widthFix" />
</button>
</view> </view>
<button hover-class="none" @click="toSignInPage">Log out</button> </view>
<view @click="toSignInPage">Log out</view>
<view> <view>
<text>Have questions? Please contact us through email: </text> <text>Have questions? Please contact us through email: </text>
<text>shelingxingqiu@163.com</text> <text>shelingxingqiu@163.com</text>
</view> </view>
</view> </view>
<view
class="edit-avatar"
:style="{ height: editAvatar ? '100vh' : '0' }"
@click="editAvatar = false"
>
<image :src="user.avatar" mode="widthFix" />
<view>
<button hover-class="none">
<text>Take a photo</text>
<image src="../static/back-grey.png" mode="widthFix" />
</button>
<button hover-class="none">
<text>Choose photo</text>
<image src="../static/back-grey.png" mode="widthFix" />
</button>
</view>
</view>
</view> </view>
</template> </template>
<style scoped> <style scoped>
.container { .profile {
display: flex; display: flex;
flex-direction: column; flex-direction: column;
align-items: center; align-items: center;
background: url("../static/app-bg6.png") no-repeat top/contain;
height: 100%; height: 100%;
position: relative;
} }
.header { .header {
position: relative; position: relative;
margin-top: -120rpx;
} }
.header > image { .header > image {
width: 180rpx; width: 160rpx;
height: 180rpx; height: 160rpx;
border-radius: 50%; border-radius: 50%;
border: 4rpx solid #fff; border: 4rpx solid #fff;
box-sizing: border-box;
} }
.header > button { .header > view {
position: absolute; position: absolute;
right: 0; right: 0;
bottom: 0; bottom: 0;
} }
.header > button > image { .header > view > image {
width: 60rpx; width: 60rpx;
height: 60rpx; height: 60rpx;
} }
.body { .body {
width: 100%; padding: 25rpx;
margin-top: 20rpx; width: calc(100% - 50rpx);
display: flex; display: flex;
flex-direction: column; flex-direction: column;
align-items: center; align-items: center;
flex: 1;
} }
.body > view:first-child { .body > view:first-child {
background-color: #fff; background-color: #fff;
@@ -114,40 +110,41 @@ const toSignInPage = () => {
padding: 0 20px; padding: 0 20px;
width: calc(100% - 80rpx); width: calc(100% - 80rpx);
} }
.body > view:first-child > button { .body > view:first-child > view {
display: flex; display: flex;
align-items: center; align-items: center;
padding: 20px 0; padding: 20px 0;
} }
.body > view:first-child > button:not(:last-child) { .body > view:first-child > view:not(:last-child) {
border-bottom: 1rpx solid #e3e3e3; border-bottom: 1rpx solid #e3e3e3;
} }
.body > view:first-child > button > image:first-child { .body > view:first-child > view > image:first-child {
width: 40rpx; width: 40rpx;
height: 40rpx; height: 40rpx;
} }
.body > view:first-child > button > text { .body > view:first-child > view > text {
flex: 1; flex: 1;
font-size: 26rpx; font-size: 26rpx;
color: #333333; color: #333333;
text-align: left; text-align: left;
padding-left: 20rpx; padding-left: 20rpx;
} }
.body > view:first-child > button > image:last-child { .body > view:first-child > view > image:last-child {
width: 28rpx; width: 28rpx;
height: 28rpx; height: 28rpx;
} }
.body > button { .body > view:nth-child(2) {
margin-top: 24rpx; margin-top: 24rpx;
background: #fff; background: #fff;
border-radius: 24rpx; border-radius: 24rpx;
font-size: 26rpx; font-size: 26rpx;
color: #287fff; color: #287fff;
text-align: center; text-align: center;
padding: 20px 0;
width: 100%; width: 100%;
height: 100rpx;
line-height: 100rpx;
} }
.body > view:last-child { .body > view:nth-child(3) {
margin-top: auto; margin-top: auto;
padding-bottom: 25rpx; padding-bottom: 25rpx;
display: flex; display: flex;
@@ -155,47 +152,10 @@ const toSignInPage = () => {
align-items: center; align-items: center;
font-size: 24rpx; font-size: 24rpx;
color: #666666; color: #666666;
position: absolute;
bottom: 120rpx;
} }
.body > view:last-child > text:last-child { .body > view:nth-child(3) > text:last-child {
color: #287fff; color: #287fff;
} }
.edit-avatar {
position: fixed;
top: 0;
right: 0;
width: 100vw;
background: rgba(0, 0, 0, 0.8);
display: flex;
flex-direction: column;
align-items: center;
justify-content: center;
overflow: hidden;
}
.edit-avatar > image {
width: 85vw;
height: 85vw;
border-radius: 50%;
}
.edit-avatar > view {
border-radius: 25rpx;
margin-top: 100rpx;
width: calc(100% - 150rpx);
padding: 0 40rpx;
background: #404040;
}
.edit-avatar > view > button {
display: flex;
align-items: center;
justify-content: space-between;
font-size: 30rpx;
color: #ffffff;
padding: 40rpx 0;
}
.edit-avatar > view > button:not(:last-child) {
border-bottom: 1rpx solid #fff3;
border-radius: 0;
}
.edit-avatar > view > button > image {
width: 28rpx;
}
</style> </style>

394
src/pages/score.vue Normal file
View File

@@ -0,0 +1,394 @@
<script setup>
import { ref, watch, onMounted } from "vue";
import { onShow } from "@dcloudio/uni-app";
import PointRecord from "@/components/PointRecord.vue";
import RingBarChart from "@/components/RingBarChart.vue";
import {
getHomeData,
getPointBookConfigAPI,
getPointBookStatisticsAPI,
} from "@/api";
import { getElementRect } from "@/util";
// import { generateKDEHeatmapImage } from "@/kde-heatmap";
import useStore from "@/store";
import { storeToRefs } from "pinia";
const store = useStore();
const { updateUser } = store;
const { user } = storeToRefs(store);
const statusBarHeight = uni.getSystemInfoSync().statusBarHeight;
const loadImage = ref(false);
const heat = ref(0);
const data = ref({
weeksCheckIn: [],
});
const bowTargetSrc = ref("");
const heatMapImageSrc = ref(""); // 存储热力图图片地址
const startScoring = () => {
if (user.value.id)
return uni.navigateTo({
url: "/pages/create",
});
uni.navigateTo({
url: "/pages/signin",
});
};
const loadData = async () => {
data.value = await getPointBookStatisticsAPI();
if (data.value.checkInCount > -3 && data.value.checkInCount < 3)
heat.value = 1;
else if (data.value.checkInCount >= 3) heat.value = 2;
else if (data.value.checkInCount >= 5) heat.value = 3;
else if (data.value.checkInCount === 7) heat.value = 4;
};
watch(
() => user.value.id,
(id) => {
if (id) loadData();
}
);
const signin = () => {
if (!user.value.id) {
uni.navigateTo({
url: "/pages/signin",
});
}
};
onShow(async () => {
uni.removeStorageSync("point-book");
if (user.value.id) loadData();
});
onMounted(async () => {
const token = uni.getStorageSync("token");
if (!user.value.id && token) {
const data = await getHomeData();
if (data.user) updateUser(data.user);
}
const config = await getPointBookConfigAPI();
uni.setStorageSync("point-book-config", config);
if (config.targetOption && config.targetOption[0]) {
bowTargetSrc.value = config.targetOption[0].icon;
}
});
</script>
<template>
<view class="score" :style="{ paddingTop: statusBarHeight + 'px' }">
<view class="user-header" @click="signin">
<block v-if="user.id">
<Avatar
:src="user.avatar"
:onClick="toUserPage"
:size="40"
borderColor="#333"
/>
<text class="truncate">{{ user.nickName }}</text>
<image v-if="heat" :src="`../static/hot${heat}.png`" mode="widthFix" />
</block>
<block v-else>
<image src="../static/user-icon.png" mode="widthFix" />
<text>Hello~</text>
</block>
</view>
<view class="daily-signin">
<view>
<image src="../static/week-check.png" />
</view>
<view :class="data.weeksCheckIn[0] ? 'checked' : ''">
<image
v-if="data.weeksCheckIn[0]"
src="../static/checked-green2.png"
mode="widthFix"
/>
<view v-else></view>
<text>Mon</text>
</view>
<view :class="data.weeksCheckIn[1] ? 'checked' : ''">
<image
v-if="data.weeksCheckIn[1]"
src="../static/checked-green2.png"
mode="widthFix"
/>
<view v-else></view>
<text>Tue</text>
</view>
<view :class="data.weeksCheckIn[2] ? 'checked' : ''">
<image
v-if="data.weeksCheckIn[2]"
src="../static/checked-green2.png"
mode="widthFix"
/>
<view v-else></view>
<text>Wed</text>
</view>
<view :class="data.weeksCheckIn[3] ? 'checked' : ''">
<image
v-if="data.weeksCheckIn[3]"
src="../static/checked-green2.png"
mode="widthFix"
/>
<view v-else></view>
<text>Thu</text>
</view>
<view :class="data.weeksCheckIn[4] ? 'checked' : ''">
<image
v-if="data.weeksCheckIn[4]"
src="../static/checked-green2.png"
mode="widthFix"
/>
<view v-else></view>
<text>Fri</text>
</view>
<view :class="data.weeksCheckIn[5] ? 'checked' : ''">
<image
v-if="data.weeksCheckIn[5]"
src="../static/checked-green2.png"
mode="widthFix"
/>
<view v-else></view>
<text>Sat</text>
</view>
<view :class="data.weeksCheckIn[6] ? 'checked' : ''">
<image
v-if="data.weeksCheckIn[6]"
src="../static/checked-green2.png"
mode="widthFix"
/>
<view v-else></view>
<text>Sun</text>
</view>
</view>
<view class="statistics">
<view>
<text>{{ data.todayTotalArrow || "-" }}</text>
<text>Arrows Today</text>
</view>
<view>
<text>{{ data.totalArrow || "-" }}</text>
<text>Total Arrows</text>
</view>
<view>
<text>{{ data.totalDay || "-" }}</text>
<text>Training Days</text>
</view>
<view>
<text>{{ data.averageRing || "-" }}</text>
<text>Average Rings</text>
</view>
<view>
<text>{{
data.yellowRate !== undefined
? Number((data.yellowRate * 100).toFixed(2)) + "%"
: "-"
}}</text>
<text>Gold Rate</text>
</view>
<view>
<view @click="startScoring">
<image src="../static/start-scoring.png" mode="widthFix" />
</view>
</view>
</view>
<view class="title" :style="{ marginBottom: 0 }">
<image src="../static/point-book-title1.png" mode="widthFix" />
</view>
<view class="heat-map">
<image
:src="bowTargetSrc || '../static/bow-target.png'"
mode="widthFix"
/>
<image v-if="heatMapImageSrc" :src="heatMapImageSrc" mode="aspectFill" />
<view v-if="loadImage" class="load-image">
<text>Generating...</text>
</view>
<canvas
id="heatMapCanvas"
canvas-id="heatMapCanvas"
type="2d"
style="
width: 100%;
height: 100%;
position: absolute;
top: -1000px;
left: 0;
z-index: 2;
"
/>
</view>
<RingBarChart :data="data.ringRate" v-if="user.id" />
</view>
</template>
<style scoped>
.score {
padding-left: 25rpx;
padding-right: 25rpx;
background: url("../static/app-bg5.png") no-repeat top/contain;
}
.statistics {
border-radius: 25rpx;
border-bottom-left-radius: 50rpx;
border-bottom-right-radius: 50rpx;
border: 2px solid #fed848;
background: #fff;
font-size: 22rpx;
display: flex;
flex-wrap: wrap;
padding: 25rpx 0;
margin-bottom: 10rpx;
}
.statistics > view {
width: 33.33%;
display: flex;
flex-direction: column;
align-items: center;
justify-content: center;
}
.statistics > view:nth-child(-n + 3) {
margin-bottom: 25rpx;
}
.statistics > view:nth-child(2),
.statistics > view:nth-child(5) {
border-left: 1rpx solid #eeeeee;
border-right: 1rpx solid #eeeeee;
box-sizing: border-box;
}
.statistics > view > text {
text-align: center;
font-size: 22rpx;
color: #333333;
}
.statistics > view > text:first-child {
font-weight: 500;
font-size: 40rpx;
margin-bottom: 10rpx;
}
.statistics > view:last-child > view {
display: flex;
align-items: center;
}
.statistics > view:last-child > view > image {
width: 164rpx;
height: 74rpx;
}
.daily-signin {
display: grid;
grid-template-columns: repeat(8, 1fr);
gap: 10rpx;
border-radius: 20rpx;
margin-bottom: 25rpx;
}
.daily-signin > view {
display: flex;
flex-direction: column;
align-items: center;
justify-content: center;
border-radius: 12rpx;
box-sizing: border-box;
}
.daily-signin > view:not(:first-child) {
background: #f8f8f8;
box-sizing: border-box;
width: 78rpx;
height: 94rpx;
padding-top: 10rpx;
}
.daily-signin > view:not(:first-child) > image {
width: 32rpx;
height: 32rpx;
}
.daily-signin > view:not(:first-child) > view {
width: 32rpx;
height: 32rpx;
border-radius: 50%;
box-sizing: border-box;
border: 2rpx solid #333;
}
.daily-signin > view > text {
font-size: 20rpx;
color: #999999;
font-weight: 500;
text-align: center;
margin-top: 10rpx;
}
.daily-signin > view:first-child > image {
width: 72rpx;
height: 94rpx;
}
.checked {
border: 2rpx solid #000;
}
.checked > text {
color: #333 !important;
}
.title {
width: 100%;
display: flex;
justify-content: center;
margin: 25rpx 0;
}
.title > image {
width: 566rpx;
}
.heat-map {
position: relative;
margin: 0 auto;
width: calc(100vw - 70rpx);
height: calc(100vw - 70rpx);
transform: scale(0.9);
}
.heat-map > image {
width: 100%;
height: 100%;
position: absolute;
top: 0;
left: 0;
}
.load-image {
position: absolute;
width: 160rpx;
top: calc(50% - 65rpx);
left: calc(50% - 75rpx);
color: #525252;
font-size: 20rpx;
display: flex;
flex-direction: column;
align-items: center;
}
.user-header {
display: flex;
align-items: start;
justify-content: flex-start;
height: 40px;
margin-bottom: 10px;
}
.user-header > image:first-child {
width: 40px;
height: 40px;
border-radius: 50%;
border: 1px solid #333;
box-sizing: border-box;
}
.user-header > image:last-child {
width: 36rpx;
}
.user-header > text:nth-child(2) {
font-weight: 500;
font-size: 30rpx;
color: #333333;
margin: 0 20rpx;
max-width: 300rpx;
line-height: 90rpx;
}
</style>

BIN
src/static/app-bg6.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 8.5 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.3 KiB

BIN
src/static/tab-history.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 820 B

BIN
src/static/tab-score-s.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.7 KiB

BIN
src/static/tab-score.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.1 KiB

BIN
src/static/tab-user-s.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.6 KiB

BIN
src/static/tab-user.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.0 KiB