community_user.vue 14 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381
  1. <template>
  2. <view class="user" :style="[background]">
  3. <u-navbar id="navbar" :border-bottom="false"
  4. :background="{ background: 'rgba(256,256,256, '+ navStyle.backgroundBg +')', }"
  5. :back-bg="'rgba(0,0,0,' + navStyle.backBg + ')'" :back-icon-color="navStyle.backColor" :immersive="false">
  6. </u-navbar>
  7. <!-- Header Start -->
  8. <view class="header">
  9. <!-- 用户信息 -->
  10. <view class="user_info flex row-between">
  11. <view class="flex">
  12. <view class="user-avatar flex row-center">
  13. <u-image :src="userInfo.avatar" width="106" height="106" borderRadius="50%"></u-image>
  14. </view>
  15. <view class="m-l-30">
  16. <view class="user-name xxl white bold line-1">{{ userInfo.nickname }}</view>
  17. <view class="user-id m-t-14 xs white">会员ID: {{ userInfo.sn }}</view>
  18. </view>
  19. </view>
  20. <!-- 去用户设置 -->
  21. <navigator v-if="userInfo.is_self" url="/bundle_b/pages/community_user_profile/community_user_profile"
  22. hover-class="none">
  23. <image src="/bundle_b/static/icon_my_setting.png" class="user-setting"></image>
  24. </navigator>
  25. </view>
  26. <!-- 用户简介 -->
  27. <view class="user-intro line-3 white sm">
  28. {{ userInfo.signature || '暂无简介~' }}
  29. </view>
  30. <!-- 用户数据底部 -->
  31. <view class="user-footer flex">
  32. <!-- 统计 -->
  33. <view class="user-statistics">
  34. <view class="user-statistics--item">
  35. <view class="xl bold">{{ userInfo.follow }}</view>
  36. <view class="sm">关注</view>
  37. </view>
  38. <view class="user-statistics--item">
  39. <view class="xl bold">{{ userInfo.fans }}</view>
  40. <view class="sm">粉丝</view>
  41. </view>
  42. <view class="user-statistics--item">
  43. <view class="xl bold">{{ userInfo.like }}</view>
  44. <view class="sm">获赞</view>
  45. </view>
  46. </view>
  47. <!-- 操作 -->
  48. <view class="user-operation flex">
  49. <!-- 发布 -->
  50. <navigator url="/bundle_b/pages/published_works/published_works" hover-class="none">
  51. <button class="btn-primary br60 xs white" v-if="userInfo.is_self">
  52. <image src="/bundle_b/static/icon_publish.png"></image>
  53. <text class="m-l-6">发布</text>
  54. </button>
  55. </navigator>
  56. <!-- 关注 -->
  57. <button class="btn-primary br60 xs white" v-if="userInfo.is_self==0 && userInfo.is_follow==0"
  58. @click="handleCommunityFollow(1)">
  59. <image src="/bundle_b/static/icon_follow.png"></image>
  60. <text class="m-l-6">关注</text>
  61. </button>
  62. <!-- 已关注 -->
  63. <button class="followed-btn br60 xs primary bold"
  64. v-if="userInfo.is_self==0 && userInfo.is_follow==1" @click="showFollowTips = true">已关注</button>
  65. <button open-type="share" @click="handleShare" class="flex-col col--center" hover-class="none">
  66. <image src="/bundle_b/static/icon_share.png" class="share"></image>
  67. </button>
  68. </view>
  69. </view>
  70. </view>
  71. <!-- Header End -->
  72. <!-- Main Start -->
  73. <view class="main">
  74. <view class="nav-title">
  75. <tabs :current="active" @change="changeTabs" bgColor="transparent" stickyBgColor="transparent"
  76. height="100" fontSize="34" :is-scroll="false" width="400rpx" borderRadius="20rpx 20rpx 0 0">
  77. <tab name="作品">
  78. <community-works v-if="!isFirstLoading" :worksNum="worksNum" :i="0" :index="active"
  79. ref="mescoll1" :userId="userId"></community-works>
  80. </tab>
  81. <tab name="赞过">
  82. <community-like v-if="!isFirstLoading" :likeNum="likeNum" :i="1" :index="active" ref="mescoll2"
  83. :userId="userId"></community-like>
  84. </tab>
  85. </tabs>
  86. </view>
  87. <!-- </u-sticky> -->
  88. </view>
  89. <!-- Main End -->
  90. <!-- 加载 -->
  91. <loading-view v-if="isFirstLoading"></loading-view>
  92. <!-- 取消关注 -->
  93. <u-modal v-model="showFollowTips" :show-cancel-button="true" comfirm-text="取消关注" cancelText="再想想"
  94. :confirm-color="colorConfig.primary" :show-title="false" @confirm="handleCommunityFollow(0)">
  95. <view class="flex-col col-center tips-dialog" style="padding-top: 40rpx">
  96. <image class="icon-lg" src="/static/images/icon_warning.png" />
  97. <view style="margin:30rpx 0;">确认取消关注?</view>
  98. </view>
  99. </u-modal>
  100. <!-- #ifdef H5 -->
  101. <u-popup :custom-style="{'background': 'none'}" class="share-tips" v-model="showTips" mode="top">
  102. <view style="overflow: hidden;">
  103. <image src="/static/images/share_arrow.png" class="share-arrow" />
  104. <view class="white" style="text-align: center;margin-top: 280rpx;">
  105. <view class="bold lg">立即分享给好友吧</view>
  106. <view class="sm m-t-10">点击屏幕右上角将本页面分享给好友</view>
  107. </view>
  108. </view>
  109. </u-popup>
  110. <!-- #endif -->
  111. </view>
  112. </template>
  113. <script>
  114. import {
  115. getCommunityUserCenter,
  116. apiCommunityFollow,
  117. } from "@/api/community.js"
  118. import CommunityLike from "./components/community-like.vue"
  119. import CommunityWorks from "./components/community-works.vue"
  120. export default {
  121. components: {
  122. CommunityLike,
  123. CommunityWorks
  124. },
  125. data() {
  126. return {
  127. isFirstLoading: true,
  128. worksNum: 0, // 用于子组件监听触底
  129. likeNum: 0, // 用于子组件监听触底
  130. navStyle: {
  131. backBg: 0.4,
  132. backgroundBg: 0,
  133. backColor: 'rgba(256,256,256,1)'
  134. },
  135. active: 0,
  136. userId: '', //用户ID(不传为当前用户
  137. showFollowTips: false, // 取消关注
  138. showTips: false, // 分享弹窗H5
  139. userInfo: {
  140. id: '', // int 用户id
  141. sn: '', //string 用户编号
  142. nickname: '', //string 用户昵称
  143. avatar: '', //string 用户头像
  144. image: '', //string 背景图
  145. signature: '', //string 签名
  146. follow: 0, //int 关注人数
  147. fans: 0, //int 粉丝数
  148. like: 0, //int 点赞数
  149. is_self: 0, // int 是否为当前登录者 0-不是 1-是
  150. is_follow: 0, // int 登录者是否关注获取信息目标 0-未关注 1-关注
  151. }
  152. }
  153. },
  154. computed: {
  155. background() {
  156. const {
  157. image
  158. } = this.userInfo
  159. return image ? {
  160. 'background-image': `url(${image})`
  161. } : {
  162. 'background-image': `url('../../static/community_user_bg.png')`
  163. }
  164. },
  165. },
  166. onLoad() {
  167. const options = this.$Route.query;
  168. this.userId = options.id;
  169. },
  170. onShow() {
  171. if (this.active == 0) {
  172. this.worksNum += 1
  173. } else if (this.active == 1) {
  174. this.likeNum += 1
  175. }
  176. this.initCommunityUserCenter()
  177. },
  178. onUnload() {
  179. uni.$off("changeItem")
  180. },
  181. onPageScroll(e) {
  182. const top = uni.upx2px(500)
  183. const {
  184. scrollTop
  185. } = e
  186. const percent = scrollTop / top;
  187. this.navStyle.backgroundBg = percent
  188. this.navStyle.backBg = 0.4 * (0.5 - percent)
  189. this.navStyle.backColor = percent < 0.5 ? 'rgba(256,256,256,' + (0.5 - percent) * 2 + ')' : 'rgba(0,0,0,' +
  190. (
  191. percent - 0.5) * 2 + ')'
  192. },
  193. // 触底加载
  194. onReachBottom() {
  195. console.log('触底')
  196. if (this.active == 0) {
  197. this.worksNum += 1
  198. } else if (this.active == 1) {
  199. this.likeNum += 1
  200. }
  201. },
  202. methods: {
  203. changeTabs(event) {
  204. this.active = event
  205. },
  206. // 分享处理
  207. handleShare() {
  208. // #ifdef H5
  209. this.showTips = true
  210. // #endif
  211. // #ifndef MP
  212. this.$store.commit('setCommunity', {
  213. user: {
  214. nickname: this.userInfo.nickname,
  215. },
  216. image: this.userInfo.avatar,
  217. content: this.userInfo.signature,
  218. url: 'bundle_b/pages/community_user/community_user'
  219. })
  220. this.$store.dispatch('communityShare')
  221. // #endif
  222. },
  223. // 初始化个人中心
  224. initCommunityUserCenter() {
  225. getCommunityUserCenter({
  226. user_id: this.userId
  227. }).then(res => {
  228. this.userInfo = res.data
  229. setTimeout(() => {
  230. this.isFirstLoading = false;
  231. }, 600)
  232. })
  233. },
  234. // 关注 / 取消关注
  235. handleCommunityFollow(status) {
  236. apiCommunityFollow({
  237. follow_id: this.userId,
  238. status
  239. }).then(res => {
  240. if (res.code === 1) this.initCommunityUserCenter()
  241. this.$toast({
  242. title: res.msg
  243. })
  244. })
  245. },
  246. },
  247. async onShareAppMessage() {
  248. return {
  249. title: `${ this.userInfo.nickname },TA的内容超级棒`,
  250. path: '/bundle_b/pages/community_user/community_user?id=' + this.userId
  251. };
  252. },
  253. }
  254. </script>
  255. <style lang="scss">
  256. .user {
  257. background-position: center;
  258. background-size: 100% auto;
  259. background-repeat: no-repeat;
  260. .header {
  261. padding: 20rpx 24rpx;
  262. // 用户信息
  263. .user_info {
  264. .user-avatar {
  265. width: 110rpx;
  266. height: 110rpx;
  267. border-radius: 50%;
  268. border: 2px solid #FFFFFF;
  269. }
  270. .user-name {
  271. width: 450rpx
  272. }
  273. .user-id {
  274. display: inline-block;
  275. padding: 4rpx 16rpx;
  276. border-radius: 20rpx;
  277. border: 1px solid #fff;
  278. }
  279. .user-setting {
  280. width: 58rpx;
  281. height: 58rpx;
  282. }
  283. }
  284. // 用户简介
  285. .user-intro {
  286. padding: 20rpx 14rpx 20rpx 0;
  287. line-height: 40rpx;
  288. height: 140rpx;
  289. }
  290. // 用户数据底部
  291. .user-footer {
  292. // 统计数据
  293. .user-statistics {
  294. display: flex;
  295. &--item {
  296. width: 160rpx;
  297. color: #FFFFFF;
  298. }
  299. }
  300. // 操作
  301. .user-operation {
  302. margin-left: 24rpx;
  303. .btn-primary {
  304. padding: 0;
  305. width: 126rpx;
  306. height: 52rpx;
  307. line-height: 52rpx;
  308. background: linear-gradient(90.00deg, #f95f2f 0%, #ff2c3c 100%);
  309. image {
  310. width: 28rpx;
  311. height: 28rpx;
  312. vertical-align: middle;
  313. }
  314. }
  315. // 已关注按钮
  316. .followed-btn {
  317. width: 126rpx;
  318. height: 52rpx;
  319. line-height: 52rpx;
  320. padding: 0;
  321. background-color: #FFFFFF;
  322. }
  323. .share {
  324. width: 36rpx;
  325. height: 36rpx;
  326. margin: 20rpx 0;
  327. margin-left: 20rpx;
  328. }
  329. }
  330. }
  331. }
  332. .main {
  333. .nav-title {
  334. width: 100%;
  335. height: 92rpx;
  336. border-radius: 20rpx 20rpx 0 0;
  337. background-color: #FFFFFF;
  338. }
  339. }
  340. .share-tips .share-arrow {
  341. width: 140rpx;
  342. height: 250rpx;
  343. float: right;
  344. margin: 15rpx 31rpx 0 0;
  345. }
  346. }
  347. </style>