index.vue 15 KB

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