index.vue 34 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241
  1. <template>
  2. <view class="page-chart">
  3. <!-- Triangle chart -->
  4. <view class="chart-section">
  5. <TriangleChart
  6. :chartData="store.currentChart"
  7. :birthYear="store.currentBirthYear"
  8. :birthMonth="store.currentBirthMonth"
  9. :birthDay="store.currentBirthDay"
  10. :recordId="store.currentRecordId"
  11. :annotations="annotations"
  12. :tags="allTags"
  13. @annotation-add="onAnnotationAdd"
  14. @annotation-delete="onAnnotationDelete"
  15. @tag-create="onTagCreate"
  16. />
  17. </view>
  18. <!-- Menu button (regenerate + share info) -->
  19. <view class="menu-bar">
  20. <text class="menu-btn" @click="showMenu">···</text>
  21. </view>
  22. <!-- US-3.1: AI Interpretation section -->
  23. <view class="interpret-bar">
  24. <button class="interpret-btn" :disabled="interpreting" @click="fetchInterpret">
  25. {{ interpreting ? '解读生成中...' : '🔮 查看AI解读' }}
  26. </button>
  27. </view>
  28. <!-- US-3.1: Interpretation panel -->
  29. <view v-if="interpretData" id="interpret-section" class="interpret-panel">
  30. <view
  31. v-for="(section, key) in interpretData"
  32. :key="key"
  33. class="interpret-card"
  34. :class="{ expanded: interpretExpanded[key] }"
  35. @click="toggleInterpretSection(key)"
  36. >
  37. <view class="interpret-card-header">
  38. <text class="interpret-num-badge">{{ section.number }}</text>
  39. <text class="interpret-card-title">{{ section.title }}</text>
  40. <text class="interpret-toggle">{{ interpretExpanded[key] ? '▾' : '▸' }}</text>
  41. </view>
  42. <view v-show="interpretExpanded[key]" class="interpret-card-body">
  43. <text class="interpret-content">{{ section.content }}</text>
  44. </view>
  45. </view>
  46. <!-- Disclaimer -->
  47. <view class="interpret-disclaimer">
  48. <text class="disclaimer-text">本解读由AI生成,仅供参考</text>
  49. </view>
  50. </view>
  51. <!-- Loading skeleton -->
  52. <view v-if="interpreting" class="interpret-skeleton">
  53. <view v-for="n in 4" :key="n" class="skeleton-card">
  54. <view class="skeleton-header"></view>
  55. <view v-if="n === 1" class="skeleton-body">
  56. <view class="skeleton-line"></view>
  57. <view class="skeleton-line short"></view>
  58. <view class="skeleton-line"></view>
  59. </view>
  60. </view>
  61. </view>
  62. <!-- US-9.1: Academic orientation button -->
  63. <view class="academic-bar">
  64. <button class="academic-btn" :disabled="academicLoading" @click="fetchAcademicOrientation">
  65. {{ academicLoading ? '分析生成中...' : '🎓 学业方向分析' }}
  66. </button>
  67. <text v-if="!userStore.isVipActive && maxAcademic > 0" class="academic-quota">
  68. 今日 {{ usedAcademic }}/{{ maxAcademic }} 次
  69. </text>
  70. </view>
  71. <!-- US-9.1: Academic orientation panel -->
  72. <view v-if="academicData" id="academic-section" class="academic-panel">
  73. <view class="academic-section-title">🎯 学业方向深度分析</view>
  74. <view
  75. v-for="(section, key) in academicData"
  76. :key="key"
  77. class="academic-card"
  78. :class="{ expanded: academicExpanded[key], talent: key==='talentTendency', direction: key==='suitableDirection', learning: key==='learningStyle', parenting: key==='parentingAdvice', periods: key==='keyPeriods' }"
  79. @click="toggleAcademicSection(key)"
  80. >
  81. <view class="academic-card-header">
  82. <text class="academic-card-title">{{ section.title }}</text>
  83. <text class="academic-toggle">{{ academicExpanded[key] ? '▾' : '▸' }}</text>
  84. </view>
  85. <view v-show="academicExpanded[key]" class="academic-card-body">
  86. <text class="academic-content">{{ section.content }}</text>
  87. <view v-if="section.matchPercentages" class="match-bars">
  88. <view v-for="(pct, dir) in section.matchPercentages" :key="dir" class="match-row">
  89. <text class="match-label">{{ dir }}</text>
  90. <view class="match-track">
  91. <view class="match-fill" :style="{ width: pct + '%' }" :class="'pct-' + pct"></view>
  92. </view>
  93. <text class="match-value">{{ pct }}%</text>
  94. </view>
  95. </view>
  96. </view>
  97. </view>
  98. <view class="academic-disclaimer">
  99. <text class="disclaimer-text">💡 以上分析由AI生成,如需人工深度方案,可申请能量师出方案</text>
  100. </view>
  101. </view>
  102. <!-- US-9.1: Loading skeleton -->
  103. <view v-if="academicLoading" class="academic-skeleton">
  104. <view v-for="n in 3" :key="n" class="skeleton-card">
  105. <view class="skeleton-header"></view>
  106. <view v-if="n === 1" class="skeleton-body">
  107. <view class="skeleton-line"></view><view class="skeleton-line short"></view><view class="skeleton-line"></view>
  108. </view>
  109. </view>
  110. </view>
  111. <!-- US-9.1: Academic quota exceeded upgrade card -->
  112. <view v-if="quotaAcademicExceeded && !academicData && !academicLoading" class="academic-upgrade-card">
  113. <text class="academic-upgrade-title">🎓 学业方向分析</text>
  114. <text class="academic-upgrade-desc">今日学业分析次数已用完,开通会员享无限次</text>
  115. <button class="academic-upgrade-btn" @click="goSubscribeC">开通会员 ¥131/年</button>
  116. </view>
  117. <!-- AI Chat -->
  118. <view class="chat-section">
  119. <view class="section-title">
  120. <text class="title-icon">◈</text>
  121. AI 解读
  122. <text v-if="!userStore.isVipActive && maxChats > 0" class="quota-badge">
  123. 今日 {{ usedChats }}/{{ maxChats }} 轮
  124. </text>
  125. <text v-if="userStore.isVipActive" class="quota-badge vip">无限次</text>
  126. </view>
  127. <scroll-view class="chat-box" scroll-y :scroll-top="scrollTop">
  128. <view v-for="(msg, idx) in messages" :key="idx" class="msg-row" :class="msg.role">
  129. <view class="msg-bubble">
  130. <text>{{ msg.content }}</text>
  131. </view>
  132. </view>
  133. </scroll-view>
  134. <!-- Quota exceeded prompt for non-VIP -->
  135. <view v-if="quotaExceeded" class="upgrade-prompt">
  136. <text class="upgrade-text">今日 AI 解读次数已用完</text>
  137. <text class="upgrade-desc">选择适合的会员方案,解锁无限次解读</text>
  138. <view class="upgrade-actions">
  139. <button class="upgrade-btn secondary" @click="goSubscribeC">C端会员 ¥131/年</button>
  140. <button class="upgrade-btn" @click="goSubscribe">能量师 ¥1,314/年</button>
  141. </view>
  142. </view>
  143. <!-- Share hint (non-intrusive) -->
  144. <view v-if="shareRemaining > 0 && !userStore.isVipActive" class="share-hint">
  145. <text class="share-hint-text">分享好友可解锁更多次数 · 今日剩余 {{ shareRemaining }} 次</text>
  146. </view>
  147. <!-- Input area — always visible, shows upgrade prompt on 4th click -->
  148. <view class="input-bar">
  149. <input
  150. class="chat-input"
  151. v-model="chatInput"
  152. :placeholder="quotaExceeded ? '今日次数已用完,点击发送开通会员' : '输入您的问题...'"
  153. @confirm="sendQuestion(chatInput)"
  154. :disabled="loading"
  155. />
  156. <button class="send-btn" @click="sendQuestion(chatInput)" :disabled="loading">
  157. {{ loading ? '···' : '发送' }}
  158. </button>
  159. </view>
  160. <!-- US-6.6: Subscription card for free users / 已开通 badge for paid -->
  161. <view v-if="userStore.isLoggedIn" class="subscribe-section">
  162. <!-- Annual paid user — always show badge -->
  163. <view v-if="userStore.vipType === 'annual'" class="vip-badge-bar">
  164. <text class="vip-badge-text">✅ 已开通AI解读</text>
  165. <text class="vip-badge-expiry" v-if="userStore.vipEndTime">有效期至 {{ userStore.vipEndTime.slice(0, 10) }}</text>
  166. <text class="vip-poster-link" @click="goPoster">📱 生成推广海报</text>
  167. </view>
  168. <!-- Practitioner paid user — always show badge -->
  169. <view v-else-if="userStore.vipType === 'practitioner'" class="vip-badge-bar pro">
  170. <text class="vip-badge-text">✅ 已开通能量师</text>
  171. <text class="vip-badge-expiry" v-if="userStore.vipEndTime">有效期至 {{ userStore.vipEndTime.slice(0, 10) }}</text>
  172. </view>
  173. <!-- Free user — subscription card only when quota exceeded -->
  174. <view v-else-if="quotaExceeded" class="subscribe-card">
  175. <text class="subscribe-title">🔮 AI解读会员</text>
  176. <text class="subscribe-desc">¥131/年 · 无限AI解读 · 个性化报告 · 推广赚佣金</text>
  177. <view class="subscribe-actions">
  178. <button class="subscribe-btn" @click="goSubscribeC">立即开通 ¥131</button>
  179. <text class="subscribe-link" @click="goSubscribe">了解能量师专业版</text>
  180. </view>
  181. </view>
  182. </view>
  183. </view>
  184. </view>
  185. </template>
  186. <script>
  187. // Page lifecycle hooks (needed for WeChat share)
  188. export default {
  189. onShareAppMessage() {
  190. const pages = getCurrentPages()
  191. const page = pages[pages.length - 1]
  192. const recordId = page?.options?.recordId || ''
  193. const store = this.$scope?.store
  194. const title = store?.currentChart?.O
  195. ? `我的命盘主性格数字是${store.currentChart.O},快来测测你的!`
  196. : '数字能量命盘分析'
  197. return {
  198. title,
  199. path: `/pages/chart/index?recordId=${recordId}`,
  200. imageUrl: '/static/share-card.png'
  201. }
  202. },
  203. onShareTimeline() {
  204. const pages = getCurrentPages()
  205. const page = pages[pages.length - 1]
  206. const recordId = page?.options?.recordId || ''
  207. return {
  208. title: '数字能量命盘分析',
  209. query: `recordId=${recordId}`,
  210. imageUrl: '/static/share-card.png'
  211. }
  212. }
  213. }
  214. </script>
  215. <script setup>
  216. import { ref, computed, onMounted } from 'vue'
  217. import { useChartStore } from '@/stores/chart'
  218. import { useUserStore } from '@/stores/user'
  219. import TriangleChart from '@/components/TriangleChart.vue'
  220. import { chartApi, chatApi, consultationApi, profileApi, annotationApi, exportApi } from '@/utils/api'
  221. const store = useChartStore()
  222. const userStore = useUserStore()
  223. const chatInput = ref('')
  224. const scrollTop = ref(0)
  225. const messages = ref([])
  226. const loading = ref(false)
  227. const usedChats = ref(0)
  228. const maxChats = ref(0)
  229. const shareCount = ref(0)
  230. const shareLimit = ref(0)
  231. const usedAcademic = ref(0)
  232. const maxAcademic = ref(0)
  233. // Annotation / Tag state (US-7.1 / US-7.2)
  234. const annotations = ref([])
  235. const allTags = ref([])
  236. // US-3.1: AI interpretation state
  237. const interpretData = ref(null)
  238. const interpreting = ref(false)
  239. const interpretExpanded = ref({})
  240. // US-9.1: Academic orientation state
  241. const academicData = ref(null)
  242. const academicLoading = ref(false)
  243. const academicExpanded = ref({})
  244. const quotaExceeded = computed(() => {
  245. if (userStore.isVipActive) return false
  246. return maxChats.value > 0 && usedChats.value >= maxChats.value
  247. })
  248. const shareRemaining = computed(() => {
  249. if (userStore.isVipActive) return -1
  250. if (shareLimit.value <= 0) return 0
  251. return Math.max(0, shareLimit.value - shareCount.value)
  252. })
  253. const quotaAcademicExceeded = computed(() => {
  254. if (userStore.isVipActive) return false
  255. return maxAcademic.value > 0 && usedAcademic.value >= maxAcademic.value
  256. })
  257. onMounted(async () => {
  258. try {
  259. await userStore.fetchQuota()
  260. } catch (e) { /* ignore */ }
  261. // URL shareability — load from recordId if no store state (US-1.1 §14)
  262. const pages = getCurrentPages()
  263. const currentPage = pages[pages.length - 1]
  264. const recordId = currentPage?.options?.recordId
  265. if (!store.currentChart && recordId) {
  266. try {
  267. await store.loadChart(Number(recordId))
  268. } catch (e) {
  269. // fall through to "no data" message
  270. }
  271. }
  272. if (store.currentChart) {
  273. maxChats.value = userStore.maxChats || 3
  274. usedChats.value = userStore.usedChats || 0
  275. shareCount.value = userStore.shareCount || 0
  276. shareLimit.value = userStore.shareLimit || 1
  277. usedAcademic.value = userStore.usedAcademic || 0
  278. maxAcademic.value = userStore.maxAcademic || 1
  279. // Load annotations and tags for this record (US-7.1/7.2)
  280. if (store.currentRecordId) {
  281. loadAnnotations()
  282. }
  283. // Use consultationMessages from store (set during startConsultation) if available
  284. if (store.consultationMessages && store.consultationMessages.length > 0) {
  285. messages.value = store.consultationMessages.map(m => ({
  286. role: m.role === 'ai' ? 'ai' : 'user',
  287. content: m.content
  288. }))
  289. } else if (store.currentRecordId) {
  290. try {
  291. const history = await chatApi.history(store.currentRecordId)
  292. messages.value = history.map(m => ({
  293. role: m.role === 'ai' ? 'ai' : 'user',
  294. content: m.content
  295. }))
  296. const userMsgCount = history.filter(m => m.role === 'user').length
  297. usedChats.value = Math.max(usedChats.value, userMsgCount)
  298. } catch (e) {
  299. // fallback to generic greeting
  300. }
  301. }
  302. // Ensure at least a greeting message if still empty
  303. if (messages.value.length === 0) {
  304. messages.value = [{
  305. role: 'ai',
  306. content: `已为您生成命盘。主性格数字为${store.currentChart.O}。请点击下方问题或输入您想了解的内容。`
  307. }]
  308. }
  309. } else {
  310. messages.value = [{
  311. role: 'ai',
  312. content: '暂无命盘数据,请先返回首页输入出生信息。'
  313. }]
  314. }
  315. })
  316. // US-3.1: Fetch AI structured interpretation
  317. async function fetchInterpret() {
  318. if (!store.currentRecordId) {
  319. uni.showToast({ title: '暂无命盘数据', icon: 'none' })
  320. return
  321. }
  322. // If already loaded, just scroll to it
  323. if (interpretData.value) {
  324. scrollToInterpret()
  325. return
  326. }
  327. interpreting.value = true
  328. try {
  329. const data = await chartApi.interpret(store.currentRecordId)
  330. interpretData.value = data
  331. // Auto-expand the main character section
  332. interpretExpanded.value = { mainCharacter: true }
  333. uni.showToast({ title: '解读已生成', icon: 'success' })
  334. scrollToInterpret()
  335. } catch (e) {
  336. uni.showToast({ title: e.message || '解读生成失败', icon: 'none' })
  337. } finally {
  338. interpreting.value = false
  339. }
  340. }
  341. function scrollToInterpret() {
  342. // Scroll to the interpret section after rendering
  343. uni.createSelectorQuery().select('#interpret-section').boundingClientRect(res => {
  344. if (res) {
  345. uni.pageScrollTo({ scrollTop: res.top - 20, duration: 300 })
  346. }
  347. }).exec()
  348. }
  349. function toggleInterpretSection(key) {
  350. interpretExpanded.value[key] = !interpretExpanded.value[key]
  351. }
  352. // US-9.1: Fetch academic orientation
  353. async function fetchAcademicOrientation() {
  354. if (!store.currentRecordId) {
  355. uni.showToast({ title: '暂无命盘数据', icon: 'none' })
  356. return
  357. }
  358. if (academicData.value) {
  359. scrollToAcademic()
  360. return
  361. }
  362. if (quotaAcademicExceeded.value) {
  363. uni.showToast({ title: '今日学业分析次数已用完', icon: 'none' })
  364. return
  365. }
  366. academicLoading.value = true
  367. try {
  368. const data = await chartApi.academicOrientation(store.currentRecordId)
  369. academicData.value = data
  370. academicExpanded.value = { talentTendency: true }
  371. usedAcademic.value++
  372. userStore.usedAcademic = usedAcademic.value
  373. uni.showToast({ title: '分析已生成', icon: 'success' })
  374. scrollToAcademic()
  375. } catch (e) {
  376. if (e.code === 1008) {
  377. usedAcademic.value = maxAcademic.value
  378. userStore.usedAcademic = maxAcademic.value
  379. }
  380. uni.showToast({ title: e.message || '分析生成失败', icon: 'none' })
  381. } finally {
  382. academicLoading.value = false
  383. }
  384. }
  385. function scrollToAcademic() {
  386. uni.createSelectorQuery().select('#academic-section').boundingClientRect(res => {
  387. if (res) uni.pageScrollTo({ scrollTop: res.top - 20, duration: 300 })
  388. }).exec()
  389. }
  390. function toggleAcademicSection(key) {
  391. academicExpanded.value[key] = !academicExpanded.value[key]
  392. }
  393. async function sendQuestion(q) {
  394. if (!q.trim() || loading.value) return
  395. if (quotaExceeded.value) {
  396. // Show upgrade prompt instead of sending
  397. uni.showModal({
  398. title: '今日解读次数已用完',
  399. content: '开通 VIP 会员享无限次 AI 解读,或分享好友获取额外次数',
  400. confirmText: '开通会员',
  401. cancelText: '分享好友',
  402. success: (res) => {
  403. if (res.confirm) {
  404. goSubscribeC()
  405. } else {
  406. triggerShare()
  407. }
  408. }
  409. })
  410. return
  411. }
  412. messages.value.push({ role: 'user', content: q })
  413. chatInput.value = ''
  414. loading.value = true
  415. try {
  416. if (store.currentRecordId) {
  417. const res = await chatApi.send({ chartRecordId: store.currentRecordId, query: q })
  418. messages.value.push({ role: 'ai', content: res.reply })
  419. usedChats.value++
  420. } else {
  421. messages.value.push({
  422. role: 'ai',
  423. content: `数字能量分析显示,${q}方面您的能量组合表明有良好的发展潜力,请结合自身情况理性决策。`
  424. })
  425. }
  426. } catch (e) {
  427. if (e.code === 1008) {
  428. usedChats.value = maxChats.value
  429. messages.value.push({
  430. role: 'ai',
  431. content: '今日解读次数已用完,开通会员可享无限次解读。'
  432. })
  433. } else {
  434. messages.value.push({
  435. role: 'ai',
  436. content: e.message || '解读服务暂时不可用,请稍后再试。'
  437. })
  438. }
  439. }
  440. loading.value = false
  441. scrollTop.value = 99999
  442. }
  443. // US-3.3: Regenerate interpretation via action sheet menu
  444. function showMenu() {
  445. const items = ['🔄 重新生成解读']
  446. // US-2.2: PDF export for paid users only
  447. if (userStore.isVipActive) {
  448. items.push('📄 导出 PDF')
  449. }
  450. if (!userStore.isVipActive && shareRemaining.value > 0) {
  451. items.push('📤 分享给好友')
  452. }
  453. items.push('❌ 取消')
  454. uni.showActionSheet({
  455. itemList: items,
  456. success: async (res) => {
  457. if (res.tapIndex === 0) {
  458. await confirmRegenerate()
  459. } else if (res.tapIndex === 1) {
  460. if (items[1] === '📄 导出 PDF') {
  461. await exportPdf()
  462. } else if (items[1] === '📤 分享给好友') {
  463. await triggerShare()
  464. }
  465. } else if (res.tapIndex === 2 && items[2] === '📤 分享给好友') {
  466. await triggerShare()
  467. }
  468. }
  469. })
  470. }
  471. async function confirmRegenerate() {
  472. uni.showModal({
  473. title: '重新生成解读',
  474. content: '将清除当前对话记录并生成全新的AI解读,确定吗?',
  475. success: async (confirm) => {
  476. if (!confirm.confirm) return
  477. if (!store.currentRecordId) {
  478. uni.showToast({ title: '暂无命盘数据', icon: 'none' })
  479. return
  480. }
  481. try {
  482. uni.showLoading({ title: '重新生成中...' })
  483. const newMessages = await consultationApi.regenerate(store.currentRecordId)
  484. messages.value = (newMessages || []).map(m => ({
  485. role: m.role === 'ai' ? 'ai' : 'user',
  486. content: m.content
  487. }))
  488. // Reset chat counters
  489. usedChats.value = 0
  490. uni.hideLoading()
  491. uni.showToast({ title: '解读已重新生成', icon: 'success' })
  492. scrollTop.value = 99999
  493. } catch (e) {
  494. uni.hideLoading()
  495. uni.showToast({ title: '重新生成失败,请重试', icon: 'none' })
  496. }
  497. }
  498. })
  499. }
  500. // US-2.1: Track share and update quota
  501. async function triggerShare() {
  502. uni.showShareMenu({
  503. withShareTicket: true,
  504. menus: ['shareAppMessage', 'shareTimeline'],
  505. success: async () => {
  506. // Call backend to track share
  507. try {
  508. const result = await profileApi.trackShare()
  509. shareCount.value = result.dailyShareCount || shareCount.value + 1
  510. } catch (e) { /* best-effort */ }
  511. }
  512. })
  513. }
  514. // US-2.2: Export PDF report
  515. async function exportPdf() {
  516. if (!store.currentRecordId) {
  517. uni.showToast({ title: '暂无命盘数据', icon: 'none' })
  518. return
  519. }
  520. uni.showLoading({ title: '正在生成 PDF...' })
  521. try {
  522. // The API returns a PDF binary. We use uni.downloadFile to get it as a temp file.
  523. const token = uni.getStorageSync('token')
  524. const url = 'http://127.0.0.1:8186/api/export/pdf'
  525. const downloadRes = await new Promise((resolve, reject) => {
  526. uni.downloadFile({
  527. url,
  528. header: { Authorization: `Bearer ${token}` },
  529. method: 'POST',
  530. data: { recordId: store.currentRecordId },
  531. success: resolve,
  532. fail: reject
  533. })
  534. })
  535. if (downloadRes.statusCode !== 200) {
  536. throw new Error('下载失败')
  537. }
  538. uni.hideLoading()
  539. // Open the PDF file
  540. uni.openDocument({
  541. filePath: downloadRes.tempFilePath,
  542. success: () => {
  543. uni.showToast({ title: 'PDF 已生成', icon: 'success' })
  544. },
  545. fail: () => {
  546. uni.showToast({ title: '打开文件失败', icon: 'none' })
  547. }
  548. })
  549. } catch (e) {
  550. uni.hideLoading()
  551. uni.showToast({ title: e.message || '导出失败', icon: 'none' })
  552. }
  553. }
  554. function goSubscribe() {
  555. uni.navigateTo({ url: '/pages/subscribe/index' })
  556. }
  557. function goSubscribeC() {
  558. uni.navigateTo({ url: '/pages/payment/index?product=annual' })
  559. }
  560. function goPoster() {
  561. uni.navigateTo({ url: '/pages/subscribe/index' })
  562. }
  563. // === Annotation / Tag handlers (US-7.1 / US-7.2) ===
  564. async function loadAnnotations() {
  565. if (!store.currentRecordId) return
  566. try {
  567. const [annoList, tagList] = await Promise.all([
  568. annotationApi.list(store.currentRecordId),
  569. annotationApi.listTags(store.currentRecordId)
  570. ])
  571. annotations.value = annoList || []
  572. allTags.value = tagList || []
  573. } catch (e) { /* best-effort */ }
  574. }
  575. async function onAnnotationAdd(data) {
  576. try {
  577. const saved = await annotationApi.add(data)
  578. // Reload annotations to include the new one with server-generated ID
  579. if (store.currentRecordId) {
  580. const annoList = await annotationApi.list(store.currentRecordId)
  581. annotations.value = annoList || []
  582. }
  583. uni.showToast({ title: '批注已保存', icon: 'success' })
  584. } catch (e) {
  585. uni.showToast({ title: '保存失败', icon: 'none' })
  586. }
  587. }
  588. async function onAnnotationDelete(annoId) {
  589. try {
  590. await annotationApi.delete(annoId)
  591. annotations.value = annotations.value.filter(a => a.id !== annoId)
  592. uni.showToast({ title: '批注已删除', icon: 'success' })
  593. } catch (e) {
  594. uni.showToast({ title: '删除失败', icon: 'none' })
  595. }
  596. }
  597. async function onTagCreate(tagData) {
  598. try {
  599. const saved = await annotationApi.addTag({ ...tagData, recordId: store.currentRecordId })
  600. if (store.currentRecordId) {
  601. const tagList = await annotationApi.listTags(store.currentRecordId)
  602. allTags.value = tagList || []
  603. }
  604. uni.showToast({ title: '标签已创建', icon: 'success' })
  605. } catch (e) {
  606. uni.showToast({ title: '创建失败', icon: 'none' })
  607. }
  608. }
  609. </script>
  610. <style scoped lang="scss">
  611. .page-chart {
  612. height: 100vh;
  613. display: flex;
  614. flex-direction: column;
  615. overflow: hidden;
  616. background: linear-gradient(180deg, #0c0a1a 0%, #120d28 50%, #0f0c1e 100%);
  617. }
  618. .chart-section {
  619. flex-shrink: 0;
  620. margin: 0 14px;
  621. }
  622. /* Menu bar — three-dot button */
  623. .menu-bar {
  624. display: flex;
  625. justify-content: flex-end;
  626. padding: 0 14px;
  627. margin: -8px 0 0;
  628. }
  629. .menu-btn {
  630. width: 32px;
  631. height: 28px;
  632. display: flex;
  633. align-items: center;
  634. justify-content: center;
  635. font-size: 20px;
  636. font-weight: 700;
  637. color: rgba(255, 255, 255, 0.4);
  638. letter-spacing: 2px;
  639. border-radius: 6px;
  640. background: rgba(255, 255, 255, 0.04);
  641. }
  642. .menu-btn:active {
  643. background: rgba(255, 255, 255, 0.08);
  644. }
  645. /* US-3.1: Interpret button bar */
  646. .interpret-bar {
  647. flex-shrink: 0;
  648. margin: 0 14px 10px;
  649. }
  650. .interpret-btn {
  651. width: 100%;
  652. height: 44px;
  653. background: linear-gradient(135deg, #7c3aed, #6366f1);
  654. color: #fff;
  655. border: none;
  656. border-radius: 12px;
  657. line-height: 44px;
  658. font-size: 15px;
  659. font-weight: 600;
  660. letter-spacing: 1px;
  661. }
  662. .interpret-btn[disabled] {
  663. opacity: 0.5;
  664. }
  665. /* Interpretation panel */
  666. .interpret-panel {
  667. flex-shrink: 0;
  668. margin: 0 14px 16px;
  669. }
  670. .interpret-card {
  671. background: rgba(124, 58, 237, 0.06);
  672. border: 1px solid rgba(124, 58, 237, 0.12);
  673. border-radius: 12px;
  674. margin-bottom: 10px;
  675. overflow: hidden;
  676. transition: border-color 0.2s;
  677. }
  678. .interpret-card.expanded {
  679. border-color: rgba(124, 58, 237, 0.25);
  680. background: rgba(124, 58, 237, 0.08);
  681. }
  682. .interpret-card-header {
  683. display: flex;
  684. align-items: center;
  685. padding: 12px 14px;
  686. gap: 10px;
  687. }
  688. .interpret-num-badge {
  689. width: 28px;
  690. height: 28px;
  691. border-radius: 50%;
  692. background: linear-gradient(135deg, #7c3aed, #6366f1);
  693. color: #fff;
  694. font-size: 13px;
  695. font-weight: 700;
  696. line-height: 28px;
  697. text-align: center;
  698. flex-shrink: 0;
  699. }
  700. .interpret-card-title {
  701. flex: 1;
  702. font-size: 14px;
  703. font-weight: 600;
  704. color: rgba(255, 255, 255, 0.85);
  705. }
  706. .interpret-toggle {
  707. font-size: 12px;
  708. color: rgba(255, 255, 255, 0.35);
  709. }
  710. .interpret-card-body {
  711. padding: 0 14px 14px 52px;
  712. }
  713. .interpret-content {
  714. display: block;
  715. font-size: 13px;
  716. line-height: 1.7;
  717. color: rgba(255, 255, 255, 0.65);
  718. white-space: pre-wrap;
  719. }
  720. /* Disclaimer */
  721. .interpret-disclaimer {
  722. text-align: center;
  723. padding: 6px 0 2px;
  724. }
  725. .disclaimer-text {
  726. font-size: 11px;
  727. color: rgba(255, 255, 255, 0.2);
  728. }
  729. /* Loading skeleton */
  730. .interpret-skeleton {
  731. flex-shrink: 0;
  732. margin: 0 14px 16px;
  733. }
  734. .skeleton-card {
  735. background: rgba(255, 255, 255, 0.03);
  736. border: 1px solid rgba(255, 255, 255, 0.05);
  737. border-radius: 12px;
  738. margin-bottom: 10px;
  739. overflow: hidden;
  740. }
  741. .skeleton-header {
  742. height: 24px;
  743. margin: 12px 14px;
  744. background: rgba(255, 255, 255, 0.06);
  745. border-radius: 6px;
  746. width: 60%;
  747. }
  748. .skeleton-body {
  749. padding: 0 14px 14px;
  750. }
  751. .skeleton-line {
  752. height: 12px;
  753. background: rgba(255, 255, 255, 0.04);
  754. border-radius: 4px;
  755. margin-bottom: 8px;
  756. }
  757. .skeleton-line.short {
  758. width: 70%;
  759. }
  760. /* US-9.1: Academic bar */
  761. .academic-bar {
  762. flex-shrink: 0;
  763. margin: 0 14px 10px;
  764. display: flex;
  765. gap: 8px;
  766. align-items: center;
  767. }
  768. .academic-btn {
  769. flex: 1;
  770. height: 44px;
  771. background: linear-gradient(135deg, #0891b2, #06b6d4);
  772. color: #fff;
  773. border: none;
  774. border-radius: 12px;
  775. line-height: 44px;
  776. font-size: 15px;
  777. font-weight: 600;
  778. letter-spacing: 1px;
  779. }
  780. .academic-btn[disabled] { opacity: 0.5; }
  781. .academic-quota {
  782. font-size: 11px;
  783. color: #22d3ee;
  784. background: rgba(34, 211, 238, 0.1);
  785. padding: 3px 10px;
  786. border-radius: 10px;
  787. border: 1px solid rgba(34, 211, 238, 0.15);
  788. white-space: nowrap;
  789. }
  790. /* US-9.1: Academic panel */
  791. .academic-panel {
  792. flex-shrink: 0;
  793. margin: 0 14px 16px;
  794. }
  795. .academic-section-title {
  796. font-size: 16px;
  797. font-weight: 700;
  798. color: #22d3ee;
  799. margin-bottom: 12px;
  800. padding-left: 2px;
  801. }
  802. .academic-card {
  803. border-radius: 12px;
  804. margin-bottom: 10px;
  805. overflow: hidden;
  806. transition: border-color 0.2s;
  807. }
  808. .academic-card.talent { background: rgba(8, 145, 178, 0.06); border: 1px solid rgba(8, 145, 178, 0.12); }
  809. .academic-card.talent.expanded { border-color: rgba(8, 145, 178, 0.25); background: rgba(8, 145, 178, 0.08); }
  810. .academic-card.direction { background: rgba(251, 191, 36, 0.06); border: 1px solid rgba(251, 191, 36, 0.12); }
  811. .academic-card.direction.expanded { border-color: rgba(251, 191, 36, 0.25); background: rgba(251, 191, 36, 0.08); }
  812. .academic-card.learning { background: rgba(52, 211, 153, 0.06); border: 1px solid rgba(52, 211, 153, 0.12); }
  813. .academic-card.learning.expanded { border-color: rgba(52, 211, 153, 0.25); background: rgba(52, 211, 153, 0.08); }
  814. .academic-card.parenting { background: rgba(244, 114, 182, 0.06); border: 1px solid rgba(244, 114, 182, 0.12); }
  815. .academic-card.parenting.expanded { border-color: rgba(244, 114, 182, 0.25); background: rgba(244, 114, 182, 0.08); }
  816. .academic-card.periods { background: rgba(167, 139, 250, 0.06); border: 1px solid rgba(167, 139, 250, 0.12); }
  817. .academic-card.periods.expanded { border-color: rgba(167, 139, 250, 0.25); background: rgba(167, 139, 250, 0.08); }
  818. .academic-card-header {
  819. display: flex;
  820. align-items: center;
  821. padding: 12px 14px;
  822. gap: 10px;
  823. }
  824. .academic-card-title {
  825. flex: 1;
  826. font-size: 14px;
  827. font-weight: 600;
  828. color: rgba(255,255,255,0.85);
  829. }
  830. .academic-toggle {
  831. font-size: 12px;
  832. color: rgba(255,255,255,0.35);
  833. }
  834. .academic-card-body {
  835. padding: 0 14px 14px;
  836. }
  837. .academic-content {
  838. display: block;
  839. font-size: 13px;
  840. line-height: 1.7;
  841. color: rgba(255,255,255,0.65);
  842. white-space: pre-wrap;
  843. }
  844. /* Match percentage bars */
  845. .match-bars {
  846. margin-top: 10px;
  847. }
  848. .match-row {
  849. display: flex;
  850. align-items: center;
  851. gap: 8px;
  852. margin-bottom: 8px;
  853. }
  854. .match-label {
  855. width: 32px;
  856. font-size: 12px;
  857. color: rgba(255,255,255,0.55);
  858. text-align: right;
  859. }
  860. .match-track {
  861. flex: 1;
  862. height: 8px;
  863. background: rgba(255,255,255,0.06);
  864. border-radius: 4px;
  865. overflow: hidden;
  866. }
  867. .match-fill {
  868. height: 100%;
  869. border-radius: 4px;
  870. transition: width 0.4s ease;
  871. }
  872. .match-fill.pct-80, .match-fill.pct-85, .match-fill.pct-90, .match-fill.pct-95 { background: linear-gradient(90deg, #22d3ee, #06b6d4); }
  873. .match-fill.pct-60, .match-fill.pct-65, .match-fill.pct-70, .match-fill.pct-75 { background: linear-gradient(90deg, #fbbf24, #f59e0b); }
  874. .match-fill.pct-40, .match-fill.pct-45, .match-fill.pct-50, .match-fill.pct-55 { background: linear-gradient(90deg, #f87171, #ef4444); }
  875. .match-value {
  876. width: 36px;
  877. font-size: 12px;
  878. font-weight: 600;
  879. color: rgba(255,255,255,0.6);
  880. text-align: right;
  881. }
  882. /* Academic disclaimer */
  883. .academic-disclaimer {
  884. text-align: center;
  885. padding: 6px 0 2px;
  886. }
  887. .academic-disclaimer .disclaimer-text {
  888. font-size: 11px;
  889. color: rgba(255,255,255,0.2);
  890. }
  891. /* Academic loading skeleton */
  892. .academic-skeleton {
  893. flex-shrink: 0;
  894. margin: 0 14px 16px;
  895. }
  896. /* Academic quota exceeded upgrade card */
  897. .academic-upgrade-card {
  898. flex-shrink: 0;
  899. margin: 0 14px 16px;
  900. background: linear-gradient(135deg, rgba(8, 145, 178, 0.08), rgba(6, 182, 212, 0.05));
  901. border: 1px solid rgba(8, 145, 178, 0.15);
  902. border-radius: 12px;
  903. padding: 20px;
  904. text-align: center;
  905. }
  906. .academic-upgrade-title {
  907. display: block;
  908. font-size: 15px;
  909. font-weight: 600;
  910. color: #22d3ee;
  911. margin-bottom: 6px;
  912. }
  913. .academic-upgrade-desc {
  914. display: block;
  915. font-size: 12px;
  916. color: rgba(255,255,255,0.45);
  917. margin-bottom: 14px;
  918. }
  919. .academic-upgrade-btn {
  920. background: linear-gradient(135deg, #0891b2, #06b6d4);
  921. color: #fff;
  922. border: none;
  923. border-radius: 10px;
  924. padding: 12px 40px;
  925. font-size: 15px;
  926. font-weight: 600;
  927. }
  928. .chat-section {
  929. flex: 1;
  930. display: flex;
  931. flex-direction: column;
  932. overflow: hidden;
  933. min-height: 0;
  934. margin: 0 14px;
  935. }
  936. .section-title {
  937. font-size: 17px;
  938. font-weight: 600;
  939. color: rgba(255, 255, 255, 0.9);
  940. margin: 12px 0 14px;
  941. display: flex;
  942. align-items: center;
  943. gap: 8px;
  944. }
  945. .title-icon {
  946. font-size: 14px;
  947. color: #fbbf24;
  948. opacity: 0.7;
  949. }
  950. .quota-badge {
  951. font-size: 11px;
  952. font-weight: 400;
  953. color: #fbbf24;
  954. background: rgba(251, 191, 36, 0.12);
  955. padding: 2px 10px;
  956. border-radius: 10px;
  957. border: 1px solid rgba(251, 191, 36, 0.15);
  958. }
  959. .quota-badge.vip {
  960. color: #34d399;
  961. background: rgba(52, 211, 153, 0.1);
  962. border-color: rgba(52, 211, 153, 0.15);
  963. }
  964. .chat-box {
  965. flex: 1;
  966. height: auto;
  967. overflow-y: auto;
  968. background: rgba(255, 255, 255, 0.04);
  969. border: 1px solid rgba(255, 255, 255, 0.06);
  970. border-radius: 14px;
  971. padding: 14px;
  972. margin-bottom: 10px;
  973. }
  974. .msg-row {
  975. margin-bottom: 14px;
  976. display: flex;
  977. }
  978. .msg-row.user {
  979. justify-content: flex-end;
  980. }
  981. .msg-bubble {
  982. max-width: 80%;
  983. padding: 10px 16px;
  984. border-radius: 14px;
  985. font-size: 14px;
  986. line-height: 1.5;
  987. color: rgba(255, 255, 255, 0.85);
  988. background: rgba(255, 255, 255, 0.06);
  989. border: 1px solid rgba(255, 255, 255, 0.06);
  990. }
  991. .msg-row.user .msg-bubble {
  992. background: rgba(251, 191, 36, 0.12);
  993. border-color: rgba(251, 191, 36, 0.15);
  994. color: #fbbf24;
  995. }
  996. .input-bar {
  997. display: flex;
  998. gap: 8px;
  999. }
  1000. .chat-input {
  1001. flex: 1;
  1002. height: 42px;
  1003. border: 1px solid rgba(255, 255, 255, 0.1);
  1004. border-radius: 10px;
  1005. padding: 0 14px;
  1006. font-size: 14px;
  1007. color: rgba(255, 255, 255, 0.85);
  1008. background: rgba(255, 255, 255, 0.04);
  1009. }
  1010. .send-btn {
  1011. height: 42px;
  1012. padding: 0 24px;
  1013. background: linear-gradient(135deg, #f59e0b, #d97706);
  1014. color: #fff;
  1015. border: none;
  1016. border-radius: 10px;
  1017. line-height: 42px;
  1018. font-size: 14px;
  1019. font-weight: 500;
  1020. }
  1021. .send-btn[disabled] {
  1022. opacity: 0.4;
  1023. }
  1024. /* Share hint */
  1025. .share-hint {
  1026. padding: 8px 0;
  1027. text-align: center;
  1028. }
  1029. .share-hint-text {
  1030. font-size: 11px;
  1031. color: rgba(255, 255, 255, 0.3);
  1032. }
  1033. /* Upgrade prompt */
  1034. .upgrade-prompt {
  1035. background: linear-gradient(135deg, rgba(251, 191, 36, 0.08), rgba(217, 119, 6, 0.06));
  1036. border: 1px solid rgba(251, 191, 36, 0.12);
  1037. border-radius: 14px;
  1038. padding: 22px;
  1039. text-align: center;
  1040. margin-bottom: 12px;
  1041. }
  1042. .upgrade-text {
  1043. display: block;
  1044. font-size: 16px;
  1045. font-weight: 600;
  1046. color: #fbbf24;
  1047. }
  1048. .upgrade-desc {
  1049. display: block;
  1050. font-size: 13px;
  1051. color: rgba(255, 255, 255, 0.45);
  1052. margin: 8px 0 16px;
  1053. }
  1054. .upgrade-actions {
  1055. display: flex;
  1056. gap: 10px;
  1057. justify-content: center;
  1058. }
  1059. .upgrade-btn {
  1060. flex: 1;
  1061. background: linear-gradient(135deg, #f59e0b, #d97706);
  1062. color: #fff;
  1063. border: none;
  1064. border-radius: 10px;
  1065. padding: 10px 0;
  1066. font-size: 14px;
  1067. font-weight: 500;
  1068. line-height: 1.4;
  1069. }
  1070. .upgrade-btn.secondary {
  1071. background: rgba(255, 255, 255, 0.06);
  1072. border: 1px solid rgba(251, 191, 36, 0.2);
  1073. color: #fbbf24;
  1074. }
  1075. /* US-6.6: Subscribe section */
  1076. .subscribe-section {
  1077. margin-top: 10px;
  1078. }
  1079. .vip-badge-bar {
  1080. background: rgba(52, 211, 153, 0.06);
  1081. border: 1px solid rgba(52, 211, 153, 0.15);
  1082. border-radius: 10px;
  1083. padding: 12px 14px;
  1084. display: flex;
  1085. flex-wrap: wrap;
  1086. align-items: center;
  1087. gap: 6px;
  1088. }
  1089. .vip-badge-bar.pro {
  1090. background: rgba(167, 139, 250, 0.06);
  1091. border-color: rgba(167, 139, 250, 0.15);
  1092. }
  1093. .vip-badge-text {
  1094. font-size: 13px;
  1095. font-weight: 600;
  1096. color: #34d399;
  1097. }
  1098. .vip-badge-bar.pro .vip-badge-text {
  1099. color: #a78bfa;
  1100. }
  1101. .vip-badge-expiry {
  1102. font-size: 11px;
  1103. color: rgba(255,255,255,0.4);
  1104. }
  1105. .vip-poster-link {
  1106. font-size: 12px;
  1107. color: #fbbf24;
  1108. margin-left: auto;
  1109. }
  1110. .subscribe-card {
  1111. background: linear-gradient(135deg, rgba(251, 191, 36, 0.08), rgba(217, 119, 6, 0.05));
  1112. border: 1px solid rgba(251, 191, 36, 0.15);
  1113. border-radius: 12px;
  1114. padding: 16px;
  1115. text-align: center;
  1116. }
  1117. .subscribe-title {
  1118. display: block;
  1119. font-size: 15px;
  1120. font-weight: 600;
  1121. color: #fbbf24;
  1122. margin-bottom: 6px;
  1123. }
  1124. .subscribe-desc {
  1125. display: block;
  1126. font-size: 12px;
  1127. color: rgba(255,255,255,0.45);
  1128. margin-bottom: 14px;
  1129. line-height: 1.5;
  1130. }
  1131. .subscribe-actions {
  1132. display: flex;
  1133. flex-direction: column;
  1134. gap: 8px;
  1135. align-items: center;
  1136. }
  1137. .subscribe-btn {
  1138. width: 100%;
  1139. background: linear-gradient(135deg, #f59e0b, #d97706);
  1140. color: #fff;
  1141. border: none;
  1142. border-radius: 10px;
  1143. padding: 12px 0;
  1144. font-size: 15px;
  1145. font-weight: 600;
  1146. }
  1147. .subscribe-btn:active {
  1148. opacity: 0.85;
  1149. }
  1150. .subscribe-link {
  1151. font-size: 12px;
  1152. color: rgba(255,255,255,0.35);
  1153. }
  1154. </style>