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

378 lines
11 KiB

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