mine.vue 3.4 KB

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