index.vue 16 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644
  1. <template>
  2. <!-- 基本信息组件 -->
  3. <BasicInfo v-if="showBasicInfo" @back="handleBackToMain" />
  4. <!-- 我的主页 -->
  5. <view v-else class="my-page">
  6. <!-- 顶部渐变背景区域 - 固定 -->
  7. <view class="header-bg" :style="{ paddingTop: statusBarHeight + 'px' }">
  8. <text class="header-title">{{ t('my.title') }}</text>
  9. </view>
  10. <!-- 页面内容 - 可滚动 -->
  11. <scroll-view
  12. scroll-y
  13. class="page-scroll"
  14. :style="{ paddingTop: (statusBarHeight + 60) + 'px' }"
  15. >
  16. <view class="page-content">
  17. <!-- 用户信息卡片 -->
  18. <view class="user-card" @click="handleUserCardClick">
  19. <view class="user-info">
  20. <image
  21. class="avatar"
  22. :src="userInfo.avatar"
  23. mode="aspectFill"
  24. @error="handleAvatarError"
  25. />
  26. <view class="user-details">
  27. <text class="nickname">{{ displayNickname }}</text>
  28. <text class="phone">{{ displayPhone }}</text>
  29. </view>
  30. </view>
  31. <view class="vip-badge" @click.stop="handleVipClick">
  32. <text class="vip-text">{{ t('my.normalMember') }}</text>
  33. <text class="arrow">›</text>
  34. </view>
  35. </view>
  36. <!-- 我的任务 -->
  37. <view class="task-section">
  38. <view class="section-header" @click="handleTaskSectionClick">
  39. <text class="section-title">{{ t('my.myTasks') }}</text>
  40. <text class="arrow">›</text>
  41. </view>
  42. <view class="task-grid">
  43. <view class="task-item" @click="handleTaskClick('pending')">
  44. <view class="task-icon-wrapper">
  45. <image class="task-icon" src="/static/pages/my/task-pending.png" mode="aspectFit" />
  46. <view v-if="taskCounts.pending > 0" class="task-badge">{{ taskCounts.pending }}</view>
  47. </view>
  48. <text class="task-label">{{ t('my.toSubmit') }}</text>
  49. </view>
  50. <view class="task-item" @click="handleTaskClick('reviewing')">
  51. <view class="task-icon-wrapper">
  52. <image class="task-icon" src="/static/pages/my/task-reviewing.png" mode="aspectFit" />
  53. <view v-if="taskCounts.reviewing > 0" class="task-badge">{{ taskCounts.reviewing }}</view>
  54. </view>
  55. <text class="task-label">{{ t('my.toAudit') }}</text>
  56. </view>
  57. </view>
  58. </view>
  59. <!-- 功能列表 -->
  60. <view class="menu-list">
  61. <view class="menu-item" @click="handleProtocol">
  62. <view class="menu-left">
  63. <image class="menu-icon" src="/static/pages/my/icon-protocol.png" mode="aspectFit" />
  64. <text class="menu-label">{{ t('my.userAgreement') }}</text>
  65. </view>
  66. <text class="arrow">›</text>
  67. </view>
  68. <view class="menu-item">
  69. <view class="menu-left">
  70. <image class="menu-icon" src="/static/pages/my/icon-language.png" mode="aspectFit" />
  71. <text class="menu-label">{{ t('my.languageSwitch') }}</text>
  72. </view>
  73. <view class="language-switcher" @click="handleLanguageChange">
  74. <text class="language-text" :class="{ active: locale === 'zh-CN' }">中</text>
  75. <text class="language-separator">|</text>
  76. <text class="language-text" :class="{ active: locale === 'en-US' }">EN</text>
  77. </view>
  78. </view>
  79. <view class="menu-item" @click="handleAbout">
  80. <view class="menu-left">
  81. <image class="menu-icon" src="/static/pages/my/icon-about.png" mode="aspectFit" />
  82. <text class="menu-label">{{ t('my.aboutUs') }}</text>
  83. </view>
  84. <text class="arrow">›</text>
  85. </view>
  86. </view>
  87. <!-- 退出登录按钮 -->
  88. <view class="logout-section">
  89. <button class="logout-btn" @click="handleLogout">{{ t('my.logout') }}</button>
  90. </view>
  91. </view>
  92. </scroll-view>
  93. <!-- 底部导航栏 -->
  94. <TabBar current-tab="mine" />
  95. </view>
  96. </template>
  97. <script setup>
  98. import BasicInfo from './info/index.vue'
  99. import { ref, computed, onMounted } from 'vue'
  100. import { useI18n } from 'vue-i18n'
  101. import { useUserStore } from '@/store/index'
  102. import { useLocaleStore } from '@/store/locale'
  103. import { getUserInfo as getUserInfoAPI, logout as logoutAPI, getTaskCount } from '@/apis/auth'
  104. import TabBar from '@/components/TabBar/index.vue'
  105. const { t, locale } = useI18n()
  106. const userStore = useUserStore()
  107. const localeStore = useLocaleStore()
  108. // 控制显示哪个组件
  109. const showBasicInfo = ref(false)
  110. // 状态栏高度
  111. const statusBarHeight = ref(0)
  112. // 用户信息
  113. const userInfo = ref({
  114. avatar: '/static/default-avatar.svg',
  115. nickname: '',
  116. phoneNumber: ''
  117. })
  118. // 任务数量
  119. const taskCounts = ref({
  120. pending: 0,
  121. reviewing: 0
  122. })
  123. // 显示的昵称
  124. const displayNickname = computed(() => {
  125. return userInfo.value.nickname || t('my.defaultNickname')
  126. })
  127. // 加密手机号
  128. const encryptPhone = (phone) => {
  129. if (!phone) return ''
  130. // 如果手机号长度为11位,则加密中间4位
  131. if (phone.length === 11) {
  132. return phone.replace(/(\d{3})\d{4}(\d{4})/, '$1****$2')
  133. }
  134. // 如果手机号长度不是11位,则加密中间部分
  135. if (phone.length > 6) {
  136. const start = phone.substring(0, 3)
  137. const end = phone.substring(phone.length - 4)
  138. return `${start}****${end}`
  139. }
  140. return phone
  141. }
  142. // 显示的手机号(加密)
  143. const displayPhone = computed(() => {
  144. return encryptPhone(userInfo.value.phoneNumber)
  145. })
  146. onMounted(() => {
  147. // 获取系统信息
  148. const windowInfo = uni.getWindowInfo()
  149. statusBarHeight.value = windowInfo.statusBarHeight || 0
  150. // 获取用户信息
  151. fetchUserInfo()
  152. // 获取任务数量
  153. fetchTaskCount()
  154. })
  155. // 头像加载失败处理
  156. const handleAvatarError = () => {
  157. userInfo.value.avatar = '/static/default-avatar.svg'
  158. }
  159. // 获取用户信息
  160. const fetchUserInfo = async () => {
  161. try {
  162. const response = await getUserInfoAPI()
  163. if (response && response.data) {
  164. userInfo.value = {
  165. avatar: response.data.avatar || '/static/default-avatar.svg',
  166. nickname: response.data.nickname || '',
  167. phoneNumber: response.data.phoneNumber || ''
  168. }
  169. userStore.setUserInfo(response.data)
  170. }
  171. } catch (error) {
  172. console.error('获取用户信息失败:', error)
  173. const storedUserInfo = userStore.userInfo
  174. if (storedUserInfo) {
  175. userInfo.value = {
  176. avatar: storedUserInfo.avatar || '/static/default-avatar.svg',
  177. nickname: storedUserInfo.nickname || '',
  178. phoneNumber: storedUserInfo.phoneNumber || ''
  179. }
  180. }
  181. }
  182. }
  183. // 获取任务数量
  184. const fetchTaskCount = async () => {
  185. try {
  186. const response = await getTaskCount()
  187. if (response && response.code === 200 && response.data) {
  188. taskCounts.value = {
  189. pending: response.data.toSubmit || 0,
  190. reviewing: response.data.toAudit || 0
  191. }
  192. }
  193. } catch (error) {
  194. console.error('获取任务数量失败:', error)
  195. // 失败时保持默认值 0
  196. }
  197. }
  198. // 从基本信息返回主页
  199. const handleBackToMain = () => {
  200. showBasicInfo.value = false
  201. }
  202. // 点击用户卡片
  203. const handleUserCardClick = () => {
  204. uni.navigateTo({
  205. url: '/pages/my/info/index'
  206. })
  207. }
  208. // VIP点击
  209. const handleVipClick = () => {
  210. uni.showToast({
  211. title: t('my.memberFeature'),
  212. icon: 'none'
  213. })
  214. }
  215. // 任务点击
  216. const handleTaskClick = (type) => {
  217. let status = null
  218. if (type === 'pending') {
  219. status = 0 // 待递交
  220. } else if (type === 'reviewing') {
  221. status = 1 // 待审核
  222. }
  223. uni.navigateTo({
  224. url: `/pages/my/taskDocuments/index?status=${status}`
  225. })
  226. }
  227. // 点击我的任务标题区域
  228. const handleTaskSectionClick = () => {
  229. // 跳转到任务列表,不传status参数显示所有任务
  230. uni.navigateTo({
  231. url: '/pages/my/taskDocuments/index'
  232. })
  233. }
  234. // 协议说明
  235. const handleProtocol = () => {
  236. uni.navigateTo({
  237. url: '/pages/my/aggreement/index'
  238. })
  239. }
  240. // 语言切换
  241. const handleLanguageChange = () => {
  242. localeStore.toggleLocale()
  243. setTimeout(() => {
  244. uni.showToast({
  245. title: t('my.languageSwitchSuccess'),
  246. icon: 'success',
  247. duration: 1500
  248. })
  249. }, 100)
  250. }
  251. // 关于我们
  252. const handleAbout = () => {
  253. uni.showToast({
  254. title: t('my.aboutUs'),
  255. icon: 'none'
  256. })
  257. }
  258. // 退出登录
  259. const handleLogout = () => {
  260. uni.showModal({
  261. title: t('my.tip'),
  262. content: t('my.logoutConfirm'),
  263. confirmText: t('my.confirm'),
  264. cancelText: t('my.cancel'),
  265. success: async (res) => {
  266. if (res.confirm) {
  267. try {
  268. uni.showLoading({
  269. title: t('my.loggingOut'),
  270. mask: true
  271. })
  272. await logoutAPI()
  273. userStore.logout()
  274. uni.hideLoading()
  275. uni.showToast({
  276. title: t('my.logoutSuccess'),
  277. icon: 'success',
  278. duration: 1500
  279. })
  280. setTimeout(() => {
  281. uni.reLaunch({
  282. url: '/pages/login/login'
  283. })
  284. }, 1500)
  285. } catch (error) {
  286. uni.hideLoading()
  287. console.error('退出登录失败:', error)
  288. userStore.logout()
  289. uni.showToast({
  290. title: t('my.logoutSuccess'),
  291. icon: 'success',
  292. duration: 1500
  293. })
  294. setTimeout(() => {
  295. uni.reLaunch({
  296. url: '/pages/login/login'
  297. })
  298. }, 1500)
  299. }
  300. }
  301. }
  302. })
  303. }
  304. </script>
  305. <style lang="scss" scoped>
  306. .my-page {
  307. width: 100%;
  308. height: 100vh;
  309. background-color: #f5f5f5;
  310. position: relative;
  311. overflow: hidden;
  312. // 顶部渐变背景 - 固定
  313. .header-bg {
  314. position: fixed;
  315. top: 0;
  316. left: 0;
  317. right: 0;
  318. background: linear-gradient(180deg, #1ec9c9 0%, #1eb8b8 100%);
  319. z-index: 100;
  320. display: flex;
  321. align-items: flex-start;
  322. justify-content: center;
  323. .header-title {
  324. font-size: 36rpx;
  325. font-weight: 600;
  326. color: #ffffff;
  327. letter-spacing: 4rpx;
  328. padding: 16rpx 0 24rpx;
  329. }
  330. }
  331. // 可滚动区域
  332. .page-scroll {
  333. width: 100%;
  334. height: 100%;
  335. // 页面内容
  336. .page-content {
  337. padding: 0 24rpx 24rpx;
  338. padding-bottom: calc(124rpx + env(safe-area-inset-bottom));
  339. // 用户信息卡片
  340. .user-card {
  341. background: #ffffff;
  342. border-radius: 16rpx;
  343. padding: 32rpx 24rpx;
  344. margin-bottom: 24rpx;
  345. display: flex;
  346. align-items: center;
  347. justify-content: space-between;
  348. box-shadow: 0 4rpx 12rpx rgba(0, 0, 0, 0.08);
  349. &:active {
  350. background-color: #f8f8f8;
  351. }
  352. .user-info {
  353. display: flex;
  354. align-items: center;
  355. flex: 1;
  356. .avatar {
  357. width: 100rpx;
  358. height: 100rpx;
  359. border-radius: 50%;
  360. margin-right: 24rpx;
  361. border: 4rpx solid #f0f0f0;
  362. }
  363. .user-details {
  364. display: flex;
  365. flex-direction: column;
  366. gap: 8rpx;
  367. .nickname {
  368. font-size: 32rpx;
  369. font-weight: 600;
  370. color: #333333;
  371. }
  372. .phone {
  373. font-size: 26rpx;
  374. color: #999999;
  375. }
  376. }
  377. }
  378. .vip-badge {
  379. background: linear-gradient(135deg, #666666 0%, #555555 100%);
  380. border-radius: 30rpx;
  381. padding: 12rpx 24rpx;
  382. display: flex;
  383. align-items: center;
  384. gap: 8rpx;
  385. .vip-text {
  386. font-size: 24rpx;
  387. color: #ffffff;
  388. font-weight: 500;
  389. }
  390. .arrow {
  391. font-size: 32rpx;
  392. color: #ffffff;
  393. font-weight: 300;
  394. }
  395. }
  396. }
  397. // 我的任务
  398. .task-section {
  399. background: #ffffff;
  400. border-radius: 16rpx;
  401. padding: 32rpx 24rpx;
  402. margin-bottom: 24rpx;
  403. box-shadow: 0 4rpx 12rpx rgba(0, 0, 0, 0.08);
  404. .section-header {
  405. display: flex;
  406. align-items: center;
  407. justify-content: space-between;
  408. margin-bottom: 32rpx;
  409. .section-title {
  410. font-size: 30rpx;
  411. font-weight: 600;
  412. color: #333333;
  413. }
  414. .arrow {
  415. font-size: 40rpx;
  416. color: #cccccc;
  417. font-weight: 300;
  418. }
  419. }
  420. .task-grid {
  421. display: flex;
  422. justify-content: space-between;
  423. .task-item {
  424. display: flex;
  425. flex-direction: column;
  426. align-items: center;
  427. gap: 16rpx;
  428. flex: 1;
  429. .task-icon-wrapper {
  430. position: relative;
  431. width: 88rpx;
  432. height: 88rpx;
  433. .task-icon {
  434. width: 88rpx;
  435. height: 88rpx;
  436. }
  437. .task-badge {
  438. position: absolute;
  439. top: -8rpx;
  440. right: -8rpx;
  441. background: #ff4444;
  442. color: #ffffff;
  443. font-size: 20rpx;
  444. font-weight: 600;
  445. min-width: 32rpx;
  446. height: 32rpx;
  447. border-radius: 16rpx;
  448. display: flex;
  449. align-items: center;
  450. justify-content: center;
  451. padding: 0 8rpx;
  452. border: 3rpx solid #ffffff;
  453. }
  454. }
  455. .task-label {
  456. font-size: 24rpx;
  457. color: #666666;
  458. }
  459. }
  460. }
  461. }
  462. // 功能列表
  463. .menu-list {
  464. background: #ffffff;
  465. border-radius: 16rpx;
  466. overflow: hidden;
  467. margin-bottom: 24rpx;
  468. box-shadow: 0 4rpx 12rpx rgba(0, 0, 0, 0.08);
  469. .menu-item {
  470. display: flex;
  471. align-items: center;
  472. justify-content: space-between;
  473. padding: 32rpx 24rpx;
  474. border-bottom: 1rpx solid #f5f5f5;
  475. &:last-child {
  476. border-bottom: none;
  477. }
  478. &:active {
  479. background-color: #f8f8f8;
  480. }
  481. .menu-left {
  482. display: flex;
  483. align-items: center;
  484. .menu-icon {
  485. width: 40rpx;
  486. height: 40rpx;
  487. margin-right: 24rpx;
  488. }
  489. .menu-label {
  490. font-size: 28rpx;
  491. color: #333333;
  492. }
  493. }
  494. .arrow {
  495. font-size: 40rpx;
  496. color: #cccccc;
  497. font-weight: 300;
  498. }
  499. .language-switcher {
  500. display: flex;
  501. align-items: center;
  502. background: rgba(30, 201, 201, 0.08);
  503. backdrop-filter: blur(10rpx);
  504. border-radius: 30rpx;
  505. padding: 8rpx 20rpx;
  506. cursor: pointer;
  507. transition: all 0.3s;
  508. gap: 8rpx;
  509. &:active {
  510. transform: scale(0.95);
  511. background: rgba(30, 201, 201, 0.15);
  512. }
  513. .language-text {
  514. font-size: 24rpx;
  515. color: #999;
  516. font-weight: 500;
  517. transition: all 0.3s;
  518. &.active {
  519. color: #1ec9c9;
  520. font-weight: 700;
  521. }
  522. }
  523. .language-separator {
  524. font-size: 24rpx;
  525. color: #ccc;
  526. font-weight: 300;
  527. }
  528. }
  529. }
  530. }
  531. // 退出登录
  532. .logout-section {
  533. padding: 32rpx 0 60rpx;
  534. .logout-btn {
  535. width: 100%;
  536. height: 88rpx;
  537. line-height: 88rpx;
  538. background: #ffffff;
  539. border-radius: 16rpx;
  540. border: none;
  541. font-size: 28rpx;
  542. color: #1ec9c9;
  543. font-weight: 500;
  544. box-shadow: 0 4rpx 12rpx rgba(0, 0, 0, 0.08);
  545. &:active {
  546. opacity: 0.8;
  547. }
  548. &::after {
  549. border: none;
  550. }
  551. }
  552. }
  553. }
  554. }
  555. }</style>