-
Notifications
You must be signed in to change notification settings - Fork 724
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
refactor: integration nuxt-ui and refactor modal component
- Loading branch information
1 parent
eb45842
commit cb9ffc3
Showing
13 changed files
with
586 additions
and
271 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
import { defineAppConfig } from "#imports"; | ||
|
||
export default defineAppConfig({ | ||
ui: { | ||
primary: "purple", | ||
gray: "cool", | ||
}, | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -11,6 +11,7 @@ | |
<NuxtPage /> | ||
</NuxtLayout> | ||
</template> | ||
<UModals /> | ||
</HttpErrorProvider> | ||
</template> | ||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,78 @@ | ||
<script lang="ts" setup> | ||
import { useModal } from "#imports"; | ||
defineProps({ | ||
title: { | ||
type: String, | ||
default: "", | ||
}, | ||
content: { | ||
type: String, | ||
default: "", | ||
}, | ||
showCancel: { | ||
type: Boolean, | ||
default: false, | ||
}, | ||
cancelText: { | ||
type: String, | ||
default: "取消", | ||
}, | ||
showConfirm: { | ||
type: Boolean, | ||
default: false, | ||
}, | ||
confirmText: { | ||
type: String, | ||
default: "确认", | ||
}, | ||
}); | ||
const modal = useModal(); | ||
const emit = defineEmits(["cancel", "confirm"]); | ||
async function onCancel() { | ||
await modal.close(); | ||
emit("cancel"); | ||
} | ||
async function onConfirm() { | ||
await modal.close(); | ||
emit("confirm"); | ||
} | ||
</script> | ||
|
||
<template> | ||
<UModal | ||
:ui="{ | ||
container: 'items-center', | ||
overlay: { | ||
background: 'bg-black/75 dark:bg-black/75', | ||
}, | ||
background: 'dark:bg-gray-800', | ||
}" | ||
> | ||
<div class="flex h-52 flex-col justify-between p-6 text-gray-900 dark:text-white"> | ||
<h2 class="mb-8 text-2xl font-bold">{{ title }}</h2> | ||
<p class="mb-8 max-w-sm text-base text-gray-700 dark:text-gray-300"> | ||
{{ content }} | ||
</p> | ||
<div class="flex w-full justify-end space-x-4"> | ||
<UButton | ||
v-if="showCancel" | ||
color="gray" | ||
class="px-6" | ||
@click="onCancel" | ||
> | ||
{{ cancelText || "取消" }} | ||
</UButton> | ||
<UButton | ||
v-if="showConfirm" | ||
class="px-6" | ||
@click="onConfirm" | ||
> | ||
{{ confirmText || "确认" }} | ||
</UButton> | ||
</div> | ||
</div> | ||
</UModal> | ||
</template> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,89 @@ | ||
<template> | ||
<UModal | ||
v-model="showGamePauseModal" | ||
@close="handleClose" | ||
:ui="{ | ||
container: 'items-center', | ||
overlay: { | ||
background: 'bg-black/75 dark:bg-black/75', | ||
}, | ||
background: 'dark:bg-gray-800', | ||
}" | ||
> | ||
<div class="flex h-52 flex-col justify-between p-6 text-gray-900 dark:text-white"> | ||
<h2 class="mb-8 text-2xl font-bold">游戏暂停</h2> | ||
<p class="mb-8 max-w-sm text-base text-gray-700 dark:text-gray-300"> | ||
{{ randomMessage }} | ||
</p> | ||
<div class="flex w-full justify-end"> | ||
<UButton | ||
class="px-6" | ||
@click="handleClose" | ||
> | ||
继续游戏 | ||
</UButton> | ||
</div> | ||
</div> | ||
</UModal> | ||
</template> | ||
|
||
<script setup lang="ts"> | ||
import { onMounted, onUnmounted, ref, watch } from "vue"; | ||
import { useQuestionInput } from "~/components/main/QuestionInput/questionInputHelper"; | ||
import { useGamePause } from "~/composables/main/useGamePause"; | ||
import { useShortcutKeyMode } from "~/composables/user/shortcutKey"; | ||
import { useGameStore } from "~/store/game"; | ||
import { cancelShortcut, registerShortcut } from "~/utils/keyboardShortcuts"; | ||
const gameStore = useGameStore(); | ||
const { showGamePauseModal, resumeGame, pauseGame } = useGamePause(); | ||
const { shortcutKeys } = useShortcutKeyMode(); | ||
const { focusInput } = useQuestionInput(); | ||
const messages = [ | ||
"别忘了回来继续练习哦,我在等着你呢!", | ||
"休息一下没关系,但别让我等太久!", | ||
"快点回来吧,你的英语能力正在蓄势待发!", | ||
]; | ||
const randomMessage = ref(""); | ||
watch( | ||
showGamePauseModal, | ||
(newValue) => { | ||
if (newValue) { | ||
randomMessage.value = messages[Math.floor(Math.random() * messages.length)]; | ||
} | ||
}, | ||
{ | ||
immediate: true, | ||
}, | ||
); | ||
function handleClose() { | ||
resumeGame(); | ||
setTimeout(() => { | ||
focusInput(); | ||
}, 300); | ||
} | ||
function handleGamePause(e: KeyboardEvent) { | ||
e.preventDefault(); | ||
if (gameStore.isGamePaused()) { | ||
resumeGame(); | ||
setTimeout(() => { | ||
focusInput(); | ||
}, 300); | ||
} else { | ||
pauseGame(); | ||
} | ||
} | ||
onMounted(() => { | ||
registerShortcut(shortcutKeys.value.pause, handleGamePause); | ||
}); | ||
onUnmounted(() => { | ||
cancelShortcut(shortcutKeys.value.pause, handleGamePause); | ||
}); | ||
</script> |
This file was deleted.
Oops, something went wrong.
Oops, something went wrong.