ChemicalsStats.vue 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317
  1. <template>
  2. <div class="panel chemicals-stats">
  3. <div class="border-beam"></div>
  4. <svg class="pc tl" viewBox="0 0 14 14"><path d="M0 14 V0 H14" fill="none" stroke="rgba(30,144,255,0.85)" stroke-width="1.5"/></svg>
  5. <svg class="pc tr" viewBox="0 0 14 14"><path d="M0 14 V0 H14" fill="none" stroke="rgba(30,144,255,0.85)" stroke-width="1.5"/></svg>
  6. <svg class="pc bl" viewBox="0 0 14 14"><path d="M0 14 V0 H14" fill="none" stroke="rgba(30,144,255,0.85)" stroke-width="1.5"/></svg>
  7. <svg class="pc br" viewBox="0 0 14 14"><path d="M0 14 V0 H14" fill="none" stroke="rgba(30,144,255,0.85)" stroke-width="1.5"/></svg>
  8. <div class="panel-header">
  9. <div class="panel-header-icon">⚗️</div>
  10. <span class="panel-title">化学品库存动态统计</span>
  11. </div>
  12. <div style="padding:12px 20px 15px;display:flex;gap:15px;height:calc(100% - 82px)">
  13. <!-- 左侧: 饼图 -->
  14. <div style="flex:1;min-width:0;display:flex;flex-direction:column">
  15. <div ref="chemPieChart" style="flex:1;min-height:0"></div>
  16. </div>
  17. <!-- 右侧: 存量统计 -->
  18. <div style="flex:0 0 380px;display:flex;flex-direction:column;gap:14px;justify-content:center">
  19. <!-- 总量 -->
  20. <div class="chem-stat-card total">
  21. <div class="csc-label-a">存量化学品总量</div>
  22. <div class="csc-value-a">{{ totalAmount.toLocaleString() }}<span class="csc-unit">L</span></div>
  23. </div>
  24. <!-- 管控 -->
  25. <div class="chem-stat-card ctrl">
  26. <div style="display:flex;justify-content:space-between;align-items:flex-start">
  27. <div>
  28. <div class="csc-label">管控类化学品</div>
  29. <div class="csc-value">{{ ctrlAmount }}<span class="csc-unit">L</span></div>
  30. </div>
  31. <div class="csc-pct-ring">
  32. <svg viewBox="0 0 60 60" width="80" height="80">
  33. <circle cx="30" cy="30" r="24" fill="none" stroke="rgba(239,68,68,0.12)" stroke-width="6"/>
  34. <circle cx="30" cy="30" r="24" fill="none" stroke="#ef4444" stroke-width="6"
  35. :stroke-dasharray="ctrlDash"
  36. stroke-linecap="round" transform="rotate(-90 30 30)"
  37. style="filter:drop-shadow(0 0 4px rgba(239,68,68,0.7))"/>
  38. <text x="30" y="35" text-anchor="middle" fill="#ef4444" font-size="11" font-weight="700" font-family="Arial">{{ ctrlPct }}%</text>
  39. </svg>
  40. </div>
  41. </div>
  42. <div class="csc-sub">占总量 {{ ctrlPct }}% · 共 {{ ctrlCategories }} 类目</div>
  43. </div>
  44. <!-- 非管控 -->
  45. <div class="chem-stat-card free">
  46. <div style="display:flex;justify-content:space-between;align-items:flex-start">
  47. <div>
  48. <div class="csc-label">非管控类化学品</div>
  49. <div class="csc-value" style="color:#00d8ff">{{ freeAmount }}<span class="csc-unit">L</span></div>
  50. </div>
  51. <div>
  52. <svg viewBox="0 0 60 60" width="80" height="80">
  53. <circle cx="30" cy="30" r="24" fill="none" stroke="rgba(0,216,255,0.12)" stroke-width="6"/>
  54. <circle cx="30" cy="30" r="24" fill="none" stroke="#00d8ff" stroke-width="6"
  55. :stroke-dasharray="freeDash"
  56. stroke-linecap="round" transform="rotate(-90 30 30)"
  57. style="filter:drop-shadow(0 0 4px rgba(0,216,255,0.7))"/>
  58. <text x="30" y="35" text-anchor="middle" fill="#00d8ff" font-size="11" font-weight="700" font-family="Arial">{{ freePct }}%</text>
  59. </svg>
  60. </div>
  61. </div>
  62. <div class="csc-sub" style="color:rgba(0,216,255,0.55)">占总量 {{ freePct }}% · 共 {{ freeCategories }} 类目</div>
  63. </div>
  64. <!-- 类目总数 -->
  65. <div class="chem-stat-card cat">
  66. <div class="csc-label">存量化学品总类目数</div>
  67. <div style="display:flex;align-items:baseline;gap:12px;margin-top:8px">
  68. <div class="csc-value" style="color:#ffd740">{{ ctrlCategories + freeCategories }}<span class="csc-unit">类</span></div>
  69. <div style="display:flex;gap:6px;align-items:center">
  70. <span style="font-size:22px;color:rgba(239,68,68,0.8)">管控 {{ ctrlCategories }}类</span>
  71. <span style="font-size:20px;color:rgba(168,204,232,0.3)">|</span>
  72. <span style="font-size:22px;color:rgba(0,216,255,0.8)">非管控 {{ freeCategories }}类</span>
  73. </div>
  74. </div>
  75. </div>
  76. </div>
  77. </div>
  78. </div>
  79. </template>
  80. <script>
  81. import * as echarts from 'echarts'
  82. const C = 2 * Math.PI * 24 // circumference r=24 ~150.8
  83. export default {
  84. name: 'ChemicalsStats',
  85. data() {
  86. return {
  87. totalAmount: 1229,
  88. ctrlAmount: 269,
  89. freeAmount: 960,
  90. ctrlCategories: 5,
  91. freeCategories: 5,
  92. chart: null
  93. }
  94. },
  95. computed: {
  96. ctrlPct() {
  97. return Math.round(this.ctrlAmount / (this.totalAmount || 1) * 1000) / 10
  98. },
  99. freePct() {
  100. return Math.round(this.freeAmount / (this.totalAmount || 1) * 1000) / 10
  101. },
  102. ctrlDash() {
  103. const arc = Math.round(this.ctrlPct / 100 * C * 10) / 10
  104. return `${arc} ${C}`
  105. },
  106. freeDash() {
  107. const arc = Math.round(this.freePct / 100 * C * 10) / 10
  108. return `${arc} ${C}`
  109. }
  110. },
  111. mounted() {
  112. this.$nextTick(() => this.initChart())
  113. },
  114. beforeDestroy() {
  115. if (this.chart) this.chart.dispose()
  116. window.removeEventListener('resize', this.handleResize)
  117. },
  118. methods: {
  119. initChart() {
  120. this.chart = echarts.init(this.$refs.chemPieChart, null, { renderer: 'canvas', devicePixelRatio: 2 })
  121. this.chart.setOption({
  122. backgroundColor: 'transparent',
  123. tooltip: {
  124. trigger: 'item',
  125. formatter: '{b}: {c}L ({d}%)',
  126. backgroundColor: 'rgba(3,14,42,0.92)',
  127. borderColor: 'rgba(30,144,255,0.3)',
  128. textStyle: { color: '#a8cce8', fontSize: 22 }
  129. },
  130. graphic: [
  131. // { type: 'text', left: 'center', top: '36%', style: { text: String(this.totalAmount), fill: '#ffd740', font: 'bold 44px Arial', textAlign: 'center' } },
  132. // { type: 'text', left: 'center', top: '55%', style: { text: '化学品总量(L)', fill: 'rgba(168,204,232,0.65)', font: '20px Arial', textAlign: 'center' } }
  133. ],
  134. legend: {
  135. show:false,
  136. orient: 'horizontal', bottom: '2%', icon: 'circle',
  137. itemWidth: 24, itemHeight: 24, itemGap: 30,
  138. textStyle: { color: '#a8cce8', fontSize: 22 }
  139. },
  140. series: [{
  141. type: 'pie', radius: ['32%', '62%'], center: ['50%', '52%'],
  142. avoidLabelOverlap: true,
  143. label: {
  144. show: true, position: 'outside',
  145. formatter: params => `{name|${params.name}}\n{val|${params.value}L ${params.percent}%}`,
  146. rich: {
  147. name: { fontSize: 24, color: '#a8cce8', lineHeight: 30 },
  148. val: { fontSize: 22, color: '#ffd740', lineHeight: 26 }
  149. },
  150. distanceToLabelLine: 10
  151. },
  152. labelLine: { show: true, length: 25, length2: 35, lineStyle: { color: 'rgba(168,204,232,0.5)' } },
  153. data: [
  154. { value: this.ctrlAmount, name: '管控类', itemStyle: { color: '#ef4444', shadowBlur: 10, shadowColor: 'rgba(239,68,68,0.6)' } },
  155. { value: this.freeAmount, name: '非管控类', itemStyle: { color: '#00d8ff', shadowBlur: 10, shadowColor: 'rgba(0,216,255,0.6)' } }
  156. ],
  157. emphasis: { label: { fontSize: 26, fontWeight: 'bold' }, scale: true, scaleSize: 8 }
  158. }]
  159. })
  160. window.addEventListener('resize', this.handleResize)
  161. },
  162. handleResize() {
  163. if (this.chart) this.chart.resize()
  164. }
  165. }
  166. }
  167. </script>
  168. <style lang="scss" scoped>
  169. .chemicals-stats {
  170. position: relative;
  171. display: flex;
  172. flex-direction: column;
  173. border-radius: 15px;
  174. overflow: hidden;
  175. background: $bg-panel;
  176. border: 1px solid $border;
  177. }
  178. /* ---- Border beam ---- */
  179. .border-beam {
  180. position: absolute;
  181. inset: 0;
  182. pointer-events: none;
  183. border-radius: inherit;
  184. overflow: hidden;
  185. z-index: 2;
  186. &::before {
  187. content: '';
  188. position: absolute;
  189. top: 0; left: -100%;
  190. width: 40%; height: 3px;
  191. background: linear-gradient(90deg, transparent, rgba(30,144,255,0.9), rgba(0,216,255,0.7), transparent);
  192. animation: beamTop 5s linear infinite;
  193. }
  194. &::after {
  195. content: '';
  196. position: absolute;
  197. bottom: 0; right: -100%;
  198. width: 40%; height: 3px;
  199. background: linear-gradient(90deg, transparent, rgba(0,216,255,0.7), rgba(30,144,255,0.9), transparent);
  200. animation: beamBottom 5s linear infinite 2.5s;
  201. }
  202. }
  203. @keyframes beamTop { from { left: -40%; } to { left: 100%; } }
  204. @keyframes beamBottom { from { right: -40%; } to { right: 100%; } }
  205. /* ---- Corner ornaments ---- */
  206. .pc {
  207. position: absolute;
  208. width: 35px; height: 35px;
  209. z-index: 3; pointer-events: none;
  210. &.tl { top: 0; left: 0; }
  211. &.tr { top: 0; right: 0; transform: scaleX(-1); }
  212. &.bl { bottom: 0; left: 0; transform: scaleY(-1); }
  213. &.br { bottom: 0; right: 0; transform: scale(-1); }
  214. }
  215. /* ---- Panel header ---- */
  216. .panel-header {
  217. display: flex;
  218. align-items: center;
  219. gap: 25px;
  220. padding: 20px 30px 18px;
  221. border-bottom: 1px solid $border;
  222. background: linear-gradient(90deg, rgba(0,60,160,0.18), transparent);
  223. flex-shrink: 0;
  224. }
  225. .panel-header-icon {
  226. width: 65px; height: 65px;
  227. border-radius: 12px;
  228. flex-shrink: 0;
  229. display: flex; align-items: center; justify-content: center;
  230. font-size: 32px;
  231. background: linear-gradient(135deg, rgba(30,144,255,0.25), rgba(0,216,255,0.15));
  232. border: 1px solid rgba(30,144,255,0.35);
  233. animation: iconGlow 3s ease-in-out infinite;
  234. }
  235. @keyframes iconGlow {
  236. 0%, 100% { box-shadow: 0 0 15px rgba(30,144,255,0.3); }
  237. 50% { box-shadow: 0 0 35px rgba(30,144,255,0.7), 0 0 12px rgba(0,216,255,0.3); }
  238. }
  239. .panel-title {
  240. font-size: 30px;
  241. font-weight: 600;
  242. letter-spacing: 2px;
  243. color: $cyan;
  244. }
  245. /* ---- Stat cards ---- */
  246. .chem-stat-card {
  247. border-radius: 10px;
  248. padding: 16px 20px;
  249. border: 1px solid $border;
  250. background: $bg-card;
  251. &.total { border-color: rgba(0,216,255,0.3); background: rgba(0,216,255,0.05); }
  252. &.ctrl { border-color: rgba(239,68,68,0.3); background: rgba(239,68,68,0.05); }
  253. &.free { border-color: rgba(0,216,255,0.3); background: rgba(0,216,255,0.05); }
  254. &.cat { border-color: rgba(255,215,64,0.2); background: rgba(255,215,64,0.04); }
  255. }
  256. .csc-label {
  257. font-size: 24px;
  258. color: $text-dim;
  259. margin-bottom: 6px;
  260. letter-spacing: 1px;
  261. }
  262. .csc-label-a{
  263. font-size: 24px;
  264. color: $text-dim;
  265. margin-bottom: 6px;
  266. letter-spacing: 1px;
  267. text-align: center;
  268. }
  269. .csc-value {
  270. font-size: 44px;
  271. font-weight: 700;
  272. color: #ef4444;
  273. line-height: 1.1;
  274. }
  275. .csc-value-a{
  276. font-size: 44px;
  277. font-weight: 700;
  278. color: #fff;
  279. line-height: 1.1;
  280. text-align: center;
  281. }
  282. .csc-unit {
  283. font-size: 24px;
  284. font-weight: 400;
  285. color: $text-dim;
  286. margin-left: 4px;
  287. }
  288. .csc-sub {
  289. font-size: 22px;
  290. color: rgba(239,68,68,0.55);
  291. margin-top: 8px;
  292. }
  293. .csc-pct-ring { flex-shrink: 0; }
  294. </style>