diff --git a/pets-be/internal/service/community.go b/pets-be/internal/service/community.go index 03aeca2..38d750e 100644 --- a/pets-be/internal/service/community.go +++ b/pets-be/internal/service/community.go @@ -48,7 +48,7 @@ func (s *Service) attachPostImages(posts []model.Post) { func tabTag(tab string) string { switch tab { case "新手求助": - return "求助" + return "新手求助" case "晒宠": return "晒宠" case "经验": @@ -111,23 +111,14 @@ type PostInput struct { // CreatePost 发帖 func (s *Service) CreatePost(userID string, in PostInput) (*model.Post, error) { - authorName := "匿名宠友" - authorEmoji := "🐾" - switch in.Identity { - case "official": - authorName = "肉垫计划官方" - case "petName": - if in.PetID != nil { - var pet model.Pet - if err := s.db.First(&pet, *in.PetID).Error; err == nil { - authorName = pet.Name + "的铲屎官" - authorEmoji = pet.Emoji - } - } - } - // 取作者 openid(内容安全接口 v2 要求带上),并把图片 file id 解析成可访问 URL + // 取作者信息:统一用发布者昵称(去掉了发布身份选择),openid 给内容安全接口用 var user model.User - s.db.Select("id, open_id").First(&user, userID) + s.db.Select("id, open_id, nickname").First(&user, userID) + authorName := user.Nickname + if authorName == "" { + authorName = "宠友" + } + authorEmoji := "🐾" imgURLs := s.resolveImageURLs(in.ImageFileIDs) // 发布前过内容安全:文本同步判、图片提交异步查。检测不了或有图 → 待人工/待回调 diff --git a/pets-fe/components/bottom-sheet/bottom-sheet.js b/pets-fe/components/bottom-sheet/bottom-sheet.js index 238fb0b..444d667 100644 --- a/pets-fe/components/bottom-sheet/bottom-sheet.js +++ b/pets-fe/components/bottom-sheet/bottom-sheet.js @@ -43,8 +43,8 @@ const REMINDER_TYPES = [ const REMINDER_LABELS = REMINDER_TYPES.map((t) => t.label); -const IDENTITY = ['petName', 'anonymous', 'official']; -const PTAG = ['晒宠', '求助', '经验', '避坑']; +// 标签和社区顶部筛选保持一致(晒宠 / 新手求助 / 经验) +const PTAG = ['晒宠', '新手求助', '经验']; Component({ options: { addGlobalClass: true }, @@ -61,6 +61,7 @@ Component({ optSel: {}, // 通用简易记录(洗护/清洁那 15 种共用) postContent: '', + pfFocus: false, // 发帖内容框聚焦标记(点整块 field 聚焦用) postImages: [], remForm: { id: '', typeIdx: 0, title: '', date: '', freq: '' }, remTypeLabels: REMINDER_LABELS, @@ -345,6 +346,9 @@ Component({ this.setData({ optSel }); }, onPostInput(e) { this.setData({ postContent: e.detail.value }); }, + // 点内容 field 任意处都聚焦(原生 textarea 在 scroll-view 里命中区域会偏) + onPostFieldTap() { this.setData({ pfFocus: true }); }, + onPostBlur() { this.setData({ pfFocus: false }); }, loadComments() { if (!this.data.postId) return; api.listComments(this.data.postId) @@ -539,8 +543,8 @@ Component({ api.getTasks(id).then((tasks) => this.setData({ manageTasks: tasks || [] })).catch(() => {}); }, onPickPostImages() { - const left = 3 - this.data.postImages.length; - if (left <= 0) return wx.showToast({ title: '最多 3 张', icon: 'none' }); + const left = 2 - this.data.postImages.length; + if (left <= 0) return wx.showToast({ title: '最多 2 张', icon: 'none' }); upload .chooseAndUploadImages(left) .then((list) => this.setData({ postImages: this.data.postImages.concat(list) })) @@ -604,14 +608,13 @@ Component({ async onCreatePost() { const content = (this.data.postContent || '').trim(); if (!content) return wx.showToast({ title: '写点什么吧', icon: 'none' }); - const identity = IDENTITY[this.segIdx('ident')]; const tag = PTAG[this.data.optSel.ptag === undefined ? 0 : this.data.optSel.ptag]; if (this.data.saving) return; this.setData({ saving: true }); try { + // 去掉发布身份,统一用发布者昵称(后端按 user 取昵称) const post = await api.createPost({ - pet_id: identity === 'petName' ? store.currentPetId() : null, - identity, + identity: 'user', content, tags: [tag], image_file_ids: this.data.postImages.map((i) => i.id), diff --git a/pets-fe/components/bottom-sheet/bottom-sheet.wxml b/pets-fe/components/bottom-sheet/bottom-sheet.wxml index 0d7c241..7850ebd 100644 --- a/pets-fe/components/bottom-sheet/bottom-sheet.wxml +++ b/pets-fe/components/bottom-sheet/bottom-sheet.wxml @@ -201,27 +201,22 @@ module.exports.sel = function (map, key, index, def) { → 其他资料),品种从后端 breeds 表来、按首字母索引。弹层塞不下这些 --> 发布图文 - 选择发布身份,分享你的养宠日常。 - - {{pet.name}} - 匿名宠友 - 官方笔记 - - - + 用你的昵称分享养宠日常。 + + + 晒宠 - 求助 + 新手求助 经验 - 避坑 - + - + diff --git a/pets-fe/pages/home/home.js b/pets-fe/pages/home/home.js index 36b649a..1ddcae6 100644 --- a/pets-fe/pages/home/home.js +++ b/pets-fe/pages/home/home.js @@ -180,13 +180,21 @@ Page({ wx.navigateTo({ url }); return; } - // 没有关联记录类型的任务(如遛狗),直接切换完成 + // 没有关联记录类型的任务(自定义/无 sheet_type):直接切换完成, + // 并且切到「完成」时补一条 note 记录,这样最近记录里也留痕 api .toggleTask(t.id) .then((res) => { const tasks = this.data.tasks.slice(); tasks[i] = Object.assign({}, tasks[i], { done: res.done }); this.setData({ tasks }); + if (!res.done) return; // 取消完成就不建记录 + const pid = store.currentPetId(); + if (!pid) return; + return api + .createRecord(pid, { type: 'note', title: '完成:' + t.title }) + .then(() => this.loadTimeline(1)) + .catch(() => {}); // 建记录失败不影响任务已完成 }) .catch((err) => toastErr(err, '操作失败')); },