金诚优选前端代码
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.

341 lines
9.5 KiB

  1. <template>
  2. <view>
  3. <lf-nav :spreadOut="true" title="发现"></lf-nav>
  4. <view>
  5. <u-tabs :list="tab_list" active-color="#15716E" inactive-color='#777777' :is-scroll="true" :current="tab_current" @change="tabChange"></u-tabs>
  6. </view>
  7. <swiper :style="{height: autoHeight}" :current="tab_current" @change="swiperChange">
  8. <swiper-item v-for="(tab, tabIndex) in tab_list" :key="tabIndex">
  9. <scroll-view :style="{height: autoHeight}" :scroll-y="true" :refresher-enabled="true" :refresher-triggered="isRefresher"
  10. @scrolltolower="onScrolltolower" @refresherrefresh="onRefresherrefresh">
  11. <view v-for="(item,index) of tab.list">
  12. <view class="lf-p-32">
  13. <view class="lf-flex" @click="$url('/pages/user/my/my')">
  14. <view class="tag-father">
  15. <image src="https://hainan.lanzulive.com/storage/images/v2-deb89623e0ee2a2dad34bcded6dfd1ed_1440w.png" mode="aspectFill" class="head-img"></image>
  16. <view class="head-tag">V</view>
  17. </view>
  18. <view class="lf-flex-column lf-m-l-20">
  19. <view class="lf-font-32 lf-color-black lf-font-bold">最新FUEJFEI</view>
  20. <view class="lf-font-24 lf-color-777 lf-m-t-15">{{item.created_at}}</view>
  21. </view>
  22. </view>
  23. <view class="lf-font-28 lf-color-333 lf-m-t-20" @click="$url('/pages/discover/discoverdetails')">
  24. {{item.content}}
  25. </view>
  26. <view class="lf-flex-wrap lf-m-t-20">
  27. <image v-for="(picture,index) in item.attachs" class="qzone-img" :src="picture.url" mode="aspectFill"></image>
  28. </view>
  29. <view class="lf-m-t-30 lf-row-between lf-p-l-50 lf-p-r-50">
  30. <view class="lf-row-center">
  31. <text class="lf-iconfont icon-shoucang"></text>
  32. <text class="lf-font-24 lf-color-777 lf-m-l-10">{{item.likes_count}}</text>
  33. </view>
  34. <view class="lf-row-center">
  35. <text class="lf-iconfont icon-fabu"></text>
  36. <text class="lf-font-24 lf-color-777 lf-m-l-10">{{item.view_count}}</text>
  37. </view>
  38. <view class="lf-row-center">
  39. <text class="lf-iconfont icon-fenxiang"></text>
  40. <text class="lf-font-24 lf-color-777 lf-m-l-10">{{item.comments_count}}</text>
  41. </view>
  42. </view>
  43. </view>
  44. <self-line/>
  45. </view>
  46. <!-- 空数据的情况 -->
  47. <view class="loading-more">
  48. <text v-if="tab.list.length"
  49. :class="{'loading-more-text': tab.loadingClass}">{{ tab.loadingText }}</text>
  50. <lf-nocontent v-else></lf-nocontent>
  51. </view>
  52. <view class="fixed-right">
  53. <view class="fixed-btn" hover-class="lf-opacity" @click="$url('/pages/discover/publish')">
  54. <text class="lf-iconfont icon-fabu lf-font-50"></text>
  55. </view>
  56. </view>
  57. <view style="height: 30rpx;"></view>
  58. </scroll-view>
  59. </swiper-item>
  60. </swiper>
  61. <lf-tabbar></lf-tabbar>
  62. </view>
  63. </template>
  64. <script>
  65. import lfTabbar from '@/components/lf-tabbar/lf-tabbar.vue';
  66. export default {
  67. components: {
  68. lfTabbar
  69. },
  70. data() {
  71. let _public = {
  72. page: 1,
  73. isPage: true,
  74. loadingClass: true,
  75. loadingText: '正在加载中'
  76. }
  77. return {
  78. tab_list: [
  79. {name: '最新',type: 'created_at',list:[]},
  80. {name: '最热',type: 'view_count',list:[]},
  81. {name: '已关注',type: 'view_count',list:[]}
  82. ],
  83. tab_current: 0,
  84. scrollH: 0,
  85. nav_height: 0,
  86. isRefresher: true,
  87. pageSize: 10
  88. }
  89. },
  90. computed: {
  91. autoHeight(){
  92. return `calc(${this.scrollH}px - ${this.nav_height}px - 86rpx)`;
  93. }
  94. },
  95. onLoad(){
  96. let info = uni.getSystemInfoSync();
  97. this.scrollH = info.screenHeight;
  98. this.getHotActivity()
  99. },
  100. methods: {
  101. getMyAttention() {
  102. let tab_item = this.tab_list[this.tab_current];
  103. this.$http
  104. .get({
  105. api: 'api/discover/follow',
  106. header: {
  107. Authorization: this.$cookieStorage.get('user_token')
  108. },
  109. })
  110. .then(res => {
  111. console.log(res)
  112. if (res.data.code == 200) {
  113. if (res.data.status) {
  114. let isPage = res.data.next_page_url == null?false:true;
  115. tab_item.isPage = isPage;
  116. if(!isPage) {
  117. tab_item.loadingClass = false;
  118. tab_item.loadingText = '没有更多数据啦~';
  119. }
  120. if(options.type == 'pageRefresh') {
  121. uni.stopPullDownRefresh();
  122. }else if(options.type == 'scrollRefresh') {
  123. this.isRefresher = false;
  124. }
  125. if(tab_item.page == 1) {
  126. tab_item.list = res.data.data.data;
  127. }else {
  128. tab_item.list.push(...res.data.data.data);
  129. }
  130. console.log('发现列表',tab_item.list)
  131. } else {
  132. wx.showModal({
  133. content: res.message || '请下拉页面刷新重试',
  134. showCancel: false
  135. });
  136. }
  137. } else {
  138. wx.showModal({
  139. content: '请下拉页面刷新重试',
  140. showCancel: false
  141. });
  142. }
  143. wx.hideLoading();
  144. })
  145. .catch(() => {
  146. wx.hideLoading();
  147. wx.showModal({
  148. content: '请求失败',
  149. showCancel: false
  150. });
  151. });
  152. },
  153. // 页面触底,加载下一页
  154. onScrolltolower(){
  155. let tab_item = this.tab_list[this.tab_current];
  156. if(tab_item.isPage){
  157. tab_item.page = tab_item.page + 1;
  158. this.getHotActivity();
  159. }
  160. },
  161. // 下拉刷新处理
  162. refreshFn(options){
  163. let tab_item = this.tab_list[this.tab_current];
  164. tab_item.page = 1;
  165. tab_item.isPage = true;
  166. tab_item.loadingClass = true;
  167. tab_item.list = []
  168. tab_item.loadingText = '正在加载中';
  169. this.getHotActivity(options);
  170. },
  171. // scroll-view 下拉刷新
  172. onRefresherrefresh(){
  173. this.isRefresher = true;
  174. this.refreshFn({type: 'scrollRefresh'});
  175. },
  176. tabChange(event){
  177. this.tab_current = event;
  178. if(this.tab_current == 2) {
  179. this.getMyAttention();
  180. console.log('执行关注列表');
  181. }else {
  182. this.getHotActivity();
  183. }
  184. },
  185. swiperChange(event){
  186. this.tab_current = event.detail.current;
  187. if (event.detail.source == '') return; // 如果是被动出发,没有事件类型则不做处理
  188. if(this.tab_current == 2) {
  189. this.getMyAttention();
  190. console.log('执行关注列表');
  191. }else {
  192. this.getHotActivity();
  193. }
  194. },
  195. getHotActivity(options = {}) {
  196. let discover_type;
  197. let tab_item = this.tab_list[this.tab_current];
  198. if(this.tab_current == 0) {
  199. discover_type = 'created_at';
  200. }else {
  201. discover_type = 'view_count';
  202. }
  203. this.$http
  204. .get({
  205. api: 'api/discover',
  206. page: tab_item.page,
  207. page_size: this.pageSize,
  208. data:{
  209. order: discover_type
  210. }
  211. })
  212. .then(res => {
  213. if (res.data.code == 200) {
  214. if (res.data.status) {
  215. let isPage = res.data.next_page_url == null?false:true;
  216. tab_item.isPage = isPage;
  217. if(!isPage) {
  218. tab_item.loadingClass = false;
  219. tab_item.loadingText = '没有更多数据啦~';
  220. }
  221. if(options.type == 'pageRefresh') {
  222. uni.stopPullDownRefresh();
  223. }else if(options.type == 'scrollRefresh') {
  224. this.isRefresher = false;
  225. }
  226. if(tab_item.page == 1) {
  227. tab_item.list = res.data.data.data;
  228. }else {
  229. tab_item.list.push(...res.data.data.data);
  230. }
  231. console.log('数组列表',tab_item.list)
  232. } else {
  233. wx.showModal({
  234. content: res.message || '请下拉页面刷新重试',
  235. showCancel: false
  236. });
  237. }
  238. } else {
  239. wx.showModal({
  240. content: '请下拉页面刷新重试',
  241. showCancel: false
  242. });
  243. }
  244. wx.hideLoading();
  245. })
  246. .catch(() => {
  247. wx.hideLoading();
  248. wx.showModal({
  249. content: '请求失败',
  250. showCancel: false
  251. });
  252. });
  253. }
  254. }
  255. }
  256. </script>
  257. <style>
  258. page {
  259. background-color: white;
  260. }
  261. </style>
  262. <style lang="scss" scoped>
  263. .tag-father {
  264. position: relative;
  265. }
  266. .head-tag {
  267. color: white;
  268. display: flex;
  269. align-items: center;
  270. justify-content: center;
  271. text-align: center;
  272. font-size: 24rpx;
  273. width: 36rpx;
  274. height: 36rpx;
  275. border-radius: 50%;
  276. background-color: #15716E;
  277. border: 1rpx solid #FFFFFF;
  278. position: absolute;
  279. left: 66rpx;
  280. top: 70rpx;
  281. z-index: 99;
  282. }
  283. .qzone-img {
  284. width: 220rpx;
  285. height: 220rpx;
  286. border-radius: 10rpx;
  287. margin-right: 12rpx;
  288. &:nth-child(3n) {
  289. margin-right: 0;
  290. }
  291. &:nth-child(n + 4) {
  292. margin-top: 12rpx;
  293. }
  294. }
  295. .head-img {
  296. width: 100rpx;
  297. height: 100rpx;
  298. border-radius: 50%;
  299. }
  300. .fixed-right{
  301. position: fixed;
  302. right: 32rpx;
  303. bottom: 188rpx;
  304. width: max-content;
  305. height: max-content;
  306. padding-bottom: constant(safe-area-inset-bottom);
  307. padding-bottom: env(safe-area-inset-bottom);
  308. .fixed-btn{
  309. width: 100rpx;
  310. height: 100rpx;
  311. border-radius: 50%;
  312. background-color: #15716E;
  313. display: flex;
  314. justify-content: center;
  315. align-items: center;
  316. color: #FFFFFF;
  317. }
  318. }
  319. // tab样式
  320. /deep/.u-scroll-box {
  321. display: flex;
  322. justify-content: center;
  323. align-items: center;
  324. border-bottom: 1rpx solid rgba(0, 0, 0, 0.1);
  325. }
  326. /deep/.u-scroll-box .u-tab-bar {
  327. background-color: #15716E!important;
  328. width: 80rpx!important;
  329. position: absolute;
  330. left: 0;
  331. bottom: -14rpx;
  332. }
  333. /deep/ .u-tab-item {
  334. font-size: 28rpx!important;
  335. }
  336. </style>