index.vue 18 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747
  1. <template>
  2. <view class="page-profile">
  3. <!-- ========== Region 1: User Card ========== -->
  4. <view class="user-card">
  5. <!-- Login prompt for unauthenticated users -->
  6. <view v-if="!userStore.isLoggedIn" class="user-card__login" @click="goLogin">
  7. <view class="avatar avatar--empty">
  8. <text class="avatar__icon">+</text>
  9. </view>
  10. <text class="user-card__nickname">未登录</text>
  11. <text class="user-card__login-hint">点击登录 / 注册</text>
  12. </view>
  13. <!-- Authenticated user card -->
  14. <view v-else class="user-card__logged">
  15. <view class="avatar">
  16. <image :src="userStore.avatarUrl || '/static/default-avatar.png'" mode="aspectFill" />
  17. <view class="avatar__edit" @click="goEditProfile">
  18. <text class="avatar__edit-icon">✏</text>
  19. </view>
  20. </view>
  21. <text class="user-card__nickname">{{ userStore.nickname }}</text>
  22. <!-- Role tag -->
  23. <view
  24. class="user-card__tag"
  25. :class="{
  26. 'user-card__tag--practitioner': userStore.vipType === 'practitioner',
  27. 'user-card__tag--annual': userStore.vipType === 'annual',
  28. 'user-card__tag--normal': !userStore.vipType
  29. }"
  30. >
  31. <text v-if="!userStore.vipType">普通用户</text>
  32. <text v-else-if="userStore.vipType === 'annual'">C端会员</text>
  33. <text v-else>能量师 🌟</text>
  34. </view>
  35. <!-- Social summary (optional) -->
  36. <text v-if="userStore.bio || userStore.city" class="user-card__summary">
  37. {{ userStore.city || '' }}{{ userStore.city && userStore.bio ? ' · ' : '' }}{{ userStore.bio || '' }}
  38. </text>
  39. </view>
  40. </view>
  41. <!-- ========== Region 2: Membership Status Cards ========== -->
  42. <!-- US-5.1 §13: Profile incomplete banner -->
  43. <view v-if="userStore.isLoggedIn && userStore.profileIncomplete" class="banner" @click="goEditProfile">
  44. <text class="banner__text">📝 请完善个人资料,开启能量匹配</text>
  45. <text class="banner__arrow">›</text>
  46. </view>
  47. <!-- US-4.3: Renewal reminder (7 days before expiry) -->
  48. <view v-if="isExpiringSoon" class="banner banner--warning" @click="goRenew">
  49. <text class="banner__text">⏰ 您的会员即将到期,请及时续费</text>
  50. <text class="banner__arrow">›</text>
  51. </view>
  52. <!-- Seed-price badge -->
  53. <view v-if="userStore.isSeedPriceUser" class="seed-badge">
  54. <text class="seed-badge__text">🌱 种子价专属会员</text>
  55. </view>
  56. <!-- VIP status card — role-based -->
  57. <!-- Case 1: Energy master (practitioner, in valid period) -->
  58. <view
  59. v-if="userStore.vipType === 'practitioner' && userStore.isVip && !isExpired"
  60. class="vip-card vip-card--practitioner"
  61. >
  62. <view class="vip-card__body">
  63. <text class="vip-card__title">能量师会员 🌟</text>
  64. <text class="vip-card__desc">
  65. 有效期至 {{ formatDate(userStore.vipEndTime) }}
  66. </text>
  67. </view>
  68. <text class="vip-card__action" @click="goRenew">续费</text>
  69. </view>
  70. <!-- Case 2: C-end annual subscriber (in valid period) -->
  71. <view
  72. v-else-if="userStore.vipType === 'annual' && userStore.isVip && !isExpired"
  73. class="vip-card vip-card--annual"
  74. >
  75. <view class="vip-card__body">
  76. <text class="vip-card__title">C端会员</text>
  77. <text class="vip-card__desc">
  78. 有效期至 {{ formatDate(userStore.vipEndTime) }}
  79. </text>
  80. </view>
  81. <text class="vip-card__action" @click="goUpgradePractitioner">升级能量师</text>
  82. </view>
  83. <!-- Case 3: Expired member (vipEndTime < now) -->
  84. <view v-else-if="userStore.vipType && isExpired" class="vip-card vip-card--expired">
  85. <view class="vip-card__body">
  86. <text class="vip-card__title">会员已过期</text>
  87. <text class="vip-card__desc">
  88. 过期时间 {{ formatDate(userStore.vipEndTime) }}
  89. </text>
  90. </view>
  91. <text class="vip-card__action" @click="goPayment">重新开通</text>
  92. </view>
  93. <!-- Case 4: Free user — upsell card -->
  94. <view v-else class="vip-card vip-card--upsell">
  95. <view class="vip-card__body">
  96. <text class="vip-card__title">开通VIP · 解锁完整分析</text>
  97. <view class="vip-card__benefits">
  98. <text class="vip-card__benefit">✅ AI 完整五区解读</text>
  99. <text class="vip-card__benefit">✅ 不限次 AI 追问互动</text>
  100. <text class="vip-card__benefit">✅ 导出 PDF 报告</text>
  101. <text class="vip-card__benefit">✅ 分销推广赚佣金</text>
  102. </view>
  103. </view>
  104. <text class="vip-card__cta" @click="goPayment">立即开通 ¥131/年</text>
  105. </view>
  106. <!-- Daily quota (non-VIP only) -->
  107. <view v-if="!userStore.isVip" class="quota-bar">
  108. <view class="quota-bar__item">
  109. <text class="quota-bar__label">今日分析</text>
  110. <text class="quota-bar__value">{{ userStore.usedCharts }}/{{ userStore.maxCharts }}</text>
  111. </view>
  112. <view class="quota-bar__divider"></view>
  113. <view class="quota-bar__item">
  114. <text class="quota-bar__label">今日解读</text>
  115. <text class="quota-bar__value">{{ userStore.usedChats }}/{{ userStore.maxChats }}</text>
  116. </view>
  117. </view>
  118. <!-- ========== Region 3: Feature Menu ========== -->
  119. <!-- Group 1: My Services -->
  120. <view class="menu-section">
  121. <view class="menu-section__header">我的服务</view>
  122. <!-- Analysis history (all logged-in) -->
  123. <view v-if="userStore.isLoggedIn" class="menu-item" @click="goRecords">
  124. <text class="menu-item__label">📋 我的分析</text>
  125. <text class="menu-item__arrow">›</text>
  126. </view>
  127. <!-- Academic orientation (all users, NEW badge) — EPIC 9 -->
  128. <view v-if="userStore.isLoggedIn" class="menu-item" @click="goAcademicOrientation">
  129. <text class="menu-item__label">📖 学业方向</text>
  130. <view class="menu-item__badge menu-item__badge--new">NEW</view>
  131. <text class="menu-item__arrow">›</text>
  132. </view>
  133. <!-- Distribution panel (paid users only) -->
  134. <view v-if="userStore.isLoggedIn && userStore.isVip" class="menu-item" @click="goCommission">
  135. <text class="menu-item__label">💰 我的推广</text>
  136. <text class="menu-item__arrow">›</text>
  137. </view>
  138. </view>
  139. <!-- Group 2: Promotion Tools (paid users only) -->
  140. <view v-if="userStore.isLoggedIn && userStore.isVip && userStore.referralCode" class="menu-section">
  141. <view class="menu-section__header">推广工具</view>
  142. <view class="promo-card">
  143. <view class="promo-card__code-area">
  144. <text class="promo-card__prefix">推广码</text>
  145. <text class="promo-card__code">{{ userStore.referralCode }}</text>
  146. </view>
  147. <view class="promo-card__actions">
  148. <text class="promo-card__btn" @click="copyReferral">复制推广码</text>
  149. <text class="promo-card__divider">|</text>
  150. <text class="promo-card__btn" @click="generatePoster">生成推广海报</text>
  151. </view>
  152. </view>
  153. </view>
  154. <!-- Group 3: More -->
  155. <view class="menu-section">
  156. <view class="menu-section__header">更多</view>
  157. <!-- My tags (practitioner only, P2) -->
  158. <view v-if="userStore.vipType === 'practitioner'" class="menu-item" @click="goTags">
  159. <text class="menu-item__label">🏷 我的标签</text>
  160. <text class="menu-item__arrow">›</text>
  161. </view>
  162. <!-- About us (all) -->
  163. <view class="menu-item" @click="goAbout">
  164. <text class="menu-item__label">ℹ️ 关于我们</text>
  165. <text class="menu-item__arrow">›</text>
  166. </view>
  167. </view>
  168. <!-- ========== Region 4: Logout ========== -->
  169. <view v-if="userStore.isLoggedIn" class="menu-section">
  170. <view class="menu-item menu-item--danger" @click="handleLogout">
  171. <text class="menu-item__label menu-item__label--danger">退出登录</text>
  172. </view>
  173. </view>
  174. </view>
  175. </template>
  176. <script setup>
  177. import { computed, onShow } from '@dcloudio/uni-app'
  178. import { useUserStore } from '@/stores/user'
  179. const userStore = useUserStore()
  180. // US-4.3: Renewal reminder if expiry within 7 days
  181. const isExpiringSoon = computed(() => {
  182. if (!userStore.vipEndTime) return false
  183. const expiry = new Date(userStore.vipEndTime)
  184. const now = new Date()
  185. const diffHours = (expiry - now) / (1000 * 60 * 60)
  186. return diffHours > 0 && diffHours <= 7 * 24
  187. })
  188. // US-4.3: Expired check
  189. const isExpired = computed(() => {
  190. if (!userStore.vipEndTime) return false
  191. return new Date(userStore.vipEndTime) < new Date()
  192. })
  193. function formatDate(dateStr) {
  194. if (!dateStr) return ''
  195. return dateStr.slice(0, 10)
  196. }
  197. onShow(() => {
  198. if (userStore.isLoggedIn) {
  199. userStore.fetchProfile()
  200. userStore.fetchQuota()
  201. userStore.fetchCommissionSummary()
  202. }
  203. })
  204. function goLogin() {
  205. uni.navigateTo({ url: '/pages/login/index' })
  206. }
  207. function goEditProfile() {
  208. if (!userStore.isLoggedIn) {
  209. uni.navigateTo({ url: '/pages/login/index' })
  210. return
  211. }
  212. uni.navigateTo({ url: '/pages/profile/edit' })
  213. }
  214. function goPayment() {
  215. uni.navigateTo({ url: '/pages/payment/index?product=annual' })
  216. }
  217. function goRenew() {
  218. const product = userStore.vipType === 'practitioner' ? 'practitioner' : 'annual'
  219. uni.navigateTo({ url: `/pages/payment/index?product=${product}` })
  220. }
  221. function goUpgradePractitioner() {
  222. uni.navigateTo({ url: '/pages/payment/index?product=practitioner' })
  223. }
  224. function goRecords() {
  225. uni.switchTab({ url: '/pages/records/index' })
  226. }
  227. function goAcademicOrientation() {
  228. // EPIC 9: Navigate to academic orientation history
  229. uni.navigateTo({ url: '/pages/academic/index' })
  230. }
  231. function goCommission() {
  232. if (!userStore.isLoggedIn) {
  233. uni.navigateTo({ url: '/pages/login/index' })
  234. return
  235. }
  236. uni.navigateTo({ url: '/pages/commission/index' })
  237. }
  238. function copyReferral() {
  239. if (userStore.referralCode) {
  240. uni.setClipboardData({
  241. data: userStore.referralCode,
  242. success: () => uni.showToast({ title: '已复制推广码', icon: 'success' })
  243. })
  244. }
  245. }
  246. function generatePoster() {
  247. uni.showToast({ title: '海报生成中…', icon: 'none' })
  248. // US-6.5: Backend generates poster with mini-program code
  249. }
  250. function goTags() {
  251. uni.navigateTo({ url: '/pages/tags/index' })
  252. }
  253. function goAbout() {
  254. uni.navigateTo({ url: '/pages/about/index' })
  255. }
  256. function handleLogout() {
  257. uni.showModal({
  258. title: '确认退出',
  259. content: '确定要退出登录吗?',
  260. success: (res) => {
  261. if (res.confirm) {
  262. userStore.logout()
  263. uni.showToast({ title: '已退出', icon: 'success' })
  264. }
  265. }
  266. })
  267. }
  268. </script>
  269. <style scoped lang="scss">
  270. // Brand colors (aligned with style-guide.md)
  271. $blue-dark: #1E3A5F;
  272. $gold: #C9A84C;
  273. $gold-light: #F8F0D8;
  274. $warm-white: #F8F6F1;
  275. $white: #FFFFFF;
  276. $text-primary: #1F2937;
  277. $text-secondary: #6B7280;
  278. $text-muted: #9CA3AF;
  279. $danger: #EF4444;
  280. .page-profile {
  281. padding: 16px;
  282. min-height: 100vh;
  283. background: $warm-white;
  284. }
  285. // ========== Region 1: User Card ==========
  286. .user-card {
  287. background: linear-gradient(135deg, $blue-dark, darken($blue-dark, 6%));
  288. border-radius: 16px;
  289. padding: 32px 20px 28px;
  290. margin-bottom: 16px;
  291. text-align: center;
  292. &__login {
  293. cursor: pointer;
  294. }
  295. &__logged {
  296. display: flex;
  297. flex-direction: column;
  298. align-items: center;
  299. }
  300. &__nickname {
  301. font-size: 18px;
  302. font-weight: 600;
  303. color: $white;
  304. display: block;
  305. margin-top: 12px;
  306. }
  307. &__login-hint {
  308. font-size: 12px;
  309. color: rgba(255, 255, 255, 0.7);
  310. display: block;
  311. margin-top: 4px;
  312. }
  313. &__tag {
  314. display: inline-flex;
  315. padding: 3px 14px;
  316. border-radius: 20px;
  317. font-size: 12px;
  318. margin-top: 8px;
  319. &--practitioner {
  320. background: $gold;
  321. color: $blue-dark;
  322. font-weight: 600;
  323. }
  324. &--annual {
  325. background: rgba($gold, 0.25);
  326. color: $gold;
  327. }
  328. &--normal {
  329. background: rgba(255, 255, 255, 0.15);
  330. color: rgba(255, 255, 255, 0.8);
  331. }
  332. }
  333. &__summary {
  334. font-size: 12px;
  335. color: rgba(255, 255, 255, 0.55);
  336. margin-top: 6px;
  337. }
  338. }
  339. // Avatar
  340. .avatar {
  341. width: 68px;
  342. height: 68px;
  343. border-radius: 50%;
  344. overflow: visible;
  345. position: relative;
  346. margin: 0 auto;
  347. image {
  348. width: 100%;
  349. height: 100%;
  350. border-radius: 50%;
  351. border: 2px solid rgba(255, 255, 255, 0.3);
  352. }
  353. &--empty {
  354. background: rgba(255, 255, 255, 0.12);
  355. display: flex;
  356. align-items: center;
  357. justify-content: center;
  358. border: 2px dashed rgba(255, 255, 255, 0.25);
  359. }
  360. &__icon {
  361. font-size: 28px;
  362. color: rgba(255, 255, 255, 0.5);
  363. }
  364. &__edit {
  365. position: absolute;
  366. right: -2px;
  367. bottom: -2px;
  368. width: 24px;
  369. height: 24px;
  370. border-radius: 50%;
  371. background: $gold;
  372. display: flex;
  373. align-items: center;
  374. justify-content: center;
  375. z-index: 1;
  376. cursor: pointer;
  377. &-icon {
  378. font-size: 12px;
  379. color: $blue-dark;
  380. font-weight: 700;
  381. }
  382. }
  383. }
  384. // ========== Region 2: Membership Status ==========
  385. // Banners
  386. .banner {
  387. display: flex;
  388. align-items: center;
  389. justify-content: space-between;
  390. padding: 10px 14px;
  391. border-radius: 10px;
  392. margin-bottom: 12px;
  393. background: #FEF3C7;
  394. border: 1px solid #FDE68A;
  395. &--warning {
  396. background: #FEF3C7;
  397. border-color: #FDE68A;
  398. }
  399. &__text {
  400. font-size: 13px;
  401. color: #92400E;
  402. flex: 1;
  403. }
  404. &__arrow {
  405. font-size: 18px;
  406. color: #92400E;
  407. margin-left: 8px;
  408. }
  409. }
  410. // Seed-price badge
  411. .seed-badge {
  412. display: flex;
  413. align-items: center;
  414. justify-content: center;
  415. padding: 6px 14px;
  416. border-radius: 8px;
  417. margin-bottom: 12px;
  418. background: $gold-light;
  419. border: 1px solid $gold;
  420. &__text {
  421. font-size: 12px;
  422. color: $blue-dark;
  423. font-weight: 500;
  424. }
  425. }
  426. // VIP status card
  427. .vip-card {
  428. border-radius: 12px;
  429. padding: 16px;
  430. display: flex;
  431. justify-content: space-between;
  432. align-items: center;
  433. margin-bottom: 16px;
  434. &__body {
  435. flex: 1;
  436. }
  437. &__title {
  438. font-weight: 600;
  439. font-size: 16px;
  440. display: block;
  441. }
  442. &__desc {
  443. font-size: 12px;
  444. opacity: 0.8;
  445. display: block;
  446. margin-top: 4px;
  447. }
  448. &__action {
  449. font-size: 14px;
  450. font-weight: 500;
  451. padding: 6px 14px;
  452. border-radius: 8px;
  453. white-space: nowrap;
  454. cursor: pointer;
  455. }
  456. // Practitioner
  457. &--practitioner {
  458. background: linear-gradient(135deg, #7c3aed, #6d28d9);
  459. .vip-card__title, .vip-card__desc { color: #fff; }
  460. .vip-card__action {
  461. color: #7c3aed;
  462. background: rgba(255, 255, 255, 0.95);
  463. }
  464. }
  465. // Annual
  466. &--annual {
  467. background: linear-gradient(135deg, #f59e0b, #d97706);
  468. .vip-card__title, .vip-card__desc { color: #fff; }
  469. .vip-card__action {
  470. color: #d97706;
  471. background: rgba(255, 255, 255, 0.95);
  472. }
  473. }
  474. // Expired
  475. &--expired {
  476. background: #E5E7EB;
  477. .vip-card__title { color: $text-secondary; }
  478. .vip-card__desc { color: $text-muted; }
  479. .vip-card__action {
  480. color: $text-secondary;
  481. background: $white;
  482. }
  483. }
  484. // Upsell (free user)
  485. &--upsell {
  486. background: linear-gradient(135deg, $blue-dark, darken($blue-dark, 4%));
  487. flex-direction: column;
  488. align-items: flex-start;
  489. gap: 14px;
  490. .vip-card__title {
  491. color: $gold;
  492. font-size: 16px;
  493. }
  494. & .vip-card__benefits {
  495. display: flex;
  496. flex-direction: column;
  497. gap: 4px;
  498. margin-top: 8px;
  499. }
  500. .vip-card__benefit {
  501. color: rgba(255, 255, 255, 0.8);
  502. font-size: 13px;
  503. }
  504. .vip-card__cta {
  505. align-self: stretch;
  506. text-align: center;
  507. background: $gold;
  508. color: $blue-dark;
  509. font-weight: 600;
  510. font-size: 15px;
  511. padding: 12px;
  512. border-radius: 10px;
  513. cursor: pointer;
  514. }
  515. }
  516. }
  517. // Daily quota
  518. .quota-bar {
  519. background: $white;
  520. border-radius: 12px;
  521. padding: 16px;
  522. margin-bottom: 16px;
  523. display: flex;
  524. align-items: center;
  525. justify-content: space-around;
  526. &__item {
  527. text-align: center;
  528. }
  529. &__label {
  530. font-size: 12px;
  531. color: $text-secondary;
  532. display: block;
  533. margin-bottom: 4px;
  534. }
  535. &__value {
  536. font-size: 20px;
  537. font-weight: 700;
  538. color: $text-primary;
  539. }
  540. &__divider {
  541. width: 1px;
  542. height: 36px;
  543. background: #E5E7EB;
  544. }
  545. }
  546. // ========== Region 3: Feature Menu ==========
  547. .menu-section {
  548. background: $white;
  549. border-radius: 12px;
  550. margin-bottom: 16px;
  551. overflow: hidden;
  552. &__header {
  553. font-size: 12px;
  554. font-weight: 600;
  555. color: $text-muted;
  556. text-transform: uppercase;
  557. letter-spacing: 0.5px;
  558. padding: 14px 16px 6px;
  559. }
  560. }
  561. .menu-item {
  562. display: flex;
  563. align-items: center;
  564. gap: 8px;
  565. padding: 14px 16px;
  566. border-bottom: 1px solid #F3F4F6;
  567. cursor: pointer;
  568. transition: background 0.15s;
  569. &:active {
  570. background: #F9FAFB;
  571. }
  572. &:last-child {
  573. border-bottom: none;
  574. }
  575. &__label {
  576. flex: 1;
  577. font-size: 15px;
  578. color: $text-primary;
  579. &--danger {
  580. color: $danger;
  581. }
  582. }
  583. &__badge {
  584. font-size: 10px;
  585. font-weight: 700;
  586. padding: 2px 6px;
  587. border-radius: 4px;
  588. &--new {
  589. background: #FEF3C7;
  590. color: #D97706;
  591. }
  592. }
  593. &__arrow {
  594. color: $text-muted;
  595. font-size: 18px;
  596. }
  597. &--danger {
  598. justify-content: center;
  599. border-bottom: none;
  600. }
  601. }
  602. // Promotion tools card
  603. .promo-card {
  604. margin: 0 16px 14px;
  605. background: #FFFBEB;
  606. border: 1px solid #FDE68A;
  607. border-radius: 10px;
  608. overflow: hidden;
  609. &__code-area {
  610. display: flex;
  611. align-items: center;
  612. justify-content: center;
  613. gap: 10px;
  614. padding: 14px 16px 8px;
  615. }
  616. &__prefix {
  617. font-size: 13px;
  618. color: $text-secondary;
  619. }
  620. &__code {
  621. font-size: 22px;
  622. font-weight: 700;
  623. color: $blue-dark;
  624. letter-spacing: 3px;
  625. font-family: monospace;
  626. }
  627. &__actions {
  628. display: flex;
  629. align-items: center;
  630. justify-content: center;
  631. gap: 10px;
  632. padding: 6px 16px 14px;
  633. }
  634. &__btn {
  635. font-size: 12px;
  636. color: $blue-dark;
  637. font-weight: 500;
  638. cursor: pointer;
  639. }
  640. &__divider {
  641. color: #D1D5DB;
  642. font-size: 12px;
  643. }
  644. }
  645. </style>