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

451 lines
13 KiB

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