Skip to content

Commit

Permalink
feat: 补充关闭房间、退出房间等更多玩一玩功能
Browse files Browse the repository at this point in the history
  • Loading branch information
YasinChan committed Mar 28, 2024
1 parent bde27d8 commit 309a4c2
Show file tree
Hide file tree
Showing 6 changed files with 314 additions and 105 deletions.
9 changes: 9 additions & 0 deletions src/common/color.ts
Original file line number Diff line number Diff line change
Expand Up @@ -134,3 +134,12 @@ export function removeAllCustomCssValue() {
removeCustomCssValue(COLOR_ENUM['GRAY_02']);
removeCustomCssValue(COLOR_ENUM['LABEL_WHITE']);
}

export function getRandomColor(): string {
const letters = '0123456789ABCDEF';
let color = '#';
for (let i = 0; i < 6; i++) {
color += letters[Math.floor(Math.random() * 16)];
}
return color;
}
33 changes: 29 additions & 4 deletions src/components/WordInput.vue
Original file line number Diff line number Diff line change
Expand Up @@ -351,7 +351,8 @@ watch(
});
const wrongLength = wrongPos.length;
const wordLength = inputTextArr.length;
const accuracy = (((wordLength - wrongLength) / wordLength) * 100).toFixed(0) + '%';
const accuracy =
wordLength === 0 ? '0%' : (((wordLength - wrongLength) / wordLength) * 100).toFixed(0) + '%';
emit('typingInfo', {
wordLength,
wrongLength,
Expand Down Expand Up @@ -426,6 +427,10 @@ function focusInput() {
inputAreaRef.value.focus();
moveCaretToEnd(inputAreaRef.value);
}
function blurInput() {
if (!inputAreaRef.value) return;
inputAreaRef.value.blur();
}
function moveCaretToEnd(element: HTMLElement) {
// 使光标移动到末尾
Expand Down Expand Up @@ -520,6 +525,7 @@ function getTypingRecord() {
defineExpose({
focusInput,
blurInput,
getTypingRecord
});
</script>
Expand All @@ -534,8 +540,7 @@ defineExpose({
<div class="y-word-input__quote">
<span
v-for="(item, index) in state.quoteArr"
style="position: relative"
:class="[item.isWrong ? 'is-wrong' : '', item.isInput ? 'is-input' : '']"
:class="['letter', item.isWrong ? 'is-wrong' : '', item.isInput ? 'is-input' : '']"
:key="item.id"
>{{ item.word
}}<template v-if="progressInfoKeys.includes(index)"
Expand Down Expand Up @@ -594,6 +599,7 @@ defineExpose({
left: 0;
width: 100%;
height: 100px;
pointer-events: none;
background: linear-gradient(
to top,
$background-gray 0%,
Expand All @@ -614,6 +620,11 @@ defineExpose({
line-height: 70px;
user-select: none;
color: $gray-04;
word-break: break-all;
white-space: normal;
.letter {
position: relative;
}
.is-input {
color: $gray-06;
}
Expand Down Expand Up @@ -666,14 +677,28 @@ defineExpose({
height: 20px;
display: block;
left: 0;
opacity: 0.6;
&:after {
position: absolute;
content: '';
width: 1px;
background: $gray-08;
height: 36px;
height: 38px;
left: 0;
top: 0;
animation: blink 1s infinite;
}
}
@keyframes blink {
0% {
opacity: 1;
}
50% {
opacity: 0;
}
100% {
opacity: 1;
}
}
</style>
4 changes: 2 additions & 2 deletions src/components/ui/Button.vue
Original file line number Diff line number Diff line change
Expand Up @@ -73,9 +73,9 @@ const handlerClick = () => {
}
.y-button--disabled {
cursor: not-allowed;
opacity: 0.3;
opacity: 0.3 !important;
&:hover {
opacity: 0.3;
opacity: 0.3 !important;
}
}
.y-button--secondary {
Expand Down
16 changes: 14 additions & 2 deletions src/components/ui/Draggable.vue
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,18 @@ function handleMouseUp() {
function toggleContent() {
state.isShowContent = !state.isShowContent;
}
function hideContent() {
state.isShowContent = false;
}
function showContent() {
state.isShowContent = true;
}
defineExpose({
hideContent,
showContent
});
</script>

<template>
Expand Down Expand Up @@ -115,15 +127,15 @@ function toggleContent() {
<style lang="scss">
.draggable {
position: fixed;
width: 340px;
width: 360px;
color: $gray-08;
background-color: $layout-background-gray;
box-shadow: 0 2px 8px rgba(0, 0, 0, 0.33);
top: 0;
left: 0;
border-radius: 2px;
overflow: hidden;
z-index: 999;
z-index: 9;
}
.draggable__head {
width: 100%;
Expand Down
15 changes: 12 additions & 3 deletions src/components/ui/Modal.vue
Original file line number Diff line number Diff line change
Expand Up @@ -9,12 +9,16 @@ const props = withDefaults(
className: string;
zIndex: number;
showCancel: boolean;
closeOnClickMask: boolean;
showCloseBtn: boolean;
}>
>(),
{
show: false,
zIndex: 1,
showCancel: false
showCancel: false,
closeOnClickMask: true,
showCloseBtn: true
}
);
Expand All @@ -39,16 +43,21 @@ watch(
immediate: true
}
);
function clickMask() {
if (props.closeOnClickMask) {
emit('close');
}
}
</script>

<template>
<Transition name="modal">
<Teleport to="body">
<div v-if="show" class="y-modal__mask" :style="{ zIndex: zIndex }" @click="emit('close')">
<div v-if="show" class="y-modal__mask" :style="{ zIndex: zIndex }" @click="clickMask">
<div class="y-modal__container" :class="className" @click.stop>
<div class="y-modal__header flex-center--y">
<slot name="header">default header</slot>
<IcoClose @click="emit('close')"></IcoClose>
<IcoClose v-if="showCloseBtn" @click="emit('close')"></IcoClose>
</div>

<div class="y-modal__body">
Expand Down
Loading

0 comments on commit 309a4c2

Please sign in to comment.