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

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