feat: 整体页面优化,删除无用svg
This commit is contained in:
+60
-13
@@ -13,7 +13,9 @@ Page({
|
||||
current: 1,
|
||||
pageSize: 10,
|
||||
hasMore: true,
|
||||
userInfo: null
|
||||
userInfo: null,
|
||||
scrollTop: 0,
|
||||
isRefreshing: false
|
||||
},
|
||||
|
||||
onLoad() {
|
||||
@@ -33,9 +35,16 @@ Page({
|
||||
}
|
||||
},
|
||||
|
||||
// Called by create post page
|
||||
// Called by create post page or Pull Down
|
||||
onRefresh() {
|
||||
this.fetchPosts(true);
|
||||
this.setData({ isRefreshing: true });
|
||||
this.fetchPosts(true).then(() => {
|
||||
this.setData({ isRefreshing: false });
|
||||
});
|
||||
},
|
||||
|
||||
onTabItemTap() {
|
||||
this.setData({ scrollTop: Math.random() * 0.01 });
|
||||
},
|
||||
|
||||
onPullDownRefresh() {
|
||||
@@ -60,7 +69,7 @@ Page({
|
||||
|
||||
try {
|
||||
// Correct API Endpoint and Params
|
||||
const res = await request.post('/post/page', { current, pageSize });
|
||||
const res = await request.post('/post/page', { current, pageSize, hasReviewed: 1 });
|
||||
|
||||
// Handle response structure: { code: 200, data: { list: [], ... } }
|
||||
// OR if request.js unwraps it: { list: [], ... }
|
||||
@@ -79,14 +88,16 @@ Page({
|
||||
content: item.content,
|
||||
images: (item.imgList || []).map(img => img.url),
|
||||
time: item.createdAtStr || '刚刚',
|
||||
likes: (item.likeList || []).map(l => l.liker ? (l.liker.nickName || l.liker.name) : '花友'),
|
||||
likes: item.hasLiked === 1 ? ['我'] : [],
|
||||
comments: (item.commentList || []).map(c => ({
|
||||
id: c.id,
|
||||
user: c.commentator ? (c.commentator.nickName || c.commentator.name) : '花友',
|
||||
content: c.content
|
||||
})),
|
||||
likedByMe: item.hasLiked === 1,
|
||||
isFavorited: item.hasStar === 1,
|
||||
likeCount: item.likeCount || 0,
|
||||
stars: (item.starList || []).map(s => s.starer ? (s.starer.nickName || s.starer.name) : '花友'),
|
||||
commentCount: item.commentCount || 0,
|
||||
isExpanded: false
|
||||
};
|
||||
@@ -125,12 +136,7 @@ Page({
|
||||
// Preview image in full screen
|
||||
previewImage(e) {
|
||||
const { url, urls } = e.currentTarget.dataset;
|
||||
const resolvedUrls = urls.map(img => {
|
||||
if (img.indexOf('http') === 0 || img.indexOf('wxfile') === 0) {
|
||||
return img;
|
||||
}
|
||||
return `/assets/${img}`;
|
||||
});
|
||||
const resolvedUrls = urls.map(img => img);
|
||||
|
||||
wx.previewImage({
|
||||
current: url,
|
||||
@@ -169,10 +175,15 @@ Page({
|
||||
try {
|
||||
await request.get('/post/like', { id: postId, type });
|
||||
|
||||
// Optimistic Update: Only toggle button state. Do NOT modify likes list text.
|
||||
// Optimistic Update
|
||||
const updatedPosts = this.data.posts.map(p => {
|
||||
if (p.id === postId) {
|
||||
return { ...p, likedByMe: !p.likedByMe };
|
||||
const liked = !p.likedByMe;
|
||||
return {
|
||||
...p,
|
||||
likedByMe: liked,
|
||||
likes: liked ? ['我'] : []
|
||||
};
|
||||
}
|
||||
return p;
|
||||
});
|
||||
@@ -192,6 +203,42 @@ Page({
|
||||
}
|
||||
},
|
||||
|
||||
// Collect post
|
||||
async collectPost(e) {
|
||||
const postId = e.currentTarget.dataset.id;
|
||||
const post = this.data.posts.find(p => p.id === postId);
|
||||
if (!post) return;
|
||||
|
||||
const type = post.isFavorited ? 2 : 1; // 1: Collect, 2: Cancel
|
||||
|
||||
try {
|
||||
await request.get('/post/star', { id: postId, type });
|
||||
|
||||
// Optimistic Update
|
||||
const updatedPosts = this.data.posts.map(p => {
|
||||
if (p.id === postId) {
|
||||
return { ...p, isFavorited: !p.isFavorited };
|
||||
}
|
||||
return p;
|
||||
});
|
||||
|
||||
this.setData({
|
||||
posts: updatedPosts,
|
||||
displayedPosts: updatedPosts,
|
||||
activePostId: null
|
||||
});
|
||||
|
||||
// Refresh list to sync detailed data (like IDs if needed)
|
||||
this.fetchPosts(true);
|
||||
|
||||
wx.showToast({ title: type === 1 ? '已收藏' : '已取消', icon: 'success' });
|
||||
|
||||
} catch (err) {
|
||||
console.error('Collect failed', err);
|
||||
wx.showToast({ title: '操作失败', icon: 'none' });
|
||||
}
|
||||
},
|
||||
|
||||
// Show comment input bar
|
||||
showCommentInput(e) {
|
||||
const postId = e.currentTarget.dataset.id;
|
||||
|
||||
Reference in New Issue
Block a user