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

383 lines
12 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">
  12. <view class="lf-p-32">
  13. <view class="lf-flex" @click="$url('/pages/user/my/my')">
  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,index) in item.attachs" 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="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:[]},
  81. {name: '最热',type: 'view_count',list:[]},
  82. {name: '已关注',type: 'view_count',list:[]}
  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: `Bearer eyJ0eXAiOiJKV1QiLCJhbGciOiJSUzI1NiIsImp0aSI6IjczYTViNTA1NDNlYmNmMjFkNmZiMGJlNzc0NmJmMDE4MDc3MTRkY2Y1MjBiMjM3MGQyZDAyYzQxMTlmMDU4ZTkwMTUxNDQwOTk4MjJhODFhIn0.eyJhdWQiOiIzIiwianRpIjoiNzNhNWI1MDU0M2ViY2YyMWQ2ZmIwYmU3NzQ2YmYwMTgwNzcxNGRjZjUyMGIyMzcwZDJkMDJjNDExOWYwNThlOTAxNTE0NDA5OTgyMmE4MWEiLCJpYXQiOjE2MzExNjk1MDIsIm5iZiI6MTYzMTE2OTUwMiwiZXhwIjoxNjYyNzA1NTAyLCJzdWIiOiIxIiwic2NvcGVzIjpbXX0.p0YoIC_bhOxIOugYxDQTOFIK9t2ORiHQq9H6JWzdByBJKWkFDBisKaXZJvzn1HdU5cjNQnHaBfWpG1Ed15cQlB2LdpXxxc38iaaGW2J6WhlLhVkehloii-TtlZTOeqNrpAHbSe5DRrmm_L07Llm9wr1T1A6pP3MhzdHiZ9d6748j3_cJjK4CJUl3WfYRTaozLFlI00OCW4zzGfgivSighjSFyhqMoHnQ2iSoeWdcJnYpXzXQdc5AXvXOt6eIIa7o2F6Ma1tUseTYVijEVfngdfd21JI1eH6tHrSqUItkQHAart9o74dJn9micI3WrN5yEBXgzemqWkQGV4QzFHLyd3wk-XvP1s2GhCeWlJZOQADzgzhLoxzFUbgM5xULWHp3yfpePGISlM4ZpBwTHcqQt1i_UkNX_zCxa3RYQbZFDfWW0-UPbvHw40t5BY6X7nTPMhPjPGnnPq18jyYBrWBbC9vBWs2o2IHAe5VlkHtmy_v5fymFJLfFzS784Nxp2qPJFWxI7IfrpNckHxohhs5LoieQivw2MyU2shFOUjgwe0xQgyg6UBg5PwNknGTTmzYdavCM4BiQ7moqOuoI15ccIEmc_uMiuLVEfDPlzejP9PQv6mj6IlkJ8HSu4KZU-LxKmtLnGeEwMjVAZBIhsOwzMkaMF1nZ70pgv2YYwBQyVVs`
  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() {
  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. console.log(res)
  153. if (res.data.code == 200) {
  154. if (res.data.status) {
  155. let isPage = res.data.next_page_url == null?false:true;
  156. tab_item.isPage = isPage;
  157. if(!isPage) {
  158. tab_item.loadingClass = false;
  159. tab_item.loadingText = '没有更多数据啦~';
  160. }
  161. if(options.type == 'pageRefresh') {
  162. uni.stopPullDownRefresh();
  163. }else if(options.type == 'scrollRefresh') {
  164. this.isRefresher = false;
  165. }
  166. if(tab_item.page == 1) {
  167. tab_item.list = res.data.data.data;
  168. }else {
  169. tab_item.list.push(...res.data.data.data);
  170. }
  171. console.log('发现列表',tab_item.list)
  172. } else {
  173. wx.showModal({
  174. content: res.data.message || '请下拉页面刷新重试',
  175. showCancel: false
  176. });
  177. }
  178. } else {
  179. wx.showModal({
  180. content: '请下拉页面刷新重试',
  181. showCancel: false
  182. });
  183. }
  184. wx.hideLoading();
  185. })
  186. .catch(() => {
  187. wx.hideLoading();
  188. wx.showModal({
  189. content: '请求失败',
  190. showCancel: false
  191. });
  192. });
  193. },
  194. // 页面触底,加载下一页
  195. onScrolltolower(){
  196. let tab_item = this.tab_list[this.tab_current];
  197. if(tab_item.isPage){
  198. tab_item.page = tab_item.page + 1;
  199. this.getHotActivity();
  200. }
  201. },
  202. // 下拉刷新处理
  203. refreshFn(options){
  204. let tab_item = this.tab_list[this.tab_current];
  205. tab_item.page = 1;
  206. tab_item.isPage = true;
  207. tab_item.loadingClass = true;
  208. tab_item.list = []
  209. tab_item.loadingText = '正在加载中';
  210. this.getHotActivity(options);
  211. },
  212. // scroll-view 下拉刷新
  213. onRefresherrefresh(){
  214. this.isRefresher = true;
  215. this.refreshFn({type: 'scrollRefresh'});
  216. },
  217. tabChange(event){
  218. this.tab_current = event;
  219. if(this.tab_current == 2) {
  220. this.getMyAttention();
  221. console.log('执行关注列表');
  222. }else {
  223. this.getHotActivity();
  224. }
  225. },
  226. swiperChange(event){
  227. this.tab_current = event.detail.current;
  228. if (event.detail.source == '') return; // 如果是被动出发,没有事件类型则不做处理
  229. if(this.tab_current == 2) {
  230. this.getMyAttention();
  231. console.log('执行关注列表');
  232. }else {
  233. this.getHotActivity();
  234. }
  235. },
  236. getHotActivity(options = {}) {
  237. let discover_type;
  238. let tab_item = this.tab_list[this.tab_current];
  239. if(this.tab_current == 0) {
  240. discover_type = 'created_at';
  241. }else {
  242. discover_type = 'view_count';
  243. }
  244. this.$http
  245. .get({
  246. api: 'api/discover',
  247. page: tab_item.page,
  248. page_size: this.pageSize,
  249. data:{
  250. order: discover_type,
  251. user_id: 1
  252. }
  253. })
  254. .then(res => {
  255. if (res.data.code == 200) {
  256. if (res.data.status) {
  257. let isPage = res.data.next_page_url == null?false:true;
  258. tab_item.isPage = isPage;
  259. if(!isPage) {
  260. tab_item.loadingClass = false;
  261. tab_item.loadingText = '没有更多数据啦~';
  262. }
  263. if(options.type == 'pageRefresh') {
  264. uni.stopPullDownRefresh();
  265. }else if(options.type == 'scrollRefresh') {
  266. this.isRefresher = false;
  267. }
  268. if(tab_item.page == 1) {
  269. tab_item.list = res.data.data.data;
  270. }else {
  271. tab_item.list.push(...res.data.data.data);
  272. }
  273. console.log('数组列表',tab_item.list)
  274. } else {
  275. wx.showModal({
  276. content: res.message || '请下拉页面刷新重试',
  277. showCancel: false
  278. });
  279. }
  280. } else {
  281. wx.showModal({
  282. content: '请下拉页面刷新重试',
  283. showCancel: false
  284. });
  285. }
  286. wx.hideLoading();
  287. })
  288. .catch(() => {
  289. wx.hideLoading();
  290. wx.showModal({
  291. content: '请求失败',
  292. showCancel: false
  293. });
  294. });
  295. }
  296. }
  297. }
  298. </script>
  299. <style>
  300. page {
  301. background-color: white;
  302. }
  303. </style>
  304. <style lang="scss" scoped>
  305. .tag-father {
  306. position: relative;
  307. }
  308. .head-tag {
  309. color: white;
  310. display: flex;
  311. align-items: center;
  312. justify-content: center;
  313. text-align: center;
  314. font-size: 24rpx;
  315. width: 36rpx;
  316. height: 36rpx;
  317. border-radius: 50%;
  318. background-color: #15716E;
  319. border: 1rpx solid #FFFFFF;
  320. position: absolute;
  321. left: 66rpx;
  322. top: 70rpx;
  323. z-index: 99;
  324. }
  325. .qzone-img {
  326. width: 220rpx;
  327. height: 220rpx;
  328. border-radius: 10rpx;
  329. margin-right: 12rpx;
  330. &:nth-child(3n) {
  331. margin-right: 0;
  332. }
  333. &:nth-child(n + 4) {
  334. margin-top: 12rpx;
  335. }
  336. }
  337. .head-img {
  338. width: 100rpx;
  339. height: 100rpx;
  340. border-radius: 50%;
  341. }
  342. .fixed-right{
  343. position: fixed;
  344. right: 32rpx;
  345. bottom: 188rpx;
  346. width: max-content;
  347. height: max-content;
  348. padding-bottom: constant(safe-area-inset-bottom);
  349. padding-bottom: env(safe-area-inset-bottom);
  350. .fixed-btn{
  351. width: 100rpx;
  352. height: 100rpx;
  353. border-radius: 50%;
  354. background-color: #15716E;
  355. display: flex;
  356. justify-content: center;
  357. align-items: center;
  358. color: #FFFFFF;
  359. }
  360. }
  361. // tab样式
  362. /deep/.u-scroll-box {
  363. display: flex;
  364. justify-content: center;
  365. align-items: center;
  366. border-bottom: 1rpx solid rgba(0, 0, 0, 0.1);
  367. }
  368. /deep/.u-scroll-box .u-tab-bar {
  369. background-color: #15716E!important;
  370. width: 80rpx!important;
  371. position: absolute;
  372. left: 0;
  373. bottom: -14rpx;
  374. }
  375. /deep/ .u-tab-item {
  376. font-size: 28rpx!important;
  377. }
  378. </style>