木邻有你前端代码仓库
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

420 lines
8.6 KiB

1 month ago
1 month ago
1 month ago
1 month ago
1 month ago
1 month ago
1 month ago
1 month ago
1 month ago
1 month ago
1 month ago
1 month ago
1 month ago
1 month ago
1 month ago
1 month ago
1 month ago
1 month ago
  1. <template>
  2. <view class="community-page">
  3. <!-- 顶部图片 -->
  4. <view class="banner-section">
  5. <image class="banner-image" src="/static/bannerImage.png" mode="aspectFill"></image>
  6. </view>
  7. <!-- Tab切换区域 -->
  8. <view class="tab-section">
  9. <view class="tab-container">
  10. <view
  11. class="tab-item"
  12. :class="{ active: currentTab === 'current' }"
  13. @click="switchTab('current')"
  14. >
  15. <text class="tab-text">木邻说</text>
  16. <view class="tab-line" v-if="currentTab === 'current'"></view>
  17. </view>
  18. <view
  19. class="tab-item"
  20. :class="{ active: currentTab === 'past' }"
  21. @click="switchTab('past')"
  22. >
  23. <text class="tab-text">木邻见</text>
  24. <view class="tab-line" v-if="currentTab === 'past'"></view>
  25. </view>
  26. </view>
  27. </view>
  28. <!-- 动态列表 -->
  29. <view class="post-list">
  30. <view
  31. class="post-item"
  32. v-for="(item, index) in postList"
  33. :key="index"
  34. @click="goToPostDetail(item)"
  35. >
  36. <!-- 用户信息 -->
  37. <view class="user-info">
  38. <image class="user-avatar" :src="item.member.headImage" mode="aspectFill"></image>
  39. <view class="user-details">
  40. <text class="username">{{ item.member.nickName }}</text>
  41. <text class="post-time">发布时间{{ item.createTime }}</text>
  42. </view>
  43. </view>
  44. <!-- 动态内容 -->
  45. <view class="post-content">
  46. <text class="post-text">{{ item.content }}</text>
  47. <!-- 图片列表 -->
  48. <view class="image-grid" v-if="item.image && item.image.length > 0">
  49. <image
  50. class="post-image"
  51. v-for="(img, imgIndex) in item.image.split(',')"
  52. :key="imgIndex"
  53. :src="img"
  54. mode="aspectFill"
  55. @click.stop="previewImage(img, item.image)"
  56. ></image>
  57. </view>
  58. </view>
  59. <!-- 回复列表 -->
  60. <view class="comment-list" v-if="item.communityCommentList && item.communityCommentList.length > 0">
  61. <view class="comment-header">
  62. <text class="comment-title">回复 ({{ item.communityCommentList.length }})</text>
  63. </view>
  64. <view
  65. class="comment-item"
  66. v-for="(comment, commentIndex) in item.communityCommentList"
  67. :key="commentIndex"
  68. >
  69. <view class="comment-user-info">
  70. <text class="comment-username">{{ comment.createBy }}</text>
  71. <text class="comment-time">{{ comment.createTime }}</text>
  72. </view>
  73. <text class="comment-content">{{ comment.content }}</text>
  74. </view>
  75. </view>
  76. </view>
  77. </view>
  78. <!-- 随手拍/我要留言按钮 -->
  79. <view class="action-btn" :class="currentTab === 'current' ? 'current-btn' : 'photo'" @click="openAction">
  80. <uv-icon name="edit-pen-fill" size="20" color="white"></uv-icon>
  81. <text class="action-text">{{ actionButtonText }}</text>
  82. </view>
  83. </view>
  84. </template>
  85. <script>
  86. export default {
  87. name: 'CommunityPage',
  88. data() {
  89. return {
  90. currentTab: 'current', // current: 木邻说, past: 木邻见
  91. postList: [],
  92. pageNo: 1,
  93. pageSize: 10
  94. }
  95. },
  96. computed: {
  97. actionButtonText() {
  98. return this.currentTab === 'current' ? '我要留言' : '随手拍'
  99. }
  100. },
  101. methods: {
  102. switchTab(tab) {
  103. this.currentTab = tab
  104. this.initData()
  105. this.getPostList()
  106. },
  107. goToPostDetail(post) {
  108. // 跳转到动态详情页面
  109. // uni.navigateTo({
  110. // url: `/subPages/community/postDetail?id=${post.id}`
  111. // })
  112. },
  113. previewImage(current, urls) {
  114. uni.previewImage({
  115. current: current,
  116. urls: urls
  117. })
  118. },
  119. openAction() {
  120. if (this.currentTab === 'current') {
  121. // 我要留言功能
  122. this.goToComment()
  123. } else {
  124. // 随手拍功能
  125. // this.goToComment()
  126. this.takePhoto()
  127. }
  128. },
  129. takePhoto() {
  130. uni.navigateTo({
  131. url: '/subPages/community/publishPost?page=photo'
  132. })
  133. },
  134. goToComment() {
  135. uni.navigateTo({
  136. url: '/subPages/community/publishPost'
  137. })
  138. },
  139. // 获取帖子数据
  140. async getPostList() {
  141. const res = await this.$api.community.queryPostList({
  142. pageNo: this.pageNo,
  143. pageSize: this.pageSize,
  144. type: this.currentTab === 'current' ? 0 : 1
  145. })
  146. if (res.result.records.length) {
  147. this.postList.push(...res.result.records)
  148. this.pageNo++
  149. }else {
  150. uni.showToast({
  151. title: '暂无数据',
  152. icon: 'none'
  153. })
  154. }
  155. },
  156. initData() {
  157. this.pageNo = 1,
  158. this.postList = []
  159. }
  160. },
  161. async onShow() {
  162. this.initData()
  163. await this.getPostList()
  164. },
  165. onReachBottom() {
  166. this.getPostList()
  167. },
  168. async onPullDownRefresh() {
  169. this.initData()
  170. await this.getPostList()
  171. uni.stopPullDownRefresh()
  172. }
  173. }
  174. </script>
  175. <style lang="scss" scoped>
  176. .community-page {
  177. min-height: 100vh;
  178. background-color: #f8f9fa;
  179. position: relative;
  180. padding-bottom: 120rpx;
  181. }
  182. // 横幅样式
  183. .banner-section {
  184. height: 400rpx;
  185. overflow: hidden;
  186. }
  187. .banner-image {
  188. width: 100%;
  189. height: 100%;
  190. }
  191. // Tab切换区域
  192. .tab-section {
  193. background: white;
  194. padding: 0 40rpx;
  195. border-bottom: 1rpx solid #f0f0f0;
  196. box-shadow: 0px 1.5px 3px 0px rgba(0,0,0,0.16);
  197. }
  198. .tab-container {
  199. display: flex;
  200. // gap: 60rpx;
  201. justify-content: space-evenly;
  202. }
  203. .tab-item {
  204. position: relative;
  205. padding: 30rpx 0;
  206. .tab-text {
  207. font-size: 32rpx;
  208. color: #666;
  209. font-weight: 500;
  210. transition: color 0.3s ease;
  211. }
  212. &.active {
  213. .tab-text {
  214. color: #007AFF;
  215. font-weight: bold;
  216. }
  217. }
  218. }
  219. .tab-line {
  220. position: absolute;
  221. bottom: 0;
  222. left: 50%;
  223. transform: translateX(-50%);
  224. width: 40rpx;
  225. height: 6rpx;
  226. background: #007AFF;
  227. border-radius: 3rpx;
  228. animation: slideIn 0.3s ease;
  229. }
  230. @keyframes slideIn {
  231. from {
  232. width: 0;
  233. }
  234. to {
  235. width: 40rpx;
  236. }
  237. }
  238. // 动态列表样式
  239. .post-list {
  240. // padding: 20rpx;
  241. }
  242. .post-item {
  243. background-color: white;
  244. border-radius: 16rpx;
  245. // margin-bottom: 24rpx;
  246. padding: 32rpx;
  247. box-shadow: 0 2rpx 16rpx rgba(0, 0, 0, 0.06);
  248. border: 1rpx solid #f5f5f5;
  249. transition: transform 0.2s ease, box-shadow 0.2s ease;
  250. &:active {
  251. transform: scale(0.98);
  252. box-shadow: 0 4rpx 20rpx rgba(0, 0, 0, 0.1);
  253. }
  254. }
  255. .user-info {
  256. display: flex;
  257. align-items: center;
  258. margin-bottom: 24rpx;
  259. }
  260. .user-avatar {
  261. width: 88rpx;
  262. height: 88rpx;
  263. border-radius: 50%;
  264. margin-right: 24rpx;
  265. border: 2rpx solid #f0f0f0;
  266. }
  267. .user-details {
  268. flex: 1;
  269. }
  270. .username {
  271. font-size: 30rpx;
  272. font-weight: bold;
  273. color: #333;
  274. display: block;
  275. margin-bottom: 8rpx;
  276. }
  277. .post-time {
  278. font-size: 24rpx;
  279. color: #999;
  280. }
  281. .post-content {
  282. .post-text {
  283. font-size: 30rpx;
  284. color: #333;
  285. line-height: 1.6;
  286. display: block;
  287. margin-bottom: 24rpx;
  288. }
  289. }
  290. .image-grid {
  291. display: flex;
  292. flex-wrap: wrap;
  293. gap: 12rpx;
  294. }
  295. .post-image {
  296. width: 200rpx;
  297. height: 200rpx;
  298. border-radius: 12rpx;
  299. border: 1rpx solid #f0f0f0;
  300. }
  301. // 回复列表样式
  302. .comment-list {
  303. margin-top: 24rpx;
  304. padding-top: 24rpx;
  305. border-top: 1rpx solid #f0f0f0;
  306. }
  307. .comment-header {
  308. margin-bottom: 20rpx;
  309. }
  310. .comment-title {
  311. font-size: 28rpx;
  312. color: #666;
  313. font-weight: 500;
  314. }
  315. .comment-item {
  316. background-color: #f8f9fa;
  317. border-radius: 12rpx;
  318. padding: 20rpx;
  319. margin-bottom: 16rpx;
  320. &:last-child {
  321. margin-bottom: 0;
  322. }
  323. }
  324. .comment-user-info {
  325. display: flex;
  326. align-items: center;
  327. justify-content: space-between;
  328. margin-bottom: 12rpx;
  329. }
  330. .comment-username {
  331. font-size: 26rpx;
  332. color: #007AFF;
  333. font-weight: 500;
  334. }
  335. .comment-time {
  336. font-size: 22rpx;
  337. color: #999;
  338. }
  339. .comment-content {
  340. font-size: 28rpx;
  341. color: #333;
  342. line-height: 1.5;
  343. display: block;
  344. }
  345. // 随手拍/我要留言按钮样式
  346. .action-btn {
  347. position: fixed;
  348. bottom: 120rpx;
  349. right: 30rpx;
  350. width: 120rpx;
  351. height: 120rpx;
  352. background: linear-gradient(135deg, #007AFF 0%, #0056CC 100%);
  353. border-radius: 50%;
  354. display: flex;
  355. flex-direction: column;
  356. align-items: center;
  357. justify-content: center;
  358. box-shadow: 0 8rpx 24rpx rgba(0, 122, 255, 0.4);
  359. z-index: 100;
  360. transition: transform 0.2s ease, box-shadow 0.2s ease;
  361. &:active {
  362. transform: scale(0.95);
  363. box-shadow: 0 4rpx 16rpx rgba(0, 122, 255, 0.6);
  364. }
  365. &.photo {
  366. background: linear-gradient(135deg, #FF6666 0%, #CC3333 100%);
  367. }
  368. }
  369. .action-text {
  370. font-size: 20rpx;
  371. color: white;
  372. margin-top: 8rpx;
  373. font-weight: bold;
  374. }
  375. </style>