Skip to content

Commit

Permalink
fix: 如果已经提交了再跳转,不要弹出没有保存的提示了
Browse files Browse the repository at this point in the history
  • Loading branch information
bangbang93 committed Oct 12, 2024
1 parent 9df2669 commit b4ec384
Showing 1 changed file with 3 additions and 1 deletion.
4 changes: 3 additions & 1 deletion packages/admin/src/pages/article/article-create.vue
Original file line number Diff line number Diff line change
Expand Up @@ -119,9 +119,10 @@ const edit = reactive({id: ''})
const categories = ref<InstanceType<typeof ElTree> | null>(null)
const categoryItems = ref<CategoryResDto[]>([])
const autoSlug = ref(true)
const submitted = ref(false)
onBeforeRouteLeave((_, __, next) => {
if (article.title || article.content) {
if (!submitted.value && article.title || article.content) {
ElMessageBox.confirm('文章没有保存,是否离开')
.then(() => next())
.catch(() => next(false))
Expand Down Expand Up @@ -193,6 +194,7 @@ async function submit(): Promise<void> {
}
if (resp.status === 201 || resp.status === 200) {

Check warning on line 195 in packages/admin/src/pages/article/article-create.vue

View workflow job for this annotation

GitHub Actions / build

No magic number: 201

Check warning on line 195 in packages/admin/src/pages/article/article-create.vue

View workflow job for this annotation

GitHub Actions / build

No magic number: 200
await ElMessageBox.alert('保存成功', 'Freyja')
submitted.value = true
await router.push({name: 'article.list'})
} else {
const body = await resp.json() as { message?: string; msg?: string }
Expand Down

0 comments on commit b4ec384

Please sign in to comment.