init: 毛孩子计划 小程序 + Go 后端 + 内嵌后台

- pets-fe: 微信原生小程序(首页/计划/记录/报告/社区/引导),
  服务端驱动、无假数据;弹层改用 scroll-view,打开时隐藏自定义 tabBar
- pets-be: Gin + GORM(MySQL, sundynix_ 前缀) + MinIO,统一响应/分页,
  微信 code2session 登录,provider-neutral AI(DeepSeek),go:embed React 后台
- 修复:分段选择类型不匹配(字符串 vs 数字)导致选不中

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
This commit is contained in:
Blizzard
2026-07-03 15:33:31 +08:00
commit 609f7d06cf
180 changed files with 15259 additions and 0 deletions
+133
View File
@@ -0,0 +1,133 @@
const store = require('../../utils/store.js');
const api = require('../../utils/api.js');
function buildCells(year, month, taskedDays, today) {
const first = new Date(year, month - 1, 1);
const lead = (first.getDay() + 6) % 7; // 周一为一周起点
const daysInMonth = new Date(year, month, 0).getDate();
const set = {};
(taskedDays || []).forEach((d) => (set[d] = true));
const cells = [];
for (let i = 0; i < lead; i++) cells.push({ day: 0 });
for (let d = 1; d <= daysInMonth; d++) {
cells.push({ day: d, tasked: !!set[d], today: d === today });
}
return cells;
}
Page({
data: {
pet: {},
planView: 'timeline',
plan: null,
calCells: [],
calLabel: '',
calLoaded: false,
aiInput: '',
aiPlan: null,
aiBusy: false,
sheetShow: false,
sheetType: '',
},
onLoad() {
this._unsub = store.subscribe((pet) => {
this.setData({ pet, calLoaded: false });
this.loadTimeline();
if (this.data.planView === 'calendar') this.loadCalendar();
});
},
onUnload() {
if (this._unsub) this._unsub();
},
onShow() {
if (typeof this.getTabBar === 'function' && this.getTabBar()) {
this.getTabBar().setData({ selected: 1 });
}
store
.ready()
.then(() => {
this.setData({ pet: store.getPet() });
this.loadTimeline();
})
.catch((e) => wx.showToast({ title: e.message || '加载失败', icon: 'none' }));
},
loadTimeline() {
const id = store.currentPetId();
if (!id) return;
api
.getPlan(id)
.then((plan) => this.setData({ plan }))
.catch(() => this.setData({ plan: null }));
},
loadCalendar() {
const id = store.currentPetId();
if (!id) return;
api
.planCalendar(id)
.then((res) => {
this.setData({
calCells: buildCells(res.year, res.month, res.tasked_days, res.today),
calLabel: `${res.year}${res.month}`,
calLoaded: true,
});
})
.catch(() => {});
},
switchPlanView(e) {
const view = e.currentTarget.dataset.view;
this.setData({ planView: view });
if (view === 'calendar' && !this.data.calLoaded) this.loadCalendar();
},
// 计划明细勾选
toggleTimelineTask(e) {
const id = e.currentTarget.dataset.id;
api.togglePlanTask(id).then(() => this.loadTimeline()).catch(() => {});
},
// AI 计划
onAiInput(e) {
this.setData({ aiInput: e.detail.value });
},
genAIPlan() {
const id = store.currentPetId();
const input = (this.data.aiInput || '').trim();
if (!id || !input) {
wx.showToast({ title: '先描述一下情况', icon: 'none' });
return;
}
this.setData({ aiBusy: true });
wx.showLoading({ title: 'AI 生成中...' });
api
.createAIPlan(id, input)
.then((plan) => {
wx.hideLoading();
this.setData({ aiPlan: plan, aiBusy: false });
})
.catch((err) => {
wx.hideLoading();
this.setData({ aiBusy: false });
wx.showToast({ title: err.message || '生成失败', icon: 'none' });
});
},
applyAIPlan() {
const p = this.data.aiPlan;
if (!p) return;
api
.applyAIPlan(p.id)
.then(() => wx.showToast({ title: '已加入我的计划', icon: 'success' }))
.catch((err) => wx.showToast({ title: err.message || '加入失败', icon: 'none' }));
},
openSheet(e) {
const type = e.currentTarget.dataset.type;
if (!type) return; // 无关联动作的计划项只可勾选,不弹层
this.setData({ sheetType: type, sheetShow: true });
},
closeSheet() {
this.setData({ sheetShow: false });
},
onAddPet() {
this.setData({ sheetType: 'addPet', sheetShow: true });
},
onFab() {
this.setData({ sheetType: 'ai', sheetShow: true });
},
});
+8
View File
@@ -0,0 +1,8 @@
{
"usingComponents": {
"nav-bar": "/components/nav-bar/nav-bar",
"pet-switch": "/components/pet-switch/pet-switch",
"bottom-sheet": "/components/bottom-sheet/bottom-sheet",
"fab": "/components/fab/fab"
}
}
+85
View File
@@ -0,0 +1,85 @@
<nav-bar title="养宠计划"></nav-bar>
<scroll-view class="page-scroll" scroll-y="{{true}}" enhanced="{{true}}" show-scrollbar="{{false}}">
<view class="page-body">
<view class="page-title">
<view class="pt-h2">养宠计划</view>
<view class="pt-p">按宠物查看路线图、日历与 AI 计划。</view>
</view>
<pet-switch bind:add="onAddPet"></pet-switch>
<view class="inline-tabs">
<view class="it-btn {{planView === 'timeline' ? 'active' : ''}}" data-view="timeline" bindtap="switchPlanView">路线图</view>
<view class="it-btn {{planView === 'calendar' ? 'active' : ''}}" data-view="calendar" bindtap="switchPlanView">日历</view>
<view class="it-btn {{planView === 'aiPlan' ? 'active' : ''}}" data-view="aiPlan" bindtap="switchPlanView">AI 计划</view>
</view>
<!-- 路线图 -->
<view wx:if="{{planView === 'timeline'}}">
<view class="card">
<view class="section-head">
<view class="sh-title">{{pet.name}}的 30 天计划</view>
<view class="tag warn">{{plan.completion_pct || 0}}%</view>
</view>
<view class="progress-row"><text>完成度</text><text>{{plan.completion_pct || 0}}%</text></view>
<view class="bar"><view class="bar-fill" style="width:{{plan.completion_pct || 0}}%"></view></view>
</view>
<view class="timeline">
<view wx:for="{{plan.tasks}}" wx:key="id" class="time-block">
<view class="time-label">{{item.day_label}}</view>
<view class="plan-task {{item.done ? 'done' : ''}}">
<view class="pk-check" catchtap="toggleTimelineTask" data-id="{{item.id}}">{{item.done ? '✓' : ''}}</view>
<view class="pk-body" data-type="{{item.sheet_type}}" bindtap="openSheet">
<text class="pk-b">{{item.title}}</text><view class="pk-p">{{item.description}}</view>
</view>
</view>
</view>
<view wx:if="{{!plan}}" class="pt-p" style="padding:20rpx 0">暂无计划</view>
</view>
</view>
<!-- 日历 -->
<view wx:elif="{{planView === 'calendar'}}">
<view class="calendar">
<view class="cal-head"><text>{{calLabel}}</text><view class="link" data-type="reminders" bindtap="openSheet">提醒</view></view>
<view class="cal-grid">
<text class="cal-w">一</text><text class="cal-w">二</text><text class="cal-w">三</text><text class="cal-w">四</text><text class="cal-w">五</text><text class="cal-w">六</text><text class="cal-w">日</text>
<view wx:for="{{calCells}}" wx:key="index"
class="cal-cell {{item.today ? 'today' : ''}} {{item.tasked ? 'tasked' : ''}} {{item.day === 0 ? 'blank' : ''}}">{{item.day || ''}}</view>
</view>
</view>
</view>
<!-- AI 计划 -->
<view wx:elif="{{planView === 'aiPlan'}}">
<view class="card">
<view class="section-head"><view class="sh-title">AI 计划模式</view><view class="tag purple">Plan</view></view>
<view class="ai-plan-tip">描述 {{pet.name}} 的近况(阶段、近期变化、担心的问题),AI 会提取关键信息并生成可执行计划。</view>
<textarea class="textarea" placeholder="例如:4 个月,刚换粮有点软便,也快打第二针疫苗" placeholder-class="placeholder" value="{{aiInput}}" bindinput="onAiInput"></textarea>
<button class="btn btn-primary btn-block" style="margin-top:16rpx" bindtap="genAIPlan" disabled="{{aiBusy}}">{{aiBusy ? '生成中…' : '生成计划'}}</button>
</view>
<view wx:if="{{aiPlan}}" class="card">
<view class="section-head"><view class="sh-title">已提取信息</view></view>
<view class="extracted">
<view class="extract"><text class="ex-b">阶段</text>{{aiPlan.extracted.stage}}</view>
<view class="extract"><text class="ex-b">风险</text>{{aiPlan.extracted.risk}}</view>
<view class="extract"><text class="ex-b">重点</text>{{aiPlan.extracted.priority}}</view>
<view class="extract"><text class="ex-b">提醒</text>{{aiPlan.extracted.reminder}}</view>
</view>
<view class="section-head" style="margin-top:20rpx"><view class="sh-title">生成的计划</view></view>
<view class="task-list">
<view wx:for="{{aiPlan.tasks}}" wx:key="id" class="task">
<view class="circle"></view>
<view class="task-text"><text class="tt-b">{{item.day_label}}· {{item.title}}</text><view class="tt-p">{{item.description}}</view></view>
</view>
</view>
<button class="btn btn-primary btn-block" style="margin-top:16rpx" bindtap="applyAIPlan">加入我的计划</button>
</view>
</view>
</view>
</scroll-view>
<fab bind:tap="onFab"></fab>
<bottom-sheet show="{{sheetShow}}" type="{{sheetType}}" bind:close="closeSheet"></bottom-sheet>
+54
View File
@@ -0,0 +1,54 @@
.page-body{padding:8rpx 40rpx calc(210rpx + env(safe-area-inset-bottom))}
.pt-h2{font-size:46rpx;letter-spacing:-.6rpx;font-weight:800}
.pt-p{color:var(--muted);font-size:26rpx;margin-top:10rpx}
.tt-b{font-size:28rpx;font-weight:700}
.tt-p{font-size:24rpx;color:var(--muted);margin-top:8rpx;line-height:1.45}
.ac-b{font-size:30rpx;font-weight:700}
.ac-p{color:var(--muted);font-size:24rpx;line-height:1.45;margin-top:10rpx}
.inline-tabs{display:flex;padding:8rpx;gap:8rpx;border-radius:32rpx;background:#EFE8DE;margin-bottom:28rpx}
.it-btn{
flex:1;height:68rpx;line-height:68rpx;text-align:center;border-radius:24rpx;
color:var(--muted);font-weight:900;font-size:26rpx;
}
.it-btn.active{background:#fff;color:var(--primary-dark);box-shadow:0 12rpx 28rpx rgba(0,0,0,.06)}
.timeline{padding-left:36rpx;position:relative}
.timeline::before{content:"";position:absolute;left:12rpx;top:12rpx;bottom:16rpx;width:4rpx;background:#E8DED0}
.time-block{position:relative;margin-bottom:28rpx}
.time-label{font-weight:900;color:var(--primary-dark);font-size:26rpx;margin-bottom:16rpx;position:relative}
.time-label::before{
content:"";position:absolute;left:-34rpx;top:8rpx;width:24rpx;height:24rpx;border-radius:50%;
background:var(--primary);border:6rpx solid #fff;box-shadow:0 0 0 4rpx #F5D5A8;
}
.plan-task{background:#fff;border-radius:36rpx;padding:26rpx;box-shadow:var(--shadow);border:1rpx solid transparent;display:flex;gap:18rpx;align-items:flex-start}
.plan-task.done{opacity:.55}
.pk-check{
width:44rpx;height:44rpx;border-radius:50%;border:4rpx solid #DED1C4;flex:none;margin-top:2rpx;
display:flex;align-items:center;justify-content:center;color:#fff;font-size:24rpx;font-weight:900;
}
.plan-task.done .pk-check{background:var(--green);border-color:var(--green)}
.pk-body{flex:1}
.pk-b{font-size:28rpx;font-weight:700}
.pk-p{color:var(--muted);font-size:24rpx;line-height:1.45;margin-top:10rpx}
.ai-plan-tip{color:var(--muted);font-size:26rpx;line-height:1.6;margin-bottom:16rpx}
.calendar{background:#fff;border-radius:44rpx;padding:28rpx;box-shadow:var(--shadow)}
.cal-head{display:flex;justify-content:space-between;align-items:center;margin-bottom:20rpx;font-weight:900;font-size:30rpx}
.cal-grid{display:grid;grid-template-columns:repeat(7,1fr);gap:12rpx;text-align:center}
.cal-w{font-size:22rpx;color:var(--muted);padding:8rpx 0}
.cal-cell{
height:76rpx;border-radius:24rpx;display:flex;align-items:center;justify-content:center;
font-weight:800;font-size:26rpx;background:#FBFAF8;position:relative;
}
.cal-cell.blank{background:transparent}
.cal-cell.today{background:#FFF3DF;color:var(--primary-dark)}
.cal-cell.tasked::after{content:"";position:absolute;bottom:10rpx;width:10rpx;height:10rpx;border-radius:50%;background:var(--green)}
.extracted{display:grid;grid-template-columns:1fr 1fr;gap:16rpx;margin:24rpx 0}
.extract{background:#FBFAF8;border-radius:30rpx;padding:20rpx;font-size:24rpx}
.ex-b{display:block;font-size:26rpx;margin-bottom:6rpx;font-weight:700}
/* 页面不自身滚动,改由 page-scroll 承载滚动(隐藏滚动条)*/
page{height:100vh;overflow:hidden;display:flex;flex-direction:column}
.page-scroll{flex:1;min-height:0}