From f8c575c33bda951255aa8c98566dbe0107199607 Mon Sep 17 00:00:00 2001 From: mathsuky Date: Sat, 14 Oct 2023 20:55:10 +0900 Subject: [PATCH] =?UTF-8?q?=E9=81=B7=E7=A7=BB=E6=99=82=E8=AD=A6=E5=91=8A?= =?UTF-8?q?=E3=82=92=E8=A4=87=E6=95=B0=E3=81=AEform=E3=81=AB=E5=AE=9F?= =?UTF-8?q?=E8=A3=85?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/components/event/EventFormBase.vue | 44 ++++++++++++++++++++++++++ src/components/main/SidebarFooter.vue | 21 +++++++----- src/pages/GroupNew.vue | 41 ++++++++++++++++++++++++ src/workers/draftConfirmer.ts | 13 ++++++++ 4 files changed, 111 insertions(+), 8 deletions(-) create mode 100644 src/workers/draftConfirmer.ts diff --git a/src/components/event/EventFormBase.vue b/src/components/event/EventFormBase.vue index 3933b7a0..68c55222 100644 --- a/src/components/event/EventFormBase.vue +++ b/src/components/event/EventFormBase.vue @@ -75,6 +75,9 @@ import EventFormSummary, { } from '@/components/event/EventFormSummary.vue' import FormNextButton from '@/components/shared/FormNextButton.vue' import FormBackButton from '@/components/shared/FormBackButton.vue' +import { useDraftConfirmer } from '@/workers/draftConfirmer' +import { removeDraftConfirmer } from '@/workers/draftConfirmer' +import router from '@/router' export type EventInput = EventInputContent & ( @@ -196,6 +199,47 @@ export default class EventFormBase extends Vue { : this.timeAndPlace.timeEnd, } } + hasContent(): boolean { + return ( + this.summary.name !== '' || + this.summary.description !== '' || + this.summary.tags.length > 0 || + this.summary.groupName !== '' || + this.summary.place !== '' || + this.summary.timeStart !== '' || + this.summary.timeEnd !== '' || + this.summary.open || + !this.summary.sharedRoom + ) + } + mounted() { + this.$watch('summary', () => { + if (this.hasContent()) { + useDraftConfirmer() + } else { + removeDraftConfirmer() + } + }) + router.beforeEach((to, from, next) => { + if (from.name === 'EventNew') { + if (this.hasContent()) { + if ( + confirm( + '入力されたデータは送信されないまま破棄されますが,よろしいですか。' + ) + ) { + next() + } else { + next(false) + } + } else { + next() + } + } else { + next() + } + }) + } @Emit() submit(): EventOutput { diff --git a/src/components/main/SidebarFooter.vue b/src/components/main/SidebarFooter.vue index dbe1810b..f4bbe878 100644 --- a/src/components/main/SidebarFooter.vue +++ b/src/components/main/SidebarFooter.vue @@ -59,6 +59,8 @@