index.vue 5.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239
  1. <route lang="json5" type="page">
  2. {
  3. layout: 'default',
  4. style: {
  5. navigationBarTitleText: '我的',
  6. navigationStyle: 'custom',
  7. },
  8. }
  9. </route>
  10. <template>
  11. <view class="user-container">
  12. <!-- 状态栏占位 -->
  13. <view class="status-bar-placeholder" :style="{ height: statusBarHeight + 'px' }"></view>
  14. <!-- 头部区域 -->
  15. <view class="header-view">
  16. <image class="logo" :src="iconMap.Logo_tj" mode="aspectFit" />
  17. <view class="dept-view">
  18. <text class="dept-text">{{ currentUserInfo.nickname }}</text>
  19. <text class="dept-text">{{ currentUserInfo.deptName }}</text>
  20. </view>
  21. </view>
  22. <!-- 表单信息 -->
  23. <view class="form-view">
  24. <view
  25. v-for="item in userConfig"
  26. :key="item.field"
  27. class="form-item"
  28. @click="handleItemClick(item)"
  29. >
  30. <text>{{ item.label }}</text>
  31. <text v-if="item.type === 'text'" class="normal-text">
  32. {{ currentUserInfo[item.field] }}
  33. </text>
  34. <image v-else-if="item.type === 'image'" class="avatar" :src="getImage(item.field)" />
  35. <text v-if="item.field === 'version'" class="arrow-indicator">&gt;</text>
  36. </view>
  37. </view>
  38. <!-- 退出登录 -->
  39. <view class="logout">
  40. <button class="logout-btn" @click="handleLogout">
  41. <text class="logout-btn-text">退出登录</text>
  42. </button>
  43. </view>
  44. </view>
  45. </template>
  46. <script lang="ts" setup>
  47. import { ref, onMounted } from 'vue'
  48. import { onShow } from '@dcloudio/uni-app'
  49. import { useUserStore } from '@/store/user'
  50. import { logout } from '@/api/login'
  51. import iconMap from '@/utils/imagesMap'
  52. import { config } from '@/utils/config'
  53. defineOptions({
  54. name: 'user',
  55. })
  56. // 状态栏高度
  57. const statusBarHeight = ref(20)
  58. const systemInfo = uni.getSystemInfoSync()
  59. statusBarHeight.value = systemInfo.statusBarHeight || 20
  60. const userStore = useUserStore()
  61. const currentUserInfo = computed(() => userStore.userInfo)
  62. // 用户配置
  63. const userConfig = [
  64. { label: '头像', field: 'avatar', type: 'image' },
  65. { label: '姓名', field: 'username', type: 'text' },
  66. { label: '昵称', field: 'nickname', type: 'text' },
  67. { label: '手机号', field: 'mobile', type: 'text' },
  68. { label: '邮箱地址', field: 'email', type: 'text' },
  69. // { label: '关于系统', field: 'version', type: 'text' },
  70. ]
  71. // onShow(() => {
  72. // console.log('load user info')
  73. // loadUserInfo()
  74. // })
  75. // 加载用户信息
  76. // const loadUserInfo = () => {
  77. // try {
  78. // const userInfo = uni.getStorageSync('APP_USER_INFO')
  79. // if (userInfo) {
  80. // const info = { ...JSON.parse(userInfo) }
  81. // currentUserInfo.value = info
  82. // } else {
  83. // // 没有用户信息,跳转到登录页
  84. // uni.redirectTo({ url: '/pages/login/login' })
  85. // }
  86. // } catch (err) {
  87. // console.error('获取用户信息失败:', err)
  88. // uni.redirectTo({ url: '/pages/login/login' })
  89. // }
  90. // }
  91. // 获取图片 URL
  92. const getImage = (key: string) => {
  93. return config.file_url + currentUserInfo.value[key]
  94. }
  95. // 处理点击
  96. const handleItemClick = (item: any) => {
  97. if (item.field === 'version') {
  98. // 跳转到关于系统页面
  99. uni.navigateTo({ url: '/pages/aboutSystem/index' })
  100. }
  101. }
  102. // 退出登录
  103. const handleLogout = async () => {
  104. try {
  105. await logout()
  106. // 清除 store
  107. userStore.clearUserInfo()
  108. // 清除本地存储
  109. uni.removeStorageSync('APP_ACCESS_TOKEN')
  110. uni.removeStorageSync('APP_USER_INFO')
  111. uni.removeStorageSync('USER_LIST')
  112. // 通知RN端也退出登录
  113. if (window.ReactNativeWebView) {
  114. window.ReactNativeWebView.postMessage(JSON.stringify({ type: 'logout' }))
  115. }
  116. // 跳转到登录页
  117. uni.reLaunch({ url: '/pages/login/login' })
  118. } catch (error) {
  119. console.error('退出登录失败:', error)
  120. }
  121. }
  122. </script>
  123. <style lang="scss" scoped>
  124. .user-container {
  125. display: flex;
  126. flex-direction: column;
  127. min-height: 100vh;
  128. background-color: #fff;
  129. }
  130. .status-bar-placeholder {
  131. width: 100%;
  132. background-color: #d8d8d8;
  133. }
  134. .header-view {
  135. display: flex;
  136. flex-direction: column;
  137. gap: 10px;
  138. align-items: center;
  139. padding-top: 20px;
  140. padding-bottom: 20px;
  141. background-color: #d8d8d8;
  142. }
  143. .logo {
  144. width: 160px;
  145. height: 160px;
  146. border-radius: 10px;
  147. }
  148. .dept-view {
  149. display: flex;
  150. flex-direction: row;
  151. gap: 10px;
  152. align-items: center;
  153. }
  154. .dept-text {
  155. font-size: 20px;
  156. color: #081f50;
  157. }
  158. .form-view {
  159. padding: 0 16px;
  160. }
  161. .form-item {
  162. display: flex;
  163. flex-direction: row;
  164. gap: 10px;
  165. align-items: center;
  166. justify-content: space-between;
  167. height: 44px;
  168. border-bottom: 1px solid rgba(0, 0, 0, 0.1);
  169. }
  170. .avatar {
  171. width: 40px;
  172. height: 40px;
  173. border-radius: 20px;
  174. }
  175. .normal-text {
  176. flex: 1;
  177. font-size: 14px;
  178. color: #333;
  179. text-align: right;
  180. }
  181. .arrow-indicator {
  182. font-size: 16px;
  183. font-weight: bold;
  184. color: #ccc;
  185. }
  186. .logout {
  187. display: flex;
  188. flex-direction: row;
  189. justify-content: center;
  190. padding: 0 16px;
  191. margin-top: 60px;
  192. }
  193. .logout-btn {
  194. display: flex;
  195. align-items: center;
  196. justify-content: center;
  197. height: 40px;
  198. padding: 0 24px;
  199. background-color: transparent;
  200. border: none;
  201. border-radius: 20px;
  202. }
  203. .logout-btn-text {
  204. font-size: 16px;
  205. color: #081f50;
  206. }
  207. </style>