1515 :key =" dataItem.key"
1616 />
1717 </VueDraggable >
18- <div
19- class =" plot-data add-data"
20- @click =" graphData.push({ key: Math.random() })"
21- >
22- + 添加
18+ <div class =" plot-data add-data" >
19+ <div
20+ @click =" graphData.push({ key: Math.random() })"
21+ class =" add-data-opt add"
22+ >
23+ + 添加
24+ </div >
25+ <div @click =" handleImport()" class =" add-data-opt import" >↓ 导入</div >
2326 </div >
2427 </div >
2528 <CodeDisplay :dataArr =" cloneDeep(graphData)" />
@@ -42,9 +45,10 @@ import Graph from "./components/graph.vue";
4245import DataBlock from " ./components/dataBlock.vue" ;
4346import CodeDisplay from " ./components/codeDisplay.vue" ;
4447import { VueDraggable } from " vue-draggable-plus" ;
45- import type { FunctionPlotDatum } from " function-plot" ;
48+ import type { FunctionPlotDatum , FunctionPlotOptions } from " function-plot" ;
4649import { onMounted , ref , watch } from " vue" ;
4750import { cloneDeep } from " lodash-es" ;
51+ import JSON5 from " json5" ;
4852const graphData = ref <(FunctionPlotDatum & { key: number })[]>([
4953 { fn: " x^2" , key: 1 },
5054]);
@@ -77,6 +81,15 @@ function handleDrag() {
7781 handleResize ();
7882 });
7983}
84+ function handleImport() {
85+ const raw = prompt (" 源数据:" );
86+ if (! raw ) return ;
87+ graphData .value =
88+ (<FunctionPlotOptions >JSON5 .parse (raw )).data ?.map ((item ) => ({
89+ key: Math .random (),
90+ ... item ,
91+ })) ?? [];
92+ }
8093 </script >
8194
8295<style >
@@ -125,15 +138,27 @@ function handleDrag() {
125138 overflow : hidden ;
126139}
127140.add-data {
128- padding-top : 10 px ;
129- padding-bottom : 10 px ;
130- margin-bottom : 50 px ;
141+ padding : 0 ;
142+ display : flex ;
143+ flex-direction : row ;
131144 cursor : default ;
132145}
133- .add-data :hover {
146+ .add-data-opt {
147+ padding : 10px 30px ;
148+ }
149+ .add-data-opt.add {
150+ flex-grow : 1 ;
151+ }
152+ .add-data-opt :not (:nth-child (1 )) {
153+ border-left : 1px solid var (--c-border );
154+ }
155+ .editor-inner {
156+ padding-bottom : 50px ;
157+ }
158+ .add-data-opt :hover {
134159 background : var (--c-bk3 );
135160}
136- .add-data :active {
161+ .add-data-opt :active {
137162 background : var (--c-bk1 );
138163}
139164
0 commit comments