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

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