index.uvue 9.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370
  1. <template>
  2. <view class="page-container">
  3. <!-- 背景图 -->
  4. <image class="bg-image" src="/static/images/profile/1.png" mode="widthFix"></image>
  5. <scroll-view class="page-content" style="flex: 1">
  6. <!-- 用户信息头部 -->
  7. <view class="header">
  8. <image class="avatar" src="/static/images/login/2.png" mode="aspectFill"></image>
  9. <text class="user-name">{{ userName }}</text>
  10. </view>
  11. <!-- 信息卡片区域 -->
  12. <view class="info-cards">
  13. <!-- 电话卡片 -->
  14. <view class="info-card">
  15. <image class="card-icon" src="/static/images/profile/2.png" mode="aspectFit"></image>
  16. <text class="card-label">电话</text>
  17. <text class="card-value">{{ userPhone }}</text>
  18. </view>
  19. <!-- 部门卡片 -->
  20. <view class="info-card">
  21. <image class="card-icon" src="/static/images/profile/3.png" mode="aspectFit"></image>
  22. <text class="card-label">部门</text>
  23. <text class="card-value">{{ userDept }}</text>
  24. </view>
  25. </view>
  26. <!-- 通讯录 -->
  27. <view class="contact-item">
  28. <text class="contact-text">{{userRole}}</text>
  29. </view>
  30. <!-- 功能菜单 -->
  31. <view class="menu-section">
  32. <view v-for="(item, index) in menuList" :key="index" class="menu-item" @click="handleMenuClick(item)">
  33. <image class="menu-icon" :src="item.icon" mode="aspectFit"></image>
  34. <text class="menu-title">{{ item.title }}</text>
  35. <text class="menu-arrow">›</text>
  36. </view>
  37. </view>
  38. <!-- 注销账号 -->
  39. <view class="logout-wrapper">
  40. <text class="logout-btn" @click="handleLogout">注销账号</text>
  41. </view>
  42. </scroll-view>
  43. <!-- 底部 TabBar -->
  44. <custom-tabbar :current="4" />
  45. </view>
  46. </template>
  47. <script setup lang="uts">
  48. import { ref, onMounted } from 'vue'
  49. import { getUserInfo } from '../../utils/storage'
  50. import { logout as logoutApi } from '../../api/auth/logout'
  51. import { useAuth } from '../../composables/useAuth'
  52. // @ts-ignore
  53. import manifest from '@/manifest.json'
  54. // 用户信息
  55. const userName = ref<string>('')
  56. const userPhone = ref<string>('')
  57. const userDept = ref<string>('')
  58. const userRole = ref<string>('')
  59. // 版本信息
  60. const manifestVersion = manifest.versionName as string | null
  61. const version = ref<string>(manifestVersion != null ? manifestVersion : '1.0.0')
  62. // 认证管理
  63. const auth = useAuth()
  64. const clearAuth = auth.logout
  65. const getCurrentAccessToken = auth.getCurrentAccessToken
  66. // 菜单列表
  67. type MenuItem = {
  68. id: number
  69. title: string
  70. icon: string
  71. path?: string
  72. action?: string
  73. }
  74. const menuList = ref<MenuItem[]>([
  75. {
  76. id: 1,
  77. title: '关于版本',
  78. icon: '/static/images/profile/5.png',
  79. action: 'version'
  80. },
  81. {
  82. id: 2,
  83. title: '关于我们',
  84. icon: '/static/images/profile/6.png',
  85. path: '/pages/profile/about/index'
  86. },
  87. {
  88. id: 3,
  89. title: '隐私条款',
  90. icon: '/static/images/profile/7.png',
  91. path: '/pages/profile/privacy/index'
  92. },
  93. {
  94. id: 4,
  95. title: '通用设置',
  96. icon: '/static/images/profile/8.png',
  97. path: '/pages/profile/settings/index'
  98. }
  99. ])
  100. // 通讯录点击
  101. const handleContactClick = (): void => {
  102. uni.showToast({
  103. title: '功能开发中',
  104. icon: 'none'
  105. })
  106. }
  107. // 菜单点击
  108. const handleMenuClick = (item: MenuItem): void => {
  109. if (item.action == 'version') {
  110. uni.showModal({
  111. title: '版本信息',
  112. content: `当前版本:v${version.value}`,
  113. showCancel: false
  114. })
  115. return
  116. }
  117. if (item.path != null && item.path.length > 0) {
  118. uni.navigateTo({
  119. url: item.path,
  120. fail: (err: any) => {
  121. uni.showToast({
  122. title: '功能开发中',
  123. icon: 'none'
  124. })
  125. }
  126. })
  127. }
  128. }
  129. // 执行退出登录(必须在 handleLogout 之前定义)
  130. const doLogout = async (): Promise<void> => {
  131. try {
  132. await logoutApi()
  133. } catch (e: any) {
  134. console.log('退出登录接口调用失败', e)
  135. } finally {
  136. clearAuth()
  137. }
  138. }
  139. // 退出登录
  140. const handleLogout = (): void => {
  141. uni.showModal({
  142. title: '提示',
  143. content: '确定要退出登录吗?',
  144. success: (res) => {
  145. // 提取属性(any 类型不能直接访问属性)
  146. const confirm = res.confirm as boolean
  147. if (confirm) {
  148. // 使用异步函数包装
  149. doLogout()
  150. }
  151. }
  152. })
  153. }
  154. // 初始化
  155. onMounted(() => {
  156. const userInfo = getUserInfo()
  157. if (userInfo != null) {
  158. const nickName = userInfo['nickName'] as string | null
  159. userName.value = nickName ?? ''
  160. const phone = userInfo['phone'] as string | null
  161. if (phone != null && phone.length > 0) {
  162. userPhone.value = phone
  163. }
  164. const deptName = userInfo['deptName'] as string | null
  165. if (deptName != null && deptName.length > 0) {
  166. userDept.value = deptName
  167. }
  168. const roleNames = userInfo['roleNames'] as string | null
  169. if (roleNames != null && roleNames.length > 0) {
  170. userRole.value = roleNames
  171. }
  172. }
  173. })
  174. </script>
  175. <style lang="scss">
  176. .page-container {
  177. position: relative;
  178. flex: 1;
  179. background: #f5f8fb;
  180. padding-top: env(safe-area-inset-top);
  181. }
  182. .bg-image {
  183. position: absolute;
  184. top: 0;
  185. left: 0;
  186. width: 100%;
  187. height: 100%;
  188. z-index: 0;
  189. }
  190. .page-content {
  191. position: relative;
  192. flex: 1;
  193. padding-bottom: 100rpx;
  194. z-index: 1;
  195. }
  196. .header {
  197. padding: 80rpx 30rpx 40rpx;
  198. flex-direction: row;
  199. align-items: center;
  200. .avatar {
  201. width: 120rpx;
  202. height: 120rpx;
  203. border: 1rpx solid #ccc;
  204. border-radius: 60rpx;
  205. background-color: #fff;
  206. margin-right: 30rpx;
  207. }
  208. .user-name {
  209. font-size: 40rpx;
  210. color: #ffffff;
  211. font-weight: bold;
  212. }
  213. }
  214. .info-cards {
  215. padding: 0 30rpx;
  216. flex-direction: row;
  217. justify-content: space-between;
  218. margin-bottom: 30rpx;
  219. .info-card {
  220. width: 330rpx;
  221. background-color: #ffffff;
  222. border-radius: 24rpx;
  223. padding: 30rpx 24rpx;
  224. /* #ifndef APP-HARMONY */
  225. box-shadow: 0 4rpx 12rpx rgba(0, 0, 0, 0.08);
  226. /* #endif */
  227. .card-icon {
  228. width: 48rpx;
  229. height: 48rpx;
  230. margin-bottom: 16rpx;
  231. }
  232. .card-label {
  233. font-size: 26rpx;
  234. color: #666666;
  235. margin-bottom: 12rpx;
  236. }
  237. .card-value {
  238. font-size: 32rpx;
  239. color: #333333;
  240. font-weight: bold;
  241. }
  242. }
  243. }
  244. .contact-item {
  245. margin: 0 30rpx 30rpx;
  246. padding: 30rpx;
  247. background-color: #ffffff;
  248. border-radius: 24rpx;
  249. flex-direction: row;
  250. align-items: center;
  251. /* #ifndef APP-HARMONY */
  252. box-shadow: 0 4rpx 12rpx rgba(0, 0, 0, 0.08);
  253. /* #endif */
  254. .contact-icon {
  255. width: 48rpx;
  256. height: 48rpx;
  257. margin-right: 24rpx;
  258. }
  259. .contact-text {
  260. flex: 1;
  261. font-size: 32rpx;
  262. color: #333333;
  263. }
  264. .contact-arrow {
  265. font-size: 48rpx;
  266. color: #cccccc;
  267. line-height: 48rpx;
  268. }
  269. }
  270. .menu-section {
  271. margin: 0 30rpx 30rpx;
  272. background-color: #ffffff;
  273. border-radius: 24rpx;
  274. overflow: hidden;
  275. /* #ifndef APP-HARMONY */
  276. box-shadow: 0 4rpx 12rpx rgba(0, 0, 0, 0.08);
  277. /* #endif */
  278. .menu-item {
  279. flex-direction: row;
  280. align-items: center;
  281. padding: 30rpx;
  282. border-bottom: 1rpx solid #f0f0f0;
  283. &:last-child {
  284. border-bottom: none;
  285. }
  286. .menu-icon {
  287. width: 48rpx;
  288. height: 48rpx;
  289. margin-right: 24rpx;
  290. }
  291. .menu-title {
  292. flex: 1;
  293. font-size: 32rpx;
  294. color: #333333;
  295. }
  296. .menu-arrow {
  297. font-size: 48rpx;
  298. color: #cccccc;
  299. line-height: 48rpx;
  300. }
  301. }
  302. }
  303. .logout-wrapper {
  304. margin: 0 30rpx 30rpx;
  305. background-color: #ffffff;
  306. border-radius: 24rpx;
  307. overflow: hidden;
  308. align-items: center;
  309. justify-content: center;
  310. height: 100rpx;
  311. /* #ifndef APP-HARMONY */
  312. box-shadow: 0 4rpx 12rpx rgba(0, 0, 0, 0.08);
  313. /* #endif */
  314. .logout-btn {
  315. font-size: 32rpx;
  316. color: #666666;
  317. padding: 20rpx 0;
  318. }
  319. }
  320. </style>