logic.js 3.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114
  1. import { logout as logoutApi } from '@/api/auth'
  2. import { getMyProfile } from '@/api/fulfiller'
  3. import { clearAuth, isLoggedIn } from '@/utils/auth'
  4. export default {
  5. data() {
  6. return {
  7. showServicePopup: false,
  8. showLogoutPopup: false,
  9. profile: null,
  10. profileLoading: false
  11. }
  12. },
  13. onShow() {
  14. if (isLoggedIn()) {
  15. this.loadProfile()
  16. }
  17. },
  18. methods: {
  19. async loadProfile() {
  20. if (this.profileLoading) return
  21. this.profileLoading = true
  22. try {
  23. const res = await getMyProfile()
  24. this.profile = res.data || null
  25. } catch (err) {
  26. console.error('获取个人信息失败:', err)
  27. } finally {
  28. this.profileLoading = false
  29. }
  30. },
  31. navToSettings() {
  32. uni.navigateTo({
  33. url: '/pages/mine/settings/index'
  34. });
  35. },
  36. navToProfile() {
  37. uni.navigateTo({
  38. url: '/pages/mine/settings/profile/index'
  39. });
  40. },
  41. navToLevel() {
  42. uni.navigateTo({
  43. url: '/pages/mine/level/index'
  44. });
  45. },
  46. navToNotification() {
  47. uni.navigateTo({
  48. url: '/pages/mine/message/index'
  49. });
  50. },
  51. navToWallet() {
  52. uni.navigateTo({
  53. url: '/pages/mine/wallet/index'
  54. });
  55. },
  56. navToPoints() {
  57. uni.navigateTo({
  58. url: '/pages/mine/points/index'
  59. });
  60. },
  61. navToOrderStats() {
  62. uni.navigateTo({
  63. url: '/pages/mine/order-stats'
  64. });
  65. },
  66. navToRewards() {
  67. uni.navigateTo({
  68. url: '/pages/mine/rewards'
  69. });
  70. },
  71. openServicePopup() {
  72. this.showServicePopup = true;
  73. },
  74. closeServicePopup() {
  75. this.showServicePopup = false;
  76. },
  77. previewQRCode() {
  78. uni.previewImage({
  79. urls: ['/static/logo.png']
  80. });
  81. },
  82. openOnlineService() {
  83. // 模拟跳转企业微信客服
  84. uni.showToast({
  85. title: '正在跳转企业微信客服...',
  86. icon: 'none'
  87. });
  88. },
  89. callServicePhone() {
  90. uni.makePhoneCall({
  91. phoneNumber: '400-123-4567'
  92. });
  93. },
  94. logout() {
  95. this.showLogoutPopup = true;
  96. },
  97. cancelLogout() {
  98. this.showLogoutPopup = false;
  99. },
  100. async confirmLogout() {
  101. this.showLogoutPopup = false;
  102. try {
  103. await logoutApi()
  104. } catch (e) {
  105. // 即使后端退出失败,也清除本地登录态
  106. }
  107. clearAuth()
  108. uni.reLaunch({
  109. url: '/pages/login/login'
  110. });
  111. }
  112. }
  113. }