kb.ts 3.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171
  1. import { LegendOption, TooltipOption } from 'echarts/types/dist/shared'
  2. export const DESIGN_WIDTH = 1920
  3. export const DESIGN_HEIGHT = 1080
  4. export interface SummaryCardConfig<CardKey> {
  5. key: CardKey
  6. title: string
  7. icon: string
  8. accent: string
  9. glow: string
  10. }
  11. export interface CardStateItem {
  12. value: number
  13. loading: boolean
  14. }
  15. export interface ChartItem {
  16. name: string
  17. value: number
  18. }
  19. export type SeriesItem = {
  20. name: string
  21. data: number[]
  22. }
  23. export type ChartData = {
  24. xAxis: string[]
  25. series: SeriesItem[]
  26. }
  27. // export const FONT_FAMILY = 'YouSheBiaoTiHei, sans-serif'
  28. export const FONT_FAMILY = undefined
  29. export const CHART_RENDERER = 'svg'
  30. export const ANIMATION = {
  31. animationDuration: 500,
  32. animationEasing: 'cubicOut' as const
  33. }
  34. export const THEME = {
  35. text: {
  36. primary: '#24364f',
  37. regular: '#000',
  38. strong: '#1f5bb8',
  39. black: '#3c3c3c'
  40. },
  41. tooltip: {
  42. cssText: `
  43. background: linear-gradient(180deg, rgba(255,255,255,0.96) 0%, rgba(235,243,255,0.96) 100%);
  44. border: 1px solid rgba(255,255,255,0.95);
  45. border-radius: 8px;
  46. box-shadow: 0 8px 20px rgba(31, 91, 184, 0.16);
  47. overflow: hidden;
  48. backdrop-filter: blur(12px);
  49. -webkit-backdrop-filter: blur(12px);
  50. `
  51. },
  52. grid: {
  53. left: 16,
  54. right: 16,
  55. top: 16,
  56. bottom: 16,
  57. containLabel: true
  58. },
  59. split: 'rgba(31, 91, 184, 0.08)',
  60. color: {
  61. blue: {
  62. line: '#1f5bb8',
  63. light: '#8ec5ff',
  64. mid: '#5e9cff',
  65. strong: '#2d7cf8',
  66. glow: 'rgba(45, 124, 248, 0.34)',
  67. bg: 'rgba(31, 91, 184, 0.08)',
  68. shadow: 'rgba(31, 91, 184, 0.16)'
  69. },
  70. orange: {
  71. line: '#f08c2e',
  72. light: '#ffd8a8',
  73. mid: '#ffb454',
  74. strong: '#ff8b3d',
  75. glow: 'rgba(255, 139, 61, 0.34)',
  76. bg: 'rgba(240, 140, 46, 0.08)',
  77. shadow: 'rgba(240, 140, 46, 0.18)'
  78. },
  79. green: {
  80. line: '#2e9a5b',
  81. light: '#a8e0c8',
  82. mid: '#82c793',
  83. strong: '#2fb990',
  84. glow: 'rgba(46, 154, 91, 0.34)',
  85. bg: 'rgba(34, 197, 94, 0.08)',
  86. shadow: 'rgba(34, 197, 94, 0.18)'
  87. },
  88. red: {
  89. line: '#ff4d4f',
  90. light: '#fdd5d5',
  91. mid: '#ff9999',
  92. strong: '#ff6666',
  93. glow: 'rgba(255, 77, 79, 0.34)',
  94. bg: 'rgba(255, 77, 79, 0.08)',
  95. shadow: 'rgba(255, 77, 79, 0.18)'
  96. }
  97. }
  98. }
  99. export function createTooltip(extra: Partial<TooltipOption> = {}): any {
  100. return {
  101. textStyle: {
  102. color: THEME.text.black,
  103. fontSize: 14,
  104. fontFamily: FONT_FAMILY
  105. },
  106. extraCssText: THEME.tooltip.cssText,
  107. ...extra
  108. }
  109. }
  110. export function createLegend(extra: Partial<LegendOption> = {}, data: string[] = []): any {
  111. return {
  112. data,
  113. textStyle: {
  114. color: THEME.text.regular,
  115. fontSize: 13,
  116. fontFamily: FONT_FAMILY
  117. },
  118. ...extra
  119. }
  120. }
  121. export function formatDateLabel(value: string) {
  122. if (!value) return value
  123. const parts = value.split('-')
  124. if (parts.length === 3) {
  125. return `${parts[1]}-${parts[2]}`
  126. }
  127. return value
  128. }
  129. export function formatSeriesName(name: string) {
  130. return name.split('~~en**')[0] || name
  131. }
  132. export function formatMonthLabel(value: string) {
  133. if (!value) return value
  134. const [year, month] = value.split('-')
  135. if (!year || !month) return value
  136. return `${year.slice(-2)}年${month}月`
  137. }
  138. export function formatGasAxisValue(value: number) {
  139. if (value >= 100000000) {
  140. return `${(value / 100000000).toFixed(1)}亿`
  141. }
  142. if (value >= 10000) {
  143. return `${(value / 10000).toFixed(0)}万`
  144. }
  145. return `${value}`
  146. }
  147. export function formatGasLabelValue(value: number) {
  148. if (!value) return ''
  149. if (value >= 100000000) {
  150. return `${(value / 100000000).toFixed(2)}亿`
  151. }
  152. if (value >= 10000) {
  153. return `${(value / 10000).toFixed(1)}万`
  154. }
  155. return `${value}`
  156. }