user.vue 7.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306
  1. <template>
  2. <navigation-bar title="个人中心"></navigation-bar>
  3. <image src="/static/images/user-bg.png" mode="widthFix" class="bg" />
  4. <block v-if="user && user.mobilePhone">
  5. <view class="container" :style="containerStyle">
  6. <view class="header flex-column">
  7. <view class="flex-grow flex-center">
  8. <image
  9. src="/static/images/user/round.png"
  10. mode="heightFix"
  11. style="height: 100%"
  12. />
  13. </view>
  14. <view class="main flex-shrink">
  15. <view
  16. class="avatar"
  17. @click="toPage(3)"
  18. :style="{
  19. 'background-image': `url(${user.avatar})`,
  20. }"
  21. ></view>
  22. <view class="phone fs-40 fw-500">{{ user.mobilePhoneFormat }}</view>
  23. <view class="money flex-align-center pressable" hover-class="pressed" hover-stay-time="80" @click="toPage(-1)">
  24. <uni-icons
  25. type="wallet-filled"
  26. size="24"
  27. color="var(--color-primary)"
  28. ></uni-icons>
  29. <view class="color-primary ml-12" style="font-size: 16px"
  30. >钱包 | 充值</view
  31. >
  32. <view class="fs-40 fw-500 ml-auto mt-12 color-primary">¥</view>
  33. <view class="fs-60 fw-500 ml-12 mr-48 color-primary">{{
  34. user.balance
  35. }}</view>
  36. </view>
  37. </view>
  38. </view>
  39. <view class="body">
  40. <block v-for="(item, index) in menu" :key="index">
  41. <view
  42. class="menu flex-align-center pressable"
  43. hover-class="pressed"
  44. hover-stay-time="80"
  45. v-if="
  46. index !== menu.length - 1 || user.mobilePhone === '15986907592'
  47. "
  48. @click="toPage(index)"
  49. >
  50. <view class="menu-icon">
  51. <uni-icons v-if="item.iconType" :type="item.iconType" size="26" color="rgba(28,43,41,0.65)"></uni-icons>
  52. <image v-else :src="item.icon" mode="aspectFit"></image>
  53. </view>
  54. <view>{{ item.title }}</view>
  55. <view class="ml-auto">
  56. <uni-icons
  57. type="right"
  58. size="12"
  59. color="rgba(28,43,41,0.4)"
  60. ></uni-icons>
  61. </view>
  62. </view>
  63. </block>
  64. </view>
  65. </view>
  66. </block>
  67. <block v-else>
  68. <view class="container" :style="containerStyle">
  69. <view class="header flex-column">
  70. <view class="flex-grow flex-center">
  71. <image
  72. src="/static/images/user/round.png"
  73. mode="heightFix"
  74. style="height: 100%"
  75. />
  76. </view>
  77. <view class="main flex-shrink flex-column flex-align-center pt-40">
  78. <view class="fs-32 color-000-6 mt-40">登录后查看更多功能</view>
  79. <view class="mt-32">
  80. <button class="login-btn" @click="goToLogin">登录/注册</button>
  81. </view>
  82. </view>
  83. </view>
  84. </view>
  85. </block>
  86. </template>
  87. <script setup lang="ts">
  88. import { fetchContact } from "@/api";
  89. import { fetchProfile } from "@/api/user";
  90. import { isAuthenticated, requireAuth } from "@/utils/auth";
  91. import { onLoad, onShow } from "@dcloudio/uni-app";
  92. import { ref } from "vue";
  93. const containerStyle = ref({});
  94. const user = ref<any>({
  95. avatar: "",
  96. });
  97. const service = ref("");
  98. const menu = ref([
  99. {
  100. title: "我的卡包",
  101. path: "/pages-charge/card/card",
  102. icon: "/static/images/user/0.png",
  103. },
  104. {
  105. title: "充电订单",
  106. path: "/pages-charge/orders/orders",
  107. icon: "/static/images/user/1.png",
  108. },
  109. {
  110. title: "发票抬头",
  111. path: "/pages-user/invoice-title",
  112. iconType: "compose",
  113. },
  114. {
  115. title: "我的收藏",
  116. path: "/pages-user/collect/collect",
  117. icon: "/static/images/user/2.png",
  118. },
  119. {
  120. title: "个人信息",
  121. path: "/pages-user/profile/profile",
  122. icon: "/static/images/user/3.png",
  123. },
  124. {
  125. title: "联系我们(工作时间7:00-24:00)",
  126. path: "",
  127. icon: "/static/images/user/4.png",
  128. },
  129. {
  130. title: "常见问题",
  131. path: "/pages-common/faq/faq",
  132. icon: "/static/images/user/5.png",
  133. },
  134. {
  135. title: "电站列表",
  136. path: "/pages/list/list",
  137. icon: "/static/images/user/1.png",
  138. },
  139. ]);
  140. const AUTH_REQUIRED_INDICES = [0, 1, 2, 3, 4];
  141. const goToLogin = () => {
  142. requireAuth("/pages/user/user");
  143. };
  144. const toPage = (index: number) => {
  145. if (index < 0) {
  146. if (!requireAuth("/pages-user/wallet/wallet")) return;
  147. uni.navigateTo({
  148. url: "/pages-user/wallet/wallet",
  149. });
  150. return;
  151. }
  152. const item = menu.value[index];
  153. if (!item.path) {
  154. uni.makePhoneCall({
  155. phoneNumber: service.value,
  156. });
  157. return;
  158. }
  159. if (AUTH_REQUIRED_INDICES.includes(index) && !requireAuth(item.path)) {
  160. return;
  161. }
  162. uni.navigateTo({
  163. url: item.path + (item.title === "常见问题" ? `?service=${service.value}` : ""),
  164. });
  165. };
  166. onLoad(() => {
  167. const bound = uni.getMenuButtonBoundingClientRect();
  168. containerStyle.value = {
  169. top: `${bound.bottom + 10}px`,
  170. };
  171. fetchContact().then((res) => {
  172. if (res && res.mobile) {
  173. service.value = res.mobile;
  174. }
  175. });
  176. });
  177. onShow(() => {
  178. if (!isAuthenticated()) {
  179. return;
  180. }
  181. fetchProfile().then((res) => {
  182. res.mobilePhoneFormat =
  183. res.mobilePhone.slice(0, 3) + "****" + res.mobilePhone.slice(7);
  184. res.avatar = res.avatar
  185. ? res.avatar
  186. : "https://mmbiz.qpic.cn/mmbiz/icTdbqWNOwNRna42FI242Lcia07jQodd2FJGIYQfG0LAJGFxM4FbnQP6yfMxBgJ0F3YRqJCJ1aPAK2dQagdusBZg/0";
  187. user.value = res;
  188. });
  189. });
  190. </script>
  191. <style lang="scss">
  192. @use "../../styles/dialog.scss";
  193. .login-btn {
  194. width: 480rpx;
  195. height: 80rpx;
  196. background: var(--color-primary);
  197. color: #fff;
  198. font-size: 30rpx;
  199. border-radius: 40rpx;
  200. line-height: 80rpx;
  201. transition: background-color 0.15s cubic-bezier(0.22, 1, 0.36, 1);
  202. }
  203. .login-btn:active {
  204. background: var(--color-primary-deep);
  205. }
  206. .bg {
  207. position: absolute;
  208. left: 0;
  209. top: 0;
  210. width: 100%;
  211. height: 660rpx;
  212. }
  213. .container {
  214. position: absolute;
  215. left: 0;
  216. top: 0;
  217. height: 100vh;
  218. width: 100%;
  219. overflow-y: auto;
  220. }
  221. .header {
  222. height: 400rpx;
  223. width: 100%;
  224. .main {
  225. height: 334rpx;
  226. background: rgba(254, 255, 255, 0.7);
  227. border-radius: 40rpx 40rpx 0 0;
  228. position: relative;
  229. text-align: center;
  230. .avatar {
  231. position: absolute;
  232. left: 50%;
  233. transform: translateX(-50%);
  234. top: -50rpx;
  235. width: 110rpx;
  236. height: 110rpx;
  237. border: 2rpx solid #ffffff;
  238. filter: drop-shadow(0px 4rpx 8rpx rgba(0, 24, 60, 0.1));
  239. background-size: cover;
  240. background-repeat: no-repeat;
  241. border-radius: 50%;
  242. }
  243. .phone {
  244. padding-top: 78rpx;
  245. color: #1c2b29;
  246. }
  247. .money {
  248. width: 690rpx;
  249. height: 118rpx;
  250. background: #ffffff;
  251. border-radius: 120rpx;
  252. margin: 0 auto;
  253. margin-top: 30rpx;
  254. color: #1c2b29;
  255. padding: 0 24rpx 0 40rpx;
  256. box-shadow: 0 4rpx 16rpx rgba(28, 43, 41, 0.05);
  257. }
  258. }
  259. }
  260. .body {
  261. width: 100%;
  262. background-color: #fff;
  263. padding: 0rpx 30rpx;
  264. .menu {
  265. background-color: #fff;
  266. height: 120rpx;
  267. border-bottom: 1rpx solid var(--divider);
  268. .menu-icon {
  269. width: 52rpx;
  270. height: 52rpx;
  271. margin-right: 20rpx;
  272. display: flex;
  273. align-items: center;
  274. justify-content: center;
  275. flex-shrink: 0;
  276. image {
  277. width: 52rpx;
  278. height: 52rpx;
  279. }
  280. }
  281. &:last-child {
  282. border-bottom: none;
  283. }
  284. }
  285. }
  286. </style>