my.vue 4.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205
  1. <template>
  2. <view class="wrapper">
  3. <view class="status_bar">
  4. </view>
  5. <view class="header" @click="userDetail">
  6. <view class="head-1">
  7. <image :src="avatarUrl || '/static/missing-face.png'" />
  8. </view>
  9. <view class="head-2" v-if="userInfo.uid">
  10. <view class="user-name">{{ userInfo.nickName }}</view>
  11. </view>
  12. <view class="head-2" v-else>
  13. <view class="user-name">点击登录</view>
  14. </view>
  15. <view style="display: flex;align-items: flex-start;">
  16. <u-icon name="arrow-right"></u-icon>
  17. </view>
  18. </view>
  19. <tool />
  20. <view style="height:40rpx;text-align:center;padding-top:4rpx;"></view>
  21. </view>
  22. </template>
  23. <script>
  24. import tool from "@/pages/tabbar/mine/utils/tool.vue";
  25. import { fetchUserInfo } from "@/api/members.js";
  26. import storage from "@/utils/storage";
  27. export default {
  28. components: {
  29. tool,
  30. },
  31. data() {
  32. return {
  33. coverTransform: "translateY(0px)",
  34. coverTransition: "0s",
  35. moving: false,
  36. userInfo: {},
  37. avatarUrl: null,
  38. };
  39. },
  40. onLoad() { },
  41. onShow() {
  42. if (this.$options.filters.isLogin("auth")) {
  43. this.getUserOrderNum();
  44. } else {
  45. this.$options.filters.navigateToLogin("navigateTo", true);
  46. }
  47. },
  48. onPullDownRefresh() {
  49. this.getUserOrderNum();
  50. this.userInfo = this.$options.filters.isLogin();
  51. this.reloadAvatar(this.userInfo.avatarUrl, true);
  52. },
  53. // #ifndef MP
  54. onNavigationBarButtonTap(e) {
  55. const index = e.index;
  56. if (index === 0) {
  57. this.navigateTo("/pages/mine/set/setUp");
  58. }
  59. },
  60. // #endif
  61. mounted() {
  62. console.log(this.userInfo);
  63. },
  64. methods: {
  65. /**
  66. * 统一跳转接口,拦截未登录路由
  67. * navigator标签现在默认没有转场动画,所以用view
  68. */
  69. navigateTo(url) {
  70. uni.navigateTo({
  71. url,
  72. });
  73. },
  74. userDetail() {
  75. this.userInfo.uid
  76. ? this.navigateTo("/pages/mine/profile/index")
  77. : this.$options.filters.navigateToLogin();
  78. },
  79. async getUserOrderNum() {
  80. uni.stopPullDownRefresh();
  81. if (this.$options.filters.isLogin("auth")) {
  82. fetchUserInfo().then((res) => {
  83. if (res.data.code == 200) {
  84. storage.setUserInfo(res.data.data.userInfo);
  85. this.userInfo = this.$options.filters.isLogin();
  86. this.reloadAvatar(this.userInfo.avatarUrl);
  87. }
  88. });
  89. }
  90. },
  91. reloadAvatar(avatarUrl, isForce) {
  92. if (isForce) {
  93. this.avatarUrl = avatarUrl;
  94. return;
  95. }
  96. let localUrl = this.avatarUrl;
  97. let toUpdateUrl = avatarUrl;
  98. if (localUrl != null) {
  99. localUrl = localUrl.split('?')[0];
  100. }
  101. if (toUpdateUrl != null) {
  102. toUpdateUrl = toUpdateUrl.split('?')[0];
  103. }
  104. if (localUrl != toUpdateUrl) {
  105. this.avatarUrl = avatarUrl;
  106. }
  107. }
  108. },
  109. };
  110. </script>
  111. <style lang="scss">
  112. page {
  113. background-color: #f7f7f7;
  114. }
  115. /* DarkMode 下的样式 start */
  116. @media (prefers-color-scheme: dark) {
  117. page {
  118. background-color: #121425;
  119. }
  120. }
  121. </style>
  122. <style lang="scss" scoped>
  123. html,
  124. body {
  125. overflow: auto;
  126. }
  127. .wrapper {
  128. padding: 0 30rpx;
  129. // height: 100%;
  130. // background-color: #f7f7f7;
  131. .header {
  132. max-width: 100%;
  133. padding: calc(50rpx + var(--status-bar-height)) 0 0;
  134. height: calc(var(--status-bar-height) + 300rpx);
  135. background-position: bottom;
  136. background-repeat: no-repeat;
  137. display: flex;
  138. justify-content: space-between;
  139. .head-1 {
  140. text-align: center;
  141. width: 152rpx;
  142. position: relative;
  143. display: flex;
  144. align-items: center;
  145. image {
  146. width: 152rpx;
  147. height: 144rpx;
  148. border-radius: 50%;
  149. // margin-bottom: 30rpx;
  150. border: 3px solid #fff;
  151. }
  152. .edti-head {
  153. position: absolute;
  154. width: 40rpx;
  155. height: 40rpx;
  156. border-radius: 50%;
  157. background-color: rgba(255, 255, 255, 0.3);
  158. top: 100rpx;
  159. right: 0;
  160. image {
  161. width: 100%;
  162. height: 100%;
  163. }
  164. }
  165. }
  166. .head-2 {
  167. flex: 1;
  168. margin-left: 30rpx;
  169. margin-top: 100rpx;
  170. line-height: 1;
  171. }
  172. /deep/ .u-icon,
  173. .u-icon {
  174. margin-top: 106rpx;
  175. }
  176. }
  177. }
  178. /* DarkMode 下的样式 start */
  179. @media (prefers-color-scheme: dark) {
  180. .wrapper {
  181. .pointBox {
  182. background-color: #222336;
  183. }
  184. }
  185. }
  186. .user-name {
  187. font-size: 34rpx;
  188. }
  189. </style>