From 926e4295713c444b72fac14d180332b9c8c922fb Mon Sep 17 00:00:00 2001 From: mathsuky Date: Mon, 25 Sep 2023 20:06:20 +0900 Subject: [PATCH 1/7] =?UTF-8?q?onbeforeunload=E3=81=A7=E3=83=A1=E3=83=83?= =?UTF-8?q?=E3=82=BB=E3=83=BC=E3=82=B8=E3=82=92=E8=A1=A8=E7=A4=BA?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/components/main/SidebarFooter.vue | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/src/components/main/SidebarFooter.vue b/src/components/main/SidebarFooter.vue index b6fc9e1f..13355a3f 100644 --- a/src/components/main/SidebarFooter.vue +++ b/src/components/main/SidebarFooter.vue @@ -75,6 +75,16 @@ export default { return this.$store.direct.state.me?.privileged ?? false }, }, + mounted: function () { + window.onbeforeunload = () => { + if (this.inputData) { + return 'このページを離れると保存されていないデータは破棄されますが,よろしいですか。' + } + } + }, + destroyed() { + window.onbeforeunload = null + }, methods: { showModal() { this.isVisible = true From 9a5e40792d2aadc53000cf3eb34abd83d494b776 Mon Sep 17 00:00:00 2001 From: mathsuky Date: Sat, 30 Sep 2023 20:53:54 +0900 Subject: [PATCH 2/7] =?UTF-8?q?form=E3=81=AEclose=E3=83=9C=E3=82=BF?= =?UTF-8?q?=E3=83=B3=E3=81=AB=E3=81=A4=E3=81=84=E3=81=A6=E3=82=82=E5=88=A4?= =?UTF-8?q?=E5=AE=9A=E3=82=92=E5=AE=9F=E8=A3=85?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/components/main/SidebarFooter.vue | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) diff --git a/src/components/main/SidebarFooter.vue b/src/components/main/SidebarFooter.vue index 13355a3f..54b89904 100644 --- a/src/components/main/SidebarFooter.vue +++ b/src/components/main/SidebarFooter.vue @@ -90,16 +90,20 @@ export default { this.isVisible = true }, hideModal() { - this.isVisible = false - this.showError = false - this.inputData = '' + if (this.inputData) { + if (confirm('入力されたデータは破棄されますが,よろしいですか。')) { + this.isVisible = false + this.showError = false + this.inputData = '' + } + return + } }, async saveData() { if (isValidVerifiedroomData(this.inputData)) { this.showError = false try { await fetch(`${baseURL}/rooms/all`, { - //開発環境url method: 'POST', credentials: 'include', headers: { From 8b70189e5caf7d7d279678e72930267e4d9138c2 Mon Sep 17 00:00:00 2001 From: mathsuky Date: Mon, 2 Oct 2023 21:14:39 +0900 Subject: [PATCH 3/7] =?UTF-8?q?=E3=83=A2=E3=83=BC=E3=83=80=E3=83=AB?= =?UTF-8?q?=E3=81=8C=E7=A9=BA=E3=81=AE=E5=A0=B4=E5=90=88=E3=81=AE=E5=87=A6?= =?UTF-8?q?=E7=90=86=E3=82=92=E8=BF=BD=E5=8A=A0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/components/main/SidebarFooter.vue | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/src/components/main/SidebarFooter.vue b/src/components/main/SidebarFooter.vue index 54b89904..dbe1810b 100644 --- a/src/components/main/SidebarFooter.vue +++ b/src/components/main/SidebarFooter.vue @@ -97,6 +97,10 @@ export default { this.inputData = '' } return + } else { + this.isVisible = false + this.showError = false + this.inputData = '' } }, async saveData() { From f8c575c33bda951255aa8c98566dbe0107199607 Mon Sep 17 00:00:00 2001 From: mathsuky Date: Sat, 14 Oct 2023 20:55:10 +0900 Subject: [PATCH 4/7] =?UTF-8?q?=E9=81=B7=E7=A7=BB=E6=99=82=E8=AD=A6?= =?UTF-8?q?=E5=91=8A=E3=82=92=E8=A4=87=E6=95=B0=E3=81=AEform=E3=81=AB?= =?UTF-8?q?=E5=AE=9F=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 @@