HomeCardGridView.vue 5.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253
  1. <template>
  2. <div
  3. v-if="visibleCells.length > 0"
  4. class="s4-kpi-grid"
  5. :class="{ 's4-kpi-grid--dense': props.cells.length > 4 }"
  6. >
  7. <div v-for="cell in visibleCells" :key="cell.key" class="s4-kpi-cell" :class="{ 's4-kpi-cell--stale': cell.stale }">
  8. <el-tooltip
  9. v-if="cell.formulaText"
  10. placement="top"
  11. :show-after="200"
  12. :content="cell.formulaText"
  13. >
  14. <div class="s4-kpi-label s4-kpi-label--formula" :title="cell.label">{{ cell.label }}</div>
  15. </el-tooltip>
  16. <div v-else class="s4-kpi-label" :title="cell.label">{{ cell.label }}</div>
  17. <div class="s4-kpi-body">
  18. <div class="s4-kpi-main">
  19. <div class="s4-kpi-value-row">
  20. <span class="s4-kpi-value" :class="{ 's4-kpi-value--status': cell.valueKind === 'status' }">{{ cell.value }}</span>
  21. <span v-if="cell.unit" class="s4-kpi-unit">{{ cell.unit }}</span>
  22. </div>
  23. <div v-if="cell.targetDisplay" class="s4-kpi-target">目标: {{ cell.targetDisplay }}</div>
  24. <div v-if="cell.asOfText" class="s4-kpi-asof" :title="cell.staleHint || cell.asOfText">{{ cell.asOfText }}</div>
  25. <div v-if="cell.latestText" class="s4-kpi-asof">{{ cell.latestText }}</div>
  26. <div v-if="cell.policyText" class="s4-kpi-asof">{{ cell.policyText }}</div>
  27. </div>
  28. <span
  29. class="s4-kpi-trend"
  30. :class="{
  31. 's4-kpi-trend--good': cell.trendTone === 'good',
  32. 's4-kpi-trend--warn': cell.trendTone === 'warn',
  33. 's4-kpi-trend--bad': cell.trendTone === 'bad',
  34. }"
  35. >
  36. <span class="s4-kpi-trend__arrow" aria-hidden="true">{{
  37. cell.trendArrow === 'up' ? '▲' : cell.trendArrow === 'down' ? '▼' : '—'
  38. }}</span>
  39. {{ cell.trend }}
  40. </span>
  41. </div>
  42. </div>
  43. <div v-if="overflowCount > 0" class="s4-kpi-overflow" :title="`还有 ${overflowCount} 个指标未显示`">
  44. +{{ overflowCount }}
  45. </div>
  46. </div>
  47. <div v-else class="home-kpi-card__empty">
  48. <span v-if="loading">加载中…</span>
  49. <span v-else>暂无指标配置,点击卡片进入模块后到"运营指标建模"配置 L1 指标</span>
  50. </div>
  51. </template>
  52. <script setup>
  53. import { computed } from 'vue'
  54. const props = defineProps({
  55. moduleCode: { type: String, required: true },
  56. cells: { type: Array, required: true },
  57. loading: { type: Boolean, default: false },
  58. })
  59. const MAX_DENSE = 8
  60. const MAX_NORMAL = 4
  61. const visibleCells = computed(() => {
  62. const arr = Array.isArray(props.cells) ? props.cells : []
  63. const cap = arr.length > MAX_NORMAL ? MAX_DENSE : MAX_NORMAL
  64. return arr.slice(0, cap)
  65. })
  66. const overflowCount = computed(() => {
  67. const arr = Array.isArray(props.cells) ? props.cells : []
  68. const cap = arr.length > MAX_NORMAL ? MAX_DENSE : MAX_NORMAL
  69. return Math.max(0, arr.length - cap)
  70. })
  71. </script>
  72. <style scoped>
  73. .s4-kpi-grid {
  74. position: relative;
  75. flex: 1;
  76. min-height: 0;
  77. display: grid;
  78. grid-template-columns: 1fr 1fr;
  79. grid-template-rows: repeat(2, minmax(0, 1fr));
  80. grid-auto-rows: 0;
  81. gap: 8px 12px;
  82. align-content: stretch;
  83. overflow: hidden;
  84. }
  85. .s4-kpi-grid--dense {
  86. grid-template-columns: repeat(4, minmax(0, 1fr));
  87. grid-template-rows: repeat(2, minmax(0, 1fr));
  88. }
  89. .s4-kpi-cell {
  90. display: flex;
  91. flex-direction: column;
  92. align-items: flex-start;
  93. justify-content: center;
  94. gap: 3px;
  95. padding: 5px 8px;
  96. min-height: 0;
  97. min-width: 0;
  98. background: rgba(0, 0, 0, 0.22);
  99. border-radius: 6px;
  100. border: 1px solid rgba(51, 65, 85, 0.35);
  101. overflow: hidden;
  102. }
  103. .s4-kpi-label {
  104. flex: 0 0 auto;
  105. min-height: 15px;
  106. font-size: 12px;
  107. color: #e2e8f0;
  108. line-height: 1.25;
  109. font-weight: 700;
  110. width: 100%;
  111. white-space: nowrap;
  112. text-overflow: ellipsis;
  113. overflow: hidden;
  114. }
  115. .s4-kpi-label--formula {
  116. cursor: help;
  117. border-bottom: 1px dashed rgba(148, 163, 184, 0.55);
  118. }
  119. .s4-kpi-body {
  120. display: flex;
  121. align-items: center;
  122. justify-content: space-between;
  123. gap: 8px;
  124. width: 100%;
  125. min-width: 0;
  126. }
  127. .s4-kpi-main {
  128. flex: 1;
  129. min-width: 0;
  130. display: flex;
  131. flex-direction: column;
  132. align-items: flex-start;
  133. gap: 3px;
  134. }
  135. .s4-kpi-value-row {
  136. display: flex;
  137. flex-wrap: wrap;
  138. align-items: baseline;
  139. gap: 4px 6px;
  140. }
  141. .s4-kpi-target {
  142. font-size: 11px;
  143. font-weight: 500;
  144. color: #94a3b8;
  145. line-height: 1.3;
  146. }
  147. .s4-kpi-asof {
  148. font-size: 10px;
  149. font-weight: 500;
  150. color: #94a3b8;
  151. line-height: 1.3;
  152. }
  153. .s4-kpi-cell--stale {
  154. opacity: 0.55;
  155. }
  156. .s4-kpi-value {
  157. font-size: clamp(16px, 3vw, 22px);
  158. font-weight: 800;
  159. color: #ffffff;
  160. line-height: 1.05;
  161. letter-spacing: 0.02em;
  162. }
  163. .s4-kpi-grid--dense .s4-kpi-value {
  164. font-size: clamp(14px, 2.2vw, 18px);
  165. }
  166. .s4-kpi-value.s4-kpi-value--status {
  167. font-size: 11px;
  168. white-space: nowrap;
  169. overflow: hidden;
  170. text-overflow: ellipsis;
  171. max-width: 100%;
  172. }
  173. .s4-kpi-unit {
  174. font-size: 11px;
  175. color: #e2e8f0;
  176. font-weight: 500;
  177. }
  178. .s4-kpi-trend {
  179. display: inline-flex;
  180. align-items: center;
  181. gap: 2px;
  182. font-size: 11px;
  183. font-weight: 700;
  184. flex-shrink: 0;
  185. align-self: center;
  186. }
  187. .s4-kpi-trend__arrow {
  188. font-size: 9px;
  189. line-height: 1;
  190. transform: translateY(0.5px);
  191. }
  192. .s4-kpi-trend--good {
  193. color: #4ade80;
  194. }
  195. .s4-kpi-trend--warn {
  196. color: #facc15;
  197. }
  198. .s4-kpi-trend--bad {
  199. color: #fb923c;
  200. }
  201. .s4-kpi-overflow {
  202. position: absolute;
  203. right: 4px;
  204. bottom: 2px;
  205. font-size: 10px;
  206. font-weight: 700;
  207. color: #93c5fd;
  208. background: rgba(15, 23, 42, 0.75);
  209. border: 1px solid rgba(96, 165, 250, 0.55);
  210. border-radius: 10px;
  211. padding: 1px 6px;
  212. pointer-events: none;
  213. line-height: 1.2;
  214. }
  215. .home-kpi-card__empty {
  216. flex: 1;
  217. display: flex;
  218. align-items: center;
  219. justify-content: center;
  220. color: #94a3b8;
  221. font-size: 11px;
  222. padding: 8px;
  223. text-align: center;
  224. line-height: 1.4;
  225. }
  226. </style>