|
81 | 81 | <Upload class="ui-icon" aria-hidden="true" /> |
82 | 82 | </button> |
83 | 83 | <input |
84 | | - ref="fileInput" |
| 84 | + :ref="setFileInput" |
85 | 85 | type="file" |
86 | 86 | accept=".txt,.json,application/json" |
87 | 87 | multiple |
@@ -118,23 +118,20 @@ import { useClipboardStore } from '@/stores/clipboardStore'; |
118 | 118 | import { useHistoryStore } from '@/stores/historyStore'; |
119 | 119 | import { useWindowStore } from '@/stores/windowStore'; |
120 | 120 | import { useActiveContext } from '@/composables/useActiveContext'; |
121 | | -import { useFileImport } from '@/composables/useImporter'; |
| 121 | +import { useFileImportInput } from '@/composables/useImporter'; |
122 | 122 | import { useProjectManager } from '@/composables/useProjectManager'; |
123 | 123 | import { vClickOutside } from '@/directives/clickOutside'; |
124 | 124 | import type { ProjectFile } from '@/types/project'; |
125 | 125 | import StoredProjectsPopover from '@/components/popovers/StoredProjectsPopover.vue'; |
126 | 126 | import ExportPopover from '@/components/popovers/ExportPopover.vue'; |
127 | 127 |
|
128 | | -const fileInput = ref<HTMLInputElement | null>(null); |
129 | | -
|
130 | 128 | const logStore = useLogStore(); |
131 | 129 | const styleStore = useStyleStore(); |
132 | 130 | const clipboardStore = useClipboardStore(); |
133 | 131 | const historyStore = useHistoryStore(); |
134 | 132 | const windowStore = useWindowStore(); |
135 | | -
|
136 | 133 | const activeContext = useActiveContext(); |
137 | | -const { importAndApply } = useFileImport(); |
| 134 | +const { setFileInput, triggerImport, handleFileChange } = useFileImportInput(); |
138 | 135 | const projectManager = useProjectManager(); |
139 | 136 |
|
140 | 137 | const showExportPopover = ref(false); |
@@ -172,25 +169,6 @@ const hasWorkspaceState = computed(() => { |
172 | 169 | ); |
173 | 170 | }); |
174 | 171 |
|
175 | | -function triggerImport() { |
176 | | - fileInput.value?.click(); |
177 | | -} |
178 | | -
|
179 | | -async function handleFileChange(event: Event) { |
180 | | - const target = event.target as HTMLInputElement; |
181 | | - const files = target.files; |
182 | | - if (!files?.length) return; |
183 | | -
|
184 | | - try { |
185 | | - await importAndApply(Array.from(files)); |
186 | | - } catch (error) { |
187 | | - console.error(error); |
188 | | - alert(error instanceof Error ? error.message : '解析文件时发生错误'); |
189 | | - } finally { |
190 | | - target.value = ''; |
191 | | - } |
192 | | -} |
193 | | -
|
194 | 172 | function refreshStoredProjects() { |
195 | 173 | storedProjects.value = projectManager.getStoredProjects(); |
196 | 174 | } |
|
0 commit comments