indicator-timeline.vue 28 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598
  1. <template>
  2. <view class="page" :style="{ '--font-scale': fontScale }">
  3. <!-- ① 顶部栏:成员 / 报告类型 -->
  4. <view class="filter-bar">
  5. <picker :range="memberNames" @change="onMemberChange">
  6. <view class="filter-item">{{ currentMemberName }} ▾</view>
  7. </picker>
  8. <picker :range="reportTypeNames" @change="onReportTypeChange">
  9. <view class="filter-item">{{ currentReportTypeName }} ▾</view>
  10. </picker>
  11. </view>
  12. <!-- ⑤ 指标横向切换(chip) -->
  13. <scroll-view scroll-x class="chip-scroll" v-if="indicatorOptions.length > 1">
  14. <view
  15. class="indicator-chip"
  16. :class="def._chipClass"
  17. v-for="def in indicatorOptions"
  18. :key="getIndicatorKey(def)"
  19. @tap="onIndicatorTap(getIndicatorId(def))"
  20. >
  21. <text class="chip-star" v-if="isFavoriteDef(getIndicatorId(def))">★</text>
  22. <text>{{ getIndicatorName(def) }}</text>
  23. </view>
  24. </scroll-view>
  25. <!-- ② 指标头部卡 -->
  26. <view class="head-card" v-if="hasItem">
  27. <view class="head-row">
  28. <text class="head-name">{{ item.name }}</text>
  29. <view class="head-side">
  30. <text class="fav-btn" :class="currentFavClass" @tap="onToggleFavorite(item.definitionId)">{{ currentFavText }}</text>
  31. <text class="status-tag" :class="latestMeta._cssClass">{{ latestMeta._statusText }}</text>
  32. </view>
  33. </view>
  34. <view class="head-value-row">
  35. <text class="head-value">{{ latestValueText }}</text>
  36. <indicator-trend-arrow
  37. v-if="chartMode !== 'pair'"
  38. :subject-id="currentMemberId"
  39. :definition-id="item.definitionId"
  40. :trend="item"
  41. :latest-text="latestValueText"
  42. :show-latest="false"
  43. />
  44. <text class="head-unit" v-if="item.unit">{{ item.unit }}</text>
  45. <text class="head-count">共 {{ pointsCount }} 期</text>
  46. </view>
  47. <view class="head-ref" v-if="item.refRange">参考 {{ item.refRange }}<text v-if="item.unit"> {{ item.unit }}</text></view>
  48. <view class="head-change" v-if="showHeadChange">
  49. <text class="head-change-text">{{ headChangeText }}</text>
  50. </view>
  51. </view>
  52. <!-- ②·5 残缺横幅(P0 红线,不可裁剪) -->
  53. <IndicatorIncompleteBanner
  54. :points-count="pointsCount"
  55. :total-report-count="totalReportCount"
  56. />
  57. <!-- ③ 图表区(形态由 chartMode 决定) -->
  58. <view class="chart-card">
  59. <!-- loading -->
  60. <view class="chart-loading" v-if="loading">
  61. <text class="loading-text">加载中...</text>
  62. </view>
  63. <!-- error -->
  64. <view v-else-if="errorState">
  65. <IndicatorDegrade scene="error" :retry="retryLoad" />
  66. </view>
  67. <!-- empty (n=0) -->
  68. <view v-else-if="chartMode === 'empty'">
  69. <text class="empty-text">暂无该指标数据</text>
  70. </view>
  71. <!-- single (n=1):不画图,单值卡 + 首次记录 -->
  72. <view v-else-if="chartMode === 'single'">
  73. <view class="single-card">
  74. <text class="single-value">{{ latestValueText }}</text>
  75. <text class="single-unit" v-if="item.unit">{{ item.unit }}</text>
  76. <text class="single-status" :class="latestMeta._cssClass">{{ latestMeta._statusText }}</text>
  77. </view>
  78. <text class="single-note">首次记录 · 暂无对比</text>
  79. </view>
  80. <!-- pair (n=2):不画折线,双期对比条 -->
  81. <view v-else-if="chartMode === 'pair'">
  82. <view class="pair-bar">
  83. <view class="pair-point">
  84. <text class="pair-dot"></text>
  85. <text class="pair-value">{{ previousValueText }}</text>
  86. <text class="pair-date">{{ previousDateText }}</text>
  87. </view>
  88. <view class="pair-arrow-box">
  89. <text class="pair-arrow" :class="pairArrowClass">{{ pairArrow }}</text>
  90. <text class="pair-delta" :class="pairArrowClass">{{ pairDeltaText }}</text>
  91. <text class="pair-trend" :class="pairArrowClass">{{ pairTrendText }}</text>
  92. </view>
  93. <view class="pair-point">
  94. <text class="pair-dot"></text>
  95. <text class="pair-value">{{ latestValueText }}</text>
  96. <text class="pair-date">{{ latestDateText }}</text>
  97. </view>
  98. </view>
  99. </view>
  100. <!-- line / line_aggregated -->
  101. <view v-else>
  102. <view class="granularity-switch" v-if="chartMode === 'line_aggregated'">
  103. <text class="gran-btn" :class="granularity === 'month' ? 'gran-active' : ''" @tap="onGranularityTap('month')">按月</text>
  104. <text class="gran-btn" :class="granularity === 'raw' ? 'gran-active' : ''" @tap="onGranularityTap('raw')">按原始点</text>
  105. </view>
  106. <TrendChart
  107. :series="series"
  108. :mode="chartMode"
  109. :ref-low="refLow"
  110. :ref-high="refHigh"
  111. :all-period-dates="allPeriodDates"
  112. :latest-unit="item.unit"
  113. :show-values="chartShowValues"
  114. :show-axis-labels="true"
  115. />
  116. </view>
  117. </view>
  118. <!-- ④ 期次明细表(倒序,最新在最上) -->
  119. <view class="period-card" v-if="periodRows.length > 0">
  120. <view class="section-title">期次明细</view>
  121. <view class="period-row" v-for="(row, ri) in periodRows" :key="getPeriodKey(row, ri)">
  122. <text class="period-date">{{ row._dateText }}</text>
  123. <text class="period-value" :class="row.isMissing ? 'period-missing' : ''">{{ row._valueText }}</text>
  124. <text class="period-status" v-if="row.status">{{ row.status }}</text>
  125. <text class="period-delta">{{ row.deltaText }}</text>
  126. <text class="period-trend" :class="row.isMissing ? 'period-missing' : ''">{{ row.trendLabel }}</text>
  127. </view>
  128. <view class="period-footnote" v-if="hasUploadDate">
  129. <text>* 未识别到采样日期,按上传日期记录</text>
  130. </view>
  131. <view class="period-footnote" v-if="hasUnitMismatch">
  132. <text>* 该期单位与其他期不同,未做换算</text>
  133. </view>
  134. </view>
  135. <!-- ⑥ 合规 footer(常显不可关) -->
  136. <view class="footer">
  137. <text class="footer-text">本页数据来自检测报告,趋势仅表示数值变化,不构成医学诊断或治疗建议。</text>
  138. </view>
  139. </view>
  140. </template>
  141. <script>
  142. import { getFamilyMemberList, getIndicatorTimeline, getIndicatorSourceTypes, getIndicatorChangeRanking } from '@/utils/api'
  143. import { resolveChange, formatCompareDate } from '@/utils/indicator-change.js'
  144. import { consumeChartMode, buildAllPeriodDates, buildPeriodRows, formatPeriodDate, dateWithSourceMark, normalizeDate } from '@/utils/indicator-timeline.js'
  145. import { readFavorites, toggleFavorite } from '@/utils/indicator-favorite.js'
  146. import IndicatorIncompleteBanner from '@/pages/health/components/IndicatorIncompleteBanner.vue'
  147. import IndicatorDegrade from '@/pages/health/components/IndicatorDegrade.vue'
  148. import TrendChart from '@/pages/health/components/TrendChart.vue'
  149. import IndicatorTrendArrow from '@/pages/health/components/IndicatorTrendArrow.vue'
  150. import fontScaleMixin from '@/mixins/font-scale.js'
  151. export default {
  152. mixins: [fontScaleMixin],
  153. components: { IndicatorIncompleteBanner, IndicatorDegrade, TrendChart, IndicatorTrendArrow },
  154. data: function() {
  155. return {
  156. members: [],
  157. currentMemberId: null,
  158. reportTypeOptions: [],
  159. activeReportType: '',
  160. definitionId: null,
  161. indicatorOptions: [],
  162. item: null,
  163. loading: false,
  164. errorState: false,
  165. granularity: 'raw',
  166. _hasLeftPage: false,
  167. _pendingEntry: false,
  168. reportId: null,
  169. favoriteIds: []
  170. }
  171. },
  172. computed: {
  173. memberNames: function() {
  174. return this.members.map(function(m) { return m.name || m.nickname || '' })
  175. },
  176. currentMemberName: function() {
  177. var self = this
  178. var m = this.members.find(function(x) { return x.id === self.currentMemberId })
  179. return (m && (m.name || m.nickname)) || '选择成员'
  180. },
  181. reportTypeNames: function() {
  182. return this.reportTypeOptions.map(function(o) { return o.label })
  183. },
  184. currentReportTypeName: function() {
  185. var self = this
  186. var o = this.reportTypeOptions.find(function(x) { return x.sourceType === self.activeReportType })
  187. return (o && o.label) || ''
  188. },
  189. hasItem: function() { return !!this.item },
  190. /** 最新一期状态(预计算,模板 :class 不调用带参方法) */
  191. latestMeta: function() {
  192. if (!this.item || !this.item.latest) return { _cssClass: 'status-normal', _statusText: '正常' }
  193. var s = this.item.latest.status ? String(this.item.latest.status).trim() : ''
  194. var cls = 'status-normal'
  195. if (s === '偏高' || s === 'high') cls = 'status-high'
  196. else if (s === '偏低' || s === 'low') cls = 'status-low'
  197. return { _cssClass: cls, _statusText: s || '正常' }
  198. },
  199. pointsCount: function() { return this.item && this.item.pointsCount || 0 },
  200. totalReportCount: function() { return this.item && this.item.totalReportCount || 0 },
  201. chartMode: function() { return this.item && this.item.chartMode || 'empty' },
  202. series: function() {
  203. if (!this.item || !Array.isArray(this.item.points)) return []
  204. var pts = this.item.points
  205. return [{
  206. name: this.item.name,
  207. color: '#F97316',
  208. points: pts.map(function(p) {
  209. return {
  210. reportDate: String(p.reportDate).slice(0, 10),
  211. value: p.value,
  212. numericValue: p.numericValue,
  213. unit: p.unit,
  214. dateSource: p.dateSource
  215. }
  216. })
  217. }]
  218. },
  219. refLow: function() { return this.item && this.item.refLow !== undefined ? this.item.refLow : null },
  220. refHigh: function() { return this.item && this.item.refHigh !== undefined ? this.item.refHigh : null },
  221. allPeriodDates: function() {
  222. if (!this.item) return []
  223. return buildAllPeriodDates(this.item.points || [], this.item.missingPeriods || [])
  224. },
  225. periodRows: function() {
  226. if (!this.item) return []
  227. var rows = buildPeriodRows(this.item.points || [], this.item.missingPeriods || [])
  228. var latestDate = this.item.latest && this.item.latest.reportDate
  229. var latestUnit = this.item.unit
  230. return rows.map(function(r) {
  231. var d = r.reportDate
  232. var nd = normalizeDate(d)
  233. r._dateText = dateWithSourceMark(formatPeriodDate(nd, latestDate), r.dateSource)
  234. if (r.isMissing) {
  235. r._valueText = '该期未检测'
  236. } else {
  237. r._valueText = r.value + (r.unit ? ' ' + r.unit : '')
  238. }
  239. return r
  240. })
  241. },
  242. latestValueText: function() {
  243. if (!this.item || !this.item.latest) return '--'
  244. var v = this.item.latest
  245. return (v.numericValue !== undefined && v.numericValue !== null) ? String(v.numericValue) : v.value
  246. },
  247. previousValueText: function() {
  248. if (!this.item || !this.item.change || !this.item.change.previous) return '--'
  249. var v = this.item.change.previous
  250. return (v.numericValue !== undefined && v.numericValue !== null) ? String(v.numericValue) : v.value
  251. },
  252. latestDateText: function() {
  253. if (!this.item || !this.item.latest || !this.item.latest.reportDate) return ''
  254. return formatPeriodDate(this.item.latest.reportDate, this.item.latest.reportDate)
  255. },
  256. previousDateText: function() {
  257. if (!this.item || !this.item.change || !this.item.change.previous || !this.item.change.previous.reportDate) return ''
  258. return formatPeriodDate(this.item.change.previous.reportDate, this.item.latest && this.item.latest.reportDate)
  259. },
  260. showHeadChange: function() { return this.pointsCount >= 2 },
  261. headChangeText: function() {
  262. if (!this.item || !this.item.change) return ''
  263. var ch = this.item.change
  264. var r = resolveChange(ch.trendCode, ch.movement, ch.trendLabel)
  265. var unitMark = ch.unitMismatch ? ' *' : ''
  266. var prevDatePart = ''
  267. if (ch.previous && ch.previous.reportDate) {
  268. prevDatePart = '较 ' + formatCompareDate(ch.previous.reportDate, this.item.latest && this.item.latest.reportDate, ch.previous.dateSource) + ':'
  269. }
  270. var deltaPart = ''
  271. if (ch.delta !== null && ch.delta !== undefined && !isNaN(ch.delta)) {
  272. deltaPart = r.arrow + ' ' + (ch.delta > 0 ? '+' : '') + (ch.delta || 0) + ' (' + (ch.deltaPct > 0 ? '+' : '') + (ch.deltaPct || 0) + '%)' + unitMark
  273. }
  274. return prevDatePart + deltaPart + ' ' + r.trendLabel
  275. },
  276. pairArrow: function() {
  277. if (!this.item || !this.item.change) return '→'
  278. var mv = this.item.change.movement
  279. return mv === 'up' ? '↑' : (mv === 'down' ? '↓' : '→')
  280. },
  281. pairDeltaText: function() {
  282. if (!this.item || !this.item.change) return ''
  283. var ch = this.item.change
  284. var d = ch.delta, pct = ch.deltaPct
  285. if (d === null || d === undefined || isNaN(d)) return '—'
  286. var sign = d > 0 ? '+' : ''
  287. if (pct === null || pct === undefined || isNaN(pct) || ch.unitMismatch) return sign + d + ' (—)'
  288. var ps = pct > 0 ? '+' : ''
  289. return sign + d + ' (' + ps + pct + '%)'
  290. },
  291. pairTrendText: function() {
  292. if (!this.item || !this.item.change) return ''
  293. return this.item.change.trendLabel
  294. },
  295. pairArrowClass: function() {
  296. if (!this.item || !this.item.change) return ''
  297. var tc = this.item.change.trendCode
  298. if (tc === 'improved') return 'pair-impr'
  299. if (tc === 'worsened') return 'pair-worst'
  300. return 'pair-flat'
  301. },
  302. chartShowValues: function() {
  303. if (!this.item) return false
  304. var n = this.pointsCount
  305. var cfg = consumeChartMode(this.chartMode, n)
  306. return cfg.showValues
  307. },
  308. hasUploadDate: function() {
  309. if (!this.item || !Array.isArray(this.item.points)) return false
  310. return this.item.points.some(function(p) { return p.dateSource && p.dateSource !== 'real' && p.dateSource !== 'unknown' })
  311. },
  312. hasUnitMismatch: function() {
  313. return this.item && this.item.unitMismatch === true
  314. },
  315. /** 单指标头部卡收藏按钮态(预计算,:class 不调用带参方法) */
  316. currentFavClass: function() { return this.isFavoriteDef(this.definitionId) ? 'fav-on' : '' },
  317. currentFavText: function() { return this.isFavoriteDef(this.definitionId) ? '★ 已关注' : '☆ 关注' },
  318. /** 收藏持久化隔离维度:用户×家庭×成员×报告类型(避免串号) */
  319. favoriteScope: function() {
  320. return {
  321. userId: uni.getStorageSync('userId'),
  322. familyId: uni.getStorageSync('familyId'),
  323. memberId: this.currentMemberId,
  324. sourceType: this.activeReportType
  325. }
  326. }
  327. },
  328. onLoad: function(options) {
  329. var o = options || {}
  330. if (o.subjectId) this.currentMemberId = Number(o.subjectId)
  331. if (o.definitionId) this.definitionId = Number(o.definitionId)
  332. if (o.reportType) this.activeReportType = String(o.reportType)
  333. if (o.reportId) this.reportId = Number(o.reportId)
  334. this._pendingEntry = true
  335. this.loadMembers()
  336. },
  337. onShow: function() {
  338. // 首次进入由 onLoad 链路加载;从其他页返回本页时按需刷新
  339. if (this._hasLeftPage) { this._hasLeftPage = false; this.reloadAll() }
  340. },
  341. onHide: function() {
  342. this._hasLeftPage = true
  343. },
  344. methods: {
  345. loadMembers: function() {
  346. var self = this
  347. getFamilyMemberList({ visibleOnly: true }).then(function(res) {
  348. var arr = (res.data && res.data.list) || (res.data instanceof Array ? res.data : [])
  349. self.members = arr
  350. if (!self.currentMemberId && arr.length > 0) { self.currentMemberId = arr[0].id }
  351. if (self._pendingEntry) { self._pendingEntry = false }
  352. self.loadSourceTypes()
  353. })
  354. },
  355. onMemberChange: function(e) {
  356. var idx = Number(e.detail.value)
  357. var m = this.members[idx]
  358. if (m) { this.currentMemberId = m.id; this.favoriteIds = []; this.reloadAll() }
  359. },
  360. loadSourceTypes: function() {
  361. var self = this
  362. if (!this.currentMemberId) return
  363. getIndicatorSourceTypes({ subjectId: this.currentMemberId }).then(function(res) {
  364. var arr = (res.data instanceof Array) ? res.data : []
  365. if (arr.length > 0) {
  366. self.reportTypeOptions = arr
  367. var first = arr[0].sourceType
  368. if (!self.activeReportType) { self.activeReportType = first }
  369. } else {
  370. self.reportTypeOptions = [
  371. { sourceType: 'gut_flora', label: '肠道菌群' },
  372. { sourceType: 'food_recommend', label: '食材推荐' }
  373. ]
  374. if (!self.activeReportType) { self.activeReportType = 'gut_flora' }
  375. }
  376. self.onReportTypeSelected()
  377. })
  378. },
  379. onReportTypeChange: function(e) {
  380. var idx = Number(e.detail.value)
  381. var o = this.reportTypeOptions[idx]
  382. if (o) { this.activeReportType = o.sourceType; this.onReportTypeSelected() }
  383. },
  384. onReportTypeSelected: function() {
  385. this.loadIndicatorOptions()
  386. this.loadFavorites()
  387. this.loadTimeline()
  388. },
  389. loadIndicatorOptions: function() {
  390. var self = this
  391. if (!this.currentMemberId) return
  392. // 以 change-ranking 为候选列表(与 indicator-curve 一致),limit 20 覆盖多数指标
  393. var rt = (!this.activeReportType || this.activeReportType === 'food_recommend') ? null : this.activeReportType
  394. getIndicatorChangeRanking({ subjectId: this.currentMemberId, reportType: rt, scope: 'adjacent', orderBy: 'magnitude', limit: 20 }).then(function(res) {
  395. var items = (res.data && res.data.items) || []
  396. self.indicatorOptions = items.map(function(it) {
  397. return {
  398. definitionId: it.definitionId,
  399. name: it.name,
  400. _chipClass: it.definitionId === self.definitionId ? 'chip-active' : ''
  401. }
  402. })
  403. // 入口传入的 definitionId 不在榜单中时,追加占位(名称由 timeline 负载补全)
  404. if (self.definitionId && !self.indicatorOptions.some(function(d) { return d.definitionId === self.definitionId })) {
  405. self.indicatorOptions.push({ definitionId: self.definitionId, name: String(self.definitionId), _chipClass: 'chip-active' })
  406. }
  407. })
  408. },
  409. loadTimeline: function() {
  410. var self = this
  411. if (!this.currentMemberId || !this.definitionId) return
  412. self.loading = true
  413. self.errorState = false
  414. getIndicatorTimeline({
  415. subjectId: this.currentMemberId,
  416. definitionIds: [this.definitionId],
  417. sourceType: this.activeReportType || undefined,
  418. granularity: this.granularity
  419. }).then(function(res) {
  420. self.loading = false
  421. if (res.code === 200) {
  422. var items = (res.data && res.data.items) || []
  423. if (items.length > 0) {
  424. self.item = items[0]
  425. // 选中态同步到 chip;入口 definitionId 不在榜单中时补全名称
  426. var found = false
  427. self.indicatorOptions = self.indicatorOptions.map(function(d) {
  428. var active = d.definitionId === self.definitionId
  429. if (active) { found = true; d.name = self.item.name }
  430. d._chipClass = active ? 'chip-active' : ''
  431. return d
  432. })
  433. if (!found) {
  434. self.indicatorOptions.unshift({
  435. definitionId: self.item.definitionId,
  436. name: self.item.name,
  437. _chipClass: 'chip-active'
  438. })
  439. }
  440. } else {
  441. self.item = null
  442. }
  443. } else {
  444. self.errorState = true
  445. self.item = null
  446. }
  447. }).catch(function() {
  448. self.loading = false
  449. self.errorState = true
  450. })
  451. },
  452. onIndicatorTap: function(definitionId) {
  453. if (definitionId === this.definitionId) return
  454. this.definitionId = definitionId
  455. this.loadTimeline()
  456. },
  457. onGranularityTap: function(gran) {
  458. if (gran === this.granularity) return
  459. this.granularity = gran
  460. this.loadTimeline()
  461. },
  462. retryLoad: function() { this.loadTimeline() },
  463. getIndicatorKey: function(def) { return def ? (def.definitionId || def.name) : '' },
  464. getIndicatorId: function(def) { return def ? def.definitionId : null },
  465. getIndicatorName: function(def) { return (def && def.name) || '' },
  466. /** 期次明细表行 key(小程序 :key 禁止运算符表达式,统一走方法) */
  467. getPeriodKey: function(row, ri) {
  468. if (!row) return 'row-' + ri
  469. return 'row-' + (row.reportDate || ri) + '-' + ri
  470. },
  471. /** 重载全部数据(切成员 / 下拉刷新) */
  472. reloadAll: function() {
  473. this.loadSourceTypes()
  474. },
  475. /** 收藏持久化(方案A:后端优先 + 本地降级读,异步) */
  476. isFavoriteDef: function(definitionId) {
  477. var id = Number(definitionId)
  478. if (isNaN(id)) return false
  479. return this.favoriteIds.indexOf(id) >= 0
  480. },
  481. /** 异步加载收藏(后端优先,失败降级本地);视角已切换则丢弃过期响应 */
  482. loadFavorites: function() {
  483. var self = this
  484. var scope = this.favoriteScope
  485. readFavorites(scope).then(function(ids) {
  486. if (!self._isSameFavoriteScope(scope)) return
  487. self.favoriteIds = ids || []
  488. })
  489. },
  490. /** 收藏/取消(异步 + 乐观更新,失败由 toggleFavorite 内部回滚) */
  491. onToggleFavorite: function(definitionId) {
  492. var self = this
  493. var scope = this.favoriteScope
  494. toggleFavorite(scope, definitionId).then(function(res) {
  495. if (!self._isSameFavoriteScope(scope)) return
  496. self.favoriteIds = res.ids || []
  497. })
  498. },
  499. /** 判断异步返回时的视角是否仍是发起请求时的视角(防串号/串态) */
  500. _isSameFavoriteScope: function(scope) {
  501. var cur = this.favoriteScope
  502. return Number(cur.memberId) === Number(scope.memberId) && cur.sourceType === scope.sourceType
  503. }
  504. }
  505. }
  506. </script>
  507. <style scoped lang="scss">
  508. /* ---- layout ---- */
  509. .page { padding: 24rpx; display: flex; flex-direction: column; gap: 24rpx; min-height: 100vh; box-sizing: border-box; }
  510. /* ---- ① 顶部筛选栏 ---- */
  511. .filter-bar { display: flex; flex-direction: row; align-items: center; justify-content: space-between; gap: 16rpx; }
  512. .filter-item { flex: 1; display: flex; align-items: center; justify-content: center; height: 72rpx; padding: 0 16rpx; background: #f7f8fa; border-radius: 16rpx; font-size: calc(26rpx * var(--font-scale, 1)); color: #374151; }
  513. /* ---- ⑤ 指标 chip ---- */
  514. .chip-scroll { display: flex; flex-direction: row; align-items: center; padding: 0 4rpx; min-height: 28rpx; white-space: nowrap; }
  515. .indicator-chip { display: flex; align-items: center; justify-content: center; height: 48rpx; padding: 0 24rpx; margin-right: 16rpx; border-radius: 24rpx; font-size: calc(24rpx * var(--font-scale, 1)); color: #374151; background: #f3f4f6; flex-shrink: 0; }
  516. .indicator-chip.chip-active { background: #F97316; color: #fff; font-weight: 600; }
  517. /* ---- ② 指标头部卡 ---- */
  518. .head-card { background: #fff; border-radius: 20rpx; padding: 28rpx; box-shadow: 0 2rpx 12rpx rgba(0,0,0,0.04); }
  519. .head-row { display: flex; flex-direction: row; align-items: center; justify-content: space-between; margin-bottom: 16rpx; }
  520. .head-name { font-size: calc(30rpx * var(--font-scale, 1)); font-weight: 700; color: #111827; }
  521. .status-tag { font-size: calc(22rpx * var(--font-scale, 1)); padding: 6rpx 16rpx; border-radius: 20rpx; }
  522. .status-tag.status-normal { background: #ecfdf5; color: #047857; }
  523. .status-tag.status-high { background: #fff7ed; color: #c2410c; }
  524. .status-tag.status-low { background: #eff6ff; color: #1d4ed8; }
  525. .head-value-row { display: flex; flex-direction: row; align-items: baseline; margin-bottom: 8rpx; }
  526. .head-value { font-size: calc(48rpx * var(--font-scale, 1)); font-weight: $uni-font-weight-extra-heavy; color: #111827; line-height: 1.2; }
  527. .head-unit { font-size: calc(24rpx * var(--font-scale, 1)); color: #6b7280; margin-left: 8rpx; }
  528. .head-count { font-size: calc(22rpx * var(--font-scale, 1)); color: #9ca3af; margin-left: 16rpx; }
  529. .head-ref { font-size: calc(22rpx * var(--font-scale, 1)); color: #6b7280; margin-bottom: 8rpx; }
  530. .head-change { padding: 12rpx 16rpx; background: #fef9c3; border-radius: 12rpx; margin-top: 8rpx; }
  531. .head-change-text { font-size: calc(24rpx * var(--font-scale, 1)); color: #92400e; }
  532. /* ---- ③ 图表卡 ---- */
  533. .chart-card { background: #fff; border-radius: 20rpx; padding: 28rpx; box-shadow: 0 2rpx 12rpx rgba(0,0,0,0.04); min-height: 320rpx; }
  534. .chart-loading { display: flex; align-items: center; justify-content: center; height: 200rpx; }
  535. .loading-text { font-size: calc(24rpx * var(--font-scale, 1)); color: #9ca3af; }
  536. .empty-text { display: block; text-align: center; font-size: calc(24rpx * var(--font-scale, 1)); color: #9ca3af; margin-top: 80rpx; }
  537. .single-card { display: flex; flex-direction: row; align-items: baseline; justify-content: center; padding: 24rpx 0; }
  538. .single-value { font-size: calc($uni-font-size-display * var(--font-scale, 1)); font-weight: $uni-font-weight-extra-heavy; color: #111827; line-height: 1.2; }
  539. .single-unit { font-size: calc(26rpx * var(--font-scale, 1)); color: #6b7280; margin-left: 8rpx; }
  540. .single-status { font-size: calc(22rpx * var(--font-scale, 1)); padding: 4rpx 12rpx; border-radius: 12rpx; margin-left: 16rpx; }
  541. .single-note { display: block; text-align: center; font-size: calc(22rpx * var(--font-scale, 1)); color: #9ca3af; margin-top: 8rpx; }
  542. .pair-bar { display: flex; flex-direction: row; align-items: center; justify-content: space-between; padding: 24rpx 0; }
  543. .pair-point { display: flex; flex-direction: column; align-items: center; }
  544. .pair-dot { width: 16rpx; height: 16rpx; border-radius: 50%; background: #F97316; }
  545. .pair-value { font-size: calc(32rpx * var(--font-scale, 1)); font-weight: 700; color: #111827; margin-top: 8rpx; }
  546. .pair-date { font-size: calc(22rpx * var(--font-scale, 1)); color: #9ca3af; margin-top: 4rpx; }
  547. .pair-arrow-box { display: flex; flex-direction: column; align-items: center; padding: 0 24rpx; }
  548. .pair-arrow { font-size: calc(40rpx * var(--font-scale, 1)); line-height: 1; }
  549. .pair-delta { font-size: calc(24rpx * var(--font-scale, 1)); margin-top: 6rpx; }
  550. .pair-trend { font-size: calc(22rpx * var(--font-scale, 1)); margin-top: 4rpx; }
  551. .pair-impr { color: #047857; }
  552. .pair-worst { color: #dc2626; }
  553. .pair-flat { color: #6b7280; }
  554. .granularity-switch { display: flex; flex-direction: row; justify-content: flex-end; margin-bottom: 16rpx; }
  555. .gran-btn { font-size: calc(22rpx * var(--font-scale, 1)); color: #6b7280; padding: 8rpx 16rpx; margin-left: 8rpx; border-radius: 8rpx; border: 1rpx solid #e5e7eb; }
  556. .gran-btn.gran-active { background: #F97316; color: #fff; border-color: #F97316; }
  557. /* ---- ④ 期次明细表 ---- */
  558. .period-card { background: #fff; border-radius: 20rpx; padding: 24rpx; box-shadow: 0 2rpx 12rpx rgba(0,0,0,0.04); }
  559. .section-title { font-size: calc(28rpx * var(--font-scale, 1)); font-weight: 700; color: #111827; margin-bottom: 16rpx; }
  560. .period-row { display: flex; flex-direction: row; align-items: center; padding: 16rpx 0; border-bottom: 1rpx solid #f3f4f6; }
  561. .period-row:last-child { border-bottom: none; }
  562. .period-date { width: 140rpx; font-size: calc(24rpx * var(--font-scale, 1)); color: #374151; }
  563. .period-value { flex: 1; font-size: calc(26rpx * var(--font-scale, 1)); color: #111827; font-weight: 600; }
  564. .period-value.period-missing { color: #9ca3af; font-weight: 400; }
  565. .period-status { width: 100rpx; font-size: calc(22rpx * var(--font-scale, 1)); text-align: right; }
  566. .period-delta { width: 200rpx; font-size: calc(24rpx * var(--font-scale, 1)); text-align: right; color: #6b7280; }
  567. .period-trend { width: 160rpx; font-size: calc(24rpx * var(--font-scale, 1)); text-align: right; }
  568. .period-footnote { font-size: calc(22rpx * var(--font-scale, 1)); color: #9ca3af; padding: 12rpx 0 0 0; }
  569. /* ---- ⑥ 合规 footer ---- */
  570. .footer { padding: 24rpx 0; }
  571. .footer-text { font-size: calc(22rpx * var(--font-scale, 1)); color: #9ca3af; text-align: center; line-height: 1.6; }
  572. /* ---- 指标收藏(方案A) ---- */
  573. .chip-star { color: #F59E0B; font-size: calc(22rpx * var(--font-scale, 1)); margin-right: 6rpx; }
  574. .head-side { display: flex; flex-direction: row; align-items: center; gap: 12rpx; }
  575. .fav-btn { font-size: calc(22rpx * var(--font-scale, 1)); padding: 6rpx 14rpx; border-radius: 20rpx; color: #6b7280; background: #f3f4f6; }
  576. .fav-btn.fav-on { color: #b45309; background: #fef3c7; font-weight: 600; }
  577. </style>