Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat:自动保存优化 #435

Merged
merged 1 commit into from
Oct 8, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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