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

318 lines
8.8 KiB

  1. <template>
  2. <view>
  3. <lf-nav :spreadOut="true" :showIcon="true" bgColor="#F3F8F8" title="个人主页"></lf-nav>
  4. <view class="user-top" v-if="$isRight(discover_info)">
  5. <view class="lf-row-between lf-w-100">
  6. <view class="lf-flex">
  7. <view class="tag-father">
  8. <image :src="discover_info.avatar" mode="aspectFill" class="head-img"></image>
  9. <view class="head-tag">V</view>
  10. </view>
  11. <view class="lf-flex-column lf-m-l-20">
  12. <text class="lf-font-42 lf-color-black lf-font-bold">{{discover_info.username}}</text>
  13. <text class="lf-font-28 lf-color-black">{{discover_info.my_follow_count}}关注 | {{discover_info.follow_me_count}}粉丝</text>
  14. </view>
  15. </view>
  16. <view>
  17. <button class="head-btn" v-if="discover_info.is_follow == true" @click="payAttention()">已关注</button>
  18. <button class="head-btn" v-if="discover_info.is_follow == false" @click="payAttention()">关注</button>
  19. <view v-if="discover_info.is_follow == -1"></view>
  20. </view>
  21. </view>
  22. </view>
  23. <scroll-view :style="{height: autoHeight}" :scroll-y="true" :refresher-enabled="true" :refresher-triggered="isRefresher"
  24. @scrolltolower="onScrolltolower" @refresherrefresh="onRefresherrefresh">
  25. <view class="lf-m-32" v-for="(item,index) in discover_info.list.data" :key="index" @click="goDetails(item.id)">
  26. <view class="lf-font-48 lf-color-black lf-font-bold">
  27. {{item.create_time[0]}}
  28. </view>
  29. <view class="lf-color-777 lf-font-24">
  30. {{item.create_time[1]}}
  31. </view>
  32. <view class="lf-flex-wrap lf-m-t-20">
  33. <image v-for="(picture,index2) in item.attachs" :key="index2" class="qzone-img" :src="picture.url" mode="aspectFill"></image>
  34. </view>
  35. <view class="lf-m-t-30 lf-row-between lf-p-l-50 lf-p-r-50">
  36. <view class="lf-row-center" @click.stop="addLike(item.id)">
  37. <text class="lf-iconfont icon-xihuanlike lf-color-price" v-if="item.is_like"></text>
  38. <text class="lf-iconfont icon-xihuan" v-else></text>
  39. <text class="lf-font-24 lf-color-777 lf-m-l-10">{{item.likes_count}}</text>
  40. </view>
  41. <view class="lf-row-center">
  42. <text class="lf-iconfont icon-chakan"></text>
  43. <text class="lf-font-24 lf-color-777 lf-m-l-10">{{item.view_count}}</text>
  44. </view>
  45. <view class="lf-row-center">
  46. <text class="lf-iconfont icon-pinglun-"></text>
  47. <text class="lf-font-24 lf-color-777 lf-m-l-10">{{item.comments_count}}</text>
  48. </view>
  49. </view>
  50. </view>
  51. <!-- 空数据的情况 -->
  52. <view class="loading-more">
  53. <text v-if="discover_info.list.data.length"
  54. :class="{'loading-more-text': loadingClass}">{{ loadingText }}</text>
  55. <lf-nocontent v-else></lf-nocontent>
  56. </view>
  57. </scroll-view>
  58. <view style="height: 40rpx;"></view>
  59. </view>
  60. </template>
  61. <script>
  62. export default {
  63. data() {
  64. return {
  65. user_id: 0,
  66. page: 1,
  67. page_size: 15,
  68. discover_info: '',
  69. isPage: true,
  70. loadingClass: true,
  71. loadingText: '正在加载中',
  72. isRefresher: false,
  73. scrollH: 0,
  74. nav_height: 0,
  75. }
  76. },
  77. onLoad(e) {
  78. let info = uni.getSystemInfoSync();
  79. this.scrollH = info.screenHeight;
  80. this.user_id = e.user_id;
  81. this.loginList();
  82. },
  83. computed: {
  84. autoHeight(){
  85. return `calc(${this.scrollH}px - ${this.nav_height}px - 460rpx)`;
  86. }
  87. },
  88. methods: {
  89. // scroll-view 下拉刷新
  90. onRefresherrefresh(){
  91. this.isRefresher = true;
  92. this.refreshFn({type: 'scrollRefresh'});
  93. },
  94. //关注
  95. payAttention() {
  96. this.$http
  97. .post({
  98. api: 'api/discover/add_follow',
  99. data: {
  100. user_id: this.user_id
  101. },
  102. header: {
  103. Authorization: this.$cookieStorage.get('user_token')
  104. },
  105. })
  106. .then(res => {
  107. if (res.data.code == 200) {
  108. if (res.data.status) {
  109. this.$msg(res.data.data);
  110. this.loginList();
  111. } else {
  112. wx.showModal({
  113. content: res.data.message,
  114. showCancel: false
  115. });
  116. }
  117. } else {
  118. wx.showModal({
  119. content: res.data.message,
  120. showCancel: false
  121. });
  122. }
  123. wx.hideLoading();
  124. })
  125. .catch(() => {
  126. wx.hideLoading();
  127. wx.showModal({
  128. content: '请求失败',
  129. showCancel: false
  130. });
  131. });
  132. },
  133. // 下拉刷新处理
  134. refreshFn(options){
  135. this.page = 1;
  136. this.isPage = true;
  137. this.loadingClass = true;
  138. this.discover_info.list.data = [];
  139. this.loadingText = '正在加载中';
  140. this.loginList(options);
  141. },
  142. // 页面触底,加载下一页
  143. onScrolltolower(){
  144. if(this.isPage){
  145. this.page = this.page + 1;
  146. this.loginList();
  147. }
  148. },
  149. //点赞发现
  150. addLike(id) {
  151. let user_info = this.$cookieStorage.get('user_token');
  152. if(user_info) {
  153. this.$http
  154. .post({
  155. api: 'api/discover/like',
  156. data: {
  157. discover_id: id
  158. },
  159. header: {
  160. Authorization: this.$cookieStorage.get('user_token')
  161. },
  162. })
  163. .then(res => {
  164. if (res.data.code == 200) {
  165. if (res.data.status) {
  166. this.refreshFn({type: 'scrollRefresh'});
  167. } else {
  168. wx.showModal({
  169. content: res.data.message || '请下拉页面刷新重试',
  170. showCancel: false
  171. });
  172. }
  173. } else {
  174. wx.showModal({
  175. content: res.data.message || '请下拉页面刷新重试',
  176. showCancel: false
  177. });
  178. }
  179. wx.hideLoading();
  180. })
  181. .catch(() => {
  182. wx.hideLoading();
  183. wx.showModal({
  184. content: '请求失败',
  185. showCancel: false
  186. });
  187. });
  188. }else {
  189. this.$msg('你还未登录,请前往登录!');
  190. }
  191. },
  192. goDetails(id) {
  193. this.$url('/pages/discover/discoverdetails?discover_id='+id)
  194. },
  195. //登录时的发现列表
  196. loginList(options = {}) {
  197. this.$http
  198. .get({
  199. api: 'api/discover/user/'+this.user_id,
  200. data: {
  201. page: this.page,
  202. page_size: this.page_size
  203. },
  204. header: {
  205. Authorization: this.$cookieStorage.get('user_token')
  206. },
  207. })
  208. .then(res => {
  209. if (res.data.code == 200) {
  210. if (res.data.status) {
  211. this.discover_info = res.data.data;
  212. let isPage = res.data.data.list.last_page == this.page?false:true;
  213. this.isPage = isPage;
  214. if(!isPage) {
  215. this.loadingClass = false;
  216. this.loadingText = '没有更多数据啦~';
  217. }
  218. if(options.type == 'pageRefresh') {
  219. uni.stopPullDownRefresh();
  220. }else if(options.type == 'scrollRefresh') {
  221. this.isRefresher = false;
  222. }
  223. if(this.page == 1) {
  224. this.discover_info.list.data = res.data.data.list.data;
  225. }else {
  226. this.discover_info.list.data.push(...res.data.data.list.data);
  227. }
  228. console.log('登录时的发现列表',this.discover_info);
  229. } else {
  230. wx.showModal({
  231. content: res.data.message || '请下拉页面刷新重试',
  232. showCancel: false
  233. });
  234. }
  235. } else {
  236. wx.showModal({
  237. content: res.data.message || '请下拉页面刷新重试',
  238. showCancel: false
  239. });
  240. }
  241. wx.hideLoading();
  242. })
  243. .catch(() => {
  244. wx.hideLoading();
  245. wx.showModal({
  246. content: '请求失败',
  247. showCancel: false
  248. });
  249. });
  250. },
  251. }
  252. }
  253. </script>
  254. <style>
  255. page {
  256. background-color: white;
  257. }
  258. </style>
  259. <style lang="scss" scoped>
  260. .tag-father {
  261. position: relative;
  262. }
  263. .head-tag {
  264. color: white;
  265. display: flex;
  266. align-items: center;
  267. justify-content: center;
  268. text-align: center;
  269. font-size: 24rpx;
  270. width: 36rpx;
  271. height: 36rpx;
  272. border-radius: 50%;
  273. background-color: #15716E;
  274. border: 1rpx solid #FFFFFF;
  275. position: absolute;
  276. left: 76rpx;
  277. top: 86rpx;
  278. z-index: 99;
  279. }
  280. .qzone-img {
  281. width: 220rpx;
  282. height: 220rpx;
  283. border-radius: 10rpx;
  284. margin-right: 12rpx;
  285. &:nth-child(3n) {
  286. margin-right: 0;
  287. }
  288. &:nth-child(n + 4) {
  289. margin-top: 12rpx;
  290. }
  291. }
  292. .user-top {
  293. background-color: #F3F8F8;
  294. height: 236rpx;
  295. padding: 60rpx;
  296. display: flex;
  297. align-items: center;
  298. }
  299. .head-img {
  300. width: 120rpx;
  301. height: 120rpx;
  302. border-radius: 50%;
  303. }
  304. .head-btn {
  305. width: 160rpx;
  306. height: 70rpx;
  307. background: #15716E;
  308. display: flex;
  309. align-items: center;
  310. font-size: 28rpx;
  311. color: white;
  312. justify-content: center;
  313. border-radius: 35rpx;
  314. }
  315. </style>