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

443 lines
12 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" :scroll-top="scrollTop" @scroll="scroll">
  11. <view v-for="(item,index) of tab.list" :key="index">
  12. <view class="lf-p-32">
  13. <view class="lf-flex" @click="$url('/pages/user/my/my?user_id='+item.user_id)">
  14. <view class="tag-father">
  15. <image :src="item.user.avatar" 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" v-if="item.user.nick_name">{{item.user.nick_name}}</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="goDetails(item.id)">
  24. {{item.content}}
  25. </view>
  26. <view class="lf-flex-wrap lf-m-t-20">
  27. <image v-for="(picture,index2) in item.attachs" @click.stop="checkPicture(item.attachs,index2)" :key="index2" 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" @click.stop="addLike(item.id)">
  31. <text class="lf-iconfont icon-xihuanlike lf-color-price" v-if="item.is_like"></text>
  32. <text class="lf-iconfont icon-xihuan" v-else></text>
  33. <text class="lf-font-24 lf-color-777 lf-m-l-10">{{item.likes_count}}</text>
  34. </view>
  35. <view class="lf-row-center">
  36. <text class="lf-iconfont icon-chakan"></text>
  37. <text class="lf-font-24 lf-color-777 lf-m-l-10">{{item.view_count}}</text>
  38. </view>
  39. <view class="lf-row-center" @click="goDetails(item.id)">
  40. <text class="lf-iconfont icon-pinglun-"></text>
  41. <text class="lf-font-24 lf-color-777 lf-m-l-10">{{item.comments_count}}</text>
  42. </view>
  43. </view>
  44. </view>
  45. <self-line/>
  46. </view>
  47. <!-- 空数据的情况 -->
  48. <view class="loading-more">
  49. <text v-if="tab.list.length"
  50. :class="{'loading-more-text': tab.loadingClass}">{{ tab.loadingText }}</text>
  51. <lf-nocontent v-else></lf-nocontent>
  52. </view>
  53. </scroll-view>
  54. </swiper-item>
  55. </swiper>
  56. <view class="fixed-right">
  57. <view class="fixed-btn" hover-class="lf-opacity" @click="$url('/pages/discover/publish')">
  58. <text class="lf-iconfont icon-fabu lf-font-50"></text>
  59. </view>
  60. </view>
  61. <view class="fixed-right1" v-if="showTotop">
  62. <view class="fixed-btn" hover-class="lf-opacity" @click="goTop()">
  63. <text class="lf-iconfont icon-zhiding lf-font-50"></text>
  64. </view>
  65. </view>
  66. <view style="height: 30rpx;"></view>
  67. <lf-tabbar></lf-tabbar>
  68. </view>
  69. </template>
  70. <script>
  71. import lfTabbar from '@/components/lf-tabbar/lf-tabbar.vue';
  72. export default {
  73. components: {
  74. lfTabbar
  75. },
  76. data() {
  77. let _public = {
  78. page: 1,
  79. isPage: true,
  80. loadingClass: true,
  81. loadingText: '正在加载中'
  82. }
  83. return {
  84. scrollTop: 0,
  85. oldScrollTop:0,
  86. showTotop: false,
  87. tab_list: [
  88. {name: '最新',type: 'created_at',list:[],..._public},
  89. {name: '最热',type: 'view_count',list:[],..._public},
  90. {name: '已关注',type: 'view_count',list:[],..._public}
  91. ],
  92. tab_current: 0,
  93. scrollH: 0,
  94. nav_height: 0,
  95. isRefresher: true,
  96. pageSize: 10
  97. }
  98. },
  99. computed: {
  100. autoHeight(){
  101. return `calc(${this.scrollH}px - ${this.nav_height}px - 86rpx)`;
  102. }
  103. },
  104. onLoad(){
  105. let info = uni.getSystemInfoSync();
  106. this.scrollH = info.screenHeight;
  107. this.getHotActivity()
  108. },
  109. methods: {
  110. scroll (e) {
  111. //记录scroll 位置
  112. this.oldScrollTop = e.detail.scrollTop;
  113. if(this.oldScrollTop > 900) {
  114. this.showTotop = true;
  115. }else {
  116. this.showTotop = false;
  117. }
  118. },
  119. goTop(e) {
  120. //视图会发生重新渲染
  121. this.scrollTop = this.oldScrollTop;
  122. //当视图渲染结束 重新设置为0
  123. this.$nextTick(() =>{
  124. this.scrollTop = 0;
  125. });
  126. },
  127. checkPicture(image_list,current) {
  128. if(image_list.length <= 0) return;
  129. let list = [];
  130. image_list.forEach((item,index) => {
  131. list.push(item.url)
  132. })
  133. this.$u.throttle(() => {
  134. uni.previewImage({
  135. urls: list,
  136. current: current
  137. });
  138. }, 500);
  139. },
  140. goDetails(id) {
  141. this.$url('/pages/discover/discoverdetails?discover_id='+id)
  142. },
  143. addLike(id) {
  144. this.$http
  145. .post({
  146. api: 'api/discover/like',
  147. data: {
  148. discover_id: id
  149. },
  150. header: {
  151. Authorization: this.$cookieStorage.get('user_token')
  152. },
  153. })
  154. .then(res => {
  155. if (res.data.code == 200) {
  156. if (res.data.status) {
  157. this.getHotActivity();
  158. } else {
  159. wx.showModal({
  160. content: res.data.message || '请下拉页面刷新重试',
  161. showCancel: false
  162. });
  163. }
  164. } else {
  165. wx.showModal({
  166. content: res.data.message || '请下拉页面刷新重试',
  167. showCancel: false
  168. });
  169. }
  170. wx.hideLoading();
  171. })
  172. .catch(() => {
  173. wx.hideLoading();
  174. });
  175. },
  176. getMyAttention(options = {}) {
  177. let tab_item = this.tab_list[this.tab_current];
  178. this.$http
  179. .get({
  180. api: 'api/discover/follow',
  181. data: {
  182. page: tab_item.page,
  183. page_size: this.pageSize,
  184. },
  185. header: {
  186. Authorization: this.$cookieStorage.get('user_token')
  187. },
  188. })
  189. .then(res => {
  190. if (res.data.code == 200) {
  191. let isPage;
  192. if(res.data.data.per_page == res.data.data.data.length) {
  193. isPage = true;
  194. }else {
  195. isPage = false;
  196. }
  197. if(!isPage) {
  198. tab_item.loadingClass = false;
  199. tab_item.loadingText = '没有更多数据啦~';
  200. }
  201. if(options.type == 'pageRefresh') {
  202. uni.stopPullDownRefresh();
  203. }else if(options.type == 'scrollRefresh') {
  204. this.isRefresher = false;
  205. }
  206. if(tab_item.page == 1) {
  207. tab_item.list = res.data.data.data;
  208. }else {
  209. tab_item.list.push(...res.data.data.data);
  210. }
  211. } else {
  212. wx.showModal({
  213. content: '请下拉页面刷新重试',
  214. showCancel: false
  215. });
  216. }
  217. wx.hideLoading();
  218. })
  219. .catch(() => {
  220. wx.hideLoading();
  221. });
  222. },
  223. // 页面触底,加载下一页
  224. onScrolltolower(){
  225. let tab_item = this.tab_list[this.tab_current];
  226. if(tab_item.isPage){
  227. tab_item.page = tab_item.page + 1;
  228. if(this.tab_current == 2) {
  229. this.getMyAttention();
  230. }else {
  231. this.getHotActivity();
  232. }
  233. }
  234. },
  235. // 下拉刷新处理
  236. refreshFn(options){
  237. let tab_item = this.tab_list[this.tab_current];
  238. tab_item.page = 1;
  239. tab_item.isPage = true;
  240. tab_item.loadingClass = true;
  241. tab_item.list = []
  242. tab_item.loadingText = '正在加载中';
  243. if(this.tab_current == 2) {
  244. this.getMyAttention(options);
  245. }else {
  246. this.getHotActivity(options);
  247. }
  248. },
  249. // scroll-view 下拉刷新
  250. onRefresherrefresh(){
  251. this.isRefresher = true;
  252. this.refreshFn({type: 'scrollRefresh'});
  253. },
  254. tabChange(event){
  255. this.tab_current = event;
  256. if(this.tab_current == 2) {
  257. this.getMyAttention();
  258. }else {
  259. this.getHotActivity();
  260. }
  261. },
  262. swiperChange(event){
  263. this.tab_current = event.detail.current;
  264. if (event.detail.source == '') return; // 如果是被动出发,没有事件类型则不做处理
  265. if(this.tab_current == 2) {
  266. this.getMyAttention();
  267. console.log('执行关注列表');
  268. }else {
  269. this.getHotActivity();
  270. }
  271. },
  272. getHotActivity(options = {}) {
  273. let discover_type;
  274. let tab_item = this.tab_list[this.tab_current];
  275. if(this.tab_current == 0) {
  276. discover_type = 'created_at';
  277. }else {
  278. discover_type = 'view_count';
  279. }
  280. this.$http
  281. .get({
  282. api: 'api/discover',
  283. data:{
  284. page: tab_item.page,
  285. page_size: this.pageSize,
  286. order: discover_type
  287. },
  288. header: {
  289. Authorization: this.$cookieStorage.get('user_token')
  290. },
  291. })
  292. .then(res => {
  293. if (res.data.code == 200) {
  294. if (res.data.status) {
  295. let isPage;
  296. if(res.data.data.per_page == res.data.data.data.length) {
  297. isPage = true;
  298. }else {
  299. isPage = false;
  300. }
  301. tab_item.isPage = isPage;
  302. if(!isPage) {
  303. tab_item.loadingClass = false;
  304. tab_item.loadingText = '没有更多数据啦~';
  305. }
  306. if(options.type == 'pageRefresh') {
  307. uni.stopPullDownRefresh();
  308. }else if(options.type == 'scrollRefresh') {
  309. this.isRefresher = false;
  310. }
  311. if(tab_item.page == 1) {
  312. tab_item.list = res.data.data.data;
  313. }else {
  314. tab_item.list.push(...res.data.data.data);
  315. }
  316. console.log('数组列表',tab_item.list)
  317. } else {
  318. wx.showModal({
  319. content: res.message || '请下拉页面刷新重试',
  320. showCancel: false
  321. });
  322. }
  323. } else {
  324. wx.showModal({
  325. content: '请下拉页面刷新重试',
  326. showCancel: false
  327. });
  328. }
  329. wx.hideLoading();
  330. })
  331. .catch(() => {
  332. wx.hideLoading();
  333. });
  334. }
  335. }
  336. }
  337. </script>
  338. <style>
  339. page {
  340. background-color: white;
  341. }
  342. </style>
  343. <style lang="scss" scoped>
  344. .tag-father {
  345. position: relative;
  346. }
  347. .head-tag {
  348. color: white;
  349. display: flex;
  350. align-items: center;
  351. justify-content: center;
  352. text-align: center;
  353. font-size: 24rpx;
  354. width: 36rpx;
  355. height: 36rpx;
  356. border-radius: 50%;
  357. background-color: #15716E;
  358. border: 1rpx solid #FFFFFF;
  359. position: absolute;
  360. left: 66rpx;
  361. top: 70rpx;
  362. z-index: 99;
  363. }
  364. .qzone-img {
  365. width: 220rpx;
  366. height: 220rpx;
  367. border-radius: 10rpx;
  368. margin-right: 12rpx;
  369. &:nth-child(3n) {
  370. margin-right: 0;
  371. }
  372. &:nth-child(n + 4) {
  373. margin-top: 12rpx;
  374. }
  375. }
  376. .head-img {
  377. width: 100rpx;
  378. height: 100rpx;
  379. border-radius: 50%;
  380. }
  381. .fixed-right{
  382. position: fixed;
  383. right: 32rpx;
  384. bottom: 188rpx;
  385. width: max-content;
  386. height: max-content;
  387. padding-bottom: constant(safe-area-inset-bottom);
  388. padding-bottom: env(safe-area-inset-bottom);
  389. .fixed-btn{
  390. width: 100rpx;
  391. height: 100rpx;
  392. border-radius: 50%;
  393. background-color: #15716E;
  394. display: flex;
  395. justify-content: center;
  396. align-items: center;
  397. color: #FFFFFF;
  398. }
  399. }
  400. .fixed-right1{
  401. position: fixed;
  402. right: 32rpx;
  403. bottom: 320rpx;
  404. width: max-content;
  405. height: max-content;
  406. padding-bottom: constant(safe-area-inset-bottom);
  407. padding-bottom: env(safe-area-inset-bottom);
  408. .fixed-btn{
  409. width: 100rpx;
  410. height: 100rpx;
  411. border-radius: 50%;
  412. background-color: #15716E;
  413. display: flex;
  414. justify-content: center;
  415. align-items: center;
  416. color: #FFFFFF;
  417. }
  418. }
  419. // tab样式
  420. /deep/.u-scroll-box {
  421. display: flex;
  422. justify-content: center;
  423. align-items: center;
  424. border-bottom: 1rpx solid rgba(0, 0, 0, 0.1);
  425. }
  426. /deep/.u-scroll-box .u-tab-bar {
  427. background-color: #15716E!important;
  428. width: 80rpx!important;
  429. position: absolute;
  430. left: 0;
  431. bottom: -14rpx;
  432. }
  433. /deep/ .u-tab-item {
  434. font-size: 28rpx!important;
  435. }
  436. </style>