RightCard.vue 7.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310
  1. <template>
  2. <el-card class="right-card">
  3. <div class="card-header">
  4. <span>营养数据分析</span>
  5. <el-button link>收起</el-button>
  6. </div>
  7. <div class="nutrition-analysis">
  8. <!-- 营养设定 -->
  9. <div class="nutrition-setting">
  10. <span>营养设定:</span>
  11. <span class="value">897.3kcal/d</span>
  12. </div>
  13. <!-- 三大营养素表格 -->
  14. <div class="nutrition-table">
  15. <el-table :data="nutritionData" border size="small">
  16. <el-table-column prop="name" label="三大营养素" align="center" />
  17. <el-table-column prop="weight" label="质量(g)" align="center" />
  18. <el-table-column prop="ratio" label="热量占比" align="center">
  19. <template #default="{row}">{{ row.ratio }}%</template>
  20. </el-table-column>
  21. <el-table-column prop="reference" label="参考值" align="center" />
  22. </el-table>
  23. <div class="total-amount">
  24. <span>含量:</span>
  25. <span class="value">7.624g/天</span>
  26. </div>
  27. </div>
  28. <!-- 营养素占比图表 -->
  29. <div class="nutrition-chart">
  30. <div class="chart-title">三大营养元素质量占比</div>
  31. <div class="chart-content">
  32. <div ref="chartRef" class="pie-chart"></div>
  33. <div class="chart-legend">
  34. <div class="legend-item">
  35. <span class="color-block protein"></span>
  36. <span>蛋白质</span>
  37. <span class="percentage">44.12%</span>
  38. </div>
  39. <div class="legend-item">
  40. <span class="color-block fat"></span>
  41. <span>脂肪</span>
  42. <span class="percentage">23.66%</span>
  43. </div>
  44. <div class="legend-item">
  45. <span class="color-block carbs"></span>
  46. <span>碳水化合物</span>
  47. <span class="percentage">32.22%</span>
  48. </div>
  49. </div>
  50. </div>
  51. </div>
  52. <!-- 产品列表 -->
  53. <div class="product-list">
  54. <el-table :data="productData" border size="small">
  55. <el-table-column prop="name" label="产品名称" min-width="180" />
  56. <el-table-column prop="code" label="商品编码" width="120" align="center" />
  57. <el-table-column prop="type" label="产品" width="80" align="center" />
  58. </el-table>
  59. </div>
  60. </div>
  61. </el-card>
  62. </template>
  63. <script setup lang="ts">
  64. import {ref, onMounted} from 'vue';
  65. import * as echarts from 'echarts';
  66. // 图表相关
  67. const chartRef = ref<HTMLElement | null>(null);
  68. let myChart: echarts.ECharts | null = null;
  69. // 营养分析数据
  70. const nutritionData = ref([
  71. {name: '蛋白质', weight: '12.7505', ratio: '34.00', reference: '10%~20%'},
  72. {name: '蛋白质', weight: '12.7505', ratio: '34.00', reference: '10%~20%'},
  73. {name: '蛋白质', weight: '12.7505', ratio: '34.00', reference: '10%~20%'}
  74. ]);
  75. // 产品列表数据
  76. const productData = ref([
  77. {name: '复合矿物质210463A', code: 'T2463098', type: '肠内'},
  78. {name: '复合矿物质210463A', code: 'T2463098', type: '肠内'},
  79. {name: '复合矿物质210463A', code: 'T2463098', type: '肠内'},
  80. {name: '复合矿物质210463A', code: 'T2463098', type: '肠内'},
  81. {name: '复合矿物质210463A', code: 'T2463098', type: '肠内'},
  82. {name: '复合矿物质210463A', code: 'T2463098', type: '肠内'},
  83. {name: '复合矿物质210463A', code: 'T2463098', type: '肠内'},
  84. {name: '复合矿物质210463A', code: 'T2463098', type: '肠内'},
  85. {name: '复合矿物质210463A', code: 'T2463098', type: '肠内'},
  86. {name: '复合矿物质210463A', code: 'T2463098', type: '肠内'},
  87. {name: '复合矿物质210463A', code: 'T2463098', type: '肠内'},
  88. {name: '复合矿物质210463A', code: 'T2463098', type: '肠内'},
  89. {name: '复合矿物质210463A', code: 'T2463098', type: '肠内'}
  90. ]);
  91. // 初始化图表
  92. const initChart = () => {
  93. if (!chartRef.value) return;
  94. myChart = echarts.init(chartRef.value);
  95. const option = {
  96. tooltip: {
  97. show: false
  98. },
  99. legend: {
  100. show: false
  101. },
  102. color: ['#4B6EFF', '#8592A6', '#8CDFFF'],
  103. series: [
  104. {
  105. name: '营养元素',
  106. type: 'pie',
  107. radius: ['65%', '85%'],
  108. center: ['50%', '50%'],
  109. startAngle: 90,
  110. avoidLabelOverlap: false,
  111. silent: true,
  112. itemStyle: {
  113. borderWidth: 0,
  114. borderRadius: 0
  115. },
  116. label: {
  117. show: false
  118. },
  119. emphasis: {
  120. disabled: true
  121. },
  122. labelLine: {
  123. show: false
  124. },
  125. data: [
  126. {value: 44.12, name: '蛋白质'},
  127. {value: 23.66, name: '脂肪'},
  128. {value: 32.22, name: '碳水化合物'}
  129. ]
  130. }
  131. ]
  132. };
  133. myChart.setOption(option);
  134. };
  135. onMounted(() => {
  136. initChart();
  137. window.addEventListener('resize', () => {
  138. myChart?.resize();
  139. });
  140. });
  141. </script>
  142. <style lang="scss" scoped>
  143. .right-card {
  144. width: 400px;
  145. .card-header {
  146. display: flex;
  147. justify-content: space-between;
  148. align-items: center;
  149. margin-bottom: 16px;
  150. padding: 0 4px;
  151. span {
  152. font-size: 16px;
  153. font-weight: 500;
  154. color: #303133;
  155. }
  156. }
  157. .nutrition-analysis {
  158. .nutrition-setting {
  159. background: #fff;
  160. padding: 12px;
  161. margin-bottom: 16px;
  162. border-radius: 4px;
  163. display: flex;
  164. align-items: center;
  165. gap: 8px;
  166. color: #606266;
  167. .value {
  168. color: var(--el-color-primary);
  169. font-weight: 500;
  170. }
  171. }
  172. .nutrition-table {
  173. margin-bottom: 16px;
  174. :deep(.el-table) {
  175. margin-bottom: 8px;
  176. th {
  177. background-color: #f5f7fa;
  178. color: #606266;
  179. font-weight: 500;
  180. padding: 8px 0;
  181. }
  182. td {
  183. padding: 8px;
  184. }
  185. }
  186. .total-amount {
  187. padding: 8px 12px;
  188. background: #f5f7fa;
  189. color: #606266;
  190. font-size: 14px;
  191. display: flex;
  192. align-items: center;
  193. gap: 8px;
  194. .value {
  195. color: #303133;
  196. }
  197. }
  198. }
  199. .nutrition-chart {
  200. margin-bottom: 16px;
  201. background: #fff;
  202. border-radius: 4px;
  203. border: 1px solid #e4e7ed;
  204. overflow: hidden;
  205. .chart-title {
  206. font-size: 14px;
  207. color: #303133;
  208. text-align: center;
  209. padding: 12px 0;
  210. background-color: #f5f7fa;
  211. border-bottom: 1px solid #e4e7ed;
  212. font-weight: 500;
  213. }
  214. .chart-content {
  215. display: flex;
  216. align-items: center;
  217. gap: 32px;
  218. padding: 16px;
  219. background-color: #fff;
  220. .pie-chart {
  221. flex: none;
  222. width: 140px;
  223. height: 140px;
  224. }
  225. .chart-legend {
  226. flex: 1;
  227. min-width: 120px;
  228. display: flex;
  229. flex-direction: column;
  230. gap: 12px;
  231. .legend-item {
  232. display: flex;
  233. align-items: center;
  234. gap: 8px;
  235. font-size: 14px;
  236. color: #606266;
  237. white-space: nowrap;
  238. .color-block {
  239. width: 12px;
  240. height: 12px;
  241. border-radius: 2px;
  242. flex-shrink: 0;
  243. &.protein {
  244. background: #4b6eff;
  245. }
  246. &.fat {
  247. background: #8592a6;
  248. }
  249. &.carbs {
  250. background: #8cdfff;
  251. }
  252. }
  253. .percentage {
  254. margin-left: 8px;
  255. color: #303133;
  256. font-weight: 500;
  257. }
  258. }
  259. }
  260. }
  261. }
  262. .product-list {
  263. :deep(.el-table) {
  264. th {
  265. background-color: #f5f7fa;
  266. color: #606266;
  267. font-weight: 500;
  268. padding: 8px 0;
  269. }
  270. td {
  271. padding: 8px;
  272. }
  273. }
  274. }
  275. }
  276. }
  277. </style>