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

319 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="widthFix" 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 list" :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="list.length"
  54. :class="{'loading-more-text': loadingClass}">{{ loadingText }}</text>
  55. <lf-nocontent src="/static/images/empty.png" 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. list: []
  76. }
  77. },
  78. onLoad(e) {
  79. let info = uni.getSystemInfoSync();
  80. this.scrollH = info.screenHeight;
  81. this.user_id = e.user_id;
  82. this.loginList();
  83. },
  84. computed: {
  85. autoHeight(){
  86. return `calc(${this.scrollH}px - ${this.nav_height}px - 460rpx)`;
  87. }
  88. },
  89. methods: {
  90. // scroll-view 下拉刷新
  91. onRefresherrefresh(){
  92. this.isRefresher = true;
  93. this.refreshFn({type: 'scrollRefresh'});
  94. },
  95. //关注
  96. payAttention() {
  97. this.$http
  98. .post({
  99. api: 'api/discover/add_follow',
  100. data: {
  101. user_id: this.user_id
  102. },
  103. header: {
  104. Authorization: this.$cookieStorage.get('user_token')
  105. },
  106. })
  107. .then(res => {
  108. if (res.data.code == 200) {
  109. if (res.data.status) {
  110. this.$msg(res.data.data);
  111. this.loginList();
  112. } else {
  113. wx.showModal({
  114. content: res.data.message,
  115. showCancel: false
  116. });
  117. }
  118. } else {
  119. wx.showModal({
  120. content: res.data.message,
  121. showCancel: false
  122. });
  123. }
  124. wx.hideLoading();
  125. })
  126. .catch(() => {
  127. wx.hideLoading();
  128. wx.showModal({
  129. content: '请求失败',
  130. showCancel: false
  131. });
  132. });
  133. },
  134. // 下拉刷新处理
  135. refreshFn(options){
  136. this.page = 1;
  137. this.isPage = true;
  138. this.loadingClass = true;
  139. this.list = [];
  140. this.loadingText = '正在加载中';
  141. this.loginList(options);
  142. },
  143. // 页面触底,加载下一页
  144. onScrolltolower(){
  145. if(this.isPage){
  146. this.page = this.page + 1;
  147. this.loginList();
  148. }
  149. },
  150. //点赞发现
  151. addLike(id) {
  152. let user_info = this.$cookieStorage.get('user_token');
  153. if(user_info) {
  154. this.$http
  155. .post({
  156. api: 'api/discover/like',
  157. data: {
  158. discover_id: id
  159. },
  160. header: {
  161. Authorization: this.$cookieStorage.get('user_token')
  162. },
  163. })
  164. .then(res => {
  165. if (res.data.code == 200) {
  166. if (res.data.status) {
  167. this.refreshFn({type: 'scrollRefresh'});
  168. } else {
  169. wx.showModal({
  170. content: res.data.message || '请下拉页面刷新重试',
  171. showCancel: false
  172. });
  173. }
  174. } else {
  175. wx.showModal({
  176. content: res.data.message || '请下拉页面刷新重试',
  177. showCancel: false
  178. });
  179. }
  180. wx.hideLoading();
  181. })
  182. .catch(() => {
  183. wx.hideLoading();
  184. wx.showModal({
  185. content: '请求失败',
  186. showCancel: false
  187. });
  188. });
  189. }else {
  190. this.$msg('你还未登录,请前往登录!');
  191. }
  192. },
  193. goDetails(id) {
  194. this.$url('/pages/discover/discoverdetails?discover_id='+id)
  195. },
  196. //登录时的发现列表
  197. loginList(options = {}) {
  198. this.$http
  199. .get({
  200. api: 'api/discover/user/'+this.user_id,
  201. data: {
  202. page: this.page,
  203. page_size: this.page_size
  204. },
  205. header: {
  206. Authorization: this.$cookieStorage.get('user_token')
  207. },
  208. })
  209. .then(res => {
  210. if (res.data.code == 200) {
  211. if (res.data.status) {
  212. this.discover_info = res.data.data;
  213. let isPage = res.data.data.list.last_page == this.page?false:true;
  214. this.isPage = isPage;
  215. if(!isPage) {
  216. this.loadingClass = false;
  217. this.loadingText = '没有更多数据啦~';
  218. }
  219. if(options.type == 'pageRefresh') {
  220. uni.stopPullDownRefresh();
  221. }else if(options.type == 'scrollRefresh') {
  222. this.isRefresher = false;
  223. }
  224. if(this.page == 1) {
  225. this.list = res.data.data.list.data;
  226. }else {
  227. this.list.push(...res.data.data.list.data);
  228. }
  229. console.log('登录时的发现列表',this.discover_info);
  230. } else {
  231. wx.showModal({
  232. content: res.data.message || '请下拉页面刷新重试',
  233. showCancel: false
  234. });
  235. }
  236. } else {
  237. wx.showModal({
  238. content: res.data.message || '请下拉页面刷新重试',
  239. showCancel: false
  240. });
  241. }
  242. wx.hideLoading();
  243. })
  244. .catch(() => {
  245. wx.hideLoading();
  246. wx.showModal({
  247. content: '请求失败',
  248. showCancel: false
  249. });
  250. });
  251. },
  252. }
  253. }
  254. </script>
  255. <style>
  256. page {
  257. background-color: white;
  258. }
  259. </style>
  260. <style lang="scss" scoped>
  261. .tag-father {
  262. position: relative;
  263. }
  264. .head-tag {
  265. color: white;
  266. display: flex;
  267. align-items: center;
  268. justify-content: center;
  269. text-align: center;
  270. font-size: 24rpx;
  271. width: 36rpx;
  272. height: 36rpx;
  273. border-radius: 50%;
  274. background-color: #15716E;
  275. border: 1rpx solid #FFFFFF;
  276. position: absolute;
  277. left: 76rpx;
  278. top: 86rpx;
  279. z-index: 99;
  280. }
  281. .qzone-img {
  282. width: 220rpx;
  283. height: 220rpx;
  284. border-radius: 10rpx;
  285. margin-right: 12rpx;
  286. &:nth-child(3n) {
  287. margin-right: 0;
  288. }
  289. &:nth-child(n + 4) {
  290. margin-top: 12rpx;
  291. }
  292. }
  293. .user-top {
  294. background-color: #F3F8F8;
  295. height: 236rpx;
  296. padding: 60rpx;
  297. display: flex;
  298. align-items: center;
  299. }
  300. .head-img {
  301. width: 120rpx;
  302. height: 120rpx;
  303. border-radius: 50%;
  304. }
  305. .head-btn {
  306. width: 160rpx;
  307. height: 70rpx;
  308. background: #15716E;
  309. display: flex;
  310. align-items: center;
  311. font-size: 28rpx;
  312. color: white;
  313. justify-content: center;
  314. border-radius: 35rpx;
  315. }
  316. </style>