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

449 lines
13 KiB

4 years ago
4 years ago
4 years ago
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 lf-font-40" v-if="item.is_like"></text>
  37. <text class="lf-iconfont icon-xihuan lf-font-40" 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 lf-font-40"></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- lf-font-40"></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. }else {
  276. this.getHotActivity();
  277. }
  278. },
  279. getHotActivity(options = {}) {
  280. let discover_type;
  281. let tab_item = this.tab_list[this.tab_current];
  282. if(this.tab_current == 0) {
  283. discover_type = 'created_at';
  284. }else {
  285. discover_type = 'view_count';
  286. }
  287. this.$http
  288. .get({
  289. api: 'api/discover',
  290. data:{
  291. page: tab_item.page,
  292. page_size: this.pageSize,
  293. order: discover_type
  294. },
  295. header: {
  296. Authorization: this.$cookieStorage.get('user_token')
  297. },
  298. })
  299. .then(res => {
  300. if (res.data.code == 200) {
  301. if (res.data.status) {
  302. let isPage;
  303. if(res.data.data.per_page == res.data.data.data.length) {
  304. isPage = true;
  305. }else {
  306. isPage = false;
  307. }
  308. tab_item.isPage = isPage;
  309. if(!isPage) {
  310. tab_item.loadingClass = false;
  311. tab_item.loadingText = '没有更多数据啦~';
  312. }
  313. if(options.type == 'pageRefresh') {
  314. uni.stopPullDownRefresh();
  315. }else if(options.type == 'scrollRefresh') {
  316. this.isRefresher = false;
  317. }
  318. if(tab_item.page == 1) {
  319. tab_item.list = res.data.data.data;
  320. }else {
  321. tab_item.list.push(...res.data.data.data);
  322. }
  323. } else {
  324. wx.showModal({
  325. content: res.message || '请下拉页面刷新重试',
  326. showCancel: false
  327. });
  328. }
  329. } else {
  330. wx.showModal({
  331. content: '请下拉页面刷新重试',
  332. showCancel: false
  333. });
  334. }
  335. wx.hideLoading();
  336. })
  337. .catch(() => {
  338. wx.hideLoading();
  339. });
  340. }
  341. }
  342. }
  343. </script>
  344. <style>
  345. page {
  346. background-color: white;
  347. }
  348. </style>
  349. <style lang="scss" scoped>
  350. .tag-father {
  351. position: relative;
  352. }
  353. .head-tag {
  354. color: white;
  355. display: flex;
  356. align-items: center;
  357. justify-content: center;
  358. text-align: center;
  359. font-size: 24rpx;
  360. width: 36rpx;
  361. height: 36rpx;
  362. border-radius: 50%;
  363. background-color: #15716E;
  364. border: 1rpx solid #FFFFFF;
  365. position: absolute;
  366. left: 66rpx;
  367. top: 70rpx;
  368. z-index: 99;
  369. }
  370. .qzone-img {
  371. width: 220rpx;
  372. height: 220rpx;
  373. border-radius: 10rpx;
  374. margin-right: 12rpx;
  375. &:nth-child(3n) {
  376. margin-right: 0;
  377. }
  378. &:nth-child(n + 4) {
  379. margin-top: 12rpx;
  380. }
  381. }
  382. .head-img {
  383. width: 100rpx;
  384. height: 100rpx;
  385. border-radius: 50%;
  386. }
  387. .fixed-right{
  388. position: fixed;
  389. right: 32rpx;
  390. bottom: 188rpx;
  391. width: max-content;
  392. height: max-content;
  393. padding-bottom: constant(safe-area-inset-bottom);
  394. padding-bottom: env(safe-area-inset-bottom);
  395. .fixed-btn{
  396. width: 100rpx;
  397. height: 100rpx;
  398. border-radius: 50%;
  399. background-color: #15716E;
  400. display: flex;
  401. justify-content: center;
  402. align-items: center;
  403. color: #FFFFFF;
  404. }
  405. }
  406. .fixed-right1{
  407. position: fixed;
  408. right: 32rpx;
  409. bottom: 320rpx;
  410. width: max-content;
  411. height: max-content;
  412. padding-bottom: constant(safe-area-inset-bottom);
  413. padding-bottom: env(safe-area-inset-bottom);
  414. .fixed-btn{
  415. width: 100rpx;
  416. height: 100rpx;
  417. border-radius: 50%;
  418. background-color: #15716E;
  419. display: flex;
  420. justify-content: center;
  421. align-items: center;
  422. color: #FFFFFF;
  423. }
  424. }
  425. // tab样式
  426. /deep/.u-scroll-box {
  427. display: flex;
  428. justify-content: center;
  429. align-items: center;
  430. border-bottom: 1rpx solid rgba(0, 0, 0, 0.1);
  431. }
  432. /deep/.u-scroll-box .u-tab-bar {
  433. background-color: #15716E!important;
  434. width: 80rpx!important;
  435. position: absolute;
  436. left: 0;
  437. bottom: -14rpx;
  438. }
  439. /deep/ .u-tab-item {
  440. font-size: 28rpx!important;
  441. }
  442. </style>