feat(calendar): 更新日历接口并优化记录流程
- 将GetRecords接口替换为GetCalendar接口获取日历数据 - 重构首页日历数据显示逻辑,支持年月维度的数据获取 - 优化打卡记录流程,合并选酒和记量步骤为单一添加酒水步骤 - 移除登录页面的游客模式选项,简化首次启动逻辑 - 调整引导页逻辑,移除登录跳转改为直接进入首页 - 优化记录页面UI布局,添加状态栏安全距离适配 - 新增酒水列表管理功能,支持添加和删除已选酒水 - 更新依赖包HaveADrink至v1.0.3版本,同步API变更
This commit is contained in:
+43
-32
@@ -91,7 +91,7 @@
|
||||
<view v-if="selectedRecord.mode === 'drank'" class="day-record-info">
|
||||
<view class="day-drinks">
|
||||
<view v-for="(drink, i) in selectedRecord.drinks" :key="i" class="day-drink-item">
|
||||
<text>{{ drink.emoji || '🥃' }} {{ drink.brand }} {{ drink.product }}</text>
|
||||
<text>{{ getCatEmoji(drink.category) }} {{ drink.brand }} {{ drink.product }}</text>
|
||||
</view>
|
||||
</view>
|
||||
<view class="day-meta flex-between">
|
||||
@@ -118,8 +118,9 @@
|
||||
<script>
|
||||
import DrinkCalendar from '../../components/DrinkCalendar.vue'
|
||||
import client from '../../common/api'
|
||||
import { GetCalendarReq } from 'HaveADrink'
|
||||
import { getGreeting, formatDate, getWeekStart } from '../../common/utils'
|
||||
import { FEELINGS } from '../../common/constants'
|
||||
import { FEELINGS, DRINK_CATEGORIES } from '../../common/constants'
|
||||
import themeMixin from '../../common/theme-mixin'
|
||||
|
||||
export default {
|
||||
@@ -156,8 +157,7 @@ export default {
|
||||
onShow() {
|
||||
// 首次启动跳转引导页
|
||||
const isFirst = uni.getStorageSync('is_first_launch')
|
||||
const isLoggedIn = uni.getStorageSync('is_logged_in')
|
||||
if (isFirst === 'true' || !isLoggedIn) {
|
||||
if (isFirst === 'true') {
|
||||
uni.reLaunch({ url: '/pages/onboarding/onboarding' })
|
||||
return
|
||||
}
|
||||
@@ -171,7 +171,7 @@ export default {
|
||||
const [userResp, statsResp, recordsResp] = await Promise.allSettled([
|
||||
client.GetUserProfile({}),
|
||||
client.GetStatsOverview({}),
|
||||
client.GetRecords({ page: 1, pageSize: 100 })
|
||||
client.GetCalendar(new GetCalendarReq(this.calendarYear, this.calendarMonth))
|
||||
])
|
||||
|
||||
// 用户信息
|
||||
@@ -207,20 +207,24 @@ export default {
|
||||
}
|
||||
}
|
||||
|
||||
// 记录列表
|
||||
// 日历数据
|
||||
if (recordsResp.status === 'fulfilled' && recordsResp.value) {
|
||||
const list = recordsResp.value.list || recordsResp.value
|
||||
this.records = Array.isArray(list) ? list.map(r => ({
|
||||
...r,
|
||||
mode: String(r.mode),
|
||||
feeling: r.feeling ? String(r.feeling) : null,
|
||||
visibility: r.visibility ? String(r.visibility) : 'private',
|
||||
drinks: (r.drinks || []).map(d => ({
|
||||
...d,
|
||||
category: String(d.category),
|
||||
unit: String(d.unit)
|
||||
}))
|
||||
})) : []
|
||||
const calData = recordsResp.value.data || recordsResp.value
|
||||
const days = calData.days || []
|
||||
this.records = days.filter(d => d && d.hasRecord).map(d => ({
|
||||
id: d.id || '',
|
||||
date: d.date,
|
||||
mode: String(d.mode),
|
||||
standardCupsTotal: d.standardCupsTotal || 0,
|
||||
drinks: (d.drinks || []).map(dr => ({
|
||||
...dr,
|
||||
category: String(dr.category)
|
||||
})),
|
||||
food: d.food ? { category: String(d.food.category), name: d.food.name || '' } : null,
|
||||
feeling: d.feeling ? String(d.feeling) : null,
|
||||
quote: d.quote || '',
|
||||
visibility: d.visibility ? String(d.visibility) : 'friends'
|
||||
}))
|
||||
}
|
||||
} catch (e) {
|
||||
console.warn('加载首页数据失败:', e)
|
||||
@@ -241,20 +245,23 @@ export default {
|
||||
},
|
||||
async loadRecordsForMonth(year, month) {
|
||||
try {
|
||||
const monthStr = `${year}-${String(month).padStart(2, '0')}`
|
||||
const resp = await client.GetRecords({ page: 1, pageSize: 100, month: monthStr })
|
||||
const list = resp.list || resp
|
||||
this.records = Array.isArray(list) ? list.map(r => ({
|
||||
...r,
|
||||
mode: String(r.mode),
|
||||
feeling: r.feeling ? String(r.feeling) : null,
|
||||
visibility: r.visibility ? String(r.visibility) : 'private',
|
||||
drinks: (r.drinks || []).map(d => ({
|
||||
...d,
|
||||
category: String(d.category),
|
||||
unit: String(d.unit)
|
||||
}))
|
||||
})) : []
|
||||
const resp = await client.GetCalendar(new GetCalendarReq(year, month))
|
||||
const calData = resp.data || resp
|
||||
const days = calData.days || []
|
||||
this.records = days.filter(d => d && d.hasRecord).map(d => ({
|
||||
id: d.id || '',
|
||||
date: d.date,
|
||||
mode: String(d.mode),
|
||||
standardCupsTotal: d.standardCupsTotal || 0,
|
||||
drinks: (d.drinks || []).map(dr => ({
|
||||
...dr,
|
||||
category: String(dr.category)
|
||||
})),
|
||||
food: d.food ? { category: String(d.food.category), name: d.food.name || '' } : null,
|
||||
feeling: d.feeling ? String(d.feeling) : null,
|
||||
quote: d.quote || '',
|
||||
visibility: d.visibility ? String(d.visibility) : 'friends'
|
||||
}))
|
||||
} catch (e) {
|
||||
console.warn('加载月度记录失败:', e)
|
||||
}
|
||||
@@ -268,6 +275,10 @@ export default {
|
||||
const f = FEELINGS.find(f => f.id === feelingId)
|
||||
return f ? `${f.emoji} ${f.name}` : ''
|
||||
},
|
||||
getCatEmoji(catId) {
|
||||
const cat = DRINK_CATEGORIES.find(c => c.id === catId)
|
||||
return cat ? cat.emoji : '🥃'
|
||||
},
|
||||
backfillDate() {
|
||||
this.showDayDetail = false
|
||||
uni.navigateTo({
|
||||
|
||||
Reference in New Issue
Block a user