瑶都万能墙
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.

371 lines
7.9 KiB

2 weeks ago
  1. <template>
  2. <view class="square-page">
  3. <navbar title="广场"/>
  4. <!-- 一级分类关注/发现 -->
  5. <view class="primary-tabs">
  6. <view
  7. class="primary-tab-item"
  8. :class="{active: currentPrimaryTab === 0}"
  9. @click="switchPrimaryTab(0)"
  10. >
  11. 关注
  12. </view>
  13. <view
  14. class="primary-tab-item"
  15. :class="{active: currentPrimaryTab === 1}"
  16. @click="switchPrimaryTab(1)"
  17. >
  18. 发现
  19. </view>
  20. </view>
  21. <!-- 二级分类城市列表 -->
  22. <!-- <view class="secondary-tabs">
  23. <scroll-view scroll-x="true" class="city-scroll">
  24. <view class="city-tabs">
  25. <view
  26. class="city-tab-item"
  27. :class="{active: currentCityIndex === -1}"
  28. @click="switchCity(-1, null)"
  29. >
  30. 全部
  31. </view>
  32. <view
  33. v-for="(city, index) in cityList"
  34. :key="city.id || index"
  35. class="city-tab-item"
  36. :class="{active: currentCityIndex === index}"
  37. @click="switchCity(index, city)"
  38. >
  39. {{ city.name || city.cityName }}
  40. </view>
  41. </view>
  42. </scroll-view>
  43. </view> -->
  44. <!-- 使用uv-tabs组件的城市分类 -->
  45. <view class="city-tabs-container">
  46. <uv-tabs
  47. :list="cityTabsList"
  48. :current="currentCityTabIndex"
  49. :activeStyle="{color: '#5baaff', fontWeight: 600}"
  50. lineColor="#5baaff"
  51. lineHeight="6rpx"
  52. lineWidth="40rpx"
  53. keyName="name"
  54. @click="onCityTabClick"
  55. />
  56. </view>
  57. <!-- 瀑布流列表 -->
  58. <view class="content-container">
  59. <waterfallContainer
  60. :list="List"
  61. @item-click="onItemClick"
  62. @item-like="onItemLike"
  63. />
  64. <!-- 加载更多提示 -->
  65. <view v-if="loadmore && List.length > 0" class="load-more">
  66. <uv-loading-icon size="28"></uv-loading-icon>
  67. <text class="load-more-text">加载更多...</text>
  68. </view>
  69. <!-- 没有更多数据提示 -->
  70. <view v-if="!loadmore && List.length > 0" class="no-more">
  71. <text> 没有更多了 </text>
  72. </view>
  73. </view>
  74. <!-- 空状态 -->
  75. <view v-if="!loading && List.length === 0" class="empty-state">
  76. <uv-empty
  77. text="暂无动态"
  78. textColor="#999"
  79. icon="list"
  80. iconColor="#ddd"
  81. iconSize="120"
  82. ></uv-empty>
  83. </view>
  84. <!-- 加载状态 -->
  85. <view v-if="loading && List.length === 0" class="loading-state">
  86. <uv-loading-icon size="40"></uv-loading-icon>
  87. <text class="loading-text">加载中...</text>
  88. </view>
  89. <tabber select="1" />
  90. </view>
  91. </template>
  92. <script>
  93. import navbar from '@/components/base/navbar.vue'
  94. import tabber from '@/components/base/tabbar.vue'
  95. import waterfallContainer from '@/components/list/square/waterfallContainer.vue'
  96. import mixinsList from '@/mixins/loadList.js'
  97. import { mapState } from 'vuex'
  98. export default {
  99. mixins: [mixinsList],
  100. components: {
  101. navbar,
  102. tabber,
  103. waterfallContainer
  104. },
  105. data() {
  106. return {
  107. mixinsListApi: 'getPostPage', // 使用与首页相同的API
  108. currentPrimaryTab: 1, // 默认显示发现
  109. currentCityIndex: -1, // 默认全部城市
  110. currentCity: null,
  111. currentCityTabIndex: 0 // uv-tabs当前选中的城市索引
  112. }
  113. },
  114. onLoad() {
  115. // 获取城市列表
  116. this.$store.commit('getCityList')
  117. // 初始化查询参数
  118. this.initQueryParams()
  119. },
  120. onShow() {
  121. this.refreshList()
  122. },
  123. onPullDownRefresh() {
  124. this.refreshList()
  125. },
  126. onReachBottom() {
  127. this.loadMore()
  128. },
  129. computed: {
  130. ...mapState(['cityList']),
  131. // 城市标签页列表(包含"全部"选项)
  132. cityTabsList() {
  133. const allTab = { id: null, name: '全部' }
  134. const cityTabs = this.cityList.map(city => ({
  135. id: city.id || city.cityId,
  136. name: city.name || city.cityName || city.title
  137. }))
  138. return [allTab, ...cityTabs]
  139. }
  140. },
  141. methods: {
  142. // 初始化查询参数
  143. initQueryParams() {
  144. // 设置默认查询参数
  145. this.queryParams = {
  146. ...this.queryParams,
  147. type: this.currentPrimaryTab // 0: 关注, 1: 发现
  148. }
  149. // 如果有选择城市,添加城市参数
  150. if (this.currentCity) {
  151. this.queryParams.cityId = this.currentCity.id || this.currentCity.cityId
  152. }
  153. },
  154. // 切换一级分类
  155. switchPrimaryTab(index) {
  156. if (this.currentPrimaryTab === index) return
  157. this.currentPrimaryTab = index
  158. this.queryParams.type = index
  159. this.refreshList()
  160. },
  161. // 切换城市(已注释,改用uv-tabs的onCityTabClick方法)
  162. // switchCity(index, city) {
  163. // if (this.currentCityIndex === index) return
  164. //
  165. // this.currentCityIndex = index
  166. // this.currentCity = city
  167. //
  168. // // 更新查询参数
  169. // if (city) {
  170. // this.queryParams.cityId = city.id || city.cityId
  171. // } else {
  172. // delete this.queryParams.cityId
  173. // }
  174. //
  175. // this.refreshList()
  176. // },
  177. // 重写刷新方法
  178. onRefresh() {
  179. this.refreshList()
  180. },
  181. // 点击动态项
  182. onItemClick(item) {
  183. this.$utils.navigateTo('/pages_order/post/postDetail?id=' + item.id)
  184. },
  185. // 点赞动态
  186. onItemLike(item) {
  187. console.log('点赞动态:', item.id)
  188. // 这里可以添加点赞API调用
  189. },
  190. // uv-tabs城市切换事件
  191. onCityTabClick(item) {
  192. this.currentCityTabIndex = item.index
  193. // 如果是第一个(全部),清除城市筛选
  194. if (item.index === 0) {
  195. this.currentCity = null
  196. this.currentCityIndex = -1
  197. delete this.queryParams.cityId
  198. } else {
  199. // 获取对应的城市数据
  200. const cityData = this.cityList[item.index - 1] // 减1是因为第一个是"全部"
  201. this.currentCity = cityData
  202. this.currentCityIndex = item.index - 1
  203. this.queryParams.cityId = cityData.id || cityData.cityId
  204. }
  205. this.refreshList()
  206. }
  207. }
  208. }
  209. </script>
  210. <style scoped lang="scss">
  211. .square-page {
  212. background-color: #f5f5f5;
  213. min-height: 100vh;
  214. }
  215. .primary-tabs {
  216. background-color: #fff;
  217. display: flex;
  218. padding: 0 30rpx;
  219. border-bottom: 1rpx solid #eee;
  220. .primary-tab-item {
  221. flex: 1;
  222. text-align: center;
  223. padding: 30rpx 0;
  224. font-size: 32rpx;
  225. color: #666;
  226. position: relative;
  227. &.active {
  228. color: #5baaff;
  229. font-weight: bold;
  230. &::after {
  231. content: '';
  232. position: absolute;
  233. bottom: 0;
  234. left: 50%;
  235. transform: translateX(-50%);
  236. width: 60rpx;
  237. height: 6rpx;
  238. background-color: #5baaff;
  239. border-radius: 3rpx;
  240. }
  241. }
  242. }
  243. }
  244. // 原有的二级分类样式(已注释)
  245. // .secondary-tabs {
  246. // background-color: #fff;
  247. // border-bottom: 1rpx solid #eee;
  248. //
  249. // .city-scroll {
  250. // padding: 20rpx 0;
  251. //
  252. // .city-tabs {
  253. // display: flex;
  254. // white-space: nowrap;
  255. // padding: 0 30rpx;
  256. //
  257. // .city-tab-item {
  258. // flex-shrink: 0;
  259. // padding: 16rpx 32rpx;
  260. // margin-right: 20rpx;
  261. // background-color: #f8f9fa;
  262. // border-radius: 30rpx;
  263. // font-size: 28rpx;
  264. // color: #666;
  265. // border: 1rpx solid transparent;
  266. //
  267. // &.active {
  268. // background-color: #5baaff;
  269. // color: #fff;
  270. // }
  271. //
  272. // &:last-child {
  273. // margin-right: 30rpx;
  274. // }
  275. // }
  276. // }
  277. // }
  278. // }
  279. // uv-tabs城市分类容器
  280. .city-tabs-container {
  281. background-color: #fff;
  282. border-bottom: 1rpx solid #eee;
  283. padding: 0 20rpx;
  284. }
  285. .content-container {
  286. padding: 0;
  287. }
  288. .empty-state {
  289. padding: 100rpx 0;
  290. text-align: center;
  291. }
  292. .loading-state {
  293. padding: 100rpx 0;
  294. text-align: center;
  295. display: flex;
  296. flex-direction: column;
  297. align-items: center;
  298. .loading-text {
  299. margin-top: 20rpx;
  300. font-size: 28rpx;
  301. color: #999;
  302. }
  303. }
  304. .load-more {
  305. padding: 30rpx 0;
  306. text-align: center;
  307. display: flex;
  308. flex-direction: column;
  309. align-items: center;
  310. .load-more-text {
  311. margin-top: 15rpx;
  312. font-size: 24rpx;
  313. color: #999;
  314. }
  315. }
  316. .no-more {
  317. padding: 30rpx 0;
  318. text-align: center;
  319. text {
  320. font-size: 24rpx;
  321. color: #ccc;
  322. }
  323. }
  324. // 原有的城市滚动条隐藏样式(已注释,uv-tabs自带滚动处理)
  325. // /deep/ .city-scroll::-webkit-scrollbar {
  326. // display: none;
  327. // }
  328. </style>