index.uvue 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502
  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. <view class="menu-section">
  31. <view class="menu-item" @click="handlePassword()">
  32. <image class="menu-icon" src="/static/images/profile/7.png" mode="aspectFit"></image>
  33. <text class="menu-title">修改密码</text>
  34. <text class="menu-arrow">›</text>
  35. </view>
  36. <view class="menu-item" @longpress="handleVersionClick()">
  37. <image class="menu-icon" src="/static/images/profile/5.png" mode="aspectFit"></image>
  38. <text class="menu-title">版本:{{version}}</text>
  39. </view>
  40. </view>
  41. <!-- 功能菜单 -->
  42. <!-- <view class="menu-section">
  43. <view v-for="(item, index) in menuList" :key="index" class="menu-item" @click="handleMenuClick(item)">
  44. <image class="menu-icon" src="/static/images/profile/7.png" mode="aspectFit"></image>
  45. <text class="menu-title">修改密码</text>
  46. <text class="menu-arrow">›</text>
  47. </view>
  48. </view> -->
  49. <!-- 注销账号 -->
  50. <view class="logout-wrapper">
  51. <text class="logout-btn" @click="handleLogout">注销账号</text>
  52. </view>
  53. </scroll-view>
  54. </view>
  55. </template>
  56. <script setup lang="uts">
  57. import { ref, onMounted } from 'vue'
  58. import { getUserInfo, getStoreIsKey } from '../../utils/storage'
  59. import { logout as logoutApi } from '../../api/auth/logout'
  60. import { useAuth } from '../../composables/useAuth'
  61. import { encryptAES, decryptAES } from '../../utils/crypto'
  62. import { getIsKey } from '../../api/auth/login'
  63. import { getBaseUrl } from '../../utils/request'
  64. // @ts-ignore
  65. import manifest from '@/manifest.json'
  66. // 用户信息
  67. const userName = ref<string>('')
  68. const userPhone = ref<string>('')
  69. const userDept = ref<string>('')
  70. const userRole = ref<string>('')
  71. // 版本信息
  72. const manifestVersion = manifest.versionName as string | null
  73. const version = ref<string>(manifestVersion != null ? manifestVersion : '1.0.0')
  74. // 认证管理
  75. const auth = useAuth()
  76. const clearAuth = auth.logout
  77. const getCurrentAccessToken = auth.getCurrentAccessToken
  78. // 菜单列表
  79. type MenuItem = {
  80. id: number
  81. title: string
  82. icon: string
  83. path?: string
  84. action?: string
  85. }
  86. const menuList = ref<MenuItem[]>([
  87. {
  88. id: 1,
  89. title: '修改密码',
  90. icon: '/static/images/profile/7.png',
  91. path: '/pages/profile/password/index'
  92. },
  93. {
  94. id: 2,
  95. title: '关于版本',
  96. icon: '/static/images/profile/5.png',
  97. action: 'version'
  98. },
  99. {
  100. id: 3,
  101. title: '关于我们',
  102. icon: '/static/images/profile/6.png',
  103. path: '/pages/profile/about/index'
  104. },
  105. {
  106. id: 4,
  107. title: '通用设置',
  108. icon: '/static/images/profile/8.png',
  109. path: '/pages/profile/settings/index'
  110. }
  111. ])
  112. // 通讯录点击
  113. const handleContactClick = (): void => {
  114. uni.showToast({
  115. title: '功能开发中',
  116. icon: 'none'
  117. })
  118. }
  119. const handlePassword = (): void =>{
  120. uni.navigateTo({
  121. url:"/pages/profile/password/index",
  122. fail: (err: any) => {
  123. uni.showToast({
  124. title: '功能开发中',
  125. icon: 'none'
  126. })
  127. }
  128. })
  129. }
  130. // 菜单点击
  131. const handleMenuClick = (item: MenuItem): void => {
  132. if (item.action == 'version') {
  133. uni.showModal({
  134. title: '版本信息',
  135. content: `当前版本:v${version.value}`,
  136. showCancel: false
  137. })
  138. return
  139. }
  140. if (item.path != null && item.path.length > 0) {
  141. uni.navigateTo({
  142. url: item.path,
  143. fail: (err: any) => {
  144. uni.showToast({
  145. title: '功能开发中',
  146. icon: 'none'
  147. })
  148. }
  149. })
  150. }
  151. }
  152. // 执行退出登录(必须在 handleLogout 之前定义)
  153. const doLogout = async (): Promise<void> => {
  154. try {
  155. await logoutApi()
  156. } catch (e: any) {
  157. console.log('退出登录接口调用失败', e)
  158. } finally {
  159. clearAuth()
  160. }
  161. }
  162. // 退出登录
  163. const handleLogout = (): void => {
  164. uni.showModal({
  165. title: '提示',
  166. content: '确定要退出登录吗?',
  167. success: (res) => {
  168. // 提取属性(any 类型不能直接访问属性)
  169. const confirm = res.confirm as boolean
  170. if (confirm) {
  171. // 使用异步函数包装
  172. doLogout()
  173. }
  174. }
  175. })
  176. }
  177. // 安装APK的单独函数
  178. const installApkFile = (filePath: string): void => {
  179. uni.installApk({
  180. filePath: filePath,
  181. success: () => {
  182. console.log('安装成功');
  183. uni.showToast({
  184. title: '安装成功',
  185. icon: 'success'
  186. });
  187. },
  188. fail: (error) => {
  189. console.error('安装失败:', error);
  190. uni.showToast({
  191. title: '安装失败',
  192. icon: 'none'
  193. });
  194. },
  195. complete: (res) => {
  196. console.log('安装完成:', res);
  197. }
  198. });
  199. }
  200. const installApkWithProgress = (): void => {
  201. // #ifdef APP-ANDROID
  202. // 显示下载进度
  203. uni.showLoading({
  204. title: '下载中...',
  205. mask: true
  206. });
  207. let donwloadUrl = '';
  208. donwloadUrl = getBaseUrl() + '/prod-api/profile/app/gxt-release.apk'
  209. // 下载APK
  210. const downloadTask = uni.downloadFile({
  211. url: donwloadUrl,
  212. filePath: `${uni.env.USER_DATA_PATH}/${Date.now()}_test.apk`, // 使用时间戳防止重名
  213. success: (downloadRes) => {
  214. uni.hideLoading();
  215. if (downloadRes.statusCode == 200) {
  216. // 确认安装
  217. uni.showModal({
  218. title: '安装提示',
  219. content: '下载完成,是否立即安装?',
  220. success: (modalRes) => {
  221. if (modalRes.confirm) {
  222. installApkFile(downloadRes.tempFilePath);
  223. }
  224. }
  225. });
  226. } else {
  227. uni.showToast({
  228. title: '下载失败',
  229. icon: 'error'
  230. });
  231. }
  232. },
  233. fail: (error) => {
  234. uni.hideLoading();
  235. uni.showToast({
  236. title: '下载失败',
  237. icon: 'none'
  238. });
  239. console.error('下载失败:', error);
  240. }
  241. });
  242. // 监听下载进度
  243. downloadTask.onProgressUpdate((res) => {
  244. console.log('下载进度:', res.progress + '%');
  245. // 如果需要,可以更新UI显示进度
  246. uni.showLoading({
  247. title: `下载中 ${res.progress}%`,
  248. mask: true
  249. });
  250. });
  251. // #endif
  252. // #ifdef APP-HARMONY
  253. uni.showToast({
  254. title: '请登录PC端,扫描二维码下载并安装',
  255. icon: 'none'
  256. });
  257. // #endif
  258. // #ifdef APP-IOS
  259. uni.showToast({
  260. title: '请登录PC端,扫描二维码下载并安装',
  261. icon: 'none'
  262. });
  263. // #endif
  264. }
  265. // 菜单点击
  266. const handleVersionClick = (): void => {
  267. installApkWithProgress();
  268. }
  269. // 初始化
  270. onMounted(() => {
  271. const userInfo = getUserInfo()
  272. if (userInfo != null) {
  273. const nickName = userInfo['nickName'] as string | null
  274. const phone = userInfo['phone'] as string | null
  275. const isKey = getStoreIsKey();
  276. if(isKey == "1"){
  277. userName.value = decryptAES(nickName ?? '')
  278. if (phone != null && phone.length > 0) {
  279. userPhone.value = decryptAES(phone ?? '')
  280. }
  281. }else{
  282. userName.value = nickName ?? ''
  283. if (phone != null && phone.length > 0) {
  284. userPhone.value = phone
  285. }
  286. }
  287. const deptName = userInfo['deptName'] as string | null
  288. if (deptName != null && deptName.length > 0) {
  289. userDept.value = deptName
  290. }
  291. const roleNames = userInfo['roleNames'] as string | null
  292. if (roleNames != null && roleNames.length > 0) {
  293. userRole.value = roleNames
  294. }
  295. }
  296. })
  297. </script>
  298. <style lang="scss">
  299. .page-container {
  300. position: relative;
  301. flex: 1;
  302. background: #f5f8fb;
  303. padding-top: env(safe-area-inset-top);
  304. }
  305. .bg-image {
  306. position: absolute;
  307. top: 0;
  308. left: 0;
  309. width: 100%;
  310. height: 100%;
  311. z-index: 0;
  312. }
  313. .page-content {
  314. position: relative;
  315. flex: 1;
  316. padding-bottom: 100rpx;
  317. z-index: 1;
  318. }
  319. .header {
  320. padding: 80rpx 30rpx 40rpx;
  321. flex-direction: row;
  322. align-items: center;
  323. .avatar {
  324. width: 120rpx;
  325. height: 120rpx;
  326. border: 1rpx solid #ccc;
  327. border-radius: 60rpx;
  328. background-color: #fff;
  329. margin-right: 30rpx;
  330. }
  331. .user-name {
  332. font-size: 40rpx;
  333. color: #ffffff;
  334. font-weight: bold;
  335. }
  336. }
  337. .info-cards {
  338. padding: 0 30rpx;
  339. flex-direction: row;
  340. justify-content: space-between;
  341. margin-bottom: 30rpx;
  342. .info-card {
  343. width: 330rpx;
  344. background-color: #ffffff;
  345. border-radius: 24rpx;
  346. padding: 30rpx 24rpx;
  347. /* #ifndef APP-HARMONY */
  348. box-shadow: 0 4rpx 12rpx rgba(0, 0, 0, 0.08);
  349. /* #endif */
  350. .card-icon {
  351. width: 48rpx;
  352. height: 48rpx;
  353. margin-bottom: 16rpx;
  354. }
  355. .card-label {
  356. font-size: 26rpx;
  357. color: #666666;
  358. margin-bottom: 12rpx;
  359. }
  360. .card-value {
  361. font-size: 32rpx;
  362. color: #333333;
  363. font-weight: bold;
  364. }
  365. }
  366. }
  367. .contact-item {
  368. margin: 0 30rpx 30rpx;
  369. padding: 30rpx;
  370. background-color: #ffffff;
  371. border-radius: 24rpx;
  372. flex-direction: row;
  373. align-items: center;
  374. /* #ifndef APP-HARMONY */
  375. box-shadow: 0 4rpx 12rpx rgba(0, 0, 0, 0.08);
  376. /* #endif */
  377. .contact-icon {
  378. width: 48rpx;
  379. height: 48rpx;
  380. margin-right: 24rpx;
  381. }
  382. .contact-text {
  383. flex: 1;
  384. font-size: 32rpx;
  385. color: #333333;
  386. }
  387. .contact-arrow {
  388. font-size: 48rpx;
  389. color: #cccccc;
  390. line-height: 48rpx;
  391. }
  392. }
  393. .menu-section {
  394. margin: 0 30rpx 30rpx;
  395. background-color: #ffffff;
  396. border-radius: 24rpx;
  397. overflow: hidden;
  398. /* #ifndef APP-HARMONY */
  399. box-shadow: 0 4rpx 12rpx rgba(0, 0, 0, 0.08);
  400. /* #endif */
  401. .menu-item {
  402. flex-direction: row;
  403. align-items: center;
  404. padding: 30rpx;
  405. border-bottom: 1rpx solid #f0f0f0;
  406. &:last-child {
  407. border-bottom: none;
  408. }
  409. .menu-icon {
  410. width: 48rpx;
  411. height: 48rpx;
  412. margin-right: 24rpx;
  413. }
  414. .menu-title {
  415. flex: 1;
  416. font-size: 32rpx;
  417. color: #333333;
  418. }
  419. .menu-arrow {
  420. font-size: 48rpx;
  421. color: #cccccc;
  422. line-height: 48rpx;
  423. }
  424. }
  425. }
  426. .logout-wrapper {
  427. margin: 0 30rpx 30rpx;
  428. background-color: #ffffff;
  429. border-radius: 24rpx;
  430. overflow: hidden;
  431. align-items: center;
  432. justify-content: center;
  433. height: 100rpx;
  434. /* #ifndef APP-HARMONY */
  435. box-shadow: 0 4rpx 12rpx rgba(0, 0, 0, 0.08);
  436. /* #endif */
  437. .logout-btn {
  438. font-size: 32rpx;
  439. color: #666666;
  440. padding: 20rpx 0;
  441. }
  442. }
  443. </style>