feat: rewrite page leave

This commit is contained in:
KUN1007 2023-09-28 18:25:35 +08:00
parent 44666ebd9c
commit 2d7218e34a
5 changed files with 56 additions and 4 deletions

View file

@ -211,7 +211,11 @@ export default {
publish: 'Confirm to publish?', publish: 'Confirm to publish?',
publishSuccess: 'Publish Successfully', publishSuccess: 'Publish Successfully',
publishCancel: 'Cancel Publish', publishCancel: 'Cancel Publish',
rewrite: 'Confirm to Rewrite?',
rewriteSuccess: 'Rewrite Successfully',
rewriteCancel: 'Cancel Rewrite',
draft: 'The draft has been saved successfully!', draft: 'The draft has been saved successfully!',
leave: 'Confirm leaving the page? Your changes will not be saved.',
}, },
login: { login: {
success: 'Login Successfully! Welcome to KUN Visual Novel ~ ', success: 'Login Successfully! Welcome to KUN Visual Novel ~ ',

View file

@ -214,6 +214,7 @@ export default {
rewriteSuccess: 'Rewrite 成功', rewriteSuccess: 'Rewrite 成功',
rewriteCancel: '取消 Rewrite', rewriteCancel: '取消 Rewrite',
draft: '草稿已经保存成功!', draft: '草稿已经保存成功!',
leave: '确认离开界面吗?您的更改将不会保存',
}, },
login: { login: {
login: '登陆成功!欢迎来到 鲲 Galgame ~ ', login: '登陆成功!欢迎来到 鲲 Galgame ~ ',

View file

@ -1,20 +1,50 @@
<script setup lang="ts"> <script setup lang="ts">
import { onBeforeRouteLeave } from 'vue-router'
//
import { useKUNGalgameMessageStore } from '@/store/modules/message'
// //
import QuillEditor from '@/components/quill-editor/QuillEditor.vue' import QuillEditor from '@/components/quill-editor/QuillEditor.vue'
import Tags from './components/Tags.vue' import Tags from './components/Tags.vue'
import Footer from './components/Footer.vue' import Footer from './components/Footer.vue'
import KUNGalgameFooter from '@/components/KUNGalgameFooter.vue' import KUNGalgameFooter from '@/components/KUNGalgameFooter.vue'
// store
import { useKUNGalgameEditStore } from '@/store/modules/edit'
// store // store
import { useKUNGalgameSettingsStore } from '@/store/modules/settings' import { useKUNGalgameSettingsStore } from '@/store/modules/settings'
import { storeToRefs } from 'pinia' import { storeToRefs } from 'pinia'
import { computed } from 'vue' import { computed } from 'vue'
// 使 store
const { topicRewrite } = storeToRefs(useKUNGalgameEditStore())
// 使 store // 使 store
const settingsStore = useKUNGalgameSettingsStore() const { showKUNGalgamePageWidth } = storeToRefs(useKUNGalgameSettingsStore())
const { showKUNGalgamePageWidth } = storeToRefs(settingsStore)
const editPageWidth = computed(() => { const editPageWidth = computed(() => {
return showKUNGalgamePageWidth.value.Edit + '%' return showKUNGalgamePageWidth.value.Edit + '%'
}) })
//
onBeforeRouteLeave(async (to, from, next) => {
//
if (topicRewrite.value.isTopicRewriting) {
//
const res = await useKUNGalgameMessageStore().alert(
'AlertInfo.edit.leave',
true
)
if (res) {
//
useKUNGalgameEditStore().resetRewriteTopicData()
//
next()
} else {
//
next(false)
}
} else {
next()
}
})
</script> </script>
<template> <template>
@ -37,6 +67,7 @@ const editPageWidth = computed(() => {
<Footer /> <Footer />
</div> </div>
</div> </div>
<!-- 版权 --> <!-- 版权 -->
<KUNGalgameFooter style="margin: 0 auto; padding-top: 10px" /> <KUNGalgameFooter style="margin: 0 auto; padding-top: 10px" />
<span style="margin: 0 auto; color: var(--kungalgame-font-color-3)" <span style="margin: 0 auto; color: var(--kungalgame-font-color-3)"

View file

@ -9,6 +9,8 @@ import { TopicUserInfo } from '@/api'
import { useKUNGalgameEditStore } from '@/store/modules/edit' import { useKUNGalgameEditStore } from '@/store/modules/edit'
// store // store
import { useKUNGalgameTopicStore } from '@/store/modules/topic' import { useKUNGalgameTopicStore } from '@/store/modules/topic'
// store
import { useKUNGalgameUserStore } from '@/store/modules/kungalgamer'
import { storeToRefs } from 'pinia' import { storeToRefs } from 'pinia'
// 使 store // 使 store
@ -39,6 +41,14 @@ const props = defineProps<{
rUser: TopicUserInfo rUser: TopicUserInfo
}>() }>()
//
/**
* 这里只是简单起见不显示重新编辑
* 实际上如果用户自己修改了 localStorage 中保存的信息这个验证就失效了
* 但是修改了也没有用验证逻辑位于后端
*/
const isShowRewrite = useKUNGalgameUserStore().uid === props.rUser.uid
// //
const handelReply = async () => { const handelReply = async () => {
// 便 // 便
@ -112,7 +122,7 @@ const handleClickEdit = () => {
<span class="icon"><Icon icon="ph:user-focus-duotone" /></span> <span class="icon"><Icon icon="ph:user-focus-duotone" /></span>
</li> </li>
<!-- 编辑 --> <!-- 编辑 -->
<li> <li v-if="isShowRewrite">
<span @click="handleClickEdit" class="icon"> <span @click="handleClickEdit" class="icon">
<Icon icon="line-md:pencil-twotone-alt" /> <Icon icon="line-md:pencil-twotone-alt" />
</span> </span>

View file

@ -121,6 +121,11 @@ const handleShowAdvance = () => {
background-color: var(--kungalgame-blue-4); background-color: var(--kungalgame-blue-4);
transition: 0.1s; transition: 0.1s;
} }
.confirm-btn:active {
background-color: var(--kungalgame-blue-3);
transform: scale(0.8);
}
/* 保存按钮的样式 */ /* 保存按钮的样式 */
.save-btn { .save-btn {
color: var(--kungalgame-pink-4); color: var(--kungalgame-pink-4);
@ -135,6 +140,7 @@ const handleShowAdvance = () => {
background-color: var(--kungalgame-pink-3); background-color: var(--kungalgame-pink-3);
transform: scale(0.8); transform: scale(0.8);
} }
/* 高级选项按钮的样式 */ /* 高级选项按钮的样式 */
.advance-btn { .advance-btn {
color: var(--kungalgame-purple-4); color: var(--kungalgame-purple-4);
@ -146,7 +152,7 @@ const handleShowAdvance = () => {
transition: 0.1s; transition: 0.1s;
} }
.advance-btn:active { .advance-btn:active {
background-color: var(--kungalgame-red-3); background-color: var(--kungalgame-purple-4);
transform: scale(0.8); transform: scale(0.8);
} }