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

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