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

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