Skip to content

Commit

Permalink
feat: 优化测试键盘页面交互
Browse files Browse the repository at this point in the history
  • Loading branch information
YasinChan committed Dec 10, 2023
1 parent 4d334a9 commit 27e9bd8
Show file tree
Hide file tree
Showing 3 changed files with 55 additions and 65 deletions.
54 changes: 6 additions & 48 deletions src/App.vue
Original file line number Diff line number Diff line change
Expand Up @@ -10,20 +10,18 @@ import { storeToRefs } from 'pinia';
import { useRouter } from 'vue-router';
import YDropDown from '@/components/ui/DropDown.vue';
const router = useRouter();
const userStore = useUserStore();
userStore.setProfile();
userStore.setConfig();
const useConfig = useConfigStore();
const { config } = storeToRefs(userStore);
const { currentSystem, onlyShowMain } = storeToRefs(useConfig);
const { onlyShowMain } = storeToRefs(useConfig);
setTheme(getTheme());
const obj = reactive({
showChangeFontModal: false,
showChangeSystemModal: false,
userName: '',
password: '',
userNameError: '',
Expand Down Expand Up @@ -75,10 +73,6 @@ const changeTheme = () => {
const currentTheme = getTheme();
currentTheme === 'light' ? setTheme('dark') : setTheme('light');
};
function changeSystem(system: string) {
useConfig.setCurrentSystem(system);
}
</script>

<template>
Expand All @@ -103,11 +97,6 @@ function changeSystem(system: string) {
<template #menu>
<div class="y-auth__menu">
<div
v-if="
router.currentRoute.value.name === 'TimeLimit' ||
router.currentRoute.value.name === 'WordsLimit' ||
router.currentRoute.value.name === 'QuoteLimit'
"
class="y-menu__change y-menu__change-font"
@click="
() => {
Expand All @@ -117,19 +106,7 @@ function changeSystem(system: string) {
>
切换字体
</div>
<div
v-else-if="router.currentRoute.value.name === 'TypingKeyboard'"
class="y-menu__change y-menu__change-keyboard"
@click="
() => {
useConfig.setKeyboardModalStatus(true);
}
"
>
切换键盘
</div>
<div class="y-menu__change" @click="changeTheme">切换主题</div>
<div class="y-menu__change" @click="obj.showChangeSystemModal = true">切换系统</div>
</div>
</template>
</y-drop-down>
Expand All @@ -143,7 +120,11 @@ function changeSystem(system: string) {
<router-view></router-view>

<Teleport to="body">
<y-modal :show="obj.showChangeFontModal" @close="obj.showChangeFontModal = false">
<y-modal
:show="obj.showChangeFontModal"
@close="obj.showChangeFontModal = false"
@confirm="obj.showChangeFontModal = false"
>
<template #header>
<h3>选择字体</h3>
</template>
Expand All @@ -170,29 +151,6 @@ function changeSystem(system: string) {
</template>
</y-modal>
</Teleport>
<Teleport to="body">
<y-modal
:show="obj.showChangeSystemModal"
@close="obj.showChangeSystemModal = false"
@confirm="obj.showChangeSystemModal = false"
>
<template #header>
<h3>选择系统</h3>
</template>
<template #body>
<div class="y-change__container gray-08">
<ul>
<li @click="changeSystem('win')" :class="currentSystem === 'win' ? 'active' : ''">
Windows
</li>
<li @click="changeSystem('mac')" :class="currentSystem === 'mac' ? 'active' : ''">
Mac
</li>
</ul>
</div>
</template>
</y-modal>
</Teleport>
<Teleport to="body">
<message :type="obj.type" :message="obj.message" :visible="obj.visible"></message>
</Teleport>
Expand Down
8 changes: 0 additions & 8 deletions src/store/config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,25 +3,17 @@ import { defineStore } from 'pinia';
export const useConfigStore = defineStore('config', {
state: () => ({
onlyShowMain: false as boolean,
currentSystem: 'win' as string, // win, mac
currentFont: 'default' as string,
keyboardModalStatus: false as boolean,
printContent: '' as string,
currentCode: [] as any[]
}),
actions: {
setOnlyShowMain(val: boolean) {
this.onlyShowMain = val;
},
setCurrentSystem(val: string) {
this.currentSystem = val;
},
setCurrentFont(val: string) {
this.currentFont = val;
},
setKeyboardModalStatus(val: boolean) {
this.keyboardModalStatus = val;
},
setPrintContent(val: string) {
this.printContent += val;
},
Expand Down
58 changes: 49 additions & 9 deletions src/view/TypingKeyboard.vue
Original file line number Diff line number Diff line change
Expand Up @@ -10,11 +10,12 @@ import YModal from '@/components/ui/Modal.vue';
const screenBottomRef = ref();
const state = reactive({
currentKeyBoard: 'standard', // '68' | 'standard'
currentSystem: 'win' // 'mac' | 'win'
currentSystem: 'win', // 'mac' | 'win'
keyboardModal: false
});
const configStore = useConfigStore();
const { printContent, keyboardModalStatus, currentCode, currentSystem } = storeToRefs(configStore);
const { printContent, currentCode, onlyShowMain } = storeToRefs(configStore);
let timeout: any = null;
Expand Down Expand Up @@ -50,6 +51,25 @@ const changeKeyboard = (keyboard: string) => {
>
<div class="y-main__sub-screen-text" v-html="currentCode.join('')"></div>
</div>
<Transition name="menu">
<div class="y-main__selection" v-show="!onlyShowMain">
<div
class="y-main__selection-item"
v-if="state.currentSystem === 'win'"
@click="state.currentSystem = 'mac'"
>
Windows
</div>
<div
class="y-main__selection-item"
v-if="state.currentSystem === 'mac'"
@click="state.currentSystem = 'win'"
>
Mac
</div>
<div class="y-main__selection-item" @click="state.keyboardModal = true">切换键盘</div>
</div>
</Transition>
</div>
<key-wrap
v-if="state.currentKeyBoard === '68'"
Expand All @@ -63,8 +83,8 @@ const changeKeyboard = (keyboard: string) => {
<single-key
v-for="item in v"
:key="item.code"
:code="currentSystem === 'mac' && item.macCode ? item.macCode : item.code"
:value="currentSystem === 'mac' && item.macValue ? item.macValue : item.value"
:code="state.currentSystem === 'mac' && item.macCode ? item.macCode : item.code"
:value="state.currentSystem === 'mac' && item.macValue ? item.macValue : item.value"
:unit="item.unit"
:keys-pressed="keysPressed"
></single-key>
Expand All @@ -84,8 +104,8 @@ const changeKeyboard = (keyboard: string) => {
<single-key
v-for="item in v"
:key="item.code"
:code="currentSystem === 'mac' && item.macCode ? item.macCode : item.code"
:value="currentSystem === 'mac' && item.macValue ? item.macValue : item.value"
:code="state.currentSystem === 'mac' && item.macCode ? item.macCode : item.code"
:value="state.currentSystem === 'mac' && item.macValue ? item.macValue : item.value"
:unit="item.unit"
:keys-pressed="keysPressed"
></single-key>
Expand All @@ -96,9 +116,9 @@ const changeKeyboard = (keyboard: string) => {
</div>
<Teleport to="body">
<y-modal
:show="keyboardModalStatus"
@close="configStore.setKeyboardModalStatus(false)"
@confirm="configStore.setKeyboardModalStatus(false)"
:show="state.keyboardModal"
@close="state.keyboardModal = false"
@confirm="state.keyboardModal = false"
>
<template #header>
<h3>选择键盘</h3>
Expand All @@ -120,6 +140,26 @@ const changeKeyboard = (keyboard: string) => {
margin: 20px auto;
justify-content: center;
align-items: flex-end;
position: relative;
}
.y-main__selection {
position: absolute;
right: 0;
width: 100px;
}
.y-main__selection-item {
padding: 4px 8px;
color: $gray-06;
margin-bottom: 4px;
cursor: pointer;
text-align: center;
transform: scale(0.9);
opacity: 0.6;
transition: all 0.3s cubic-bezier(0.55, 0, 0.1, 1);
&:hover {
opacity: 1;
transform: scale(1);
}
}
.y-main__screen {
width: 600px;
Expand Down

0 comments on commit 27e9bd8

Please sign in to comment.