index.vue 14 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547
  1. <template>
  2. <!-- 基本信息组件 -->
  3. <BasicInfo v-if="showBasicInfo" @back="handleBackToMain" />
  4. <!-- 我的主页 -->
  5. <view v-else class="my-page">
  6. <!-- 自定义头部 -->
  7. <view class="custom-header" :style="{ paddingTop: statusBarHeight + 'px' }">
  8. <view class="header-content">
  9. <text class="header-title">{{ t('common.mine.title') }}</text>
  10. </view>
  11. </view>
  12. <!-- 页面内容 -->
  13. <view class="page-body">
  14. <!-- 用户名片区域 -->
  15. <view class="user-card">
  16. <image
  17. class="avatar"
  18. :src="userInfo.avatar"
  19. mode="aspectFill"
  20. :class="{ loading: loading }"
  21. @error="handleAvatarError"
  22. />
  23. <text class="nickname" :class="{ loading: loading }">{{ displayNickname }}</text>
  24. </view>
  25. <!-- 功能列表 -->
  26. <view class="function-list">
  27. <!-- 基本信息 -->
  28. <view class="list-item" @click="handleBasicInfo">
  29. <view class="item-left">
  30. <image class="item-icon" src="/static/pages-content/my/info.png" mode="aspectFit" />
  31. <text class="item-label">{{ t('common.mine.basicInfo') }}</text>
  32. </view>
  33. <text class="item-arrow">›</text>
  34. </view>
  35. <!-- 文件管理 -->
  36. <view class="list-item" @click="handleFileManage">
  37. <view class="item-left">
  38. <image class="item-icon" src="/static/pages-content/my/file.png" mode="aspectFit" />
  39. <text class="item-label">{{ t('common.mine.fileManage') }}</text>
  40. </view>
  41. <text class="item-arrow">›</text>
  42. </view>
  43. <!-- 审核管理 -->
  44. <view class="list-item" @click="handleAuditManage">
  45. <view class="item-left">
  46. <image class="item-icon" src="/static/pages-content/my/audit.png" mode="aspectFit" />
  47. <text class="item-label">{{ t('common.mine.auditManage') }}</text>
  48. </view>
  49. <text class="item-arrow">›</text>
  50. </view>
  51. <!-- 语言切换 -->
  52. <view class="list-item">
  53. <view class="item-left">
  54. <image class="item-icon" src="/static/pages-content/my/language.png" mode="aspectFit" />
  55. <text class="item-label">{{ t('common.mine.languageSwitch') }}</text>
  56. </view>
  57. <view class="language-switcher" @click="handleLanguageChange">
  58. <text class="language-text" :class="{ active: locale === 'zh-CN' }">中</text>
  59. <text class="language-separator">|</text>
  60. <text class="language-text" :class="{ active: locale === 'en-US' }">EN</text>
  61. </view>
  62. </view>
  63. <!-- 协议说明 -->
  64. <view class="list-item" @click="handleProtocol">
  65. <view class="item-left">
  66. <image class="item-icon" src="/static/pages-content/my/aggrement.png" mode="aspectFit" />
  67. <text class="item-label">{{ t('common.mine.protocol') }}</text>
  68. </view>
  69. <text class="item-arrow">›</text>
  70. </view>
  71. </view>
  72. <!-- 退出登录按钮 -->
  73. <view class="logout-section">
  74. <button class="logout-btn" @click="handleLogout">{{ t('common.mine.logout') }}</button>
  75. </view>
  76. </view>
  77. </view>
  78. </template>
  79. <script setup>
  80. import BasicInfo from './info/index.vue'
  81. import { ref, computed, onMounted } from 'vue'
  82. import { useI18n } from 'vue-i18n'
  83. import { useUserStore } from '@/store/index'
  84. import { useLocaleStore } from '@/store/locale'
  85. import { getUserInfo as getUserInfoAPI, logout as logoutAPI } from '@/apis/auth'
  86. const { t, locale } = useI18n()
  87. const userStore = useUserStore()
  88. const localeStore = useLocaleStore()
  89. // 控制显示哪个组件
  90. const showBasicInfo = ref(false)
  91. // 状态栏高度
  92. const statusBarHeight = ref(0)
  93. // 用户信息
  94. const userInfo = ref({
  95. avatar: '/static/default-avatar.svg',
  96. nickname: ''
  97. })
  98. // 加载状态
  99. const loading = ref(false)
  100. // 显示的昵称(带加载状态)
  101. const displayNickname = computed(() => {
  102. if (loading.value) {
  103. return t('common.mine.loading')
  104. }
  105. return userInfo.value.nickname || t('common.mine.defaultNickname')
  106. })
  107. onMounted(() => {
  108. // 获取系统信息
  109. const systemInfo = uni.getSystemInfoSync()
  110. statusBarHeight.value = systemInfo.statusBarHeight || 0
  111. // 获取用户信息
  112. fetchUserInfo()
  113. console.log('我的内容组件已加载')
  114. })
  115. // 头像加载失败处理
  116. const handleAvatarError = () => {
  117. console.log('头像加载失败,使用默认头像')
  118. userInfo.value.avatar = '/static/default-avatar.svg'
  119. }
  120. // 获取用户信息
  121. const fetchUserInfo = async () => {
  122. try {
  123. loading.value = true
  124. // 调用 API 获取用户信息
  125. const response = await getUserInfoAPI()
  126. if (response && response.data) {
  127. // 更新用户信息
  128. userInfo.value = {
  129. avatar: response.data.avatar || '/static/default-avatar.svg',
  130. nickname: response.data.nickname || ''
  131. }
  132. // 同步更新 store
  133. userStore.setUserInfo(response.data)
  134. }
  135. } catch (error) {
  136. console.error('获取用户信息失败:', error)
  137. // 如果API失败,尝试从本地store获取
  138. const storedUserInfo = userStore.userInfo
  139. if (storedUserInfo && storedUserInfo.nickname) {
  140. userInfo.value = {
  141. avatar: storedUserInfo.avatar || '/static/default-avatar.svg',
  142. nickname: storedUserInfo.nickname
  143. }
  144. } else {
  145. userInfo.value = {
  146. avatar: '/static/default-avatar.svg',
  147. nickname: ''
  148. }
  149. }
  150. uni.showToast({
  151. title: t('common.mine.getUserInfoFailed'),
  152. icon: 'none',
  153. duration: 2000
  154. })
  155. } finally {
  156. loading.value = false
  157. }
  158. }
  159. // 基本信息
  160. const handleBasicInfo = () => {
  161. showBasicInfo.value = true
  162. }
  163. // 从基本信息返回主页
  164. const handleBackToMain = () => {
  165. showBasicInfo.value = false
  166. }
  167. // 文件管理
  168. const handleFileManage = () => {
  169. uni.showToast({
  170. title: '文件管理',
  171. icon: 'none'
  172. })
  173. // TODO: 跳转到文件管理页面
  174. }
  175. // 审核管理
  176. const handleAuditManage = () => {
  177. uni.showToast({
  178. title: '审核管理',
  179. icon: 'none'
  180. })
  181. // TODO: 跳转到审核管理页面
  182. }
  183. // 语言切换
  184. const handleLanguageChange = () => {
  185. localeStore.toggleLocale()
  186. // 延迟一下让语言切换生效后再显示提示
  187. setTimeout(() => {
  188. uni.showToast({
  189. title: t('common.language.switchSuccess'),
  190. icon: 'success',
  191. duration: 1500
  192. })
  193. }, 100)
  194. }
  195. // 协议说明
  196. const handleProtocol = () => {
  197. uni.navigateTo({
  198. url: '/pages-content/my/aggreement/index'
  199. })
  200. }
  201. // 退出登录
  202. const handleLogout = () => {
  203. uni.showModal({
  204. title: t('common.button.confirm'),
  205. content: t('common.mine.logoutConfirm'),
  206. confirmText: t('common.button.confirm'),
  207. cancelText: t('common.button.cancel'),
  208. success: async (res) => {
  209. if (res.confirm) {
  210. try {
  211. // 显示加载状态
  212. uni.showLoading({
  213. title: t('common.message.loading'),
  214. mask: true
  215. })
  216. // 调用后端API
  217. await logoutAPI()
  218. // API调用成功后,清除本地token和用户信息缓存
  219. userStore.logout()
  220. uni.hideLoading()
  221. // 显示退出成功提示
  222. uni.showToast({
  223. title: t('common.mine.logoutSuccess'),
  224. icon: 'success',
  225. duration: 1500
  226. })
  227. // 延迟跳转到登录页
  228. setTimeout(() => {
  229. uni.reLaunch({
  230. url: '/pages/login/login'
  231. })
  232. }, 1500)
  233. } catch (error) {
  234. uni.hideLoading()
  235. console.error('退出登录失败:', error)
  236. // 即使 API失败,也清除本地数据并跳转
  237. userStore.logout()
  238. uni.showToast({
  239. title: t('common.mine.logoutSuccess'),
  240. icon: 'success',
  241. duration: 1500
  242. })
  243. setTimeout(() => {
  244. uni.reLaunch({
  245. url: '/pages/login/login'
  246. })
  247. }, 1500)
  248. }
  249. }
  250. }
  251. })
  252. }
  253. </script>
  254. <style lang="scss" scoped>
  255. .my-page {
  256. width: 100%;
  257. min-height: 100vh;
  258. display: flex;
  259. flex-direction: column;
  260. background: linear-gradient(180deg, #f8fcff 0%, #ffffff 100%);
  261. // 自定义头部
  262. .custom-header {
  263. position: fixed;
  264. top: 0;
  265. left: 0;
  266. right: 0;
  267. background-color: #ffffff;
  268. border-bottom: 1rpx solid #e5e5e5;
  269. z-index: 100;
  270. .header-content {
  271. height: 88rpx;
  272. display: flex;
  273. align-items: center;
  274. justify-content: center;
  275. .header-title {
  276. font-size: 32rpx;
  277. font-weight: 500;
  278. color: #000000;
  279. }
  280. }
  281. }
  282. // 页面内容
  283. .page-body {
  284. flex: 1;
  285. margin-top: 88rpx;
  286. padding: 40rpx;
  287. // 用户名片区域
  288. .user-card {
  289. background: linear-gradient(135deg, #6ec7f5 0%, #4eb8f0 100%);
  290. border-radius: 24rpx;
  291. padding: 80rpx 40rpx 60rpx;
  292. display: flex;
  293. flex-direction: column;
  294. align-items: center;
  295. margin-bottom: 40rpx;
  296. box-shadow: 0 8rpx 24rpx rgba(110, 199, 245, 0.25);
  297. position: relative;
  298. overflow: hidden;
  299. // 背景装饰
  300. &::before {
  301. content: '';
  302. position: absolute;
  303. top: -50%;
  304. right: -20%;
  305. width: 400rpx;
  306. height: 400rpx;
  307. background: rgba(255, 255, 255, 0.1);
  308. border-radius: 50%;
  309. }
  310. &::after {
  311. content: '';
  312. position: absolute;
  313. bottom: -30%;
  314. left: -10%;
  315. width: 300rpx;
  316. height: 300rpx;
  317. background: rgba(255, 255, 255, 0.08);
  318. border-radius: 50%;
  319. }
  320. .avatar {
  321. width: 140rpx;
  322. height: 140rpx;
  323. border-radius: 70rpx;
  324. margin-bottom: 24rpx;
  325. border: 6rpx solid rgba(255, 255, 255, 0.3);
  326. box-shadow: 0 4rpx 16rpx rgba(0, 0, 0, 0.2);
  327. position: relative;
  328. z-index: 1;
  329. transition: opacity 0.3s;
  330. &.loading {
  331. opacity: 0.5;
  332. animation: pulse 1.5s ease-in-out infinite;
  333. }
  334. }
  335. .nickname {
  336. font-size: 40rpx;
  337. font-weight: bold;
  338. color: #ffffff;
  339. text-shadow: 0 2rpx 8rpx rgba(0, 0, 0, 0.2);
  340. position: relative;
  341. z-index: 1;
  342. transition: opacity 0.3s;
  343. &.loading {
  344. opacity: 0.7;
  345. }
  346. }
  347. }
  348. // 功能列表
  349. .function-list {
  350. background-color: #ffffff;
  351. border-radius: 20rpx;
  352. overflow: hidden;
  353. margin-bottom: 40rpx;
  354. box-shadow: 0 2rpx 12rpx rgba(0, 0, 0, 0.06);
  355. .list-item {
  356. display: flex;
  357. align-items: center;
  358. justify-content: space-between;
  359. padding: 36rpx 40rpx;
  360. border-bottom: 1rpx solid #f0f0f0;
  361. transition: all 0.3s ease;
  362. position: relative;
  363. &:last-child {
  364. border-bottom: none;
  365. }
  366. &:active {
  367. background-color: #f0faff;
  368. }
  369. // 左侧渐变条
  370. &::before {
  371. content: '';
  372. position: absolute;
  373. left: 0;
  374. top: 50%;
  375. transform: translateY(-50%);
  376. width: 6rpx;
  377. height: 60%;
  378. background: linear-gradient(180deg, #6ec7f5 0%, #4eb8f0 100%);
  379. border-radius: 0 6rpx 6rpx 0;
  380. opacity: 0;
  381. transition: opacity 0.3s;
  382. }
  383. &:active::before {
  384. opacity: 1;
  385. }
  386. .item-left {
  387. display: flex;
  388. align-items: center;
  389. .item-icon {
  390. width: 44rpx;
  391. height: 44rpx;
  392. margin-right: 28rpx;
  393. }
  394. .item-label {
  395. font-size: 30rpx;
  396. color: #333333;
  397. font-weight: 500;
  398. }
  399. }
  400. .language-switcher {
  401. display: flex;
  402. align-items: center;
  403. background: rgba(110, 199, 245, 0.08);
  404. backdrop-filter: blur(10rpx);
  405. border-radius: 30rpx;
  406. padding: 8rpx 20rpx;
  407. cursor: pointer;
  408. transition: all 0.3s;
  409. gap: 8rpx;
  410. &:active {
  411. transform: scale(0.95);
  412. background: rgba(110, 199, 245, 0.15);
  413. }
  414. .language-text {
  415. font-size: 24rpx;
  416. color: #999;
  417. font-weight: 500;
  418. transition: all 0.3s;
  419. &.active {
  420. color: #6ec7f5;
  421. font-weight: 700;
  422. }
  423. }
  424. .language-separator {
  425. font-size: 24rpx;
  426. color: #ccc;
  427. font-weight: 300;
  428. }
  429. }
  430. .item-arrow {
  431. font-size: 48rpx;
  432. color: #d0d0d0;
  433. font-weight: 300;
  434. }
  435. }
  436. }
  437. // 退出登录
  438. .logout-section {
  439. padding: 0;
  440. .logout-btn {
  441. width: 100%;
  442. height: 96rpx;
  443. line-height: 96rpx;
  444. background: linear-gradient(135deg, #ff6b6b 0%, #ee5a6f 100%);
  445. border-radius: 20rpx;
  446. border: none;
  447. font-size: 32rpx;
  448. color: #ffffff;
  449. font-weight: 600;
  450. box-shadow: 0 6rpx 20rpx rgba(255, 107, 107, 0.3);
  451. letter-spacing: 2rpx;
  452. padding: 0;
  453. &:active {
  454. opacity: 0.9;
  455. transform: scale(0.98);
  456. }
  457. &::after {
  458. border: none;
  459. }
  460. }
  461. }
  462. }
  463. }
  464. // 加载动画
  465. @keyframes pulse {
  466. 0%, 100% {
  467. opacity: 0.5;
  468. }
  469. 50% {
  470. opacity: 0.8;
  471. }
  472. }
  473. </style>