index.vue 5.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246
  1. <template>
  2. <div class="app">
  3. <!-- 上半部分:两个卡片 -->
  4. <div class="top-section">
  5. <!-- 本月 -->
  6. <div class="card">
  7. <h3>本月</h3>
  8. <div class="data-container">
  9. <div class="data-row">
  10. <div class="data-item">
  11. <span class="value">8.405</span><span class="unit">t</span>
  12. <span class="label">当月</span>
  13. </div>
  14. <div class="data-item">
  15. <span class="value">8.477</span><span class="unit">t</span>
  16. <span class="label">上月同期</span>
  17. </div>
  18. <div class="data-item trend">
  19. <span class="value" style="color: #00c853;">-0.072</span><span class="unit">↓</span>
  20. <span class="label">趋势</span>
  21. </div>
  22. </div>
  23. </div>
  24. </div>
  25. <!-- 本年 -->
  26. <div class="card">
  27. <h3>本年</h3>
  28. <div class="data-container">
  29. <div class="data-row">
  30. <div class="data-item">
  31. <span class="value">144.747</span><span class="unit">t</span>
  32. <span class="label">当年</span>
  33. </div>
  34. <div class="data-item">
  35. <span class="value">123.812</span><span class="unit">t</span>
  36. <span class="label">去年同期</span>
  37. </div>
  38. <div class="data-item trend">
  39. <span class="value" style="color: #d50000;">20.935</span><span class="unit">↑</span>
  40. <span class="label">趋势</span>
  41. </div>
  42. </div>
  43. </div>
  44. </div>
  45. </div>
  46. <!-- 筛选区域 -->
  47. <div class="filter-container">
  48. <span>分类能耗</span>
  49. <select v-model="selectedCategory">
  50. <option value="电">电</option>
  51. <option value="水">水</option>
  52. <option value="天然气">天然气</option>
  53. </select>
  54. <input type="text" v-model="selectedYear" placeholder="输入年份" />
  55. <button @click="fetchData">查询</button>
  56. </div>
  57. <!-- 图表区域 -->
  58. <div id="chart" ref="chartRef" style="width: 100%; height: 400px;"></div>
  59. </div>
  60. </template>
  61. <script>
  62. import * as echarts from 'echarts';
  63. export default {
  64. data() {
  65. return {
  66. selectedCategory: '电',
  67. selectedYear: '',
  68. chartInstance: null,
  69. };
  70. },
  71. mounted() {
  72. this.initChart();
  73. },
  74. methods: {
  75. initChart() {
  76. const chartDom = this.$refs.chartRef;
  77. this.chartInstance = echarts.init(chartDom);
  78. const option = {
  79. title: { text: '能耗分布', left: 'center' },
  80. tooltip: {
  81. trigger: 'axis',
  82. axisPointer: { type: 'shadow' }
  83. },
  84. xAxis: {
  85. type: 'category',
  86. data: ['1月', '2月', '3月', '4月', '5月'],
  87. axisLabel: { color: '#333' }
  88. },
  89. yAxis: {
  90. type: 'value',
  91. axisLabel: { color: '#333' }
  92. },
  93. series: [
  94. {
  95. name: '能耗',
  96. type: 'bar',
  97. data: [39, 30, 28, 22, 6],
  98. itemStyle: { color: '#2196f3' }
  99. }
  100. ],
  101. grid: {
  102. top: 30,
  103. bottom: 30,
  104. left: 60,
  105. right: 20
  106. }
  107. };
  108. this.chartInstance.setOption(option);
  109. },
  110. fetchData() {
  111. console.log('查询:', this.selectedCategory, this.selectedYear);
  112. // 模拟数据更新
  113. this.updateChart([40, 32, 29, 23, 7]);
  114. },
  115. updateChart(data) {
  116. if (this.chartInstance) {
  117. this.chartInstance.setOption({
  118. series: [{ data: data }]
  119. });
  120. }
  121. }
  122. }
  123. };
  124. </script>
  125. <style scoped>
  126. .app {
  127. background-color: #fff;
  128. color: #333;
  129. font-family: "Segoe UI", sans-serif;
  130. padding: 30px;
  131. }
  132. /* 上方两个卡片并列 */
  133. .top-section {
  134. display: flex;
  135. justify-content: space-between;
  136. gap: 30px;
  137. margin-bottom: 30px;
  138. }
  139. .card {
  140. flex: 1;
  141. background-color: #f8f9fa;
  142. border-radius: 10px;
  143. box-shadow: 0 2px 6px rgba(0, 0, 0, 0.05);
  144. border: 1px solid #e0e0e0;
  145. height: 300px; /* 固定高度 */
  146. position: relative; /* 用于绝对定位标题 */
  147. }
  148. .card h3 {
  149. margin: 15px;
  150. font-size: 18px;
  151. font-weight: 600;
  152. color: #212121;
  153. position: absolute;
  154. top: 15px;
  155. left: 15px; /* 标题固定在左上角 */
  156. }
  157. .data-container {
  158. width: 100%;
  159. display: flex;
  160. justify-content: center; /* 水平居中 */
  161. align-items: center; /* 垂直居中 */
  162. height: calc(100% - 40px); /* 减去标题的高度 */
  163. }
  164. .data-row {
  165. display: flex;
  166. justify-content: space-around;
  167. align-items: center;
  168. width: 80%; /* 调整宽度以适应居中 */
  169. }
  170. .data-item {
  171. text-align: center;
  172. }
  173. .value {
  174. font-size: 24px;
  175. font-weight: bold;
  176. color: #000;
  177. }
  178. .unit {
  179. font-size: 14px;
  180. margin-left: 4px;
  181. color: #666;
  182. }
  183. .label {
  184. font-size: 12px;
  185. color: #999;
  186. display: block;
  187. margin-top: 4px;
  188. }
  189. .trend .value {
  190. font-size: 20px;
  191. }
  192. /* 筛选区域 */
  193. .filter-container {
  194. display: flex;
  195. align-items: center;
  196. margin-bottom: 25px;
  197. gap: 15px;
  198. }
  199. .filter-container span {
  200. font-weight: 500;
  201. min-width: 70px;
  202. }
  203. .filter-container select,
  204. .filter-container input {
  205. padding: 8px 12px;
  206. border-radius: 6px;
  207. border: 1px solid #ccc;
  208. outline: none;
  209. font-size: 14px;
  210. }
  211. .filter-container button {
  212. padding: 8px 16px;
  213. background-color: #2196f3;
  214. color: white;
  215. border: none;
  216. border-radius: 6px;
  217. cursor: pointer;
  218. transition: background-color 0.3s ease;
  219. }
  220. .filter-container button:hover {
  221. background-color: #1976d2;
  222. }
  223. </style>