my.vue 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460
  1. <template>
  2. <view class="container">
  3. <!-- 用户信息卡片 -->
  4. <view class="user-card">
  5. <view class="user-avatar">
  6. <view class="avatar-icon-modern"></view>
  7. </view>
  8. <view class="user-details">
  9. <view class="user-phone">{{ displayPhone }}</view>
  10. </view>
  11. </view>
  12. <!-- 菜单分组 -->
  13. <view class="menu-section">
  14. <view class="section-title">订单与服务</view>
  15. <view class="menu-card">
  16. <view class="menu-item" @click="goToOrders">
  17. <view class="menu-icon">
  18. <image class="menu-svg-icon" src="/static/icons/orders.svg" mode="aspectFit"></image>
  19. </view>
  20. <view class="menu-text">我的订单</view>
  21. <view class="menu-arrow"></view>
  22. </view>
  23. <view class="menu-item" @click="goToCoupons">
  24. <view class="menu-icon">
  25. <image class="menu-svg-icon" src="/static/icons/coupon.svg" mode="aspectFit"></image>
  26. </view>
  27. <view class="menu-text">我的优惠券</view>
  28. <view v-if="availableCouponCount > 0" class="menu-badge">{{ availableCouponCount }}</view>
  29. <view class="menu-arrow"></view>
  30. </view>
  31. <view class="menu-item" @click="goToCouponCenter">
  32. <view class="menu-icon">
  33. <image class="menu-svg-icon" src="/static/icons/coupon.svg" mode="aspectFit"></image>
  34. </view>
  35. <view class="menu-text">领券中心</view>
  36. <view class="menu-arrow"></view>
  37. </view>
  38. </view>
  39. </view>
  40. <view class="menu-section">
  41. <view class="section-title">个人中心</view>
  42. <view class="menu-card">
  43. <view class="menu-item" @click="goToMembership">
  44. <view class="menu-icon">
  45. <image class="menu-svg-icon" src="/static/icons/membership.svg" mode="aspectFit"></image>
  46. </view>
  47. <view class="menu-text">我的会员卡</view>
  48. <view class="menu-arrow"></view>
  49. </view>
  50. <view class="menu-item" @click="goToCards">
  51. <view class="menu-icon">
  52. <image class="menu-svg-icon" src="/static/icons/wallet.svg" mode="aspectFit"></image>
  53. </view>
  54. <view class="menu-text">我的卡片</view>
  55. <view class="menu-arrow"></view>
  56. </view>
  57. <view class="menu-item" @click="goToInvoice">
  58. <view class="menu-icon">
  59. <image class="menu-svg-icon" src="/static/icons/invoice.svg" mode="aspectFit"></image>
  60. </view>
  61. <view class="menu-text">发票管理</view>
  62. <view class="menu-arrow"></view>
  63. </view>
  64. </view>
  65. </view>
  66. <view class="menu-section">
  67. <view class="section-title">帮助与支持</view>
  68. <view class="menu-card">
  69. <view class="menu-item" @click="goToFAQ">
  70. <view class="menu-icon">
  71. <image class="menu-svg-icon" src="/static/icons/faq.svg" mode="aspectFit"></image>
  72. </view>
  73. <view class="menu-text">常见问题</view>
  74. <view class="menu-arrow"></view>
  75. </view>
  76. <CustomerServiceButton
  77. mode="menu-item"
  78. title="个人中心-联系客服"
  79. :path="'/pages/my/my'"
  80. >
  81. <view class="menu-icon">
  82. <image class="menu-svg-icon" src="/static/icons/service.svg" mode="aspectFit"></image>
  83. </view>
  84. <view class="menu-text">联系客服</view>
  85. <view class="service-phone">在线咨询</view>
  86. <view class="menu-arrow"></view>
  87. </CustomerServiceButton>
  88. <view class="menu-item" @click="goToOfficialAccount">
  89. <view class="menu-icon">
  90. <image class="menu-svg-icon" src="/static/icons/official.svg" mode="aspectFit"></image>
  91. </view>
  92. <view class="menu-text">公众号信息</view>
  93. <view class="menu-arrow"></view>
  94. </view>
  95. </view>
  96. </view>
  97. <!-- 退出登录 -->
  98. <view class="logout-section">
  99. <button class="logout-btn" @click="handleLogout">退出登录</button>
  100. </view>
  101. <!-- 版本信息 -->
  102. <view class="version-info">
  103. {{ appVersion }}
  104. </view>
  105. </view>
  106. </template>
  107. <script setup lang="ts">
  108. import { ref, computed, onMounted } from 'vue';
  109. import { onShow } from '@dcloudio/uni-app';
  110. import { logout as logoutApi } from '../../api/user';
  111. import { getCouponCount } from '../../api/coupon';
  112. import { clearAuth, getUserInfo as getStoredUserInfo } from '../../utils/auth';
  113. import { logger } from '../../utils/logger';
  114. import { APP_VERSION } from '../../utils/config';
  115. import type { UserInfo } from '../../api/user';
  116. const userInfo = ref<UserInfo | null>(null);
  117. const availableCouponCount = ref(0);
  118. const appVersion = APP_VERSION;
  119. // 显示手机号(脱敏)
  120. const displayPhone = computed(() => {
  121. const phone = userInfo.value?.phone;
  122. if (phone && phone.length >= 7) {
  123. return phone.substring(0, 3) + '****' + phone.substring(phone.length - 4);
  124. }
  125. return phone || '未绑定手机号';
  126. });
  127. // 每次页面显示时刷新用户信息
  128. onShow(() => {
  129. loadUserInfo();
  130. });
  131. const loadUserInfo = () => {
  132. const stored = getStoredUserInfo();
  133. if (stored) {
  134. userInfo.value = stored;
  135. }
  136. };
  137. onMounted(async () => {
  138. // 加载用户信息(从本地存储)
  139. loadUserInfo();
  140. // 加载可用优惠券数量
  141. try {
  142. const result = await getCouponCount();
  143. availableCouponCount.value = result.availableCount || 0;
  144. } catch (e) {
  145. logger.log('获取优惠券数量失败', e);
  146. }
  147. });
  148. const goBack = () => {
  149. uni.navigateBack();
  150. };
  151. const goToOrders = () => {
  152. uni.navigateTo({
  153. url: '/pages/orders/orders'
  154. });
  155. };
  156. const goToCoupons = () => {
  157. uni.navigateTo({
  158. url: '/pages/coupons/coupons'
  159. });
  160. };
  161. const goToCouponCenter = () => {
  162. uni.navigateTo({
  163. url: '/pages/couponCenter/couponCenter'
  164. });
  165. };
  166. const goToMembership = () => {
  167. uni.vibrateShort({ type: 'light' });
  168. uni.showToast({
  169. title: '会员卡功能开发中',
  170. icon: 'none'
  171. });
  172. };
  173. const goToCards = () => {
  174. uni.vibrateShort({ type: 'light' });
  175. uni.showToast({
  176. title: '卡片功能开发中',
  177. icon: 'none'
  178. });
  179. };
  180. const goToInvoice = () => {
  181. uni.vibrateShort({ type: 'light' });
  182. uni.showToast({
  183. title: '发票管理功能开发中',
  184. icon: 'none'
  185. });
  186. };
  187. const goToFAQ = () => {
  188. uni.vibrateShort({ type: 'light' });
  189. uni.showToast({
  190. title: '常见问题功能开发中',
  191. icon: 'none'
  192. });
  193. };
  194. const callService = () => {
  195. uni.vibrateShort({ type: 'light' });
  196. uni.makePhoneCall({
  197. phoneNumber: '400-0755-315'
  198. });
  199. };
  200. const goToOfficialAccount = () => {
  201. uni.vibrateShort({ type: 'light' });
  202. uni.showToast({
  203. title: '公众号信息功能开发中',
  204. icon: 'none'
  205. });
  206. };
  207. const goToSettings = () => {
  208. uni.showToast({
  209. title: '设置功能开发中',
  210. icon: 'none'
  211. });
  212. };
  213. const handleLogout = () => {
  214. uni.showModal({
  215. title: '提示',
  216. content: '确定要退出登录吗?',
  217. success: async (res) => {
  218. if (res.confirm) {
  219. try {
  220. await logoutApi();
  221. } catch (e) {
  222. logger.log('退出登录接口调用失败', e);
  223. } finally {
  224. clearAuth();
  225. uni.reLaunch({
  226. url: '/pages/login/login'
  227. });
  228. }
  229. }
  230. }
  231. });
  232. };
  233. </script>
  234. <style lang="scss">
  235. .container {
  236. min-height: 100vh;
  237. background: $color-bg-secondary;
  238. display: flex;
  239. flex-direction: column;
  240. padding-bottom: $spacing-xl;
  241. }
  242. /* ========== 用户信息卡片 ========== */
  243. .user-card {
  244. background: linear-gradient(135deg, $color-primary-light 0%, $color-primary 100%);
  245. padding: $spacing-lg $spacing-lg;
  246. padding-bottom: $spacing-md;
  247. display: flex;
  248. align-items: center;
  249. animation: slideDown 0.3s ease;
  250. .user-avatar {
  251. width: 88rpx;
  252. height: 88rpx;
  253. border-radius: $radius-circle;
  254. background: rgba(255, 255, 255, 0.95);
  255. display: flex;
  256. align-items: center;
  257. justify-content: center;
  258. margin-right: $spacing-md;
  259. box-shadow: 0 4rpx 16rpx rgba(0, 0, 0, 0.12);
  260. flex-shrink: 0;
  261. .avatar-icon-modern {
  262. width: 44rpx;
  263. height: 44rpx;
  264. background: linear-gradient(135deg, $color-primary-light, $color-primary);
  265. border-radius: 50%;
  266. position: relative;
  267. &::before {
  268. content: '';
  269. position: absolute;
  270. width: 20rpx;
  271. height: 20rpx;
  272. background: #ffffff;
  273. border-radius: 50%;
  274. top: 6rpx;
  275. left: 50%;
  276. transform: translateX(-50%);
  277. }
  278. &::after {
  279. content: '';
  280. position: absolute;
  281. width: 36rpx;
  282. height: 24rpx;
  283. background: #ffffff;
  284. border-radius: 18rpx 18rpx 0 0;
  285. bottom: 0;
  286. left: 50%;
  287. transform: translateX(-50%);
  288. }
  289. }
  290. }
  291. .user-details {
  292. flex: 1;
  293. }
  294. .user-phone {
  295. font-size: 28rpx;
  296. font-weight: 500;
  297. color: $color-text-primary;
  298. }
  299. }
  300. /* ========== 菜单分组 ========== */
  301. .menu-section {
  302. margin-top: $spacing-lg;
  303. animation: slideUp 0.3s ease;
  304. .section-title {
  305. font-size: 24rpx;
  306. color: $color-text-secondary;
  307. padding: 0 $spacing-lg $spacing-sm;
  308. font-weight: 500;
  309. }
  310. }
  311. .menu-card {
  312. background: $color-bg-primary;
  313. margin: 0 $spacing-lg;
  314. border-radius: $radius-lg;
  315. box-shadow: $shadow-sm;
  316. overflow: hidden;
  317. }
  318. .menu-item {
  319. display: flex;
  320. align-items: center;
  321. padding: $spacing-md $spacing-lg;
  322. border-bottom: 1rpx solid $color-border;
  323. transition: all $duration-fast $ease-out;
  324. position: relative;
  325. &:last-child {
  326. border-bottom: none;
  327. }
  328. &:active {
  329. background: $color-bg-secondary;
  330. }
  331. .menu-icon {
  332. width: 40rpx;
  333. height: 40rpx;
  334. margin-right: $spacing-md;
  335. display: flex;
  336. align-items: center;
  337. justify-content: center;
  338. .menu-svg-icon {
  339. width: 100%;
  340. height: 100%;
  341. }
  342. }
  343. .menu-text {
  344. flex: 1;
  345. font-size: 28rpx;
  346. color: $color-text-primary;
  347. }
  348. .menu-arrow {
  349. width: 16rpx;
  350. height: 16rpx;
  351. border-top: 2rpx solid $color-text-tertiary;
  352. border-right: 2rpx solid $color-text-tertiary;
  353. transform: rotate(45deg);
  354. margin-left: $spacing-sm;
  355. }
  356. .menu-badge {
  357. background: $color-error;
  358. color: #ffffff;
  359. font-size: 20rpx;
  360. min-width: 32rpx;
  361. height: 32rpx;
  362. line-height: 32rpx;
  363. text-align: center;
  364. border-radius: 16rpx;
  365. padding: 0 8rpx;
  366. margin-right: $spacing-sm;
  367. animation: bounce 0.3s ease;
  368. }
  369. .service-phone {
  370. font-size: 24rpx;
  371. color: $color-text-secondary;
  372. margin-left: auto;
  373. margin-right: $spacing-sm;
  374. }
  375. }
  376. /* ========== 退出登录 ========== */
  377. .logout-section {
  378. padding: $spacing-xxl $spacing-lg $spacing-lg;
  379. display: flex;
  380. justify-content: center;
  381. animation: fadeIn 0.35s ease;
  382. .logout-btn {
  383. width: 60%;
  384. height: 88rpx;
  385. background: $color-bg-primary;
  386. border: 2rpx solid $color-border;
  387. border-radius: $radius-xl;
  388. color: $color-text-secondary;
  389. font-size: 28rpx;
  390. font-weight: 500;
  391. display: flex;
  392. align-items: center;
  393. justify-content: center;
  394. transition: all $duration-fast $ease-out;
  395. &::after {
  396. border: none;
  397. }
  398. &:active {
  399. background: $color-bg-secondary;
  400. border-color: $color-text-tertiary;
  401. }
  402. }
  403. }
  404. /* ========== 版本信息 ========== */
  405. .version-info {
  406. text-align: center;
  407. font-size: 22rpx;
  408. color: $color-text-tertiary;
  409. padding: $spacing-lg 0;
  410. animation: fadeIn 0.4s ease;
  411. }
  412. </style>