index.vue 18 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748
  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. <!-- Distribution panel (paid users only) -->
  128. <view v-if="userStore.isLoggedIn && userStore.isVip" class="menu-item" @click="goCommission">
  129. <text class="menu-item__label">💰 我的推广</text>
  130. <text class="menu-item__arrow">›</text>
  131. </view>
  132. <!-- Practitioner workbench (practitioners only) — EPIC 9 -->
  133. <view v-if="userStore.vipType === 'practitioner' && userStore.isVip" class="menu-item" @click="goWorkbench">
  134. <text class="menu-item__label">🔧 工作台</text>
  135. <view class="menu-item__badge menu-item__badge--new">NEW</view>
  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 } from 'vue'
  178. import { onShow } from '@dcloudio/uni-app'
  179. import { useUserStore } from '@/stores/user'
  180. const userStore = useUserStore()
  181. // US-4.3: Renewal reminder if expiry within 7 days
  182. const isExpiringSoon = computed(() => {
  183. if (!userStore.vipEndTime) return false
  184. const expiry = new Date(userStore.vipEndTime)
  185. const now = new Date()
  186. const diffHours = (expiry - now) / (1000 * 60 * 60)
  187. return diffHours > 0 && diffHours <= 7 * 24
  188. })
  189. // US-4.3: Expired check
  190. const isExpired = computed(() => {
  191. if (!userStore.vipEndTime) return false
  192. return new Date(userStore.vipEndTime) < new Date()
  193. })
  194. function formatDate(dateStr) {
  195. if (!dateStr) return ''
  196. return dateStr.slice(0, 10)
  197. }
  198. onShow(() => {
  199. if (userStore.isLoggedIn) {
  200. userStore.fetchProfile()
  201. userStore.fetchQuota()
  202. userStore.fetchCommissionSummary()
  203. }
  204. })
  205. function goLogin() {
  206. uni.navigateTo({ url: '/pages/login/index' })
  207. }
  208. function goEditProfile() {
  209. if (!userStore.isLoggedIn) {
  210. uni.navigateTo({ url: '/pages/login/index' })
  211. return
  212. }
  213. uni.navigateTo({ url: '/pages/profile/edit' })
  214. }
  215. function goPayment() {
  216. uni.navigateTo({ url: '/pages/payment/index?product=annual' })
  217. }
  218. function goRenew() {
  219. const product = userStore.vipType === 'practitioner' ? 'practitioner' : 'annual'
  220. uni.navigateTo({ url: `/pages/payment/index?product=${product}` })
  221. }
  222. function goUpgradePractitioner() {
  223. uni.navigateTo({ url: '/pages/payment/index?product=practitioner' })
  224. }
  225. function goRecords() {
  226. uni.switchTab({ url: '/pages/records/index' })
  227. }
  228. function goCommission() {
  229. if (!userStore.isLoggedIn) {
  230. uni.navigateTo({ url: '/pages/login/index' })
  231. return
  232. }
  233. uni.navigateTo({ url: '/pages/commission/index' })
  234. }
  235. // EPIC 9: Navigate to practitioner workbench
  236. function goWorkbench() {
  237. uni.navigateTo({ url: '/pages/plan/workbench' })
  238. }
  239. function copyReferral() {
  240. if (userStore.referralCode) {
  241. uni.setClipboardData({
  242. data: userStore.referralCode,
  243. success: () => uni.showToast({ title: '已复制推广码', icon: 'success' })
  244. })
  245. }
  246. }
  247. function generatePoster() {
  248. uni.showToast({ title: '海报生成中…', icon: 'none' })
  249. // US-6.5: Backend generates poster with mini-program code
  250. }
  251. function goTags() {
  252. uni.navigateTo({ url: '/pages/tags/index' })
  253. }
  254. function goAbout() {
  255. uni.navigateTo({ url: '/pages/about/index' })
  256. }
  257. function handleLogout() {
  258. uni.showModal({
  259. title: '确认退出',
  260. content: '确定要退出登录吗?',
  261. success: (res) => {
  262. if (res.confirm) {
  263. userStore.logout()
  264. uni.showToast({ title: '已退出', icon: 'success' })
  265. }
  266. }
  267. })
  268. }
  269. </script>
  270. <style scoped lang="scss">
  271. // Brand colors (aligned with style-guide.md)
  272. $blue-dark: #1E3A5F;
  273. $gold: #C9A84C;
  274. $gold-light: #F8F0D8;
  275. $warm-white: #F8F6F1;
  276. $white: #FFFFFF;
  277. $text-primary: #1F2937;
  278. $text-secondary: #6B7280;
  279. $text-muted: #9CA3AF;
  280. $danger: #EF4444;
  281. .page-profile {
  282. padding: 16px;
  283. min-height: 100vh;
  284. background: $warm-white;
  285. }
  286. // ========== Region 1: User Card ==========
  287. .user-card {
  288. background: linear-gradient(135deg, $blue-dark, darken($blue-dark, 6%));
  289. border-radius: 16px;
  290. padding: 32px 20px 28px;
  291. margin-bottom: 16px;
  292. text-align: center;
  293. &__login {
  294. cursor: pointer;
  295. }
  296. &__logged {
  297. display: flex;
  298. flex-direction: column;
  299. align-items: center;
  300. }
  301. &__nickname {
  302. font-size: 18px;
  303. font-weight: 600;
  304. color: $white;
  305. display: block;
  306. margin-top: 12px;
  307. }
  308. &__login-hint {
  309. font-size: 12px;
  310. color: rgba(255, 255, 255, 0.7);
  311. display: block;
  312. margin-top: 4px;
  313. }
  314. &__tag {
  315. display: inline-flex;
  316. padding: 3px 14px;
  317. border-radius: 20px;
  318. font-size: 12px;
  319. margin-top: 8px;
  320. &--practitioner {
  321. background: $gold;
  322. color: $blue-dark;
  323. font-weight: 600;
  324. }
  325. &--annual {
  326. background: rgba($gold, 0.25);
  327. color: $gold;
  328. }
  329. &--normal {
  330. background: rgba(255, 255, 255, 0.15);
  331. color: rgba(255, 255, 255, 0.8);
  332. }
  333. }
  334. &__summary {
  335. font-size: 12px;
  336. color: rgba(255, 255, 255, 0.55);
  337. margin-top: 6px;
  338. }
  339. }
  340. // Avatar
  341. .avatar {
  342. width: 68px;
  343. height: 68px;
  344. border-radius: 50%;
  345. overflow: visible;
  346. position: relative;
  347. margin: 0 auto;
  348. image {
  349. width: 100%;
  350. height: 100%;
  351. border-radius: 50%;
  352. border: 2px solid rgba(255, 255, 255, 0.3);
  353. }
  354. &--empty {
  355. background: rgba(255, 255, 255, 0.12);
  356. display: flex;
  357. align-items: center;
  358. justify-content: center;
  359. border: 2px dashed rgba(255, 255, 255, 0.25);
  360. }
  361. &__icon {
  362. font-size: 28px;
  363. color: rgba(255, 255, 255, 0.5);
  364. }
  365. &__edit {
  366. position: absolute;
  367. right: -2px;
  368. bottom: -2px;
  369. width: 24px;
  370. height: 24px;
  371. border-radius: 50%;
  372. background: $gold;
  373. display: flex;
  374. align-items: center;
  375. justify-content: center;
  376. z-index: 1;
  377. cursor: pointer;
  378. &-icon {
  379. font-size: 12px;
  380. color: $blue-dark;
  381. font-weight: 700;
  382. }
  383. }
  384. }
  385. // ========== Region 2: Membership Status ==========
  386. // Banners
  387. .banner {
  388. display: flex;
  389. align-items: center;
  390. justify-content: space-between;
  391. padding: 10px 14px;
  392. border-radius: 10px;
  393. margin-bottom: 12px;
  394. background: #FEF3C7;
  395. border: 1px solid #FDE68A;
  396. &--warning {
  397. background: #FEF3C7;
  398. border-color: #FDE68A;
  399. }
  400. &__text {
  401. font-size: 13px;
  402. color: #92400E;
  403. flex: 1;
  404. }
  405. &__arrow {
  406. font-size: 18px;
  407. color: #92400E;
  408. margin-left: 8px;
  409. }
  410. }
  411. // Seed-price badge
  412. .seed-badge {
  413. display: flex;
  414. align-items: center;
  415. justify-content: center;
  416. padding: 6px 14px;
  417. border-radius: 8px;
  418. margin-bottom: 12px;
  419. background: $gold-light;
  420. border: 1px solid $gold;
  421. &__text {
  422. font-size: 12px;
  423. color: $blue-dark;
  424. font-weight: 500;
  425. }
  426. }
  427. // VIP status card
  428. .vip-card {
  429. border-radius: 12px;
  430. padding: 16px;
  431. display: flex;
  432. justify-content: space-between;
  433. align-items: center;
  434. margin-bottom: 16px;
  435. &__body {
  436. flex: 1;
  437. }
  438. &__title {
  439. font-weight: 600;
  440. font-size: 16px;
  441. display: block;
  442. }
  443. &__desc {
  444. font-size: 12px;
  445. opacity: 0.8;
  446. display: block;
  447. margin-top: 4px;
  448. }
  449. &__action {
  450. font-size: 14px;
  451. font-weight: 500;
  452. padding: 6px 14px;
  453. border-radius: 8px;
  454. white-space: nowrap;
  455. cursor: pointer;
  456. }
  457. // Practitioner
  458. &--practitioner {
  459. background: linear-gradient(135deg, #7c3aed, #6d28d9);
  460. .vip-card__title, .vip-card__desc { color: #fff; }
  461. .vip-card__action {
  462. color: #7c3aed;
  463. background: rgba(255, 255, 255, 0.95);
  464. }
  465. }
  466. // Annual
  467. &--annual {
  468. background: linear-gradient(135deg, #f59e0b, #d97706);
  469. .vip-card__title, .vip-card__desc { color: #fff; }
  470. .vip-card__action {
  471. color: #d97706;
  472. background: rgba(255, 255, 255, 0.95);
  473. }
  474. }
  475. // Expired
  476. &--expired {
  477. background: #E5E7EB;
  478. .vip-card__title { color: $text-secondary; }
  479. .vip-card__desc { color: $text-muted; }
  480. .vip-card__action {
  481. color: $text-secondary;
  482. background: $white;
  483. }
  484. }
  485. // Upsell (free user)
  486. &--upsell {
  487. background: linear-gradient(135deg, $blue-dark, darken($blue-dark, 4%));
  488. flex-direction: column;
  489. align-items: flex-start;
  490. gap: 14px;
  491. .vip-card__title {
  492. color: $gold;
  493. font-size: 16px;
  494. }
  495. & .vip-card__benefits {
  496. display: flex;
  497. flex-direction: column;
  498. gap: 4px;
  499. margin-top: 8px;
  500. }
  501. .vip-card__benefit {
  502. color: rgba(255, 255, 255, 0.8);
  503. font-size: 13px;
  504. }
  505. .vip-card__cta {
  506. align-self: stretch;
  507. text-align: center;
  508. background: $gold;
  509. color: $blue-dark;
  510. font-weight: 600;
  511. font-size: 15px;
  512. padding: 12px;
  513. border-radius: 10px;
  514. cursor: pointer;
  515. }
  516. }
  517. }
  518. // Daily quota
  519. .quota-bar {
  520. background: $white;
  521. border-radius: 12px;
  522. padding: 16px;
  523. margin-bottom: 16px;
  524. display: flex;
  525. align-items: center;
  526. justify-content: space-around;
  527. &__item {
  528. text-align: center;
  529. }
  530. &__label {
  531. font-size: 12px;
  532. color: $text-secondary;
  533. display: block;
  534. margin-bottom: 4px;
  535. }
  536. &__value {
  537. font-size: 20px;
  538. font-weight: 700;
  539. color: $text-primary;
  540. }
  541. &__divider {
  542. width: 1px;
  543. height: 36px;
  544. background: #E5E7EB;
  545. }
  546. }
  547. // ========== Region 3: Feature Menu ==========
  548. .menu-section {
  549. background: $white;
  550. border-radius: 12px;
  551. margin-bottom: 16px;
  552. overflow: hidden;
  553. &__header {
  554. font-size: 12px;
  555. font-weight: 600;
  556. color: $text-muted;
  557. text-transform: uppercase;
  558. letter-spacing: 0.5px;
  559. padding: 14px 16px 6px;
  560. }
  561. }
  562. .menu-item {
  563. display: flex;
  564. align-items: center;
  565. gap: 8px;
  566. padding: 14px 16px;
  567. border-bottom: 1px solid #F3F4F6;
  568. cursor: pointer;
  569. transition: background 0.15s;
  570. &:active {
  571. background: #F9FAFB;
  572. }
  573. &:last-child {
  574. border-bottom: none;
  575. }
  576. &__label {
  577. flex: 1;
  578. font-size: 15px;
  579. color: $text-primary;
  580. &--danger {
  581. color: $danger;
  582. }
  583. }
  584. &__badge {
  585. font-size: 10px;
  586. font-weight: 700;
  587. padding: 2px 6px;
  588. border-radius: 4px;
  589. &--new {
  590. background: #FEF3C7;
  591. color: #D97706;
  592. }
  593. }
  594. &__arrow {
  595. color: $text-muted;
  596. font-size: 18px;
  597. }
  598. &--danger {
  599. justify-content: center;
  600. border-bottom: none;
  601. }
  602. }
  603. // Promotion tools card
  604. .promo-card {
  605. margin: 0 16px 14px;
  606. background: #FFFBEB;
  607. border: 1px solid #FDE68A;
  608. border-radius: 10px;
  609. overflow: hidden;
  610. &__code-area {
  611. display: flex;
  612. align-items: center;
  613. justify-content: center;
  614. gap: 10px;
  615. padding: 14px 16px 8px;
  616. }
  617. &__prefix {
  618. font-size: 13px;
  619. color: $text-secondary;
  620. }
  621. &__code {
  622. font-size: 22px;
  623. font-weight: 700;
  624. color: $blue-dark;
  625. letter-spacing: 3px;
  626. font-family: monospace;
  627. }
  628. &__actions {
  629. display: flex;
  630. align-items: center;
  631. justify-content: center;
  632. gap: 10px;
  633. padding: 6px 16px 14px;
  634. }
  635. &__btn {
  636. font-size: 12px;
  637. color: $blue-dark;
  638. font-weight: 500;
  639. cursor: pointer;
  640. }
  641. &__divider {
  642. color: #D1D5DB;
  643. font-size: 12px;
  644. }
  645. }
  646. </style>