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

448 lines
12 KiB

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