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

445 lines
12 KiB

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