Skip to content

Commit 3a1466b

Browse files
committed
fix: 修复导入、导出错误
1 parent cf788b1 commit 3a1466b

File tree

1 file changed

+17
-11
lines changed

1 file changed

+17
-11
lines changed

src/components/common/PromptStore/index.vue

Lines changed: 17 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,7 @@ const modalMode = ref('')
6161
const tempModifiedItem = ref<any>({})
6262
6363
// 添加修改导入都使用一个Modal, 临时修改内容占用tempPromptKey,切换状态前先将内容都清楚
64-
const changeShowModal = (mode: string, selected = { key: '', value: '' }) => {
64+
const changeShowModal = (mode: 'add' | 'modify' | 'local_import', selected = { key: '', value: '' }) => {
6565
if (mode === 'add') {
6666
tempPromptKey.value = ''
6767
tempPromptValue.value = ''
@@ -103,7 +103,7 @@ const addPromptTemplate = () => {
103103
}
104104
promptList.value.unshift({ key: tempPromptKey.value, value: tempPromptValue.value } as never)
105105
message.success(t('common.addSuccess'))
106-
changeShowModal('')
106+
changeShowModal('add')
107107
}
108108
109109
const modifyPromptTemplate = () => {
@@ -132,7 +132,7 @@ const modifyPromptTemplate = () => {
132132
133133
promptList.value = [{ key: tempPromptKey.value, value: tempPromptValue.value }, ...tempList] as never
134134
message.success(t('common.editSuccess'))
135-
changeShowModal('')
135+
changeShowModal('modify')
136136
}
137137
138138
const deletePromptTemplate = (row: { key: string; value: string }) => {
@@ -187,11 +187,9 @@ const importPromptTemplate = () => {
187187
promptList.value.unshift({ key: i[key], value: i[value] } as never)
188188
}
189189
message.success(t('common.importSuccess'))
190-
changeShowModal('')
191190
}
192191
catch {
193192
message.error('JSON 格式错误,请检查 JSON 格式')
194-
changeShowModal('')
195193
}
196194
}
197195
@@ -213,17 +211,25 @@ const exportPromptTemplate = () => {
213211
const downloadPromptTemplate = async () => {
214212
try {
215213
importLoading.value = true
216-
await fetch(downloadURL.value)
217-
.then(response => response.json())
218-
.then((jsonData) => {
219-
tempPromptValue.value = JSON.stringify(jsonData)
220-
}).then(() => {
221-
importPromptTemplate()
214+
const response = await fetch(downloadURL.value)
215+
const jsonData = await response.json()
216+
if ('key' in jsonData[0] && 'value' in jsonData[0])
217+
tempPromptValue.value = JSON.stringify(jsonData)
218+
if ('act' in jsonData[0] && 'prompt' in jsonData[0]) {
219+
const newJsonData = jsonData.map((item: { act: string; prompt: string }) => {
220+
return {
221+
key: item.act,
222+
value: item.prompt,
223+
}
222224
})
225+
tempPromptValue.value = JSON.stringify(newJsonData)
226+
}
227+
importPromptTemplate()
223228
downloadURL.value = ''
224229
}
225230
catch {
226231
message.error(t('store.downloadError'))
232+
downloadURL.value = ''
227233
}
228234
finally {
229235
importLoading.value = false

0 commit comments

Comments
 (0)