Skip to content

Commit

Permalink
feat:自动保存优化 (#435)
Browse files Browse the repository at this point in the history
  • Loading branch information
fforever14 authored and luch1994 committed Oct 8, 2024
1 parent f73bf6f commit ea6b0d5
Showing 1 changed file with 24 additions and 11 deletions.
35 changes: 24 additions & 11 deletions web/src/management/pages/edit/modules/contentModule/SavePanel.vue
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
{{ saveText }}
</span>
<i-ep-loading class="icon" v-if="autoSaveStatus === 'saving'" />
<i-ep-check class="icon succeed" v-else-if="autoSaveStatus === 'succeed'" />
<i-ep-check class="icon succeed" v-if="autoSaveStatus === 'succeed'" />
</div>
</transition>
</div>
Expand Down Expand Up @@ -99,27 +99,41 @@ const triggerAutoSave = () => {
isShowAutoSave.value = true
nextTick(async () => {
try {
const res: any = await handleSave()
if (res.code === 200) {
autoSaveStatus.value = 'succeed'
} else {
autoSaveStatus.value = 'failed'
const res: any = await doSave()
if (res !== undefined) {
if (res.code === 200) {
autoSaveStatus.value = 'succeed'
} else {
autoSaveStatus.value = 'failed'
}
isShowAutoSave.value = true
}
} catch (err) {
autoSaveStatus.value = 'failed'
isShowAutoSave.value = true
} finally {
setTimeout(() => {
isShowAutoSave.value = false
timerHandle.value = null
}, 300)
} catch (err) {
autoSaveStatus.value = 'failed'
isShowAutoSave.value = true
}
})
}, 2000)
}
}
const handleSave = async () => {
const res: any = await doSave()
if (res !== undefined && res.code === 200) {
ElMessage.success('保存成功')
}
}
/**
* 保存问卷
* @return 无返回时说明保存失败并由函数内部完成统一提示,有返回时,code为200为保存成功,不为200时,使用errmsg由外部实现错误信息展示
*/
const doSave = async () => {
if (isSaving.value) {
return
}
Expand All @@ -141,7 +155,6 @@ const handleSave = async () => {
return
}
if (res.code === 200) {
ElMessage.success('保存成功')
return res
} else if (res.code === 3006) {
ElMessageBox.alert(res.errmsg, '提示', {
Expand Down

0 comments on commit ea6b0d5

Please sign in to comment.