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:
@@ -0,0 +1,94 @@
|
||||
const store = require('../../utils/store.js');
|
||||
const api = require('../../utils/api.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] || '',
|
||||
};
|
||||
}
|
||||
|
||||
Page({
|
||||
data: {
|
||||
pet: {},
|
||||
feedTabs: ['推荐', '关注', '新手求助', '晒宠', '经验'],
|
||||
feedIdx: 0,
|
||||
posts: [],
|
||||
sheetShow: false,
|
||||
sheetType: '',
|
||||
sheetPostId: 0,
|
||||
},
|
||||
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];
|
||||
api
|
||||
.listPosts(tab, 1)
|
||||
.then((page) => this.setData({ posts: (page.list || []).map(mapPost) }))
|
||||
.catch(() => {});
|
||||
},
|
||||
switchFeedTab(e) {
|
||||
this.setData({ feedIdx: e.currentTarget.dataset.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: 0, 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() {
|
||||
this.setData({ sheetType: 'ai', sheetPostId: 0, sheetShow: true });
|
||||
},
|
||||
});
|
||||
@@ -0,0 +1,7 @@
|
||||
{
|
||||
"usingComponents": {
|
||||
"nav-bar": "/components/nav-bar/nav-bar",
|
||||
"bottom-sheet": "/components/bottom-sheet/bottom-sheet",
|
||||
"fab": "/components/fab/fab"
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,44 @@
|
||||
<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">和宠友交流、晒宠、求助与经验分享。</view>
|
||||
</view>
|
||||
|
||||
<scroll-view class="feed-tabs" scroll-x="true" enhanced="{{true}}" show-scrollbar="{{false}}">
|
||||
<view wx:for="{{feedTabs}}" wx:key="*this"
|
||||
class="feed-tab {{feedIdx === index ? 'active' : ''}}" data-index="{{index}}" bindtap="switchFeedTab">{{item}}</view>
|
||||
</scroll-view>
|
||||
|
||||
<view class="compose-card" data-type="createPost" bindtap="openSheet">
|
||||
<view class="post-avatar">{{pet.emoji}}</view>
|
||||
<view class="compose-input">分享一下今天和 {{pet.name}} 的日常...</view>
|
||||
<button class="btn btn-primary btn-small" catchtap="openSheet" data-type="createPost">发布</button>
|
||||
</view>
|
||||
|
||||
<view wx:for="{{posts}}" wx:key="id" class="post-card">
|
||||
<view class="post-head">
|
||||
<view class="post-avatar">{{item.author_emoji}}</view>
|
||||
<view class="post-user"><text class="pu-b">{{item.author_name}}</text><text class="pu-s">宠友</text></view>
|
||||
<view wx:if="{{item.tag}}" class="tag {{item.tagClass}}">{{item.tag}}</view>
|
||||
</view>
|
||||
<view class="post-content">{{item.content}}</view>
|
||||
<view wx:if="{{item.images.length}}" class="photo-grid">
|
||||
<view wx:for="{{item.images}}" wx:for-item="img" wx:key="*this" class="photo-tile">{{img}}</view>
|
||||
</view>
|
||||
<view class="post-actions">
|
||||
<view class="pa-btn {{item.liked ? 'liked' : ''}}" data-index="{{index}}" bindtap="likePost">{{item.liked ? '♥' : '♡'}} {{item.like_count}}</view>
|
||||
<view class="pa-btn" data-id="{{item.id}}" bindtap="openComments">💬 {{item.comment_count}}</view>
|
||||
<view class="pa-btn" data-type="sharePost" bindtap="openSheet">↗ 分享</view>
|
||||
</view>
|
||||
</view>
|
||||
|
||||
<view wx:if="{{posts.length === 0}}" class="empty-hint">还没有帖子,来发第一条吧 🐾</view>
|
||||
</view>
|
||||
</scroll-view>
|
||||
|
||||
<fab bind:tap="onFab"></fab>
|
||||
<bottom-sheet show="{{sheetShow}}" type="{{sheetType}}" post-id="{{sheetPostId}}"
|
||||
bind:close="closeSheet" bind:posted="onPosted" bind:commented="onCommented"></bottom-sheet>
|
||||
@@ -0,0 +1,48 @@
|
||||
.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}
|
||||
|
||||
.feed-tabs{white-space:nowrap;padding:0 0 24rpx}
|
||||
.feed-tab{
|
||||
display:inline-block;border:1rpx solid var(--line);background:#fff;border-radius:999rpx;
|
||||
height:68rpx;line-height:68rpx;padding:0 26rpx;color:var(--muted);font-size:26rpx;font-weight:900;
|
||||
box-shadow:0 12rpx 32rpx rgba(70,48,25,.05);margin-right:16rpx;
|
||||
}
|
||||
.feed-tab.active{color:var(--primary-dark);background:#FFF4E4;border-color:#FFD39A}
|
||||
|
||||
.compose-card{
|
||||
display:flex;gap:20rpx;align-items:center;background:#fff;border-radius:44rpx;
|
||||
box-shadow:var(--shadow);padding:24rpx;margin-bottom:28rpx;
|
||||
}
|
||||
.compose-input{
|
||||
flex:1;height:76rpx;line-height:76rpx;border-radius:999rpx;background:#FBFAF8;
|
||||
border:1rpx solid var(--line);color:var(--muted);padding:0 26rpx;font-size:26rpx;
|
||||
overflow:hidden;white-space:nowrap;text-overflow:ellipsis;
|
||||
}
|
||||
|
||||
.post-card{background:#fff;border-radius:48rpx;box-shadow:var(--shadow);padding:30rpx;margin-bottom:28rpx}
|
||||
.post-head{display:flex;align-items:center;gap:20rpx;margin-bottom:22rpx}
|
||||
.post-avatar{
|
||||
width:84rpx;height:84rpx;border-radius:32rpx;background:#FFF0D8;
|
||||
display:flex;align-items:center;justify-content:center;font-size:44rpx;flex:none;
|
||||
}
|
||||
.post-user{flex:1}
|
||||
.pu-b{font-size:28rpx;display:block;font-weight:700}
|
||||
.pu-s{font-size:24rpx;color:var(--muted)}
|
||||
.post-content{font-size:28rpx;line-height:1.62;color:#443D37;margin-bottom:24rpx}
|
||||
|
||||
.photo-grid{display:grid;grid-template-columns:repeat(3,1fr);gap:12rpx;margin-bottom:24rpx}
|
||||
.photo-tile{
|
||||
aspect-ratio:1;border-radius:32rpx;background:linear-gradient(135deg,#FFE6BA,#FFF8ED);
|
||||
display:flex;align-items:center;justify-content:center;font-size:60rpx;
|
||||
}
|
||||
|
||||
.post-actions{display:flex;justify-content:space-around;border-top:1rpx solid var(--line);padding-top:20rpx}
|
||||
.pa-btn{color:var(--muted);font-weight:900;font-size:26rpx}
|
||||
.pa-btn.liked{color:var(--red)}
|
||||
|
||||
.empty-hint{text-align:center;color:var(--muted);font-size:26rpx;padding:80rpx 0}
|
||||
|
||||
/* 页面不自身滚动,改由 page-scroll 承载滚动(隐藏滚动条)*/
|
||||
page{height:100vh;overflow:hidden;display:flex;flex-direction:column}
|
||||
.page-scroll{flex:1;min-height:0}
|
||||
Reference in New Issue
Block a user