index.uvue 10 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379
  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. </view>
  44. </template>
  45. <script setup lang="uts">
  46. import { ref, onMounted } from 'vue'
  47. import { getUserInfo, getStoreIsKey } from '../../utils/storage'
  48. import { logout as logoutApi } from '../../api/auth/logout'
  49. import { useAuth } from '../../composables/useAuth'
  50. import { encryptAES, decryptAES } from '../../utils/crypto'
  51. import { getIsKey } from '../../api/auth/login'
  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. const phone = userInfo['phone'] as string | null
  160. const isKey = getStoreIsKey();
  161. if(isKey == "1"){
  162. userName.value = decryptAES(nickName ?? '')
  163. if (phone != null && phone.length > 0) {
  164. userPhone.value = decryptAES(phone ?? '')
  165. }
  166. }else{
  167. userName.value = nickName ?? ''
  168. if (phone != null && phone.length > 0) {
  169. userPhone.value = phone
  170. }
  171. }
  172. const deptName = userInfo['deptName'] as string | null
  173. if (deptName != null && deptName.length > 0) {
  174. userDept.value = deptName
  175. }
  176. const roleNames = userInfo['roleNames'] as string | null
  177. if (roleNames != null && roleNames.length > 0) {
  178. userRole.value = roleNames
  179. }
  180. }
  181. })
  182. </script>
  183. <style lang="scss">
  184. .page-container {
  185. position: relative;
  186. flex: 1;
  187. background: #f5f8fb;
  188. padding-top: env(safe-area-inset-top);
  189. }
  190. .bg-image {
  191. position: absolute;
  192. top: 0;
  193. left: 0;
  194. width: 100%;
  195. height: 100%;
  196. z-index: 0;
  197. }
  198. .page-content {
  199. position: relative;
  200. flex: 1;
  201. padding-bottom: 100rpx;
  202. z-index: 1;
  203. }
  204. .header {
  205. padding: 80rpx 30rpx 40rpx;
  206. flex-direction: row;
  207. align-items: center;
  208. .avatar {
  209. width: 120rpx;
  210. height: 120rpx;
  211. border: 1rpx solid #ccc;
  212. border-radius: 60rpx;
  213. background-color: #fff;
  214. margin-right: 30rpx;
  215. }
  216. .user-name {
  217. font-size: 40rpx;
  218. color: #ffffff;
  219. font-weight: bold;
  220. }
  221. }
  222. .info-cards {
  223. padding: 0 30rpx;
  224. flex-direction: row;
  225. justify-content: space-between;
  226. margin-bottom: 30rpx;
  227. .info-card {
  228. width: 330rpx;
  229. background-color: #ffffff;
  230. border-radius: 24rpx;
  231. padding: 30rpx 24rpx;
  232. /* #ifndef APP-HARMONY */
  233. box-shadow: 0 4rpx 12rpx rgba(0, 0, 0, 0.08);
  234. /* #endif */
  235. .card-icon {
  236. width: 48rpx;
  237. height: 48rpx;
  238. margin-bottom: 16rpx;
  239. }
  240. .card-label {
  241. font-size: 26rpx;
  242. color: #666666;
  243. margin-bottom: 12rpx;
  244. }
  245. .card-value {
  246. font-size: 32rpx;
  247. color: #333333;
  248. font-weight: bold;
  249. }
  250. }
  251. }
  252. .contact-item {
  253. margin: 0 30rpx 30rpx;
  254. padding: 30rpx;
  255. background-color: #ffffff;
  256. border-radius: 24rpx;
  257. flex-direction: row;
  258. align-items: center;
  259. /* #ifndef APP-HARMONY */
  260. box-shadow: 0 4rpx 12rpx rgba(0, 0, 0, 0.08);
  261. /* #endif */
  262. .contact-icon {
  263. width: 48rpx;
  264. height: 48rpx;
  265. margin-right: 24rpx;
  266. }
  267. .contact-text {
  268. flex: 1;
  269. font-size: 32rpx;
  270. color: #333333;
  271. }
  272. .contact-arrow {
  273. font-size: 48rpx;
  274. color: #cccccc;
  275. line-height: 48rpx;
  276. }
  277. }
  278. .menu-section {
  279. margin: 0 30rpx 30rpx;
  280. background-color: #ffffff;
  281. border-radius: 24rpx;
  282. overflow: hidden;
  283. /* #ifndef APP-HARMONY */
  284. box-shadow: 0 4rpx 12rpx rgba(0, 0, 0, 0.08);
  285. /* #endif */
  286. .menu-item {
  287. flex-direction: row;
  288. align-items: center;
  289. padding: 30rpx;
  290. border-bottom: 1rpx solid #f0f0f0;
  291. &:last-child {
  292. border-bottom: none;
  293. }
  294. .menu-icon {
  295. width: 48rpx;
  296. height: 48rpx;
  297. margin-right: 24rpx;
  298. }
  299. .menu-title {
  300. flex: 1;
  301. font-size: 32rpx;
  302. color: #333333;
  303. }
  304. .menu-arrow {
  305. font-size: 48rpx;
  306. color: #cccccc;
  307. line-height: 48rpx;
  308. }
  309. }
  310. }
  311. .logout-wrapper {
  312. margin: 0 30rpx 30rpx;
  313. background-color: #ffffff;
  314. border-radius: 24rpx;
  315. overflow: hidden;
  316. align-items: center;
  317. justify-content: center;
  318. height: 100rpx;
  319. /* #ifndef APP-HARMONY */
  320. box-shadow: 0 4rpx 12rpx rgba(0, 0, 0, 0.08);
  321. /* #endif */
  322. .logout-btn {
  323. font-size: 32rpx;
  324. color: #666666;
  325. padding: 20rpx 0;
  326. }
  327. }
  328. </style>