report-blocks-renderer.vue 8.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151
  1. <template>
  2. <view class="blocks-renderer" :style="{ '--font-scale': fontScale }">
  3. <view v-for="(block, bi) in blocks" :key="bi" class="block-wrap">
  4. <!-- score: 评分圆环组 -->
  5. <view v-if="block.type === 'score'" class="block score-block">
  6. <view class="block-title">{{ block.title }}</view>
  7. <view class="score-grid">
  8. <view class="score-item" v-for="(item, si) in block.items" :key="si">
  9. <view class="score-circle" :style="'border-color:' + (item.color || BrandColors.primary)">
  10. <text class="score-value">{{ item.value }}</text>
  11. </view>
  12. <text class="score-label">{{ item.label }}</text>
  13. <view class="sub-items" v-if="item.subItems && item.subItems.length">
  14. <view class="sub-item" v-for="(sub, ssi) in item.subItems" :key="ssi">
  15. <text class="sub-label">{{ sub.label }}:</text>
  16. <text class="sub-value">{{ sub.value }}</text>
  17. </view>
  18. </view>
  19. </view>
  20. </view>
  21. </view>
  22. <!-- risk_group: 风险分组(按等级徽章) -->
  23. <view v-else-if="block.type === 'risk_group'" class="block risk-block">
  24. <view class="block-title">{{ block.title }}</view>
  25. <view class="risk-card" v-for="(item, ri) in block.items" :key="ri"
  26. :class="'risk-level-' + riskCss(item.level)">
  27. <text class="risk-name">{{ item.name }}</text>
  28. <text class="risk-value">风险值: {{ item.value || '--' }}</text>
  29. <text class="risk-badge" :class="'badge-' + riskCss(item.level)">{{ riskText(item.level) }}</text>
  30. <text class="ind-help-btn" @tap.stop="onHelp(item, 'indicator')">?</text>
  31. </view>
  32. </view>
  33. <!-- indicator: 指标明细 -->
  34. <view v-else-if="block.type === 'indicator'" class="block indicator-block">
  35. <view class="block-title">
  36. <text>{{ block.title }}</text>
  37. <text class="title-abnormal" v-if="block.abnormalCount && block.abnormalCount > 0">,{{ block.abnormalCount }} 项异常</text>
  38. </view>
  39. <view class="indicator-item" v-for="(item, ii) in block.items" :key="ii">
  40. <text class="ind-name">{{ item.name }}</text>
  41. <text class="ind-value">{{ item.value }} {{ item.unit }}</text>
  42. <text class="ind-status" :class="'status-' + statusCss(item.status)">{{ item.status }}</text>
  43. <text class="ind-help-btn" @tap.stop="onHelp(item, 'indicator')">?</text>
  44. </view>
  45. </view>
  46. <!-- list: 通用列表(columns 驱动,含 ? 按钮) -->
  47. <view v-else-if="block.type === 'list'" class="block list-block">
  48. <view class="block-title">{{ block.title }}</view>
  49. <view class="list-head" v-if="block.columns">
  50. <text class="list-cell head-cell" v-for="(colItem, ci) in block.columns" :key="ci"
  51. :style="'flex:' + (ci === 0 ? 2 : 1)">{{ colItem.label }}</text>
  52. <text class="list-cell head-cell" style="flex:0 0 60rpx;">帮助</text>
  53. </view>
  54. <view class="list-row" v-for="(item, li) in block.items" :key="li">
  55. <text class="list-cell" :style="'flex:' + (ci === 0 ? 2 : 1)"
  56. v-for="(colItem, ci) in block.columns" :key="ci">{{ item[colItem.key] || '--' }}</text>
  57. <text class="list-cell ind-help-btn" style="flex:0 0 60rpx; text-align:center;" @tap.stop="onHelp(item, 'bacteria')">?</text>
  58. </view>
  59. </view>
  60. <!-- text: 文本段落 -->
  61. <view v-else-if="block.type === 'text'" class="block text-block">
  62. <view class="block-title">{{ block.title }}</view>
  63. <text class="text-content">{{ block.content }}</text>
  64. </view>
  65. <!-- chart: 预留 -->
  66. <view v-else class="block chart-block">
  67. <view class="block-title">{{ block.title }}</view>
  68. <text class="chart-placeholder">图表组件开发中</text>
  69. </view>
  70. </view>
  71. </view>
  72. </template>
  73. <script>
  74. import { BrandColors } from '../../utils/brand-colors.js'
  75. import fontScaleMixin from '@/mixins/font-scale.js'
  76. export default {
  77. mixins: [fontScaleMixin],
  78. name: 'ReportBlocksRenderer',
  79. props: {
  80. blocks: { type: Array, default: function() { return [] } }
  81. },
  82. methods: {
  83. riskCss: function(level) {
  84. var important = ['需注意', '注意', '高风险', '异常']
  85. return important.indexOf(level) >= 0 ? 'warning' : 'low'
  86. },
  87. riskText: function(level) {
  88. var map = { '低风险': '✓ 低', '需注意': '⚠ 注意', '注意': '⚠ 注意', '高风险': '⚠ 高', '异常': '⚠ 异常' }
  89. return map[level] || level || ''
  90. },
  91. statusCss: function(status) {
  92. var map = { '偏高': 'high', '偏低': 'low', '缺乏': 'low', '不足': 'low', '过多': 'high', '异常': 'high' }
  93. return map[status] || 'normal'
  94. },
  95. onHelp: function(item, blockType) {
  96. this.$emit('help', item, blockType)
  97. }
  98. }
  99. }
  100. </script>
  101. <style scoped lang="scss">
  102. .blocks-renderer { width: 100%; }
  103. .block { background: $app-surface; border-radius: 16rpx; padding: 24rpx; margin-bottom: 20rpx; }
  104. .block-title { font-size: calc(30rpx * var(--font-scale, 1)); font-weight: 600; color: $facade-text-strong; margin-bottom: 20rpx; display: flex; align-items: baseline; }
  105. .title-abnormal { font-size: calc(24rpx * var(--font-scale, 1)); color: $status-danger-strong-2; font-weight: 400; }
  106. /* score */
  107. .score-grid { display: flex; flex-wrap: wrap; }
  108. .score-item { width: 33.33%; display: flex; flex-direction: column; align-items: center; margin-bottom: 24rpx; }
  109. .score-circle { width: 96rpx; height: 96rpx; border-radius: 50%; border: 8rpx solid; display: flex; align-items: center; justify-content: center; }
  110. .score-value { font-size: calc(30rpx * var(--font-scale, 1)); font-weight: 600; color: $facade-text-strong; }
  111. .score-label { font-size: calc(24rpx * var(--font-scale, 1)); color: $facade-text-body; margin-top: 8rpx; }
  112. /* 分数明细(subItems) */
  113. .sub-items { margin-top: 8rpx; display: flex; flex-direction: column; align-items: center; }
  114. .sub-item { display: flex; flex-direction: row; align-items: center; }
  115. .sub-label { font-size: calc(20rpx * var(--font-scale, 1)); color: $facade-text-body; margin-right: 4rpx; }
  116. .sub-value { font-size: calc(20rpx * var(--font-scale, 1)); color: $facade-text-strong; }
  117. /* risk */
  118. .risk-card { display: flex; align-items: center; padding: 16rpx 0; border-bottom: 1rpx solid $facade-fill; }
  119. .risk-card:last-child { border-bottom: none; }
  120. .risk-name { flex: 1; font-size: calc(28rpx * var(--font-scale, 1)); color: $facade-text-strong; }
  121. .risk-value { font-size: calc(24rpx * var(--font-scale, 1)); color: $facade-text-muted; margin-right: 16rpx; }
  122. .risk-badge { padding: 4rpx 14rpx; border-radius: 24rpx; font-size: calc(22rpx * var(--font-scale, 1)); }
  123. .badge-warning { background: $fortune-1-tint; color: $mat-orange-strong; }
  124. .badge-low { background: $mat-green-tint; color: $mat-green-strong; }
  125. /* indicator */
  126. .indicator-item { display: flex; align-items: center; padding: 14rpx 0; border-bottom: 1rpx solid $facade-fill; }
  127. .indicator-item:last-child { border-bottom: none; }
  128. .ind-name { flex: 1; font-size: calc(26rpx * var(--font-scale, 1)); color: $facade-text-strong; }
  129. .ind-value { font-size: calc(26rpx * var(--font-scale, 1)); color: $facade-text-body; margin-right: 16rpx; }
  130. .ind-status { font-size: calc(22rpx * var(--font-scale, 1)); padding: 2rpx 12rpx; border-radius: 16rpx; }
  131. .status-high { background: $fortune-0-tint; color: $status-danger-strong-2; }
  132. .status-low { background: $fortune-1-tint; color: $mat-orange-strong; }
  133. .status-normal { background: $mat-green-tint; color: $mat-green-strong; }
  134. /* list */
  135. .list-head { display: flex; padding: 12rpx 0; border-bottom: 2rpx solid $facade-hairline-2; }
  136. .list-row { display: flex; padding: 12rpx 0; border-bottom: 1rpx solid $facade-fill-2; }
  137. .list-cell { font-size: calc(24rpx * var(--font-scale, 1)); color: $facade-text-strong; }
  138. .head-cell { font-size: calc(24rpx * var(--font-scale, 1)); color: $facade-text-muted; font-weight: 600; }
  139. /* text */
  140. .text-content { font-size: calc(26rpx * var(--font-scale, 1)); color: $facade-text-deep; line-height: 1.7; white-space: pre-wrap; }
  141. .chart-placeholder { font-size: calc(24rpx * var(--font-scale, 1)); color: $facade-text-ghost; }
  142. /* help button */
  143. .ind-help-btn { display: inline-flex; align-items: center; justify-content: center; width: 36rpx; height: 36rpx; border-radius: 50%; background: $mat-blue-tint; color: $mat-blue; font-size: calc(22rpx * var(--font-scale, 1)); font-weight: 600; margin-left: 8rpx; flex-shrink: 0; }
  144. </style>