feat:自动保存优化 (#435)

This commit is contained in:
Donald Yang 2024-10-08 20:47:33 +08:00 committed by GitHub
parent 26d92b35ea
commit 3d4171a7f7
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

View File

@ -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>
@ -99,20 +99,23 @@ const triggerAutoSave = () => {
isShowAutoSave.value = true
nextTick(async () => {
try {
const res: any = await handleSave()
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)
@ -120,6 +123,17 @@ const triggerAutoSave = () => {
}
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
}
@ -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, '提示', {