index.vue 16 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631
  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">
  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. console.log('任务数量:', taskCounts.value)
  193. }
  194. } catch (error) {
  195. console.error('获取任务数量失败:', error)
  196. // 失败时保持默认值 0
  197. }
  198. }
  199. // 从基本信息返回主页
  200. const handleBackToMain = () => {
  201. showBasicInfo.value = false
  202. }
  203. // 点击用户卡片
  204. const handleUserCardClick = () => {
  205. uni.navigateTo({
  206. url: '/pages/my/info/index'
  207. })
  208. }
  209. // VIP点击
  210. const handleVipClick = () => {
  211. uni.showToast({
  212. title: t('my.memberFeature'),
  213. icon: 'none'
  214. })
  215. }
  216. // 任务点击
  217. const handleTaskClick = (type) => {
  218. uni.showToast({
  219. title: `${type}任务`,
  220. icon: 'none'
  221. })
  222. }
  223. // 协议说明
  224. const handleProtocol = () => {
  225. uni.navigateTo({
  226. url: '/pages/my/aggreement/index'
  227. })
  228. }
  229. // 语言切换
  230. const handleLanguageChange = () => {
  231. localeStore.toggleLocale()
  232. setTimeout(() => {
  233. uni.showToast({
  234. title: t('my.languageSwitchSuccess'),
  235. icon: 'success',
  236. duration: 1500
  237. })
  238. }, 100)
  239. }
  240. // 关于我们
  241. const handleAbout = () => {
  242. uni.showToast({
  243. title: t('my.aboutUs'),
  244. icon: 'none'
  245. })
  246. }
  247. // 退出登录
  248. const handleLogout = () => {
  249. uni.showModal({
  250. title: t('my.tip'),
  251. content: t('my.logoutConfirm'),
  252. confirmText: t('my.confirm'),
  253. cancelText: t('my.cancel'),
  254. success: async (res) => {
  255. if (res.confirm) {
  256. try {
  257. uni.showLoading({
  258. title: t('my.loggingOut'),
  259. mask: true
  260. })
  261. await logoutAPI()
  262. userStore.logout()
  263. uni.hideLoading()
  264. uni.showToast({
  265. title: t('my.logoutSuccess'),
  266. icon: 'success',
  267. duration: 1500
  268. })
  269. setTimeout(() => {
  270. uni.reLaunch({
  271. url: '/pages/login/login'
  272. })
  273. }, 1500)
  274. } catch (error) {
  275. uni.hideLoading()
  276. console.error('退出登录失败:', error)
  277. userStore.logout()
  278. uni.showToast({
  279. title: t('my.logoutSuccess'),
  280. icon: 'success',
  281. duration: 1500
  282. })
  283. setTimeout(() => {
  284. uni.reLaunch({
  285. url: '/pages/login/login'
  286. })
  287. }, 1500)
  288. }
  289. }
  290. }
  291. })
  292. }
  293. </script>
  294. <style lang="scss" scoped>
  295. .my-page {
  296. width: 100%;
  297. height: 100vh;
  298. background-color: #f5f5f5;
  299. position: relative;
  300. overflow: hidden;
  301. // 顶部渐变背景 - 固定
  302. .header-bg {
  303. position: fixed;
  304. top: 0;
  305. left: 0;
  306. right: 0;
  307. background: linear-gradient(180deg, #1ec9c9 0%, #1eb8b8 100%);
  308. z-index: 100;
  309. display: flex;
  310. align-items: flex-start;
  311. justify-content: center;
  312. .header-title {
  313. font-size: 36rpx;
  314. font-weight: 600;
  315. color: #ffffff;
  316. letter-spacing: 4rpx;
  317. padding: 16rpx 0 24rpx;
  318. }
  319. }
  320. // 可滚动区域
  321. .page-scroll {
  322. width: 100%;
  323. height: 100%;
  324. // 页面内容
  325. .page-content {
  326. padding: 0 24rpx 24rpx;
  327. padding-bottom: calc(124rpx + env(safe-area-inset-bottom));
  328. // 用户信息卡片
  329. .user-card {
  330. background: #ffffff;
  331. border-radius: 16rpx;
  332. padding: 32rpx 24rpx;
  333. margin-bottom: 24rpx;
  334. display: flex;
  335. align-items: center;
  336. justify-content: space-between;
  337. box-shadow: 0 4rpx 12rpx rgba(0, 0, 0, 0.08);
  338. &:active {
  339. background-color: #f8f8f8;
  340. }
  341. .user-info {
  342. display: flex;
  343. align-items: center;
  344. flex: 1;
  345. .avatar {
  346. width: 100rpx;
  347. height: 100rpx;
  348. border-radius: 50%;
  349. margin-right: 24rpx;
  350. border: 4rpx solid #f0f0f0;
  351. }
  352. .user-details {
  353. display: flex;
  354. flex-direction: column;
  355. gap: 8rpx;
  356. .nickname {
  357. font-size: 32rpx;
  358. font-weight: 600;
  359. color: #333333;
  360. }
  361. .phone {
  362. font-size: 26rpx;
  363. color: #999999;
  364. }
  365. }
  366. }
  367. .vip-badge {
  368. background: linear-gradient(135deg, #666666 0%, #555555 100%);
  369. border-radius: 30rpx;
  370. padding: 12rpx 24rpx;
  371. display: flex;
  372. align-items: center;
  373. gap: 8rpx;
  374. .vip-text {
  375. font-size: 24rpx;
  376. color: #ffffff;
  377. font-weight: 500;
  378. }
  379. .arrow {
  380. font-size: 32rpx;
  381. color: #ffffff;
  382. font-weight: 300;
  383. }
  384. }
  385. }
  386. // 我的任务
  387. .task-section {
  388. background: #ffffff;
  389. border-radius: 16rpx;
  390. padding: 32rpx 24rpx;
  391. margin-bottom: 24rpx;
  392. box-shadow: 0 4rpx 12rpx rgba(0, 0, 0, 0.08);
  393. .section-header {
  394. display: flex;
  395. align-items: center;
  396. justify-content: space-between;
  397. margin-bottom: 32rpx;
  398. .section-title {
  399. font-size: 30rpx;
  400. font-weight: 600;
  401. color: #333333;
  402. }
  403. .arrow {
  404. font-size: 40rpx;
  405. color: #cccccc;
  406. font-weight: 300;
  407. }
  408. }
  409. .task-grid {
  410. display: flex;
  411. justify-content: space-between;
  412. .task-item {
  413. display: flex;
  414. flex-direction: column;
  415. align-items: center;
  416. gap: 16rpx;
  417. flex: 1;
  418. .task-icon-wrapper {
  419. position: relative;
  420. width: 88rpx;
  421. height: 88rpx;
  422. .task-icon {
  423. width: 88rpx;
  424. height: 88rpx;
  425. }
  426. .task-badge {
  427. position: absolute;
  428. top: -8rpx;
  429. right: -8rpx;
  430. background: #ff4444;
  431. color: #ffffff;
  432. font-size: 20rpx;
  433. font-weight: 600;
  434. min-width: 32rpx;
  435. height: 32rpx;
  436. border-radius: 16rpx;
  437. display: flex;
  438. align-items: center;
  439. justify-content: center;
  440. padding: 0 8rpx;
  441. border: 3rpx solid #ffffff;
  442. }
  443. }
  444. .task-label {
  445. font-size: 24rpx;
  446. color: #666666;
  447. }
  448. }
  449. }
  450. }
  451. // 功能列表
  452. .menu-list {
  453. background: #ffffff;
  454. border-radius: 16rpx;
  455. overflow: hidden;
  456. margin-bottom: 24rpx;
  457. box-shadow: 0 4rpx 12rpx rgba(0, 0, 0, 0.08);
  458. .menu-item {
  459. display: flex;
  460. align-items: center;
  461. justify-content: space-between;
  462. padding: 32rpx 24rpx;
  463. border-bottom: 1rpx solid #f5f5f5;
  464. &:last-child {
  465. border-bottom: none;
  466. }
  467. &:active {
  468. background-color: #f8f8f8;
  469. }
  470. .menu-left {
  471. display: flex;
  472. align-items: center;
  473. .menu-icon {
  474. width: 40rpx;
  475. height: 40rpx;
  476. margin-right: 24rpx;
  477. }
  478. .menu-label {
  479. font-size: 28rpx;
  480. color: #333333;
  481. }
  482. }
  483. .arrow {
  484. font-size: 40rpx;
  485. color: #cccccc;
  486. font-weight: 300;
  487. }
  488. .language-switcher {
  489. display: flex;
  490. align-items: center;
  491. background: rgba(30, 201, 201, 0.08);
  492. backdrop-filter: blur(10rpx);
  493. border-radius: 30rpx;
  494. padding: 8rpx 20rpx;
  495. cursor: pointer;
  496. transition: all 0.3s;
  497. gap: 8rpx;
  498. &:active {
  499. transform: scale(0.95);
  500. background: rgba(30, 201, 201, 0.15);
  501. }
  502. .language-text {
  503. font-size: 24rpx;
  504. color: #999;
  505. font-weight: 500;
  506. transition: all 0.3s;
  507. &.active {
  508. color: #1ec9c9;
  509. font-weight: 700;
  510. }
  511. }
  512. .language-separator {
  513. font-size: 24rpx;
  514. color: #ccc;
  515. font-weight: 300;
  516. }
  517. }
  518. }
  519. }
  520. // 退出登录
  521. .logout-section {
  522. padding: 32rpx 0 60rpx;
  523. .logout-btn {
  524. width: 100%;
  525. height: 88rpx;
  526. line-height: 88rpx;
  527. background: #ffffff;
  528. border-radius: 16rpx;
  529. border: none;
  530. font-size: 28rpx;
  531. color: #1ec9c9;
  532. font-weight: 500;
  533. box-shadow: 0 4rpx 12rpx rgba(0, 0, 0, 0.08);
  534. &:active {
  535. opacity: 0.8;
  536. }
  537. &::after {
  538. border: none;
  539. }
  540. }
  541. }
  542. }
  543. }
  544. }</style>