diff --git a/.eslintrc.cjs b/.eslintrc.cjs index d6c9537..a0cb221 100644 --- a/.eslintrc.cjs +++ b/.eslintrc.cjs @@ -2,17 +2,20 @@ module.exports = { root: true, env: { browser: true, es2020: true }, extends: [ - 'eslint:recommended', - 'plugin:@typescript-eslint/recommended', - 'plugin:react-hooks/recommended', + "eslint:recommended", + "plugin:@typescript-eslint/recommended", + "plugin:react-hooks/recommended", ], - ignorePatterns: ['dist', '.eslintrc.cjs'], - parser: '@typescript-eslint/parser', - plugins: ['react-refresh'], + ignorePatterns: ["dist", ".eslintrc.cjs"], + parser: "@typescript-eslint/parser", + plugins: ["react-refresh"], rules: { - 'react-refresh/only-export-components': [ - 'warn', + "react-refresh/only-export-components": [ + "warn", { allowConstantExport: true }, ], + "@typescript-eslint/no-explicit-any": "off", + "prefer-const": "off", + "@typescript-eslint/no-unused-vars": "off", }, -} +}; diff --git a/package.json b/package.json index bef8251..861a0e6 100644 --- a/package.json +++ b/package.json @@ -19,6 +19,7 @@ "nprogress": "^0.2.0", "react": "^18.2.0", "react-dom": "^18.2.0", + "react-echarts-core": "^1.0.2", "react-redux": "^8.1.2", "react-router-dom": "^6.15.0", "redux-persist": "^6.0.0", diff --git a/src/view/custom-query/echarts-editor/index.tsx b/src/view/custom-query/echarts-editor/index.tsx new file mode 100644 index 0000000..6f5919d --- /dev/null +++ b/src/view/custom-query/echarts-editor/index.tsx @@ -0,0 +1,171 @@ +import { useState, useRef, useEffect } from "react"; +import "../index.scss"; +import { Button, Select } from "antd"; +// import type { EChartsOption } from "node_modules/react-echarts-core/lib/ChartCore"; +// import ChartCore from "node_modules/react-echarts-core/lib/ChartCore"; +import * as echarts from "echarts"; +export default function EchartsEditor() { + const echartRef: any = useRef(null); + const [xList, setXList] = useState([]); + const [yList, setYList] = useState([]); + const [currentDrag, setCurrentDrag] = useState({}); + const [dataList, setDataList] = useState([ + { id: 1, name: "Vue", state: "Value" }, + { id: 2, name: "React", state: "Value" }, + { id: 3, name: "Angular", state: "Key" }, + ]); + const [echartOption, setEchartOption] = useState({ + xAxis: { + data: ["A", "B", "C", "D", "E"], + }, + yAxis: { + type: "value", + }, + series: [ + { + data: [1, 2, 3, 4, 5], + type: "line", + }, + ], + }); + + const onDragStart: any = (item: any) => { + console.log(item.name, "开始拖拽"); + setCurrentDrag(item); + }; + + const onDragEnd: any = (item: any) => { + console.log(item.name, "结束拖拽"); + }; + + const onYDragOver: any = (e: any) => { + e.preventDefault(); + }; + + const onXDrop: any = () => { + console.log("拖拽至X轴区域"); + setXList(xList.concat(currentDrag)); + let newDataList = handleDelDataList(currentDrag.id); + setDataList(newDataList); + setEchartOption({ + ...echartOption, + xAxis: { + data: xList.map((item) => item.name), + }, + }); + }; + + const onXDragOver: any = (e: any) => { + e.preventDefault(); + }; + + const onYDrop: any = () => { + console.log("拖拽至Y轴区域"); + setYList(yList.concat(currentDrag)); + let newDataList = handleDelDataList(currentDrag.id); + setDataList(newDataList); + }; + + const handleDelDataList = (id: number) => { + let newDataList = dataList; + const curIndex = newDataList.findIndex((item) => item.id === id); + newDataList.splice(curIndex, 1); + return newDataList; + }; + + // const res = () => { + // let res: any[] = []; + // setXList(xList); + // xList.forEach((item: any) => { + // res.push(item.name); + // }); + // setXEchartList(res); + // console.log(xEchartList); + // return xEchartList; + // }; + + useEffect(() => { + const myEchart: any = echarts.init(document.querySelector(".canvas")); + myEchart.setOption(echartOption); + console.log(echartOption); + }, [echartOption]); + + return ( + <> +
+
+