feat: 增加今日资讯模块
This commit is contained in:
33
src/components/Home/TipPopup.vue
Normal file
33
src/components/Home/TipPopup.vue
Normal file
@@ -0,0 +1,33 @@
|
|||||||
|
<template>
|
||||||
|
<wd-popup
|
||||||
|
v-model="appStore.showTipPopup"
|
||||||
|
position="bottom"
|
||||||
|
:lock-scroll="true"
|
||||||
|
:safe-area-inset-bottom="true"
|
||||||
|
:close-on-click-modal="true"
|
||||||
|
custom-style="border-radius: 32rpx 32rpx 0 0; padding: 40rpx 32rpx"
|
||||||
|
@close="handeClosePopup"
|
||||||
|
>
|
||||||
|
<view class="flex flex-col max-h-[85vh] overflow-y-auto">
|
||||||
|
<view class="mb-5 text-center text-[30rpx] font-semibold text-[#333] shrink-0">
|
||||||
|
{{ appStore.currentTip.title }}
|
||||||
|
</view>
|
||||||
|
|
||||||
|
<wd-text type="primary" :text="appStore.currentTip.content"/>
|
||||||
|
</view>
|
||||||
|
</wd-popup>
|
||||||
|
</template>
|
||||||
|
|
||||||
|
<script setup lang="ts">
|
||||||
|
import { useAppStore } from '@/store/app'
|
||||||
|
import { useRecordStore } from '@/store/record'
|
||||||
|
|
||||||
|
const appStore = useAppStore()
|
||||||
|
const recordStore = useRecordStore()
|
||||||
|
|
||||||
|
function handeClosePopup() {
|
||||||
|
setTimeout(() => {
|
||||||
|
recordStore.showFab = true
|
||||||
|
}, 300)
|
||||||
|
}
|
||||||
|
</script>
|
||||||
@@ -68,6 +68,27 @@
|
|||||||
</view>
|
</view>
|
||||||
</wd-card>
|
</wd-card>
|
||||||
|
|
||||||
|
<wd-card title="🔥 今日资讯">
|
||||||
|
<view
|
||||||
|
v-for="(item, index) in tipList"
|
||||||
|
:key="index"
|
||||||
|
class="content-text flex flex-col py-[20rpx] border-b border-[#f5f5f5] last:border-b-0"
|
||||||
|
@click="viewTipClick(item)"
|
||||||
|
>
|
||||||
|
<view class="flex items-center gap-[12rpx]">
|
||||||
|
<wd-tag type="primary" round>{{ item.category }}</wd-tag>
|
||||||
|
<text class="text-[30rpx] font-semibold text-[#333] truncate">
|
||||||
|
{{ item.title }}
|
||||||
|
</text>
|
||||||
|
<wd-icon name="caret-right" size="24px"></wd-icon>
|
||||||
|
</view>
|
||||||
|
|
||||||
|
<text class="mt-[8rpx] text-[26rpx] text-[#999] leading-normal line-clamp-2">
|
||||||
|
{{ item.summary }}
|
||||||
|
</text>
|
||||||
|
</view>
|
||||||
|
</wd-card>
|
||||||
|
|
||||||
<record-popup />
|
<record-popup />
|
||||||
|
|
||||||
<weight-popup />
|
<weight-popup />
|
||||||
@@ -76,6 +97,7 @@
|
|||||||
<blood-pressure-popup />
|
<blood-pressure-popup />
|
||||||
<blood-sugar-popup />
|
<blood-sugar-popup />
|
||||||
<temperature-popup />
|
<temperature-popup />
|
||||||
|
<tip-popup />
|
||||||
|
|
||||||
<liu-drag-button v-if="recordStore.showFab" @clickBtn="handelFabClick">
|
<liu-drag-button v-if="recordStore.showFab" @clickBtn="handelFabClick">
|
||||||
<wd-icon name="plus" size="24px"></wd-icon>
|
<wd-icon name="plus" size="24px"></wd-icon>
|
||||||
@@ -93,6 +115,7 @@ import BloodSugarPopup from "@/components/Home/BloodSugarPopup.vue";
|
|||||||
import TemperaturePopup from "@/components/Home/TemperaturePopup.vue";
|
import TemperaturePopup from "@/components/Home/TemperaturePopup.vue";
|
||||||
import { ref, computed, watch } from 'vue'
|
import { ref, computed, watch } from 'vue'
|
||||||
import { useRecordStore } from '@/store/record'
|
import { useRecordStore } from '@/store/record'
|
||||||
|
import { useAppStore } from '@/store/app'
|
||||||
import { getDateStr, getDayRecords, getTimeStr } from '@/utils/record'
|
import { getDateStr, getDayRecords, getTimeStr } from '@/utils/record'
|
||||||
import type { IHealthRecord } from "@/type/record";
|
import type { IHealthRecord } from "@/type/record";
|
||||||
import { onShow } from "@dcloudio/uni-app";
|
import { onShow } from "@dcloudio/uni-app";
|
||||||
@@ -100,6 +123,8 @@ import { getOverview, getPlan, getProfile } from "@/utils/profile";
|
|||||||
import appLogo from '@/static/logo.png'
|
import appLogo from '@/static/logo.png'
|
||||||
import type { IOverview, IPlan } from "@/type/profile";
|
import type { IOverview, IPlan } from "@/type/profile";
|
||||||
import { addSignInPoint } from "@/utils/points";
|
import { addSignInPoint } from "@/utils/points";
|
||||||
|
import type { ITip } from "@/type";
|
||||||
|
import TipPopup from "@/components/Home/TipPopup.vue";
|
||||||
|
|
||||||
defineOptions({
|
defineOptions({
|
||||||
name: 'Home',
|
name: 'Home',
|
||||||
@@ -108,8 +133,10 @@ defineOptions({
|
|||||||
const imgURL = appLogo
|
const imgURL = appLogo
|
||||||
|
|
||||||
const recordStore = useRecordStore()
|
const recordStore = useRecordStore()
|
||||||
|
const appStore = useAppStore()
|
||||||
|
|
||||||
const todayRecords = ref<IHealthRecord[]>([])
|
const todayRecords = ref<IHealthRecord[]>([])
|
||||||
|
const tipList = ref<ITip[]>([])
|
||||||
const hasSignedToday = ref(checkSignedToday())
|
const hasSignedToday = ref(checkSignedToday())
|
||||||
|
|
||||||
const now = new Date()
|
const now = new Date()
|
||||||
@@ -144,12 +171,30 @@ const today = computed(() => {
|
|||||||
onShow(() => {
|
onShow(() => {
|
||||||
todayRecords.value = getDayRecords(getDateStr(Date.now()))
|
todayRecords.value = getDayRecords(getDateStr(Date.now()))
|
||||||
hasSignedToday.value = checkSignedToday()
|
hasSignedToday.value = checkSignedToday()
|
||||||
|
|
||||||
|
wx.request({
|
||||||
|
url: 'https://cxx0822.s.3q.hair/health-api/agent/tip/latest',
|
||||||
|
method: 'GET',
|
||||||
|
header: { 'Content-Type': 'application/json' },
|
||||||
|
success: (res) => {
|
||||||
|
tipList.value = res.data as ITip[]
|
||||||
|
},
|
||||||
|
fail: (err) => {
|
||||||
|
console.error('请求失败:', err);
|
||||||
|
}
|
||||||
|
});
|
||||||
})
|
})
|
||||||
|
|
||||||
watch(() => recordStore.isRecord, () => {
|
watch(() => recordStore.isRecord, () => {
|
||||||
todayRecords.value = getDayRecords(getDateStr(Date.now()))
|
todayRecords.value = getDayRecords(getDateStr(Date.now()))
|
||||||
})
|
})
|
||||||
|
|
||||||
|
const viewTipClick = (item: ITip) => {
|
||||||
|
appStore.currentTip = item
|
||||||
|
appStore.showTipPopup = true
|
||||||
|
recordStore.showFab = false
|
||||||
|
}
|
||||||
|
|
||||||
// 今日概览
|
// 今日概览
|
||||||
const overviewItems = computed(() => {
|
const overviewItems = computed(() => {
|
||||||
const list = todayRecords.value
|
const list = todayRecords.value
|
||||||
|
|||||||
@@ -1,4 +1,5 @@
|
|||||||
import { defineStore } from 'pinia'
|
import { defineStore } from 'pinia'
|
||||||
|
import type { ITip } from "@/type";
|
||||||
|
|
||||||
export const useAppStore = defineStore('app', {
|
export const useAppStore = defineStore('app', {
|
||||||
state: () => ({
|
state: () => ({
|
||||||
@@ -6,7 +7,14 @@ export const useAppStore = defineStore('app', {
|
|||||||
viewRecordType: 'calendar',
|
viewRecordType: 'calendar',
|
||||||
points: 0,
|
points: 0,
|
||||||
recordCount: 0,
|
recordCount: 0,
|
||||||
achievement: ''
|
achievement: '',
|
||||||
|
showTipPopup: false,
|
||||||
|
currentTip: {
|
||||||
|
title: '',
|
||||||
|
summary: '',
|
||||||
|
category: '',
|
||||||
|
content: '',
|
||||||
|
} as ITip
|
||||||
}),
|
}),
|
||||||
actions: {
|
actions: {
|
||||||
|
|
||||||
|
|||||||
@@ -1,4 +1,11 @@
|
|||||||
export interface IStats {
|
export interface IStats {
|
||||||
name: string;
|
name: string;
|
||||||
value: number
|
value: number;
|
||||||
|
}
|
||||||
|
|
||||||
|
export interface ITip {
|
||||||
|
title: string;
|
||||||
|
summary: string;
|
||||||
|
category: string;
|
||||||
|
content: string;
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user