瀏覽代碼

feat: echart增加枚举

sunxiao 8 月之前
父節點
當前提交
1382590c2c

+ 0 - 2
src/components/BaseTable/index.vue

@@ -38,14 +38,12 @@ const rowClassName = (row) => {
     <template #empty>
       <span class="leading-[32px]">暂无数据</span>
     </template>
-
   </n-data-table>
 
 </template>
 
 <style scoped lang="scss">
 :deep(.custom-row .small) {
-  // color: red !important;
   line-height: 32px;
   padding-top: 0;
   padding-bottom: 0;

+ 6 - 0
src/utils/format.js

@@ -74,4 +74,10 @@ export const colorToRgba = (color, alpha) => {
   const b = parseInt(color.slice(5, 7), 16);
 
   return `rgba(${r}, ${g}, ${b}, ${alpha})`
+}
+
+
+// 判断是不是数字
+export const isNumberComprehensive = (value) => {
+  return isFinite(value) && !isNaN(parseFloat(value));
 }

+ 37 - 10
src/views/analyse/WorkOrder.vue

@@ -1,11 +1,12 @@
 <script setup>
-import { ref, unref, computed, onMounted, onUnmounted, nextTick } from 'vue';
+import { ref, unref, computed, onMounted, onUnmounted, h } from 'vue';
 import { useMessage, NDatePicker, NTabs, NTab, NRadioGroup, NRadio, NCheckboxGroup, NCheckbox, NDataTable } from 'naive-ui';
 import { BaseButton, RecodeCardItem, TheSubMenu, TheChatView, ChatWelcome, SvgIcon } from '@/components';
 import { ChatAsk, ChatAnswer } from '@/components/Chat';
 import { orderApi } from "@/api/order";
 import { chatApi } from '@/api/chat';
-import { formatEchart } from '@/utils/format';
+import { formatEchart, isNumberComprehensive } from '@/utils/format';
+import { ORDER_OPTION_ENUM } from './config/enum';
 import { getAreaOptions, getOrderAreaOptions } from './config/echartOptions'
 import * as echarts from 'echarts';
 import dayjs from 'dayjs';
@@ -196,16 +197,36 @@ const handleSubmit = async (question, params) => {
     const reuslt = Object.entries(data).map(([key, value]) => {
       if ( value.length ) {
         const [ xAxisData, yAxisData ] = formatEchart(value);
+        const [ item ] = value; 
+        const columns = Object.keys(item).map(k => ({
+          title: ORDER_OPTION_ENUM[k],
+          key: k,
+          width: '150px',
+          align: 'center',
+        }))
+        const data = value.map(item => {
+          Object.entries(item).forEach(([k, v]) => {  
+            console.log(k, isNumberComprehensive(v));
+            if (isNumberComprehensive(v)) {
+              item[k] = v ? Number(v.toFixed(2)) : 0
+            }
+          })
+          return item;
+        })
         return {
           id: key,
           title: titleEnum[key],
           xAxisData,
-          yAxisData
+          yAxisData,
+          columns,
+          data
         }
       }
     }).filter(Boolean);
 
     option.echartWithTableData = reuslt;
+
+    console.log( option );
   }
 
   addChat(option);
@@ -219,10 +240,6 @@ const handleSubmit = async (question, params) => {
       const chart = echarts.init(dom, null, { width: 680, height: 300 });
       const option = getOrderAreaOptions({ xAxisData, yAxisData });
       chart.setOption(option);
-      updateChat({
-        ...chatDataSource.value[0],
-        delayLoading: false
-      })
     })
 
     // if(!chart) {
@@ -230,7 +247,6 @@ const handleSubmit = async (question, params) => {
     //   chart = echarts.init(dom, null, { width: 680, height: 300 });
     // }
     
-    // chart.resize();
     // onRegenerate({ question }), 2 * 1000
   }, 2 * 1000);
 }
@@ -365,8 +381,19 @@ onUnmounted(() => {
                   <div :id="item.id" class="w-[680px] h-[300px]" style="width: 680px; height: 300px;"></div>
                 </div>
                 <div class="w-[700px]">
-                  <NDataTable :bordered="true" :single-line="false" single-column :columns="columns" :data="tableData"
-                    scroll="{ x: true }" size="small"></NDataTable>
+                  <NDataTable
+                    :max-height="250"
+                    bordered
+                    :single-line="false"
+                    :columns="item.columns"
+                    :data="item.data"
+                    scroll="{ x: true }"
+                    size="small"
+                  >
+                  <template #empty>
+                      <span class="leading-[32px]">暂无数据</span>
+                    </template>
+                  </NDataTable>
                 </div>
               </div>
             </div>

+ 1 - 0
src/views/analyse/components/config.js

@@ -13,3 +13,4 @@ export const SIMULATE_ENUM = {
   T:            '水温 ℃',
   pH:           'pH'
 }
+

+ 2 - 41
src/views/analyse/config/echartOptions.js

@@ -166,10 +166,8 @@ export const getOrderAreaOptions = ({ xAxisData, yAxisData }) => {
       smooth: true,
       symbolSize: 5,
       lineStyle: {
-        normal: {
-          width: 2,
-          color: itemColor
-        },
+        width: 2,
+        color: itemColor,
         borderColor: 'rgba(0,0,0,.4)',
       },
       itemStyle: {
@@ -177,21 +175,6 @@ export const getOrderAreaOptions = ({ xAxisData, yAxisData }) => {
         borderColor: itemColor,
         borderWidth: 3,
       },
-      // areaStyle: {
-      //   normal: {
-      //     color: new echarts.graphic.LinearGradient(0, 0, 0, 1, [{
-      //       offset: 0,
-      //       color: colorToRgba(itemColor, 0.3) 
-      //     },
-      //     {
-      //       offset: 1,
-      //       color: colorToRgba(itemColor, 0) 
-      //     }
-      //     ], false),
-      //     shadowColor: 'rgba(25,163,223, 0.5)',
-      //     shadowBlur: 20
-      //   }
-      // },
       tooltip: {
         valueFormatter: function (value) {
           return value + 'mg/L';
@@ -204,25 +187,8 @@ export const getOrderAreaOptions = ({ xAxisData, yAxisData }) => {
   return {
     series,
 
-    // label: {
-    //   show: true,
-    //   position: 'top',
-    //   color: '#a0cbff',
-    //   formatter: (e) => {
-    //     return e.value + '元';
-    //   },
-    // },
     tooltip: {
       trigger: 'axis',
-      // axisPointer: {
-      //   snap: true,
-      //   type: 'line',
-      //   lineStyle: {
-      //     color: '#1BD5DF', // 线的颜色
-      //     width: 3, // 线宽
-      //     type: 'solid', // 线型
-      //   },
-      // },
     },
     backgroundColor: '#fff',
     grid: {
@@ -230,11 +196,6 @@ export const getOrderAreaOptions = ({ xAxisData, yAxisData }) => {
       left: 40,
       right: 40,
       bottom: 30,
-      // x: 40,
-      // y: 10,
-      // x2: 40,
-      // y2: 30,
-      // borderWidth: 1,
     },
     legend: {
       orient: 'horizontal',

+ 22 - 0
src/views/analyse/config/enum.js

@@ -0,0 +1,22 @@
+export const ORDER_OPTION_ENUM = {
+  time:         '日期',
+  jsSlq:        '进水水量',
+  jsCod:        'COD',
+  jsTn:         '总氮',
+  jsTp:         '总磷',
+  jsNh3:        '氨氮',
+  jsSs:         'SS',
+  csSlqc:       '出水水量',
+  csCod:        'COD',
+  csTn:         '总氮',
+  csTp:         '总磷',
+  csNh3:        '氨氮',
+  csSs:         'SS',
+  no3Hlj1Jqr:   '1#好氧池硝酸盐',
+  no3Hlj2Jqr:   '2#好氧池硝酸盐',
+  nh31Jqr:      '1#缺氧氨氮',
+  nh32Jqr:      '2#缺氧氨氮',
+  no3Qyc1Jqr:   '1#缺氧池硝酸盐',
+  no3Qyc2Jqr:   '2#缺氧池硝酸盐',
+  tpRccJqr:     '二沉池正磷酸盐'
+}

+ 1 - 1
src/views/analyse/config/index.jsx

@@ -58,7 +58,7 @@ export const columns = [
     key: '流量',
     titleAlign: 'center',
     align: 'center',
-    className: 'age',
+    className: 'small',
     width: '78px',
     render: (row) => renderRowDom({ row, key: 'SS' })
   }

+ 11 - 6
yarn.lock

@@ -364,10 +364,10 @@
   resolved "https://registry.npmmirror.com/@emotion/hash/-/hash-0.8.0.tgz"
   integrity sha512-kBJtf7PH6aWwZ6fka3zQ0p6SBYzx4fl1LoZXE2RrnYST9Xljm7WfKJrU4g/Xr3Beg72MLrp1AWNUmuYJTL7Cow==
 
-"@esbuild/win32-x64@0.20.2":
+"@esbuild/darwin-x64@0.20.2":
   version "0.20.2"
-  resolved "https://registry.npmmirror.com/@esbuild/win32-x64/-/win32-x64-0.20.2.tgz"
-  integrity sha512-N49X4lJX27+l9jbLKSqZ6bKNjzQvHaT8IIFUy+YIqmXQdjYCToGWwOItDrfby14c78aDd5NHQl29xingXfCdLQ==
+  resolved "https://registry.npmmirror.com/@esbuild/darwin-x64/-/darwin-x64-0.20.2.tgz"
+  integrity sha512-tBcXp9KNphnNH0dfhv8KYkZhjc+H3XBkF5DKtswJblV7KlT9EI2+jeA8DgBjp908WEuYll6pF+UStUCfEpdysA==
 
 "@iktakahiro/markdown-it-katex@^4.0.1":
   version "4.0.1"
@@ -465,10 +465,10 @@
     estree-walker "^2.0.2"
     picomatch "^2.3.1"
 
-"@rollup/rollup-win32-x64-msvc@4.18.0":
+"@rollup/rollup-darwin-x64@4.18.0":
   version "4.18.0"
-  resolved "https://registry.npmmirror.com/@rollup/rollup-win32-x64-msvc/-/rollup-win32-x64-msvc-4.18.0.tgz"
-  integrity sha512-UOo5FdvOL0+eIVTgS4tIdbW+TtnBLWg1YBCcU2KWM7nuNwRz9bksDX1bekJJCpu25N1DVWaCwnT39dVQxzqS8g==
+  resolved "https://registry.npmmirror.com/@rollup/rollup-darwin-x64/-/rollup-darwin-x64-4.18.0.tgz"
+  integrity sha512-n2LMsUz7Ynu7DoQrSQkBf8iNrjOGyPLrdSg802vk6XT3FtsgX6JbE8IHRvposskFm9SNxzkLYGSq9QdpLYpRNA==
 
 "@trysound/sax@0.2.0":
   version "0.2.0"
@@ -1807,6 +1807,11 @@ fs-extra@^11.2.0:
     jsonfile "^6.0.1"
     universalify "^2.0.0"
 
+fsevents@~2.3.2, fsevents@~2.3.3:
+  version "2.3.3"
+  resolved "https://registry.npmmirror.com/fsevents/-/fsevents-2.3.3.tgz"
+  integrity sha512-5xoDfX+fL7faATnagmWPpbFtwh/R77WmMMqqHGS65C3vvB0YHrgF+B1YmZ3441tMj5n63k0212XNoJwzlhffQw==
+
 function-bind@^1.1.2:
   version "1.1.2"
   resolved "https://registry.npmmirror.com/function-bind/-/function-bind-1.1.2.tgz"