mine.vue 3.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108
  1. <script setup>
  2. import { computed, ref } from 'vue'
  3. import { onShow } from '@dcloudio/uni-app'
  4. import { useUserStore } from '@/stores/user'
  5. import { PAGE_PATHS } from '@/config/api'
  6. import { resolveUserAvatarUrl } from '@/utils/avatar'
  7. import { useShareToLogin } from '@/utils/shareToLogin'
  8. useShareToLogin()
  9. const userStore = useUserStore()
  10. const loggingOut = ref(false)
  11. const displayName = computed(() => {
  12. const info = userStore.userInfo
  13. if (!info) return '未登录'
  14. return info.realName || info.username || '用户'
  15. })
  16. const username = computed(() => userStore.userInfo?.username || '-')
  17. const phone = computed(() => userStore.userInfo?.phone || userStore.userInfo?.mobile || '-')
  18. const email = computed(() => userStore.userInfo?.email || '-')
  19. const deptName = computed(
  20. () => userStore.userInfo?.deptName || userStore.userInfo?.dept_name || '-'
  21. )
  22. const roleLabel = computed(() => userStore.userRole || '-')
  23. const avatarUrl = computed(() =>
  24. resolveUserAvatarUrl(userStore.userInfo?.avatarUrl, userStore.userRole)
  25. )
  26. onShow(() => {
  27. userStore.checkLoginStatus()
  28. if (!userStore.isLoggedIn) {
  29. uni.reLaunch({ url: PAGE_PATHS.login })
  30. return
  31. }
  32. userStore.refreshUserInfo()
  33. })
  34. const handleSaveHint = () => {
  35. uni.showToast({ title: '个人信息修改将在后续开放', icon: 'none' })
  36. }
  37. const handleLogout = async () => {
  38. if (loggingOut.value) return
  39. loggingOut.value = true
  40. try {
  41. await userStore.logout()
  42. } finally {
  43. loggingOut.value = false
  44. }
  45. }
  46. </script>
  47. <template>
  48. <view class="mp-page mp-page--tab">
  49. <view class="mp-profile-hero">
  50. <view class="mp-profile-hero__user">
  51. <view class="mp-profile-hero__avatar">
  52. <image v-if="avatarUrl" :src="avatarUrl" mode="aspectFill" />
  53. </view>
  54. <view>
  55. <text class="mp-profile-hero__name">{{ displayName }}</text>
  56. <text class="mp-profile-hero__dept">山峡化工 · {{ deptName }}</text>
  57. </view>
  58. </view>
  59. </view>
  60. <view class="mp-profile-panel">
  61. <view class="mp-form-item">
  62. <text class="mp-form-item__label">姓名</text>
  63. <text class="mp-form-item__value">{{ displayName }}</text>
  64. </view>
  65. <view class="mp-form-item">
  66. <text class="mp-form-item__label">账号</text>
  67. <text class="mp-form-item__value">{{ username }}</text>
  68. </view>
  69. <view class="mp-form-item">
  70. <text class="mp-form-item__label">手机号</text>
  71. <text class="mp-form-item__value">{{ phone }}</text>
  72. </view>
  73. <view class="mp-form-item">
  74. <text class="mp-form-item__label">邮箱</text>
  75. <text class="mp-form-item__value">{{ email }}</text>
  76. </view>
  77. <view class="mp-form-item">
  78. <text class="mp-form-item__label">所属部门</text>
  79. <text class="mp-form-item__value">{{ deptName }}</text>
  80. </view>
  81. <view class="mp-form-item">
  82. <text class="mp-form-item__label">角色</text>
  83. <text class="mp-form-item__value">{{ roleLabel }}</text>
  84. </view>
  85. </view>
  86. <view class="mp-profile-actions">
  87. <button class="mp-btn mp-btn--primary mp-btn--block" @click="handleSaveHint">保存修改</button>
  88. <button
  89. class="mp-btn mp-btn--ghost mp-btn--block"
  90. :loading="loggingOut || userStore.isLoading"
  91. @click="handleLogout"
  92. >
  93. 退出登录
  94. </button>
  95. </view>
  96. <text class="mp-hint">本期支持查看个人信息与退出登录;资料编辑后续开放</text>
  97. <app-env-badge />
  98. </view>
  99. </template>