1 line
14 KiB
Plaintext
1 line
14 KiB
Plaintext
{"version":3,"file":"UserPost.js","sources":["../../../../../../src/pages/space/components/UserPost.vue","../../../../../../uniComponent:/RDovQXBwL1dvcmsvYWRkci9hY2RyLXVpL3NyYy9wYWdlcy9zcGFjZS9jb21wb25lbnRzL1VzZXJQb3N0LnZ1ZQ"],"sourcesContent":["<template>\r\n <view class=\"user-post relative\">\r\n <!-- 这里是关注功能 -->\r\n <view v-if=\"post.isFollowed != undefined\" class=\"absolute top-2 right-2 space-x-2\">\r\n <!-- 实心按钮 - 关注+ -->\r\n <button\r\n @click=\"follow\"\r\n v-if=\"!post.isFollowed\"\r\n class=\"bg-amber-500 text-white rounded w-16 h-8 text-size-14px\"\r\n >\r\n 关注+\r\n </button>\r\n <!-- 空心按钮 - 取消关注 -->\r\n <button @click=\"unfollow\" v-else class=\"border border-amber-500 text-amber-500 rounded\">\r\n 取消关注\r\n </button>\r\n </view>\r\n\r\n <view class=\"user-info\">\r\n <image :src=\"imgUrl(post.avatar)\" alt=\"avatar\" class=\"avatar\"></image>\r\n <view class=\"user-details\">\r\n <view class=\"user-name\">{{ post.username }}</view>\r\n <view class=\"location\">{{ post.location }}</view>\r\n </view>\r\n </view>\r\n <view class=\"time\">{{ post.time }}</view>\r\n <view class=\"images-grid\">\r\n <wd-img\r\n :radius=\"8\"\r\n mode=\"center\"\r\n :enable-preview=\"true\"\r\n v-for=\"(image, index) in post.images\"\r\n :key=\"index\"\r\n :src=\"imgUrl(image)\"\r\n :alt=\"image\"\r\n class=\"post-image\"\r\n />\r\n </view>\r\n <view class=\"post-content\">\r\n <view>{{ post.content }}</view>\r\n </view>\r\n <view class=\"actions\">\r\n <view class=\"action-item\">\r\n <image\r\n v-if=\"!action.likes\"\r\n @click=\"like\"\r\n class=\"icon\"\r\n :src=\"imgUrl('@/static/space/thumbs.svg')\"\r\n mode=\"scaleToFill\"\r\n />\r\n <image\r\n v-else\r\n @click=\"unlike\"\r\n class=\"icon\"\r\n :src=\"imgUrl('@/static/space/favorites.png')\"\r\n mode=\"scaleToFill\"\r\n />\r\n <text>{{ post.likes || '0' }}</text>\r\n </view>\r\n <view class=\"action-item\">\r\n <image\r\n v-if=\"!action.favorites\"\r\n @click=\"favorite\"\r\n class=\"icon\"\r\n :src=\"imgUrl('@/static/space/like.svg')\"\r\n mode=\"scaleToFill\"\r\n />\r\n <image\r\n v-else\r\n @click=\"unfavorite\"\r\n class=\"icon\"\r\n :src=\"imgUrl('@/static/space/likes-on.png')\"\r\n mode=\"scaleToFill\"\r\n />\r\n <text>{{ post.favorites || '0' }}</text>\r\n </view>\r\n <view class=\"action-item\">\r\n <image\r\n @click=\"popAction\"\r\n class=\"icon\"\r\n :src=\"imgUrl('@/static/space/comment.svg')\"\r\n mode=\"scaleToFill\"\r\n />\r\n <text>{{ post.comments || '0' }}</text>\r\n </view>\r\n </view>\r\n <!-- 这里是评论区 -->\r\n <view class=\"bg-gray-100\" v-if=\"isPop\">\r\n <view v-if=\"comments.total > 0\">\r\n <view\r\n v-for=\"(comment, index) in comments.records\"\r\n @click=\"beComment(comment)\"\r\n :key=\"comment.id\"\r\n class=\"w-full mx-auto bg-white rounded-lg p-1 flex items-start\"\r\n >\r\n <image\r\n :src=\"imgUrl(comment.avatar)\"\r\n class=\"w-12 h-12 rounded-full mr-4\"\r\n mode=\"aspectFill\"\r\n />\r\n <view class=\"flex-grow\">\r\n <text class=\"font-bold text-lg txt w-40\">{{ comment.userName }}</text>\r\n <view class=\"text-sm text-gray-800 mt-2\">\r\n {{ comment.content }}\r\n </view>\r\n <view class=\"text-xs text-gray-500 mt-2 flex items-center\">\r\n <text>{{ comment.createdTime }}</text>\r\n <text class=\"mx-2\">•</text>\r\n <text>{{ '国内' }}</text>\r\n </view>\r\n </view>\r\n </view>\r\n <view v-if=\"comments.total > 10\" class=\"text-blue-500\" @click=\"commentsList(-1, -1)\">\r\n 加载更多...\r\n </view>\r\n </view>\r\n </view>\r\n <view v-if=\"isPop\" class=\"flex items-center relative\">\r\n <textarea\r\n class=\"flex-grow p-2 border border-gray-300 rounded-lg\"\r\n placeholder=\"评论...\"\r\n rows=\"3\"\r\n v-model=\"contentText\"\r\n />\r\n <view class=\"absolute bottom-0 left-0 text-gray-500\">\r\n {{ beCommentId ? '@' + beCommentId.userName : beCommentId.userNamebeCommentId.userName }}\r\n </view>\r\n <button\r\n class=\"bg-blue-500 text-white rounded-lg absolute right-0 bottom-0\"\r\n @click=\"sendComment\"\r\n >\r\n 发送\r\n </button>\r\n </view>\r\n </view>\r\n</template>\r\n\r\n<script setup>\r\nimport { imgUrl, toast } from '@/utils/commUtils'\r\nimport { http, httpGet, httpPost } from '@/utils/http'\r\nimport { defineProps } from 'vue'\r\n\r\n// 接收 props\r\nconst props = defineProps({\r\n post: Object,\r\n})\r\n\r\nconst action = ref({})\r\nconst isPop = ref(false)\r\nconst comments = ref({})\r\nconst beCommentId = ref(null)\r\nconst contentText = ref('')\r\n\r\nconst beComment = (comment) => {\r\n beCommentId.value = comment\r\n}\r\nconst popAction = async () => {\r\n isPop.value = !isPop.value\r\n // 查询评论数据\r\n if (isPop.value) {\r\n await commentsList()\r\n }\r\n}\r\n\r\n// 获取评论列表\r\nconst commentsList = async (current = 1, size = 10) => {\r\n try {\r\n const res = await httpGet(\r\n `/posts/commentsList?postId=${props.post.id}¤t=${current}&size=${size}`,\r\n )\r\n if (res.code == 200) {\r\n comments.value = res\r\n } else {\r\n toast(res.message)\r\n }\r\n } catch (e) {\r\n toast(e.data?.message || '评论获取失败')\r\n }\r\n}\r\n\r\n// 发表评论\r\nconst sendComment = async () => {\r\n try {\r\n const res = await httpPost('/posts/comments/' + props.post.id, {\r\n postId: props.post.id,\r\n content: contentText.value,\r\n beCommentsId: beCommentId.value?.id || null,\r\n })\r\n if (res.code == 200) {\r\n toast('评论成功')\r\n // 刷新评论数据\r\n await commentsList()\r\n beCommentId.value = null\r\n contentText.value = ''\r\n } else {\r\n toast(res.message)\r\n }\r\n } catch (e) {\r\n toast(e.data?.message || '评论失败')\r\n }\r\n}\r\n\r\n// 判断该帖子的状态,是否点赞,是否评论,是否收藏\r\nconst isAction = async () => {\r\n try {\r\n const res = await httpGet(`/posts/actions?postId=${props.post.id}`)\r\n if (res.code == 200) {\r\n action.value = res.data\r\n props.post.favorites = res.data.post.favorites\r\n props.post.comments = res.data.post.comments\r\n props.post.likes = res.data.post.likes\r\n props.post.isFollowed = res.data.post.isFollowed\r\n } else {\r\n toast(res.message)\r\n }\r\n } catch (e) {\r\n console.log(e)\r\n }\r\n}\r\n\r\n// 点赞\r\nconst like = async () => {\r\n try {\r\n const res = await httpPost('/posts/like', {}, { postId: props.post.id })\r\n if (res.code == 200) {\r\n // toast(\"点赞成功\");\r\n await isAction()\r\n } else {\r\n toast(res.message)\r\n }\r\n } catch (e) {\r\n console.log(e)\r\n toast(e.data?.message || '点赞失败')\r\n }\r\n}\r\n\r\n// 取消点赞\r\nconst unlike = async () => {\r\n try {\r\n const res = await http({\r\n url: '/posts/unlike?postId=' + props.post.id,\r\n method: 'DELETE',\r\n })\r\n if (res.code == 200) {\r\n // toast(\"取消点赞成功\");\r\n await isAction()\r\n } else {\r\n toast(res.message)\r\n }\r\n } catch (e) {\r\n toast(e.data?.message || '取消点赞失败')\r\n }\r\n}\r\n\r\n// 收藏\r\nconst favorite = async () => {\r\n try {\r\n const res = await httpPost('/posts/favorite', {}, { postId: props.post.id })\r\n if (res.code == 200) {\r\n // toast(\"收藏成功\");\r\n await isAction()\r\n } else {\r\n toast(res.message)\r\n }\r\n } catch (e) {\r\n toast(e.data?.message || '收藏失败')\r\n }\r\n}\r\n\r\n// 取消收藏\r\nconst unfavorite = async () => {\r\n try {\r\n const res = await http({\r\n url: '/unfavorite?postId=' + props.post.id,\r\n method: 'DELETE',\r\n })\r\n if (res.code == 200) {\r\n // toast(\"取消收藏成功\");\r\n await isAction()\r\n } else {\r\n toast(res.message)\r\n }\r\n } catch (e) {\r\n toast(e.data?.message || '取消收藏失败')\r\n }\r\n}\r\n\r\n// 编写关注和取消关注\r\nconst follow = async () => {\r\n try {\r\n const res = await httpPost('/posts/follow', {}, { followingId: props.post.userId })\r\n if (res.code == 200) {\r\n // toast(\"关注成功\");\r\n await isAction()\r\n } else {\r\n toast(res.message)\r\n }\r\n } catch (e) {\r\n toast(e.data?.message || '关注失败')\r\n }\r\n}\r\n\r\n// 编写取消关注\r\nconst unfollow = async () => {\r\n try {\r\n const res = await http({\r\n url: '/posts/unfollow?followingId=' + props.post.userId,\r\n method: 'POST',\r\n })\r\n if (res.code == 200) {\r\n // toast(\"取消关注成功\");\r\n await isAction()\r\n } else {\r\n toast(res.message)\r\n }\r\n } catch (e) {}\r\n}\r\n\r\nonLoad(async () => {\r\n await isAction()\r\n})\r\n</script>\r\n\r\n<style lang=\"scss\" scoped>\r\n.user-post {\r\n padding: 16px;\r\n background-color: #fff;\r\n border: 1px solid #eaeaea;\r\n border-radius: 8px;\r\n\r\n .icon {\r\n width: 35rpx;\r\n height: 35rpx;\r\n object-fit: contain;\r\n }\r\n\r\n .user-info {\r\n display: flex;\r\n align-items: center;\r\n }\r\n\r\n .avatar {\r\n width: 50px;\r\n height: 50px;\r\n margin-right: 12px;\r\n border-radius: 50%;\r\n }\r\n\r\n .user-details {\r\n flex: 1;\r\n }\r\n\r\n .user-name {\r\n margin: 0;\r\n font-size: 16px;\r\n font-weight: bold;\r\n }\r\n\r\n .location {\r\n margin: 0;\r\n font-size: 12px;\r\n color: #888;\r\n }\r\n\r\n .time {\r\n font-size: 12px;\r\n color: #888;\r\n text-align: right;\r\n }\r\n\r\n .images-grid {\r\n display: grid;\r\n grid-template-columns: repeat(3, 1fr);\r\n gap: 8px;\r\n margin: 16px 0;\r\n }\r\n\r\n .post-image {\r\n width: 100%;\r\n height: 200rpx;\r\n object-fit: cover;\r\n }\r\n\r\n .post-content {\r\n font-size: 14px;\r\n color: #333;\r\n }\r\n\r\n .actions {\r\n display: flex;\r\n justify-content: space-around;\r\n margin-top: 16px;\r\n }\r\n\r\n .action-item {\r\n display: flex;\r\n gap: 5px;\r\n align-items: center;\r\n color: #888;\r\n }\r\n\r\n .action-item .iconfont {\r\n margin-right: 4px;\r\n font-size: 20px;\r\n }\r\n}\r\n</style>\r\n","import Component from 'D:/App/Work/addr/acdr-ui/src/pages/space/components/UserPost.vue'\nwx.createComponent(Component)"],"names":["ref","httpGet","toast","httpPost","http","onLoad"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AA+IA,UAAM,QAAQ;AAId,UAAM,SAASA,cAAG,IAAC,EAAE;AACrB,UAAM,QAAQA,cAAG,IAAC,KAAK;AACvB,UAAM,WAAWA,cAAG,IAAC,EAAE;AACvB,UAAM,cAAcA,cAAG,IAAC,IAAI;AAC5B,UAAM,cAAcA,cAAG,IAAC,EAAE;AAE1B,UAAM,YAAY,CAAC,YAAY;AAC7B,kBAAY,QAAQ;AAAA,IACtB;AACA,UAAM,YAAY,MAAY;AAC5B,YAAM,QAAQ,CAAC,MAAM;AAErB,UAAI,MAAM,OAAO;AACf,cAAM,aAAc;AAAA,MACrB;AAAA,IACH;AAGA,UAAM,eAAe,CAAO,UAAU,GAAG,OAAO,OAAO;;AACrD,UAAI;AACF,cAAM,MAAM,MAAMC,WAAO;AAAA,UACvB,8BAA8B,MAAM,KAAK,EAAE,YAAY,OAAO,SAAS,IAAI;AAAA,QAC5E;AACD,YAAI,IAAI,QAAQ,KAAK;AACnB,mBAAS,QAAQ;AAAA,QACvB,OAAW;AACLC,0BAAK,MAAC,IAAI,OAAO;AAAA,QAClB;AAAA,MACF,SAAQ,GAAG;AACVA,wBAAAA,QAAM,OAAE,SAAF,mBAAQ,YAAW,QAAQ;AAAA,MAClC;AAAA,IACH;AAGA,UAAM,cAAc,MAAY;;AAC9B,UAAI;AACF,cAAM,MAAM,MAAMC,WAAQ,SAAC,qBAAqB,MAAM,KAAK,IAAI;AAAA,UAC7D,QAAQ,MAAM,KAAK;AAAA,UACnB,SAAS,YAAY;AAAA,UACrB,gBAA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