logic.js 3.1 KB

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