Skip to content

Commit b27e1bf

Browse files
authored
Merge pull request #2 from Linho1219/i18n
i18n 部署
2 parents b2299c3 + 3a8c238 commit b27e1bf

File tree

16 files changed

+491
-232
lines changed

16 files changed

+491
-232
lines changed

package-lock.json

Lines changed: 72 additions & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,8 @@
1818
"prettier": "^3.4.2",
1919
"utf8": "^3.0.0",
2020
"vue": "^3.5.13",
21-
"vue-draggable-plus": "^0.6.0"
21+
"vue-draggable-plus": "^0.6.0",
22+
"vue-i18n": "^10.0.7"
2223
},
2324
"devDependencies": {
2425
"@types/base-64": "^1.0.2",

src/App.vue

Lines changed: 32 additions & 53 deletions
Original file line numberDiff line numberDiff line change
@@ -18,20 +18,28 @@
1818
</VueDraggable>
1919
<div class="plot-data add-data">
2020
<div
21-
@click="graphData.push({ key: Math.random() })"
21+
@click="
22+
graphData.push({
23+
key: Math.random(),
24+
fnType: 'linear',
25+
graphType: 'polyline',
26+
})
27+
"
2228
class="add-data-opt add"
2329
>
24-
+ 添加
30+
+ {{ t("buttons.add") }}
31+
</div>
32+
<div @click="handleImport()" class="add-data-opt import">
33+
↓ {{ t("buttons.import") }}
2534
</div>
26-
<div @click="handleImport()" class="add-data-opt import">↓ 导入</div>
2735
</div>
2836
</div>
29-
<CodeDisplay :dataArr="cloneArr(graphData)" />
37+
<CodeDisplay :dataArr="toOriginalDatum(graphData)" />
3038
</div>
3139
<div id="divider" @mousedown="handleDrag"></div>
3240
<div id="graph" ref="shellRef">
3341
<Graph
34-
:data="cloneArr(graphData)"
42+
:data="toOriginalDatum(graphData)"
3543
:width="graphWidth"
3644
:height="graphHeight"
3745
:key="key"
@@ -44,20 +52,24 @@
4452
</template>
4553

4654
<script setup lang="ts">
55+
import { useI18n } from 'vue-i18n'
56+
const { t } = useI18n()
57+
4758
import Navbar from "./components/nav.vue";
4859
import Graph from "./components/graph.vue";
4960
import DataBlock from "./components/dataBlock.vue";
5061
import CodeDisplay from "./components/codeDisplay.vue";
5162
import { VueDraggable } from "vue-draggable-plus";
52-
import type { FunctionPlotDatum, FunctionPlotOptions } from "function-plot";
63+
import type { FunctionPlotDatum } from "function-plot";
5364
import { onMounted, ref } from "vue";
54-
import { cloneDeep } from "lodash-es";
5565
import JSON5 from "json5";
5666
import base64 from "base-64";
5767
import utf8 from "utf8";
58-
import { Datum } from "./consts";
68+
import { InternalDatum, toInternalDatum, toOriginalDatum } from "./consts";
5969
60-
const graphData = ref<Datum[]>([{ fn: "x^2", key: 1 }]);
70+
const graphData = ref<InternalDatum[]>([
71+
{ fnType: "linear", graphType: "polyline", fn: "x^2", key: 1 },
72+
]);
6173
6274
const graphWidth = ref(0),
6375
graphHeight = ref(0);
@@ -73,38 +85,6 @@ function handleResize() {
7385
}
7486
}
7587
76-
function cloneArr<T extends Object[]>(obj: T) {
77-
const cloned = cloneDeep(obj);
78-
function removeUndefined(obj: Record<string, any>) {
79-
for (const key in obj) {
80-
console.log(1);
81-
if (obj[key] === undefined) delete obj[key];
82-
if (
83-
typeof obj[key] === "object" &&
84-
obj[key] !== null &&
85-
!Array.isArray(obj[key])
86-
)
87-
removeUndefined(obj[key]);
88-
}
89-
}
90-
cloned.forEach((item) => removeUndefined(item));
91-
return cloned as T;
92-
}
93-
94-
function importMapper(item: FunctionPlotDatum): Datum {
95-
if (item.graphType === "text")
96-
return {
97-
...item,
98-
fnType: "text",
99-
key: Math.random(),
100-
};
101-
else
102-
return {
103-
...item,
104-
key: Math.random(),
105-
};
106-
}
107-
10888
function fullUpdate() {
10989
fullUpdateState.value = true;
11090
key.value++;
@@ -115,14 +95,13 @@ onMounted(() => {
11595
if (rawCode)
11696
try {
11797
const code = utf8.decode(base64.decode(decodeURIComponent(rawCode)));
118-
const data = (<FunctionPlotDatum[]>JSON5.parse(code).data).map(
119-
importMapper
98+
const data = toInternalDatum(
99+
(JSON5.parse(code).data as FunctionPlotDatum[]) ?? []
120100
);
121-
graphData.value = <Datum[]>data;
101+
graphData.value = toInternalDatum(<FunctionPlotDatum[]>data);
122102
console.log(code);
123103
console.log(data);
124104
} catch (e) {}
125-
126105
window.addEventListener("resize", handleResize);
127106
handleResize();
128107
});
@@ -143,8 +122,9 @@ function handleDrag() {
143122
function handleImport() {
144123
const raw = prompt("源数据:");
145124
if (!raw) return;
146-
graphData.value =
147-
(<FunctionPlotOptions>JSON5.parse(raw)).data?.map(importMapper) ?? [];
125+
graphData.value = toInternalDatum(
126+
(JSON5.parse(raw).data as FunctionPlotDatum[]) ?? []
127+
);
148128
}
149129
</script>
150130

@@ -171,6 +151,7 @@ function handleImport() {
171151
#navbar {
172152
height: 50px;
173153
width: 100vw;
154+
box-sizing: border-box;
174155
background: var(--c-bk1);
175156
border-bottom: var(--c-border) 1px solid;
176157
position: relative;
@@ -179,15 +160,14 @@ function handleImport() {
179160
#editor {
180161
border-right: var(--c-border) 1px solid;
181162
position: relative;
163+
display: flex;
164+
flex-direction: column;
182165
}
183166
.editor-inner {
184167
overflow: scroll;
185-
position: absolute;
186-
top: 0;
187-
left: 0;
188-
right: 0;
189-
bottom: 300px;
168+
flex-grow: 1;
190169
}
170+
191171
#graph {
192172
flex-grow: 1;
193173
position: relative;
@@ -197,7 +177,6 @@ function handleImport() {
197177
padding: 0;
198178
display: flex;
199179
flex-direction: row;
200-
cursor: default;
201180
}
202181
.add-data-opt {
203182
padding: 10px 30px;

src/components/codeDisplay.vue

Lines changed: 42 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -1,28 +1,32 @@
11
<template>
2-
<div class="plot-data output">
3-
<span class="output-title">代码</span>
2+
<div class="plot-data output" :class="{ collapse }">
3+
<span class="output-title"
4+
>{{ t("title.output") }}
5+
<button class="codeCollapse" @click="collapse = !collapse">
6+
{{ t(collapse ? "buttons.expand" : "buttons.collapse") }}
7+
</button>
8+
</span>
49
<pre>{{ formatted }}</pre>
510
</div>
611
</template>
712

813
<script setup lang="ts">
14+
import { useI18n } from "vue-i18n";
15+
const { t } = useI18n();
16+
917
import JSON5 from "json5";
1018
import prettier from "prettier/standalone";
1119
import prettierPluginBabel from "prettier/plugins/babel";
1220
import prettierPluginEstree from "prettier/plugins/estree";
1321
import { ref, watch } from "vue";
14-
import { Datum } from "../consts";
22+
import { FunctionPlotDatum } from "function-plot";
1523
const { dataArr } = defineProps<{
16-
dataArr: (Omit<Datum, "key"> & { key?: number })[];
24+
dataArr: FunctionPlotDatum[];
1725
}>();
1826
const formatted = ref("");
1927
watch(
2028
() => dataArr,
2129
() => {
22-
dataArr.forEach((item) => {
23-
if (item.graphType === "text") delete item.fnType;
24-
delete item.key;
25-
});
2630
prettier
2731
.format(JSON5.stringify({ data: dataArr }), {
2832
parser: "json5",
@@ -33,32 +37,50 @@ watch(
3337
},
3438
{ immediate: true }
3539
);
40+
41+
const collapse = ref(true);
3642
</script>
3743

3844
<style>
3945
.plot-data.output {
40-
position: absolute;
41-
left: 0;
42-
right: 0;
43-
bottom: 0;
4446
border-top: var(--c-border) 1px solid;
45-
padding: 20px 15px;
47+
padding: 15px 15px;
4648
height: 260px;
49+
display: flex;
50+
flex-direction: column;
51+
gap: 10px;
52+
overflow: hidden;
4753
}
4854
.plot-data.output .output-title {
4955
font-size: 20px;
5056
font-weight: bold;
5157
display: block;
52-
margin-bottom: 10px;
5358
}
5459
.plot-data.output pre {
55-
position: absolute;
56-
top: 60px;
57-
bottom: 15px;
58-
left: 15px;
59-
right: 15px;
60-
margin: 0;
60+
flex-grow: 1;
6161
overflow: scroll;
6262
user-select: all;
63+
margin: 0;
64+
}
65+
66+
.plot-data.output.collapse {
67+
height: 30px;
68+
}
69+
70+
.codeCollapse{
71+
float: right;
72+
height:100%;
73+
padding:0 10px;
74+
background: var(--c-bk3);
75+
border:var(--c-border) 1px solid;
76+
border-radius: 5px;
77+
opacity: 0.75;
78+
}
79+
.codeCollapse:hover{
80+
opacity: 1;
81+
}
82+
.codeCollapse:active{
83+
opacity: 1;
84+
filter: brightness(0.5);
6385
}
6486
</style>

0 commit comments

Comments
 (0)