Skip to content

Commit 469f050

Browse files
committed
数据导入弹窗改为自定义 UI
1 parent 7653be7 commit 469f050

7 files changed

Lines changed: 137 additions & 69 deletions

File tree

src/App.vue

Lines changed: 51 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@
1313
<s-scroll-view>
1414
<VueDraggable
1515
v-model="graphData"
16-
:animation="150"
16+
:animation="300"
1717
handle=".datablock-drag"
1818
>
1919
<DataBlock
@@ -40,21 +40,37 @@
4040
<s-ripple attached></s-ripple>
4141
</div>
4242
</s-scroll-view>
43-
44-
<s-tooltip class="data-import">
45-
<s-fab slot="trigger" @click.stop="handleImport()">
46-
<s-icon>
47-
<svg viewBox="0 -960 960 960">
48-
<path
49-
d="M480-120v-80h280v-560H480v-80h280q33 0 56.5 23.5T840-760v560q0 33-23.5 56.5T760-120H480Zm-80-160-55-58 102-102H120v-80h327L345-622l55-58 200 200-200 200Z"
50-
></path>
51-
</svg>
52-
</s-icon>
53-
</s-fab>
54-
{{ t("buttons.import") }}
55-
</s-tooltip>
43+
<s-dialog>
44+
<s-tooltip class="data-import" slot="trigger">
45+
<s-fab slot="trigger">
46+
<s-icon>
47+
<svg viewBox="0 -960 960 960">
48+
<path
49+
d="M480-120v-80h280v-560H480v-80h280q33 0 56.5 23.5T840-760v560q0 33-23.5 56.5T760-120H480Zm-80-160-55-58 102-102H120v-80h327L345-622l55-58 200 200-200 200Z"
50+
></path>
51+
</svg>
52+
</s-icon>
53+
</s-fab>
54+
{{ t("buttons.import") }}
55+
</s-tooltip>
56+
<div slot="headline">{{ t("title.source") }}</div>
57+
<s-text-field
58+
slot="text"
59+
label="JSON5 / JSON"
60+
multiLine
61+
style="min-height: 180px; min-width: 40vw"
62+
v-model.lazy="importStr"
63+
class="monospace"
64+
></s-text-field>
65+
<s-button slot="action" type="text">
66+
{{ t("buttons.cancel") }}
67+
</s-button>
68+
<s-button slot="action" type="text" @click="handleImport">
69+
{{ t("buttons.confirm") }}
70+
</s-button>
71+
</s-dialog>
5672
</div>
57-
<CodeDisplay :dataArr="toOriginalDatum(graphData)" />
73+
<CodeDisplay :dataArr="toOriginalDatum(graphData, true)" />
5874
<div id="divider" @mousedown="handleDrag"></div>
5975
</div>
6076
<div id="graph" ref="shellRef">
@@ -74,7 +90,6 @@
7490
</template>
7591

7692
<script setup lang="ts">
77-
import "sober";
7893
import { useI18n } from "vue-i18n";
7994
const { t } = useI18n();
8095
@@ -149,12 +164,27 @@ function handleDrag() {
149164
function toogleDrawer() {
150165
innerDrawer.value?.toggle();
151166
}
167+
168+
const importStr = ref("");
169+
import { Snackbar } from "sober";
152170
function handleImport() {
153-
const raw = prompt("源数据:");
154-
if (!raw) return;
155-
graphData.value = toInternalDatum(
156-
(JSON5.parse(raw).data as FunctionPlotDatum[]) ?? []
157-
);
171+
if (importStr.value !== "") {
172+
try {
173+
graphData.value = toInternalDatum(
174+
(JSON5.parse(importStr.value).data as FunctionPlotDatum[]) ?? []
175+
);
176+
Snackbar.builder({
177+
text: t("title.importSuccess"),
178+
type: "success",
179+
});
180+
} catch (e) {
181+
Snackbar.builder({
182+
text: t("title.importFail"),
183+
type: "error",
184+
});
185+
}
186+
importStr.value = "";
187+
}
158188
}
159189
</script>
160190

src/components/dataBlock.vue

Lines changed: 52 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -29,39 +29,58 @@
2929
</s-picker-item>
3030
</s-picker>
3131
<div style="flex-grow: 1"></div>
32-
<s-tooltip>
33-
<s-icon-button slot="trigger" @click="emit('delete')">
32+
<div class="dataBlockBtns">
33+
<s-tooltip>
34+
<s-icon-button slot="trigger" @click="emit('delete')">
35+
<s-icon style="color: var(--s-color-error)">
36+
<svg viewBox="0 -960 960 960">
37+
<path
38+
d="M280-120q-33 0-56.5-23.5T200-200v-520h-40v-80h200v-40h240v40h200v80h-40v520q0 33-23.5 56.5T680-120H280Zm400-600H280v520h400v-520ZM360-280h80v-360h-80v360Zm160 0h80v-360h-80v360ZM280-720v520-520Z"
39+
></path>
40+
</svg>
41+
</s-icon>
42+
</s-icon-button>
43+
{{ t("buttons.del") }}
44+
</s-tooltip>
45+
<s-tooltip>
46+
<s-icon-button
47+
slot="trigger"
48+
@click="dataItem.hidden = !dataItem.hidden"
49+
:type="dataItem.hidden ? 'filled-tonal' : 'standard'"
50+
>
51+
<s-icon>
52+
<svg viewBox="0 -960 960 960">
53+
<path
54+
d="M280-440h400v-80H280v80ZM480-80q-83 0-156-31.5T197-197q-54-54-85.5-127T80-480q0-83 31.5-156T197-763q54-54 127-85.5T480-880q83 0 156 31.5T763-763q54 54 85.5 127T880-480q0 83-31.5 156T763-197q-54 54-127 85.5T480-80Zm0-80q134 0 227-93t93-227q0-134-93-227t-227-93q-134 0-227 93t-93 227q0 134 93 227t227 93Zm0-320Z"
55+
></path>
56+
</svg>
57+
</s-icon>
58+
</s-icon-button>
59+
{{ t("buttons.hide") }}
60+
</s-tooltip>
61+
<s-tooltip>
62+
<s-icon-button
63+
slot="trigger"
64+
@click="
65+
blockFolded = !blockFolded;
66+
console.log(foldShell);
67+
"
68+
>
69+
<s-icon :name="blockFolded ? 'chevron_down' : 'chevron_up'">
70+
</s-icon>
71+
</s-icon-button>
72+
{{ t(blockFolded ? "buttons.expand" : "buttons.collapse") }}
73+
</s-tooltip>
74+
<span class="datablock-drag">
3475
<s-icon>
3576
<svg viewBox="0 -960 960 960">
3677
<path
37-
d="M280-120q-33 0-56.5-23.5T200-200v-520h-40v-80h200v-40h240v40h200v80h-40v520q0 33-23.5 56.5T680-120H280Zm400-600H280v520h400v-520ZM360-280h80v-360h-80v360Zm160 0h80v-360h-80v360ZM280-720v520-520Z"
78+
d="M320-440v-287L217-624l-57-56 200-200 200 200-57 56-103-103v287h-80ZM600-80 400-280l57-56 103 103v-287h80v287l103-103 57 56L600-80Z"
3879
></path>
3980
</svg>
4081
</s-icon>
41-
</s-icon-button>
42-
{{ t("buttons.del") }}
43-
</s-tooltip>
44-
<s-tooltip>
45-
<s-icon-button
46-
slot="trigger"
47-
@click="
48-
blockFolded = !blockFolded;
49-
console.log(foldShell);
50-
"
51-
>
52-
<s-icon :name="blockFolded ? 'chevron_down' : 'chevron_up'"> </s-icon>
53-
</s-icon-button>
54-
{{ t(blockFolded ? "buttons.expand" : "buttons.collapse") }}
55-
</s-tooltip>
56-
<span class="datablock-drag">
57-
<s-icon>
58-
<svg viewBox="0 -960 960 960">
59-
<path
60-
d="M320-440v-287L217-624l-57-56 200-200 200 200-57 56-103-103v287h-80ZM600-80 400-280l57-56 103 103v-287h80v287l103-103 57 56L600-80Z"
61-
></path>
62-
</svg>
63-
</s-icon>
64-
</span>
82+
</span>
83+
</div>
6584
</div>
6685

6786
<div class="inputs">
@@ -198,13 +217,17 @@ const allowedGraphType = computed(() =>
198217
.selectors s-picker {
199218
width: 8em;
200219
}
201-
220+
.dataBlockBtns {
221+
display: flex;
222+
}
202223
.datablock-drag {
203224
width: 40px;
225+
height: 40px;
204226
text-align: center;
205-
line-height: 40px;
206227
border-radius: 50%;
207228
cursor: grab;
229+
display: inline-flex;
230+
justify-content: center;
208231
}
209232
210233
.sortable-chosen .datablock-drag {

src/components/dataBlockInner/coordArrInputs.vue

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
class="coordarr-wrapper styled"
44
v-if="fnType.coordArr"
55
v-model="privateData"
6-
:animation="150"
6+
:animation="300"
77
handle="span.coordarr-drag"
88
>
99
<div

src/consts.ts

Lines changed: 13 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -74,11 +74,20 @@ export type InternalDatum = Omit<FunctionPlotDatum, "fnType" | "graphType"> & {
7474
fnType: "text" | FunctionPlotDatum["fnType"];
7575
graphType: FunctionPlotDatum["graphType"];
7676
key: number;
77+
hidden?: boolean;
7778
};
7879

79-
export function toOriginalDatum(items: InternalDatum[]) {
80+
export function toOriginalDatum(items: InternalDatum[], forExport?: boolean) {
8081
const cloned = cloneDeep(items);
81-
cloned.forEach((item) => {
82+
return cloned.flatMap((item) => {
83+
if (item.hidden)
84+
if (forExport) return [];
85+
else
86+
return {
87+
fnType: "points",
88+
graphType: "polyline",
89+
points: [],
90+
};
8291
const fnType = item.fnType;
8392
const graphType = item.graphType;
8493
const graphTypeObj = getAllowedGraphType(fnType).find(
@@ -91,8 +100,8 @@ export function toOriginalDatum(items: InternalDatum[]) {
91100
delete (<any>item).graphType;
92101
}
93102
delete (<any>item).key;
94-
});
95-
return cloned as FunctionPlotDatum[];
103+
return item;
104+
}) as FunctionPlotDatum[];
96105
}
97106
export function toInternalDatum(items: FunctionPlotDatum[]) {
98107
const cloned = cloneDeep(items) as InternalDatum[];
@@ -364,13 +373,3 @@ export const fnTypeArr = [
364373
],
365374
},
366375
] as const satisfies FnType[];
367-
368-
export function findError(graphData: FunctionPlotDatum[]) {
369-
for (const [index, dataItem] of graphData.entries()) {
370-
const fnType = getFnType(dataItem.fnType);
371-
for (const input of fnType.inputs) if (!dataItem[input.value]) return index;
372-
for (const coord of fnType.coord ?? [])
373-
if (!dataItem[coord.value] && !coord.optional) return index;
374-
}
375-
return 0;
376-
}

src/i18n.ts

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,12 +7,14 @@ export default createI18n({
77
buttons: {
88
add: "添加",
99
import: "导入",
10-
raw: "原始数据",
1110
del: "删除",
1211
expand: "展开",
1312
collapse: "收起",
1413
reset: "重置",
1514
addPoint: "添加点",
15+
hide: "隐藏",
16+
cancel: "取消",
17+
confirm: "确定",
1618
},
1719
graphType: {
1820
interval: "默认",
@@ -46,18 +48,23 @@ export default createI18n({
4648
},
4749
title: {
4850
output: "输出代码",
51+
source: "数据源",
52+
importSuccess: "导入成功",
53+
importFail: "导入失败",
4954
},
5055
},
5156
"en-US": {
5257
buttons: {
5358
add: "Add",
5459
import: "Import",
55-
raw: "Raw data",
5660
del: "Delete",
5761
expand: "Expand",
5862
collapse: "Collapse",
5963
reset: "Reset",
6064
addPoint: "Add Point",
65+
hide: "Hide",
66+
cancel: "Cancel",
67+
confirm: "Confirm",
6168
},
6269
graphType: {
6370
interval: "Interval",
@@ -91,7 +98,9 @@ export default createI18n({
9198
},
9299
title: {
93100
output: "Output code",
94-
defaultTo: "Default to {defaultValue}",
101+
source: "Data Source",
102+
importSuccess: "Import success",
103+
importFail: "Import failed",
95104
},
96105
},
97106
},

src/main.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,8 @@ import i18n from "./i18n";
44
import "./style.css";
55
import App from "./App.vue";
66

7+
import "sober";
8+
79
const app = createApp(App);
810

911
app.use(i18n);

src/style.css

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -61,5 +61,10 @@ input[type="number"] {
6161

6262
.styled::part(input),
6363
.styled {
64-
font-family: "KaTeX-Italic", "KaTeX", "KaTeX-Math","Times new roman";
64+
font-family: "KaTeX-Italic", "KaTeX", "KaTeX-Math", "Times new roman";
65+
}
66+
67+
.monospace,
68+
.monospace::part(input) {
69+
font-family: "Jetbrains Mono", monospace;
6570
}

0 commit comments

Comments
 (0)