index.vue 15 KB

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