木邻有你前端代码仓库
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.

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