|
13 | 13 | <s-scroll-view> |
14 | 14 | <VueDraggable |
15 | 15 | v-model="graphData" |
16 | | - :animation="150" |
| 16 | + :animation="300" |
17 | 17 | handle=".datablock-drag" |
18 | 18 | > |
19 | 19 | <DataBlock |
|
40 | 40 | <s-ripple attached></s-ripple> |
41 | 41 | </div> |
42 | 42 | </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> |
56 | 72 | </div> |
57 | | - <CodeDisplay :dataArr="toOriginalDatum(graphData)" /> |
| 73 | + <CodeDisplay :dataArr="toOriginalDatum(graphData, true)" /> |
58 | 74 | <div id="divider" @mousedown="handleDrag"></div> |
59 | 75 | </div> |
60 | 76 | <div id="graph" ref="shellRef"> |
|
74 | 90 | </template> |
75 | 91 |
|
76 | 92 | <script setup lang="ts"> |
77 | | -import "sober"; |
78 | 93 | import { useI18n } from "vue-i18n"; |
79 | 94 | const { t } = useI18n(); |
80 | 95 |
|
@@ -149,12 +164,27 @@ function handleDrag() { |
149 | 164 | function toogleDrawer() { |
150 | 165 | innerDrawer.value?.toggle(); |
151 | 166 | } |
| 167 | +
|
| 168 | +const importStr = ref(""); |
| 169 | +import { Snackbar } from "sober"; |
152 | 170 | 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 | + } |
158 | 188 | } |
159 | 189 | </script> |
160 | 190 |
|
|
0 commit comments