index.vue 12 KB

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