35fc57e8de
AI 从底部弹层改成独立页面 pages/ai/ai: - 整屏聊天,输入框固定在底部,不再是「问题都打不完」的小格子 - 回复逐字吐出(30ms/2 字),点一下可跳过 - 会话 session 从 sheet 改为 chat,历史拉 50 条 - 组件里对应的 ai 分支和 aiMessages/aiInput/sendAI 一并删掉, 避免两套实现并存 快速记录九个入口逐个排查,修掉 6 处: 1. 疫苗/驱虫的默认日期写死成 2026-07-21 / 2026-07-15,早已是过去的 日期 —— 改成打开时按今天 +30 / +90 天算 2. 异常观察没选症状时,optIdx 返回 0 会被当成选了「呕吐」,等于替 用户瞎填 —— 加 optPicked 判断,没选就提示 3. 体重为空时会静默存成「上次的体重」,凭空造一条假数据 —— 改为必填校验 4. 消费金额为空会存成 ¥0 —— 必填校验 5. 用药药品名为空 —— 必填校验 6. 照片弹层里「模拟上传预览」是没删掉的假文案 顺带清理:保存按钮上的 data-text / data-icon 从来没被读过(onSave 只用 buildRecord 的返回值),是纯误导的死属性,删掉。我上一条 commit 把它们 说成「写库值」是说错了 —— 真正写库的是 buildRecord 里的 icon 字段,那部分 仍然没动。 导航栏原来是一整条半透明色块,底边和页面渐变硬碰硬,屏幕上横着一道接缝。 改成上实下虚的渐变,并用同一条 mask 把毛玻璃一起淡出(只淡背景不淡 blur 的话,接缝会从色差变成糊边)。返回键做成圆形,和右上角胶囊视觉对称。 Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
153 lines
4.7 KiB
JavaScript
153 lines
4.7 KiB
JavaScript
const store = require('../../utils/store.js');
|
|
const api = require('../../utils/api.js');
|
|
const { toastErr } = require('../../utils/ui.js');
|
|
|
|
const TAG_CLASS = { 求助: 'warn', 经验: 'blue', 精选: 'purple', 避坑: 'red', 晒宠: '' };
|
|
|
|
function mapPost(p) {
|
|
const tags = p.tags || [];
|
|
const tag = tags[0] || '';
|
|
return {
|
|
id: p.id,
|
|
author_name: p.author_name,
|
|
author_emoji: p.author_emoji || '🐾',
|
|
content: p.content,
|
|
images: p.images || [],
|
|
like_count: p.like_count,
|
|
comment_count: p.comment_count,
|
|
liked: false,
|
|
tag,
|
|
tagClass: TAG_CLASS[tag] || '',
|
|
is_ai: !!p.is_ai,
|
|
user_id: p.user_id,
|
|
followed: !!p.followed,
|
|
is_self: !!p.is_self,
|
|
};
|
|
}
|
|
|
|
Page({
|
|
data: {
|
|
pet: {},
|
|
feedTabs: ['推荐', '关注', '新手求助', '晒宠', '经验'],
|
|
feedIdx: 0,
|
|
posts: [],
|
|
sheetShow: false,
|
|
sheetType: '',
|
|
sheetPostId: '',
|
|
loaded: false,
|
|
loadErr: '',
|
|
},
|
|
onLoad() {
|
|
this._unsub = store.subscribe((pet) => this.setData({ pet }));
|
|
},
|
|
onUnload() {
|
|
if (this._unsub) this._unsub();
|
|
},
|
|
onShow() {
|
|
if (typeof this.getTabBar === 'function' && this.getTabBar()) {
|
|
this.getTabBar().setData({ selected: 4 });
|
|
}
|
|
store
|
|
.ready()
|
|
.then(() => {
|
|
this.setData({ pet: store.getPet() });
|
|
this.loadPosts();
|
|
})
|
|
.catch((e) => wx.showToast({ title: e.message || '加载失败', icon: 'none' }));
|
|
},
|
|
loadPosts() {
|
|
const tab = this.data.feedTabs[this.data.feedIdx];
|
|
this.setData({ loadErr: '' });
|
|
api
|
|
.listPosts(tab, 1)
|
|
.then((page) => this.setData({ posts: (page.list || []).map(mapPost), loaded: true }))
|
|
.catch((e) => {
|
|
// 不能让「加载失败」显示成「还没有帖子」,那是在骗用户
|
|
this.setData({ loadErr: e.message || '加载失败', loaded: true });
|
|
toastErr(e);
|
|
});
|
|
},
|
|
// 来自 seg-tabs 的 change 事件
|
|
switchFeedTab(e) {
|
|
this.setData({ feedIdx: Number(e.detail.index) });
|
|
this.loadPosts();
|
|
},
|
|
likePost(e) {
|
|
const i = e.currentTarget.dataset.index;
|
|
const post = this.data.posts[i];
|
|
api
|
|
.likePost(post.id)
|
|
.then((res) => {
|
|
this.setData({ [`posts[${i}].like_count`]: res.like_count, [`posts[${i}].liked`]: true });
|
|
})
|
|
.catch(() => {});
|
|
},
|
|
openComments(e) {
|
|
this.setData({ sheetPostId: e.currentTarget.dataset.id, sheetType: 'comments', sheetShow: true });
|
|
},
|
|
openSheet(e) {
|
|
this.setData({ sheetType: e.currentTarget.dataset.type, sheetPostId: '', sheetShow: true });
|
|
},
|
|
closeSheet() {
|
|
this.setData({ sheetShow: false });
|
|
},
|
|
onPosted() {
|
|
this.setData({ sheetShow: false });
|
|
this.loadPosts();
|
|
},
|
|
onCommented() {
|
|
this.loadPosts();
|
|
},
|
|
goLearn() {
|
|
wx.navigateTo({ url: '/pages/learn/learn' });
|
|
},
|
|
onFab() {
|
|
wx.navigateTo({ url: '/pages/ai/ai' });
|
|
},
|
|
// 长按自己的帖子可删除
|
|
onLongPressPost(e) {
|
|
const p = this.data.posts[e.currentTarget.dataset.index];
|
|
if (!p || !p.is_self) return;
|
|
wx.showModal({
|
|
title: '删除帖子',
|
|
content: '确定删除这条帖子?删除后其他人将看不到。',
|
|
confirmColor: '#D9534F',
|
|
success: (res) => {
|
|
if (!res.confirm) return;
|
|
api.deletePost(p.id)
|
|
.then(() => { wx.showToast({ title: '已删除', icon: 'success' }); this.loadPosts(); })
|
|
.catch((err) => wx.showToast({ title: err.message || '删除失败', icon: 'none' }));
|
|
},
|
|
});
|
|
},
|
|
// 关注 / 取关帖子作者
|
|
toggleFollow(e) {
|
|
const i = e.currentTarget.dataset.index;
|
|
const p = this.data.posts[i];
|
|
if (!p || !p.user_id || p.is_self) return;
|
|
const fn = p.followed ? api.unfollowUser : api.followUser;
|
|
fn(p.user_id)
|
|
.then(() => {
|
|
// 同一作者的所有帖子一起更新状态
|
|
const posts = this.data.posts.map((x) =>
|
|
x.user_id === p.user_id ? { ...x, followed: !p.followed } : x,
|
|
);
|
|
this.setData({ posts });
|
|
wx.showToast({ title: p.followed ? '已取消关注' : '已关注', icon: 'none' });
|
|
if (this.data.feedTabs[this.data.feedIdx] === '关注') this.loadPosts();
|
|
})
|
|
.catch((err) => wx.showToast({ title: err.message || '操作失败', icon: 'none' }));
|
|
},
|
|
onShareAppMessage(e) {
|
|
// 从帖子上的分享按钮转发:带上该帖内容做标题
|
|
if (e && e.from === 'button') {
|
|
const c = (e.target.dataset.content || '').slice(0, 40);
|
|
return { title: c ? '宠友圈:' + c : '来宠友圈看看大家的毛孩子', path: '/pages/community/community' };
|
|
}
|
|
return { title: '宠友圈 · 和铲屎官们交流养宠经验', path: '/pages/community/community' };
|
|
},
|
|
onShareTimeline() {
|
|
return { title: '宠友圈 · 和铲屎官们交流养宠经验' };
|
|
},
|
|
});
|