Files
hejiu/common/mock-data.js
T
cg 93e19caa75 refactor(components): 重构饮酒卡片组件的多照片布局和样式结构
- 将多照片布局从拼贴模式改为网格系统,支持2-9张照片的不同排列
- 优化卡片宽度为650rpx并调整整体布局结构
- 更新品牌底栏为左右分栏布局并添加二维码区域
- 简化模板数量计算逻辑,合并少照片情况的处理
- 为单照片模式添加object-fit: cover确保图片填充效果
- 移除多余的换行和注释,精简代码结构
- 调整CSS样式以适应新的网格布局系统
2026-07-13 23:12:10 +08:00

151 lines
4.5 KiB
JavaScript

/* 喝酒了么 - Mock 数据 */
import { formatDate, calcStandardCups, unitToMl } from './utils'
// 模拟用户数据
export const MOCK_USER = {
id: 'user_001',
nickname: '酒友小王',
avatar: '/static/logo.png',
preferences: {
favoriteCategories: ['baijiu', 'beer'],
frequency: 'often'
},
joinedAt: '2026-01-15'
}
// 生成过去一个月的模拟打卡记录
export function generateMockRecords() {
const records = []
const today = new Date()
// 预设一些打卡日
const drinkDays = [0, 1, 3, 5, 6, 8, 10, 12, 13, 15, 17, 19, 20, 22, 24, 25, 27, 29]
const abstainDays = [2, 4, 7, 9, 11, 14, 16, 18, 21, 23, 26, 28]
const drinkTemplates = [
{
drinks: [{ category: 'baijiu', brand: '茅台', product: '飞天茅台53度', amount: 100, unit: 'ml', degree: 53 }],
food: { category: 'hotpot', name: '重庆老火锅' },
feeling: 'tipsy'
},
{
drinks: [
{ category: 'beer', brand: '青岛啤酒', product: '经典', amount: 2, unit: 'bottle', degree: 4.3 },
],
food: { category: 'bbq', name: '烤串配毛豆' },
feeling: 'buzzed'
},
{
drinks: [{ category: 'wine', brand: '奔富', product: 'Bin 389', amount: 2, unit: 'cup', degree: 14.5 }],
food: { category: 'western', name: '牛排' },
feeling: 'tipsy'
},
{
drinks: [
{ category: 'baijiu', brand: '五粮液', product: '普五52度', amount: 150, unit: 'ml', degree: 52 },
{ category: 'beer', brand: '雪花', product: '勇闯天涯', amount: 1, unit: 'bottle', degree: 3.3 }
],
food: { category: 'stirfry', name: '水煮鱼+回锅肉' },
feeling: 'drunk'
},
{
drinks: [{ category: 'whisky', brand: '麦卡伦', product: '12年雪莉桶', amount: 3, unit: 'shot', degree: 40 }],
food: { category: 'snack', name: '坚果拼盘' },
feeling: 'tipsy'
},
{
drinks: [{ category: 'beer', brand: '百威', product: '经典', amount: 3, unit: 'bottle', degree: 5.0 }],
food: { category: 'seafood', name: '小龙虾' },
feeling: 'buzzed'
},
{
drinks: [{ category: 'fruit', brand: '梅见', product: '青梅酒', amount: 200, unit: 'ml', degree: 12 }],
food: { category: 'japanese', name: '刺身拼盘' },
feeling: 'tipsy'
}
]
drinkDays.forEach(daysAgo => {
const date = new Date(today)
date.setDate(date.getDate() - daysAgo)
const dateStr = formatDate(date, 'YYYY-MM-DD')
const template = drinkTemplates[daysAgo % drinkTemplates.length]
const standardCupsTotal = template.drinks.reduce((sum, d) => {
const ml = unitToMl(d.amount, d.unit)
return sum + calcStandardCups(ml, d.degree)
}, 0)
records.push({
id: `record_${daysAgo}`,
date: dateStr,
mode: 'drank',
drinks: template.drinks.map(d => ({ ...d, categoryId: d.category })),
food: template.food,
feeling: template.feeling,
photos: [],
visibility: 'friends',
standardCupsTotal: Math.round(standardCupsTotal * 100) / 100,
createdAt: date.toISOString()
})
})
abstainDays.forEach(daysAgo => {
const date = new Date(today)
date.setDate(date.getDate() - daysAgo)
const dateStr = formatDate(date, 'YYYY-MM-DD')
records.push({
id: `record_abs_${daysAgo}`,
date: dateStr,
mode: 'abstain',
drinks: [],
food: null,
feeling: null,
photos: [],
visibility: 'private',
standardCupsTotal: 0,
createdAt: date.toISOString()
})
})
return records.sort((a, b) => new Date(b.date) - new Date(a.date))
}
// 初始化并缓存Mock数据
export function initMockData() {自己看
const records = generateMockRecords()
uni.setStorageSync('drink_records', JSON.stringify(records))
uni.setStorageSync('user_info', JSON.stringify(MOCK_USER))
uni.setStorageSync('is_first_launch', 'true')
return records
}
// 获取记录
export function getRecords() {
const data = uni.getStorageSync('drink_records')
if (data) {
try { return JSON.parse(data) } catch (e) { return [] }
}
return initMockData()
}
// 添加记录
export function addRecord(record) {
const records = getRecords()
record.id = `record_${Date.now()}`
record.createdAt = new Date().toISOString()
records.unshift(record)
uni.setStorageSync('drink_records', JSON.stringify(records))
return record
}
// 获取用户信息
export function getUserInfo() {
const data = uni.getStorageSync('user_info')
if (data) {
try { return JSON.parse(data) } catch (e) { return MOCK_USER }
}
return MOCK_USER
}