index.vue 15 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610
  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>
  32. <!-- 我的任务 -->
  33. <view class="task-section">
  34. <view class="section-header" @click="handleTaskSectionClick">
  35. <text class="section-title">{{ t('my.myTasks') }}</text>
  36. <text class="arrow">›</text>
  37. </view>
  38. <view class="task-grid">
  39. <view class="task-item" @click="handleTaskClick('pending')">
  40. <view class="task-icon-wrapper">
  41. <image class="task-icon" src="/static/pages/my/toSubmit.svg" mode="aspectFit" />
  42. <view v-if="taskCounts.pending > 0" class="task-badge">{{ taskCounts.pending }}</view>
  43. </view>
  44. <text class="task-label">{{ t('my.toSubmit') }}</text>
  45. </view>
  46. <view class="task-item" @click="handleTaskClick('reviewing')">
  47. <view class="task-icon-wrapper">
  48. <image class="task-icon" src="/static/pages/my/toAudit.svg" mode="aspectFit" />
  49. <view v-if="taskCounts.reviewing > 0" class="task-badge">{{ taskCounts.reviewing }}</view>
  50. </view>
  51. <text class="task-label">{{ t('my.toAudit') }}</text>
  52. </view>
  53. </view>
  54. </view>
  55. <!-- 功能列表 -->
  56. <view class="menu-list">
  57. <view class="menu-item" @click="handleProtocol">
  58. <view class="menu-left">
  59. <image class="menu-icon" src="/static/pages/my/icon-protocol.png" mode="aspectFit" />
  60. <text class="menu-label">{{ t('my.userAgreement') }}</text>
  61. </view>
  62. <text class="arrow">›</text>
  63. </view>
  64. <view class="menu-item">
  65. <view class="menu-left">
  66. <image class="menu-icon" src="/static/pages/my/icon-language.png" mode="aspectFit" />
  67. <text class="menu-label">{{ t('my.languageSwitch') }}</text>
  68. </view>
  69. <view class="language-switcher" @click="handleLanguageChange">
  70. <text class="language-text" :class="{ active: locale === 'zh-CN' }">中</text>
  71. <text class="language-separator">|</text>
  72. <text class="language-text" :class="{ active: locale === 'en-US' }">EN</text>
  73. </view>
  74. </view>
  75. <!-- <view class="menu-item" @click="handleAbout">
  76. <view class="menu-left">
  77. <image class="menu-icon" src="/static/pages/my/icon-about.png" mode="aspectFit" />
  78. <text class="menu-label">{{ t('my.aboutUs') }}</text>
  79. </view>
  80. <text class="arrow">›</text>
  81. </view> -->
  82. </view>
  83. <!-- 退出登录按钮 -->
  84. <view class="logout-section">
  85. <button class="logout-btn" @click="handleLogout">{{ t('my.logout') }}</button>
  86. </view>
  87. </view>
  88. </scroll-view>
  89. <!-- 底部导航栏 -->
  90. <TabBar current-tab="mine" />
  91. </view>
  92. </template>
  93. <script setup>
  94. import BasicInfo from './info/index.vue'
  95. import { ref, computed, onMounted } from 'vue'
  96. import { useI18n } from 'vue-i18n'
  97. import { useUserStore } from '@/store/index'
  98. import { useLocaleStore } from '@/store/locale'
  99. import { getUserInfo as getUserInfoAPI, logout as logoutAPI, getTaskCount } from '@/apis/auth'
  100. import TabBar from '@/components/TabBar/index.vue'
  101. const { t, locale } = useI18n()
  102. const userStore = useUserStore()
  103. const localeStore = useLocaleStore()
  104. // 控制显示哪个组件
  105. const showBasicInfo = ref(false)
  106. // 状态栏高度
  107. const statusBarHeight = ref(0)
  108. // 用户信息
  109. const userInfo = ref({
  110. avatar: '/static/default-avatar.svg',
  111. nickname: '',
  112. phoneNumber: ''
  113. })
  114. // 任务数量
  115. const taskCounts = ref({
  116. pending: 0,
  117. reviewing: 0
  118. })
  119. // 显示的昵称
  120. const displayNickname = computed(() => {
  121. return userInfo.value.nickname || t('my.defaultNickname')
  122. })
  123. // 加密手机号
  124. const encryptPhone = (phone) => {
  125. if (!phone) return ''
  126. // 如果手机号长度为11位,则加密中间4位
  127. if (phone.length === 11) {
  128. return phone.replace(/(\d{3})\d{4}(\d{4})/, '$1****$2')
  129. }
  130. // 如果手机号长度不是11位,则加密中间部分
  131. if (phone.length > 6) {
  132. const start = phone.substring(0, 3)
  133. const end = phone.substring(phone.length - 4)
  134. return `${start}****${end}`
  135. }
  136. return phone
  137. }
  138. // 显示的手机号(加密)
  139. const displayPhone = computed(() => {
  140. return encryptPhone(userInfo.value.phoneNumber)
  141. })
  142. onMounted(() => {
  143. // 获取系统信息
  144. const windowInfo = uni.getWindowInfo()
  145. statusBarHeight.value = windowInfo.statusBarHeight || 0
  146. // 获取用户信息
  147. fetchUserInfo()
  148. // 获取任务数量
  149. fetchTaskCount()
  150. })
  151. // 头像加载失败处理
  152. const handleAvatarError = () => {
  153. userInfo.value.avatar = '/static/default-avatar.svg'
  154. }
  155. // 获取用户信息
  156. const fetchUserInfo = async () => {
  157. try {
  158. const response = await getUserInfoAPI()
  159. if (response && response.data) {
  160. userInfo.value = {
  161. avatar: response.data.avatar || '/static/default-avatar.svg',
  162. nickname: response.data.nickname || '',
  163. phoneNumber: response.data.phoneNumber || ''
  164. }
  165. userStore.setUserInfo(response.data)
  166. }
  167. } catch (error) {
  168. console.error('获取用户信息失败:', error)
  169. const storedUserInfo = userStore.userInfo
  170. if (storedUserInfo) {
  171. userInfo.value = {
  172. avatar: storedUserInfo.avatar || '/static/default-avatar.svg',
  173. nickname: storedUserInfo.nickname || '',
  174. phoneNumber: storedUserInfo.phoneNumber || ''
  175. }
  176. }
  177. }
  178. }
  179. // 获取任务数量
  180. const fetchTaskCount = async () => {
  181. try {
  182. const response = await getTaskCount()
  183. if (response && response.code === 200 && response.data) {
  184. taskCounts.value = {
  185. pending: response.data.toSubmit || 0,
  186. reviewing: response.data.toAudit || 0
  187. }
  188. }
  189. } catch (error) {
  190. console.error('获取任务数量失败:', error)
  191. // 失败时保持默认值 0
  192. }
  193. }
  194. // 从基本信息返回主页
  195. const handleBackToMain = () => {
  196. showBasicInfo.value = false
  197. }
  198. // 点击用户卡片
  199. const handleUserCardClick = () => {
  200. uni.navigateTo({
  201. url: '/pages/my/info/index'
  202. })
  203. }
  204. // 任务点击
  205. const handleTaskClick = (type) => {
  206. let status = null
  207. if (type === 'pending') {
  208. status = 0 // 待递交
  209. } else if (type === 'reviewing') {
  210. status = 1 // 待审核
  211. }
  212. uni.navigateTo({
  213. url: `/pages/my/taskDocuments/index?status=${status}`
  214. })
  215. }
  216. // 点击我的任务标题区域
  217. const handleTaskSectionClick = () => {
  218. // 跳转到任务列表,不传status参数显示所有任务
  219. uni.navigateTo({
  220. url: '/pages/my/taskDocuments/index'
  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. box-shadow: 0 4rpx 12rpx rgba(0, 0, 0, 0.08);
  337. &:active {
  338. background-color: #f8f8f8;
  339. }
  340. .user-info {
  341. display: flex;
  342. align-items: center;
  343. flex: 1;
  344. .avatar {
  345. width: 100rpx;
  346. height: 100rpx;
  347. border-radius: 50%;
  348. margin-right: 24rpx;
  349. border: 4rpx solid #f0f0f0;
  350. }
  351. .user-details {
  352. display: flex;
  353. flex-direction: column;
  354. gap: 8rpx;
  355. .nickname {
  356. font-size: 32rpx;
  357. font-weight: 600;
  358. color: #333333;
  359. }
  360. .phone {
  361. font-size: 26rpx;
  362. color: #999999;
  363. }
  364. }
  365. }
  366. }
  367. // 我的任务
  368. .task-section {
  369. background: #ffffff;
  370. border-radius: 16rpx;
  371. padding: 32rpx 24rpx;
  372. margin-bottom: 24rpx;
  373. box-shadow: 0 4rpx 12rpx rgba(0, 0, 0, 0.08);
  374. .section-header {
  375. display: flex;
  376. align-items: center;
  377. justify-content: space-between;
  378. margin-bottom: 32rpx;
  379. .section-title {
  380. font-size: 30rpx;
  381. font-weight: 600;
  382. color: #333333;
  383. }
  384. .arrow {
  385. font-size: 40rpx;
  386. color: #cccccc;
  387. font-weight: 300;
  388. }
  389. }
  390. .task-grid {
  391. display: flex;
  392. justify-content: space-between;
  393. .task-item {
  394. display: flex;
  395. flex-direction: column;
  396. align-items: center;
  397. gap: 16rpx;
  398. flex: 1;
  399. .task-icon-wrapper {
  400. position: relative;
  401. width: 88rpx;
  402. height: 88rpx;
  403. .task-icon {
  404. width: 88rpx;
  405. height: 88rpx;
  406. }
  407. .task-badge {
  408. position: absolute;
  409. top: -8rpx;
  410. right: -8rpx;
  411. background: #ff4444;
  412. color: #ffffff;
  413. font-size: 20rpx;
  414. font-weight: 600;
  415. min-width: 32rpx;
  416. height: 32rpx;
  417. border-radius: 16rpx;
  418. display: flex;
  419. align-items: center;
  420. justify-content: center;
  421. padding: 0 8rpx;
  422. border: 3rpx solid #ffffff;
  423. }
  424. }
  425. .task-label {
  426. font-size: 24rpx;
  427. color: #666666;
  428. }
  429. }
  430. }
  431. }
  432. // 功能列表
  433. .menu-list {
  434. background: #ffffff;
  435. border-radius: 16rpx;
  436. overflow: hidden;
  437. margin-bottom: 24rpx;
  438. box-shadow: 0 4rpx 12rpx rgba(0, 0, 0, 0.08);
  439. .menu-item {
  440. display: flex;
  441. align-items: center;
  442. justify-content: space-between;
  443. padding: 32rpx 24rpx;
  444. border-bottom: 1rpx solid #f5f5f5;
  445. &:last-child {
  446. border-bottom: none;
  447. }
  448. &:active {
  449. background-color: #f8f8f8;
  450. }
  451. .menu-left {
  452. display: flex;
  453. align-items: center;
  454. .menu-icon {
  455. width: 40rpx;
  456. height: 40rpx;
  457. margin-right: 24rpx;
  458. }
  459. .menu-label {
  460. font-size: 28rpx;
  461. color: #333333;
  462. }
  463. }
  464. .arrow {
  465. font-size: 40rpx;
  466. color: #cccccc;
  467. font-weight: 300;
  468. }
  469. .language-switcher {
  470. display: flex;
  471. align-items: center;
  472. background: rgba(30, 201, 201, 0.08);
  473. backdrop-filter: blur(10rpx);
  474. border-radius: 30rpx;
  475. padding: 8rpx 20rpx;
  476. cursor: pointer;
  477. transition: all 0.3s;
  478. gap: 8rpx;
  479. &:active {
  480. transform: scale(0.95);
  481. background: rgba(30, 201, 201, 0.15);
  482. }
  483. .language-text {
  484. font-size: 24rpx;
  485. color: #999;
  486. font-weight: 500;
  487. transition: all 0.3s;
  488. &.active {
  489. color: #1ec9c9;
  490. font-weight: 700;
  491. }
  492. }
  493. .language-separator {
  494. font-size: 24rpx;
  495. color: #ccc;
  496. font-weight: 300;
  497. }
  498. }
  499. }
  500. }
  501. // 退出登录
  502. .logout-section {
  503. padding: 32rpx 0 60rpx;
  504. .logout-btn {
  505. width: 100%;
  506. height: 88rpx;
  507. line-height: 88rpx;
  508. background: #ffffff;
  509. border-radius: 16rpx;
  510. border: none;
  511. font-size: 28rpx;
  512. color: #1ec9c9;
  513. font-weight: 500;
  514. box-shadow: 0 4rpx 12rpx rgba(0, 0, 0, 0.08);
  515. &:active {
  516. opacity: 0.8;
  517. }
  518. &::after {
  519. border: none;
  520. }
  521. }
  522. }
  523. }
  524. }
  525. }</style>