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

493 lines
14 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="widthFix" class="head-img"></image>
  16. <image src="/static/images/empty.png" v-else mode="widthFix" 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 src="/static/images/empty.png" 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. getCurrentPageUrlWithArgs() {
  149. var pages = getCurrentPages() //获取加载的页面
  150. var currentPage = pages[pages.length-1] //获取当前页面的对象
  151. var url = currentPage.route //当前页面url
  152. var options = currentPage.options //如果要获取url中所带的参数可以查看options
  153. //拼接url的参数
  154. var urlWithArgs = url + '?'
  155. for(var key in options){
  156. var value = options[key]
  157. urlWithArgs += key + '=' + value + '&'
  158. }
  159. urlWithArgs = urlWithArgs.substring(0, urlWithArgs.length-1)
  160. return encodeURIComponent(urlWithArgs)
  161. },
  162. goDetails(id) {
  163. let token = this.$cookieStorage.get('user_token');
  164. if(!token) {
  165. var url = this.getCurrentPageUrlWithArgs();
  166. wx.showModal({
  167. content:'请重新登录',
  168. duration:1500,
  169. showCancel: false,
  170. success:(res)=>{
  171. if (res.confirm) {
  172. // wx.navigateTo 邓平艺 于2021.09.24修改,
  173. // 原因:未登录点击后跳转到登录页,当登录成功,
  174. // 再次跳转回来时,用户点击页面返回,原有页面和弹窗还存在
  175. uni.redirectTo({
  176. url:`/pages/user/register/register?url=${url}`
  177. })
  178. return;
  179. }
  180. },
  181. cancel:()=>{
  182. uni.redirectTo({
  183. url:`/pages/user/register/register?url=${url}`
  184. })
  185. return;
  186. }
  187. })
  188. }else {
  189. this.$url('/pages/discover/discoverdetails?discover_id='+id)
  190. }
  191. },
  192. addLike(id) {
  193. this.$http
  194. .post({
  195. api: 'api/discover/like',
  196. data: {
  197. discover_id: id
  198. },
  199. header: {
  200. Authorization: this.$cookieStorage.get('user_token')
  201. },
  202. })
  203. .then(res => {
  204. if (res.data.code == 200) {
  205. if (res.data.status) {
  206. this.getHotActivity();
  207. } else {
  208. wx.showModal({
  209. content: res.data.message || '请下拉页面刷新重试',
  210. showCancel: false
  211. });
  212. }
  213. } else {
  214. wx.showModal({
  215. content: res.data.message || '请下拉页面刷新重试',
  216. showCancel: false
  217. });
  218. }
  219. wx.hideLoading();
  220. })
  221. .catch(() => {
  222. wx.hideLoading();
  223. });
  224. },
  225. getMyAttention(options = {}) {
  226. let tab_item = this.tab_list[this.tab_current];
  227. this.$http
  228. .get({
  229. api: 'api/discover/follow',
  230. data: {
  231. page: tab_item.page,
  232. page_size: this.pageSize,
  233. },
  234. header: {
  235. Authorization: this.$cookieStorage.get('user_token')
  236. },
  237. })
  238. .then(res => {
  239. if (res.data.code == 200) {
  240. let isPage;
  241. if(res.data.data.per_page == res.data.data.data.length) {
  242. isPage = true;
  243. }else {
  244. isPage = false;
  245. }
  246. if(!isPage) {
  247. tab_item.loadingClass = false;
  248. tab_item.loadingText = '没有更多数据啦~';
  249. }
  250. if(options.type == 'pageRefresh') {
  251. uni.stopPullDownRefresh();
  252. }else if(options.type == 'scrollRefresh') {
  253. this.isRefresher = false;
  254. }
  255. if(tab_item.page == 1) {
  256. tab_item.list = res.data.data.data;
  257. }else {
  258. tab_item.list.push(...res.data.data.data);
  259. }
  260. } else {
  261. wx.showModal({
  262. content: '请下拉页面刷新重试',
  263. showCancel: false
  264. });
  265. }
  266. wx.hideLoading();
  267. })
  268. .catch(() => {
  269. wx.hideLoading();
  270. });
  271. },
  272. // 页面触底,加载下一页
  273. onScrolltolower(){
  274. let tab_item = this.tab_list[this.tab_current];
  275. if(tab_item.isPage){
  276. tab_item.page = tab_item.page + 1;
  277. if(this.tab_current == 2) {
  278. this.getMyAttention();
  279. }else {
  280. this.getHotActivity();
  281. }
  282. }
  283. },
  284. // 下拉刷新处理
  285. refreshFn(options){
  286. let tab_item = this.tab_list[this.tab_current];
  287. tab_item.page = 1;
  288. tab_item.isPage = true;
  289. tab_item.loadingClass = true;
  290. tab_item.list = []
  291. tab_item.loadingText = '正在加载中';
  292. if(this.tab_current == 2) {
  293. this.getMyAttention(options);
  294. }else {
  295. this.getHotActivity(options);
  296. }
  297. },
  298. // scroll-view 下拉刷新
  299. onRefresherrefresh(){
  300. this.isRefresher = true;
  301. this.refreshFn({type: 'scrollRefresh'});
  302. },
  303. tabChange(event){
  304. this.tab_current = event;
  305. if(this.tab_current == 2) {
  306. this.getMyAttention();
  307. }else {
  308. this.getHotActivity();
  309. }
  310. },
  311. swiperChange(event){
  312. this.tab_current = event.detail.current;
  313. if (event.detail.source == '') return; // 如果是被动出发,没有事件类型则不做处理
  314. if(this.tab_current == 2) {
  315. this.getMyAttention();
  316. }else {
  317. this.getHotActivity();
  318. }
  319. },
  320. getHotActivity(options = {}) {
  321. let discover_type;
  322. let tab_item = this.tab_list[this.tab_current];
  323. if(this.tab_current == 0) {
  324. discover_type = 'created_at';
  325. }else {
  326. discover_type = 'view_count';
  327. }
  328. this.$http
  329. .get({
  330. api: 'api/discover',
  331. data:{
  332. page: tab_item.page,
  333. page_size: this.pageSize,
  334. order: discover_type
  335. },
  336. header: {
  337. Authorization: this.$cookieStorage.get('user_token')
  338. },
  339. })
  340. .then(res => {
  341. if (res.data.code == 200) {
  342. if (res.data.status) {
  343. let isPage;
  344. if(res.data.data.per_page == res.data.data.data.length) {
  345. isPage = true;
  346. }else {
  347. isPage = false;
  348. }
  349. tab_item.isPage = isPage;
  350. if(!isPage) {
  351. tab_item.loadingClass = false;
  352. tab_item.loadingText = '没有更多数据啦~';
  353. }
  354. if(options.type == 'pageRefresh') {
  355. uni.stopPullDownRefresh();
  356. }else if(options.type == 'scrollRefresh') {
  357. this.isRefresher = false;
  358. }
  359. if(tab_item.page == 1) {
  360. tab_item.list = res.data.data.data;
  361. }else {
  362. tab_item.list.push(...res.data.data.data);
  363. }
  364. } else {
  365. wx.showModal({
  366. content: res.message || '请下拉页面刷新重试',
  367. showCancel: false
  368. });
  369. }
  370. } else {
  371. wx.showModal({
  372. content: '请下拉页面刷新重试',
  373. showCancel: false
  374. });
  375. }
  376. wx.hideLoading();
  377. })
  378. .catch(() => {
  379. wx.hideLoading();
  380. });
  381. }
  382. }
  383. }
  384. </script>
  385. <style>
  386. page {
  387. background-color: white;
  388. }
  389. </style>
  390. <style lang="scss" scoped>
  391. .tag-father {
  392. position: relative;
  393. }
  394. .head-tag {
  395. color: white;
  396. display: flex;
  397. align-items: center;
  398. justify-content: center;
  399. text-align: center;
  400. font-size: 24rpx;
  401. width: 36rpx;
  402. height: 36rpx;
  403. border-radius: 50%;
  404. background-color: #15716E;
  405. border: 1rpx solid #FFFFFF;
  406. position: absolute;
  407. left: 66rpx;
  408. top: 70rpx;
  409. z-index: 99;
  410. }
  411. .qzone-img {
  412. width: 220rpx;
  413. height: 220rpx;
  414. border-radius: 10rpx;
  415. margin-right: 12rpx;
  416. &:nth-child(3n) {
  417. margin-right: 0;
  418. }
  419. &:nth-child(n + 4) {
  420. margin-top: 12rpx;
  421. }
  422. }
  423. .head-img {
  424. width: 100rpx;
  425. height: 100rpx;
  426. border-radius: 50%;
  427. }
  428. .fixed-right{
  429. position: fixed;
  430. right: 32rpx;
  431. bottom: 188rpx;
  432. width: max-content;
  433. height: max-content;
  434. padding-bottom: constant(safe-area-inset-bottom);
  435. padding-bottom: env(safe-area-inset-bottom);
  436. .fixed-btn{
  437. width: 100rpx;
  438. height: 100rpx;
  439. border-radius: 50%;
  440. background-color: #15716E;
  441. display: flex;
  442. justify-content: center;
  443. align-items: center;
  444. color: #FFFFFF;
  445. }
  446. }
  447. .fixed-right1{
  448. position: fixed;
  449. right: 32rpx;
  450. bottom: 320rpx;
  451. width: max-content;
  452. height: max-content;
  453. padding-bottom: constant(safe-area-inset-bottom);
  454. padding-bottom: env(safe-area-inset-bottom);
  455. .fixed-btn{
  456. width: 100rpx;
  457. height: 100rpx;
  458. border-radius: 50%;
  459. background-color: #15716E;
  460. display: flex;
  461. justify-content: center;
  462. align-items: center;
  463. color: #FFFFFF;
  464. }
  465. }
  466. // tab样式
  467. /deep/.u-scroll-box {
  468. display: flex;
  469. justify-content: center;
  470. align-items: center;
  471. border-bottom: 1rpx solid rgba(0, 0, 0, 0.1);
  472. }
  473. /deep/.u-scroll-box .u-tab-bar {
  474. background-color: #15716E!important;
  475. width: 80rpx!important;
  476. position: absolute;
  477. left: 0;
  478. bottom: -14rpx;
  479. }
  480. /deep/ .u-tab-item {
  481. font-size: 28rpx!important;
  482. }
  483. </style>