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

This commit is contained in:
Donald Yang 2024-10-08 20:47:33 +08:00 committed by luch1994
parent f73bf6fdeb
commit ea6b0d50f0

View File

@ -8,7 +8,7 @@
{{ saveText }} {{ saveText }}
</span> </span>
<i-ep-loading class="icon" v-if="autoSaveStatus === 'saving'" /> <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> </div>
</transition> </transition>
</div> </div>
@ -99,20 +99,23 @@ const triggerAutoSave = () => {
isShowAutoSave.value = true isShowAutoSave.value = true
nextTick(async () => { nextTick(async () => {
try { try {
const res: any = await handleSave() const res: any = await doSave()
if (res.code === 200) { if (res !== undefined) {
autoSaveStatus.value = 'succeed' if (res.code === 200) {
} else { autoSaveStatus.value = 'succeed'
autoSaveStatus.value = 'failed' } else {
autoSaveStatus.value = 'failed'
}
isShowAutoSave.value = true
} }
} catch (err) {
autoSaveStatus.value = 'failed'
isShowAutoSave.value = true
} finally {
setTimeout(() => { setTimeout(() => {
isShowAutoSave.value = false isShowAutoSave.value = false
timerHandle.value = null timerHandle.value = null
}, 300) }, 300)
} catch (err) {
autoSaveStatus.value = 'failed'
isShowAutoSave.value = true
} }
}) })
}, 2000) }, 2000)
@ -120,6 +123,17 @@ const triggerAutoSave = () => {
} }
const handleSave = async () => { 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) { if (isSaving.value) {
return return
} }
@ -141,7 +155,6 @@ const handleSave = async () => {
return return
} }
if (res.code === 200) { if (res.code === 200) {
ElMessage.success('保存成功')
return res return res
} else if (res.code === 3006) { } else if (res.code === 3006) {
ElMessageBox.alert(res.errmsg, '提示', { ElMessageBox.alert(res.errmsg, '提示', {