feat: 记录删除与筛选、用户侧内容删除、AI 聊天历史
修复雪花 ID 精度丢失(真 bug) - bottom-sheet 的 postId 声明为 Number,而 ID 是 18 位雪花字符串, 超出 JS 安全整数范围:339346584095428608 会被转成 ...600, 评论弹层实际查的是不存在的帖子。改为 String 记录 - 后端 DELETE /records/:id 早已就绪但前端从未调用,记错了删不掉。 时间轴支持长按删除 - 时间轴加类型筛选(体重/便便/饮食/异常/用药/疫苗/消费/照片), 后端 ?type= 本就支持 用户侧内容删除(UGC 合规:用户应能删除自己发布的内容) - 新增 DELETE /posts/:id 与 DELETE /comments/:id,仅限本人, 越权返回 40300;帖子软删除,评论删除同步递减 comment_count - 评论列表返回 is_self;社区长按自己的帖子、长按自己的评论可删 AI 聊天历史 - ai_messages 一直在写但没有查询接口,每次打开弹层都是空白。 新增 GET /api/ai/messages,弹层打开时接在开场白后加载 Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
This commit is contained in:
@@ -52,7 +52,8 @@ Component({
|
||||
properties: {
|
||||
show: { type: Boolean, value: false },
|
||||
type: { type: String, value: '' },
|
||||
postId: { type: Number, value: 0 },
|
||||
// 雪花 ID 是 18 位字符串,声明成 Number 会超出 JS 安全整数范围而丢精度
|
||||
postId: { type: String, value: '' },
|
||||
},
|
||||
data: {
|
||||
innerType: '',
|
||||
@@ -182,13 +183,15 @@ Component({
|
||||
} else if (type === 'exportData') {
|
||||
this.buildExport();
|
||||
} else if (type === 'comments' && this.data.postId) {
|
||||
api.listComments(this.data.postId).then((page) => this.setData({ comments: page.list || [] })).catch(() => {});
|
||||
this.loadComments();
|
||||
} else if (type === 'reminders' && id) {
|
||||
this.loadReminders();
|
||||
} else if (type === 'poster' && id) {
|
||||
api.getPoster(id).then((p) => this.setData({ poster: p })).catch(() => {});
|
||||
} else if (type === 'reportDetail' && id) {
|
||||
api.weeklyReport(id).then((r) => this.setData({ reportDetail: r })).catch(() => {});
|
||||
} else if (type === 'ai') {
|
||||
this.loadAIHistory();
|
||||
} else if (type === 'pro') {
|
||||
api.getPro().then((p) => this.setData({ proInfo: p })).catch(() => {});
|
||||
}
|
||||
@@ -244,6 +247,28 @@ Component({
|
||||
onCostNote(e) { this.setData({ costNote: e.detail.value }); },
|
||||
onCostInput(e) { this.setData({ costAmount: e.detail.value }); },
|
||||
onPostInput(e) { this.setData({ postContent: e.detail.value }); },
|
||||
loadComments() {
|
||||
if (!this.data.postId) return;
|
||||
api.listComments(this.data.postId)
|
||||
.then((page) => this.setData({ comments: page.list || [] }))
|
||||
.catch(() => {});
|
||||
},
|
||||
// 长按删除自己的评论
|
||||
onDeleteComment(e) {
|
||||
const c = this.data.comments[e.currentTarget.dataset.index];
|
||||
if (!c || !c.is_self) return;
|
||||
wx.showModal({
|
||||
title: '删除评论',
|
||||
content: '确定删除这条评论?',
|
||||
confirmColor: '#D9534F',
|
||||
success: (res) => {
|
||||
if (!res.confirm) return;
|
||||
api.deleteComment(c.id)
|
||||
.then(() => { this.loadComments(); this.triggerEvent('commented'); })
|
||||
.catch((err) => wx.showToast({ title: err.message || '删除失败', icon: 'none' }));
|
||||
},
|
||||
});
|
||||
},
|
||||
// ---- 多宠物管理 ----
|
||||
loadMyPets() {
|
||||
const cur = store.currentPetId();
|
||||
@@ -722,6 +747,17 @@ Component({
|
||||
|
||||
// AI 聊天
|
||||
onAiInput(e) { this.setData({ aiInput: e.detail.value }); },
|
||||
// 拉取历史对话,接在开场白之后;没有历史就保持开场白
|
||||
loadAIHistory() {
|
||||
api
|
||||
.aiMessages('sheet', 30)
|
||||
.then((list) => {
|
||||
if (!list || !list.length) return;
|
||||
const history = list.map((m) => ({ role: m.role === 'user' ? 'user' : 'ai', text: m.text }));
|
||||
this.setData({ aiMessages: this.data.aiMessages.concat(history) });
|
||||
})
|
||||
.catch(() => {});
|
||||
},
|
||||
sendAI(e) {
|
||||
const preset = e.currentTarget.dataset.text;
|
||||
const text = (preset || this.data.aiInput || '').trim();
|
||||
|
||||
@@ -331,8 +331,12 @@ module.exports.sel = function (map, key, index, def) {
|
||||
<!-- 评论 -->
|
||||
<block wx:elif="{{innerType === 'comments'}}">
|
||||
<view class="sheet-h3">评论</view>
|
||||
<view wx:for="{{comments}}" wx:key="id" class="record-row"><text class="bold">{{item.author_name}}</text><text class="muted">{{item.content}}</text></view>
|
||||
<view wx:for="{{comments}}" wx:key="id" class="record-row" bindlongpress="onDeleteComment" data-index="{{index}}">
|
||||
<text class="bold">{{item.author_name}}<text wx:if="{{item.is_self}}" class="mine-tag">我</text></text>
|
||||
<text class="muted">{{item.content}}</text>
|
||||
</view>
|
||||
<view wx:if="{{!comments.length}}" class="sheet-p">还没有评论,来抢沙发~</view>
|
||||
<view wx:if="{{comments.length}}" class="sheet-p" style="font-size:22rpx;color:var(--muted)">长按自己的评论可删除</view>
|
||||
<view class="ai-input-row" style="margin-top:24rpx">
|
||||
<input class="input" placeholder="友善交流,分享经验..." placeholder-class="placeholder" value="{{commentText}}" bindinput="onCommentInput"/>
|
||||
<button class="btn btn-primary ai-send" bindtap="onSendComment">发</button>
|
||||
|
||||
@@ -61,3 +61,4 @@
|
||||
border:1rpx solid var(--line);margin-bottom:24rpx;
|
||||
}
|
||||
.export-box::-webkit-scrollbar{width:0;height:0;display:none}
|
||||
.mine-tag{margin-left:10rpx;font-size:20rpx;font-weight:700;color:var(--primary-dark);background:#FFF2DC;padding:2rpx 10rpx;border-radius:999rpx}
|
||||
|
||||
Reference in New Issue
Block a user