Skip to content

Commit

Permalink
fix: 修复一些bug
Browse files Browse the repository at this point in the history
  • Loading branch information
fuqihao.foliet committed Sep 16, 2023
1 parent 7423e83 commit ff0d72f
Show file tree
Hide file tree
Showing 11 changed files with 46 additions and 93 deletions.
2 changes: 1 addition & 1 deletion src/apis/moment/moment.ts
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ export async function getMomentPreviews(req: GetMomentPreviewsReq) {
reject(res);
}
const data = res.data as GetMomentPreviewsResp;
data.moments.forEach((moment) => {
data.moments?.forEach((moment) => {
moment.photos[0] += PictureStyle.thumbnail;
moment.user.avatarUrl += PictureStyle.thumbnail;
});
Expand Down
2 changes: 1 addition & 1 deletion src/apis/post/post.ts
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ export async function getPostPreviews(req: GetPostPreviewsReq) {
...data,
posts: []
};
data.posts.forEach((post) => {
data.posts?.forEach((post) => {
if (!post.user) return;
if (post.coverUrl) {
post.coverUrl += PictureStyle.thumbnail;
Expand Down
8 changes: 3 additions & 5 deletions src/pages/cat/photos.vue
Original file line number Diff line number Diff line change
Expand Up @@ -97,10 +97,9 @@ let getCatImageReq = reactive<GetImageByCatReq>({
let number = 0;
const getCatImageHandler = () => {
console.log("here");
if (!noMore.value)
getCatImage(getCatImageReq).then((res) => {
for (let i = 0; i < res.images.length; i++) {
for (let i = 0; i < res.images?.length; i++) {
let imageUrl = reactive<ImageInfo>({
id: res.images[i].id,
url: res.images[i].url,
Expand All @@ -118,10 +117,9 @@ const getCatImageHandler = () => {
});
imgUrlList.push(imageUrl);
}
let arr = Object.keys(res.images);
//获取得到的images的长度用以判断是否还有尚未加载的照片
number += arr.length;
if (number === 0 || imgUrlList[number - 1].id === getCatImageReq.prevId) {
number += res.images?.length;
if (!number || imgUrlList[number - 1].id === getCatImageReq.prevId) {
noMore.value = true;
} else getCatImageReq.prevId = imgUrlList[number - 1].id;
});
Expand Down
2 changes: 1 addition & 1 deletion src/pages/community/Masonry.vue
Original file line number Diff line number Diff line change
Expand Up @@ -154,7 +154,7 @@ const addBatch = async () => {
});
getComments({ scope: "moment", page: 0, id: moments[i].id }).then((res) => {
momentData.comments += res.total;
for (let i = 0; i < res.comments.length; i++) {
for (let i = 0; i < res.comments?.length; i++) {
// eslint-disable-next-line no-prototype-builtins
if (res.comments[i].hasOwnProperty("comments"))
momentData.comments += res.comments[i].comments;
Expand Down
20 changes: 9 additions & 11 deletions src/pages/community/MasonryFrame.vue
Original file line number Diff line number Diff line change
Expand Up @@ -22,17 +22,15 @@ const props = withDefaults(defineProps<Props>(), {
const page = ref<number>(0); //每往下翻页一次page加1直到没有内容
const isInitialized = ref(false);
const getPreviews = ref<() => Promise<Moment[]>>();
if (props.search === "default") {
getPreviews.value = async () => {
return (
await getMomentPreviews({
page: page.value++,
communityId: uni.getStorageSync(StorageKeys.CommunityId)
})
).moments;
};
} else if (props.search === "search") {
const getPreviews = ref<() => Promise<Moment[]>>(async () => {
return (
await getMomentPreviews({
page: page.value++,
communityId: uni.getStorageSync(StorageKeys.CommunityId)
})
).moments;
});
if (props.search === "search") {
getPreviews.value = async () => {
return (
await searchMomentPreviews({
Expand Down
49 changes: 13 additions & 36 deletions src/pages/moment/moment.vue
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
<template>
<TopBar has-go-back="true">
<TopBar :has-go-back="true">
<template #center>动态详情</template>
</TopBar>
<view class="reply-mask" @click="leaveReply()" />
Expand Down Expand Up @@ -41,7 +41,7 @@
:key="index"
:mode="chooseImageMode(moment.data.photos.length)"
:src="item"
@click="onClickImage(index, moment.data.photos)"
@click="onClickImage(String(index), moment.data.photos)"
/>
<view
v-if="moment.data.photos.length > 9"
Expand All @@ -65,11 +65,11 @@
{{ moment.likeData.count }} 位喵友觉得很赞
</view>
</view>
<view v-if="comments.data.length === 0" class="commentNum"> 评论</view>
<view v-if="!comments.data.length" class="commentNum"> 评论</view>
<view v-else class="commentNum">
评论 {{ comments.data.length + comments.replyNumber }}
</view>
<view v-if="comments.data.length === 0">
<view v-if="!comments.data.length">
<view class="nomore">这里还没有评论,快发布第一条评论吧!</view>
</view>
<CommentBox
Expand All @@ -83,22 +83,6 @@
@local-do-like="asyncCommentDoLike(index)"
/>
<view :style="'padding-bottom:' + wcbHeight.toString() + 'px'"></view>
<!-- <view class="out-write-comment-box">-->
<!-- <write-comment-box-->
<!-- v-model:placeholder-text="placeholderText"-->
<!-- :focus="newCommentFocus"-->
<!-- :like-data="moment.likeData"-->
<!-- :new-comment-req="newCommentReq"-->
<!-- @update-text="-->
<!-- (newText) => {-->
<!-- newCommentReq.text = newText;-->
<!-- }-->
<!-- "-->
<!-- @do-like="asyncDoLike"-->
<!-- @after-create-comment="init"-->
<!-- @after-blur="afterBlur"-->
<!-- />-->
<!-- </view>-->
</view>
</view>
<WriteCommentBox
Expand Down Expand Up @@ -179,6 +163,7 @@ import Reply from "@/pages/moment/Reply.vue";
import WriteCommentBox from "@/pages/moment/WriteCommentBox.vue";
import CommentBox from "@/pages/moment/CommentBox.vue";
import { Pages } from "@/utils/url";
import NodeInfo = UniNamespace.NodeInfo;
const props = defineProps<{
id: string;
Expand Down Expand Up @@ -247,10 +232,12 @@ const isShowDeleteDialogue = ref(false);
let catName = ref("");
function onClickCatBox(id: string) {
uni.navigateTo({
url: `${Pages.Cat}?id=${id}`
});
function onClickCatBox(id?: string) {
if (id) {
uni.navigateTo({
url: `${Pages.Cat}?id=${id}`
});
}
}
const getData = async () => {
Expand Down Expand Up @@ -298,14 +285,14 @@ const localGetCommentsData = async () => {
page: page
}).then((res) => {
comments.replyNumber = 0;
for (let i = 0; i < res.data.length; i++) {
for (let i = 0; i < res.data?.length; i++) {
comments.data.push(res.data[i]);
comments.likeData.push(res.likeData[i]);
comments.replyNumber += res.data[i].comments ? res.data[i].comments : 0;
}
isCommentsLoaded = true;
page += 1;
if (res.data.length < 10) allCommentsLoaded = true;
if (res.data?.length < 10) allCommentsLoaded = true;
});
};
Expand Down Expand Up @@ -418,16 +405,6 @@ const init = async () => {
const wcbHeight = ref(81);
onMounted(() => {
const query = uni.createSelectorQuery();
const dom = query.select(".out-write-comment-box >>> .write-comment-box");
dom
.boundingClientRect((data) => {
wcbHeight.value = data.height;
})
.exec();
});
uni.onKeyboardHeightChange((res) => {
keyboardHeight.value = res.height;
});
Expand Down
2 changes: 1 addition & 1 deletion src/pages/moment/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ export const localDoLike = async (req: DoLikeReq) => {
export const getCommentsData = async (req: GetCommentsReq) => {
const commentsTemp = (await getComments(req)).comments;
const likeDataTemp = [];
if (commentsTemp.length > 0) {
if (commentsTemp?.length > 0) {
for (let i = 0; i < commentsTemp.length; i++) {
likeDataTemp.push(
await getLikeData({
Expand Down
33 changes: 4 additions & 29 deletions src/pages/post/post.vue
Original file line number Diff line number Diff line change
Expand Up @@ -63,22 +63,6 @@
@local-do-like="asyncCommentDoLike(index)"
/>
<view :style="'padding-bottom:' + wcbHeight.toString() + 'px'"></view>
<!-- <view class="out-write-comment-box">-->
<!-- <write-comment-box-->
<!-- v-model:placeholder-text="placeholderText"-->
<!-- :focus="newCommentFocus"-->
<!-- :like-data="post.likeData"-->
<!-- :new-comment-req="newCommentReq"-->
<!-- @update-text="-->
<!-- (newText) => {-->
<!-- newCommentReq.text = newText;-->
<!-- }-->
<!-- "-->
<!-- @do-like="asyncDoLike"-->
<!-- @after-create-comment="init"-->
<!-- @after-blur="afterBlur"-->
<!-- />-->
<!-- </view>-->
</view>
</view>
<write-comment-box
Expand Down Expand Up @@ -154,6 +138,7 @@ import { GetCountReq } from "@/apis/like/like-interface";
import WriteCommentBox from "@/pages/moment/WriteCommentBox.vue";
import CommentBox from "@/pages/moment/CommentBox.vue";
import { onClickImage } from "@/pages/post/utils";
import { Pages } from "@/utils/url";
const props = defineProps<{
id: string;
Expand Down Expand Up @@ -259,14 +244,14 @@ const localGetCommentsData = async () => {
page: page
}).then((res) => {
comments.replyNumber = 0;
for (let i = 0; i < res.data.length; i++) {
for (let i = 0; i < res.data?.length; i++) {
comments.data.push(res.data[i]);
comments.likeData.push(res.likeData[i]);
comments.replyNumber += res.data[i].comments ? res.data[i].comments : 0;
}
isCommentsLoaded = true;
page += 1;
if (res.data.length < 10) allCommentsLoaded = true;
if (res.data?.length < 10) allCommentsLoaded = true;
});
};
Expand Down Expand Up @@ -344,7 +329,7 @@ const deleteThisPost = () => {
}).then(
() => {
uni.reLaunch({
url: "/pages/world/world"
url: Pages.World
});
},
(reason) => {
Expand Down Expand Up @@ -374,16 +359,6 @@ const init = async () => {
const wcbHeight = ref(81);
onMounted(() => {
const query = uni.createSelectorQuery();
const dom = query.select(".out-write-comment-box >>> .write-comment-box");
dom
.boundingClientRect((data) => {
wcbHeight.value = data.height;
})
.exec();
});
onLoad(() => {
init();
});
Expand Down
17 changes: 11 additions & 6 deletions src/pages/profile/my-publish/my-masonry.vue
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,7 @@ import { displayTime } from "@/utils/time";
import { onClickMoment } from "./utils";
import { doLike, getCount, getUserLikes } from "@/apis/like/like";
import { getComments } from "@/apis/comment/comment";
import { StorageKeys } from "@/utils/const";
interface Props {
type?: string;
Expand Down Expand Up @@ -157,7 +158,7 @@ const addTile = (tileIndex: number, side: string) => {
};
const addBatch = async () => {
momentsInBatch = [];
myUserId.value = uni.getStorageSync("userId");
myUserId.value = uni.getStorageSync(StorageKeys.UserId);
if (props.type === "liked") {
if (isLikedLoaded.value === false) {
let targetUser = props.userId;
Expand All @@ -170,7 +171,11 @@ const addBatch = async () => {
).likes;
isLikedLoaded.value = true;
}
// 塞入五条消息
for (let i = 0; i < 5; i++) {
if (!LikedList?.length) {
continue;
}
await getMomentDetail({
momentId: LikedList[LikedLoaded].targetId
})
Expand All @@ -193,7 +198,7 @@ const addBatch = async () => {
getComments({ scope: "moment", page: 0, id: res.moment.id }).then(
(res2) => {
momentData.comments += res2.total;
for (let i = 0; i < res2.comments.length; i++) {
for (let i = 0; i < res2.comments?.length; i++) {
momentData.comments += res2.comments[i].comments;
}
}
Expand All @@ -215,19 +220,19 @@ const addBatch = async () => {
if (props.type === "my") {
const res = await getMomentPreviews({
page: page,
communityId: uni.getStorageSync("communityId"),
communityId: uni.getStorageSync(StorageKeys.CommunityId),
onlyUserId: myUserId.value
});
moments = res.moments;
} else {
const res = await getMomentPreviews({
page: page,
communityId: uni.getStorageSync("communityId"),
communityId: uni.getStorageSync(StorageKeys.CommunityId),
onlyUserId: props.userId
});
moments = res.moments;
}
for (let i = 0; i < moments.length; i++) {
for (let i = 0; i < moments?.length; i++) {
let momentData = reactive<MomentData>({
id: moments[i].id,
createAt: moments[i].createAt,
Expand All @@ -246,7 +251,7 @@ const addBatch = async () => {
getComments({ scope: "moment", page: 0, id: moments[i].id }).then(
(res) => {
momentData.comments += res.total;
for (let i = 0; i < res.comments.length; i++) {
for (let i = 0; i < res.comments?.length; i++) {
momentData.comments += res.comments[i].comments;
}
}
Expand Down
2 changes: 1 addition & 1 deletion src/pages/profile/my-publish/my-posts.vue
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
{{ post.text }}
</view>
<view v-if="post.tags" class="tags">
<template v-if="post.tags.length > 4">
<template v-if="post.tags?.length > 4">
<view class="tag">
{{ post.tags[0] }}
</view>
Expand Down
2 changes: 1 addition & 1 deletion src/pages/profile/personal-info/personal-info.vue
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,7 @@ onReady(() => {
uni.hideLoading();
});
onBeforeUnmount(() => {
if (!followInfo.followed === followInfo.originFollow) {
if (Boolean(followInfo.followed) !== Boolean(followInfo.originFollow)) {
doLike({
targetId: userInfo.id,
targetType: 6
Expand Down

0 comments on commit ff0d72f

Please sign in to comment.