Skip to content

Commit 58ce5e0

Browse files
committed
区分手机和电脑
- 电脑端点击mask关闭 - 手机端下滑关闭
1 parent d031af4 commit 58ce5e0

File tree

3 files changed

+81
-24
lines changed

3 files changed

+81
-24
lines changed

src/App.vue

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,24 @@ function text(e: any) {
99
messages.value = e.split('\n\n')
1010
messages.value = messages.value.filter((i) => i && i.trim())
1111
}
12+
13+
var timeOutEvent = 0 //记录触摸时长
14+
15+
function goTouchstart() {
16+
timeOutEvent = 0
17+
timeOutEvent = setTimeout(function () {
18+
timeOutEvent = 0
19+
// 处理长按事件...
20+
s.value = true
21+
}, 600)
22+
}
23+
//手如果在600毫秒内就释放,则取消长按事件
24+
function goTouchend() {
25+
timeOutEvent = 0
26+
if (timeOutEvent !== 0) {
27+
// 处理单击事件
28+
}
29+
}
1230
</script>
1331

1432
<template>

src/components/MoDrawer.vue

Lines changed: 57 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -4,25 +4,42 @@ const props = defineProps({
44
show: Boolean, // 是否显示 Drawer
55
direction: { type: String, default: 'bottom', values: ['top', 'bottom', 'left', 'right'] },
66
distance: { type: [String, Number], default: '100%' },
7+
withHeader: { type: Boolean, default: true },
78
})
89
10+
const emit = defineEmits(['close'])
11+
912
const isHorizontal = computed(() => props.direction === 'left' || props.direction === 'right')
13+
14+
function handleMaskClick() {
15+
emit('close')
16+
}
17+
18+
var move = 0
19+
function handeContainerTouchStart(e: TouchEvent) {
20+
move = e.changedTouches[0].pageY
21+
}
22+
23+
function handeContainerTouchMove(e: TouchEvent) {
24+
let moveEndY = e.changedTouches[0].pageY
25+
let Y = moveEndY - move //如果值为正,则代表手指下滑,反则则为上滑,为0则表示点击
26+
if (Y > 0) {
27+
emit('close')
28+
}
29+
}
1030
</script>
1131

1232
<template>
1333
<Transition name="drawer">
14-
<div v-if="show" class="drawer-mask">
34+
<div v-if="show" class="drawer-layout">
1535
<div
1636
class="drawer-container"
17-
:style="
18-
isHorizontal
19-
? 'width: ' + distance + '; height: 100%;'
20-
: 'height: ' + distance + '; width: 100%;'
21-
"
37+
@touchstart="handeContainerTouchStart"
38+
@touchmove="handeContainerTouchMove"
2239
>
23-
<div class="drawer-header">
40+
<header v-if="withHeader" class="drawer-header">
2441
<slot name="header" />
25-
</div>
42+
</header>
2643

2744
<div class="drawer-body">
2845
<slot name="body" />
@@ -32,12 +49,13 @@ const isHorizontal = computed(() => props.direction === 'left' || props.directio
3249
<slot name="footer" />
3350
</div>
3451
</div>
52+
<div class="drawer-mask" @click="handleMaskClick"></div>
3553
</div>
3654
</Transition>
3755
</template>
3856

3957
<style>
40-
.drawer-mask {
58+
.drawer-layout {
4159
position: fixed;
4260
z-index: 9998;
4361
top: 0;
@@ -46,15 +64,30 @@ const isHorizontal = computed(() => props.direction === 'left' || props.directio
4664
bottom: 0;
4765
width: 100%;
4866
height: 100%;
49-
background-color: rgba(0, 0, 0, 0.5);
67+
background-color: inherit;
5068
display: flex;
5169
transition: opacity 0.3s ease;
5270
}
71+
.drawer-mask {
72+
position: fixed;
73+
z-index: 818;
74+
top: 0;
75+
left: 0;
76+
right: 0;
77+
bottom: 0;
78+
width: 100%;
79+
height: 100%;
80+
background-color: rgba(0, 0, 0, 0.5);
81+
transition: opacity 0.3s ease;
82+
}
5383
5484
.drawer-container {
85+
z-index: 9998;
5586
overflow: auto;
5687
position: absolute;
5788
bottom: 0;
89+
width: 100%;
90+
height: 100%;
5891
background-color: #f5f5f5;
5992
box-shadow: 0 2px 8px rgba(0, 0, 0, 0.33);
6093
transition: all 0.3s ease;
@@ -80,4 +113,18 @@ const isHorizontal = computed(() => props.direction === 'left' || props.directio
80113
.drawer-leave-to .drawer-mask {
81114
opacity: 0;
82115
}
116+
117+
@media (min-width: 1024px) {
118+
.drawer-container {
119+
bottom: unset;
120+
right: 0;
121+
width: 37%;
122+
height: 100%;
123+
}
124+
125+
.drawer-enter-from .drawer-container,
126+
.drawer-leave-to .drawer-container {
127+
transform: translate(100%, 0);
128+
}
129+
}
83130
</style>

src/views/SettingsView.vue

Lines changed: 6 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
import config from '../../package.json'
33
import { useStorage } from '@vueuse/core'
44
5-
const defineText = 'Moth\n\n织蛾'
5+
const defineText = '织蛾\n\nMoth'
66
77
const message = useStorage('my-store', defineText)
88
@@ -41,7 +41,10 @@ function toLicenseUrl() {
4141
<template>
4242
<mo-drawer :show="props.drawer" distance="100%" @close="$emit('close')">
4343
<template #header>
44-
<h1>Setting</h1>
44+
<h1>Settings</h1>
45+
</template>
46+
47+
<template #body>
4548
<div>
4649
<mo-tag class="tags" @click="toReleaseUrl">
4750
{{ config.version }}
@@ -53,9 +56,6 @@ function toLicenseUrl() {
5356
{{ config.license }}
5457
</mo-tag>
5558
</div>
56-
</template>
57-
58-
<template #body>
5959
<div class="setting-content">
6060
<h2>Slogan</h2>
6161
<div>
@@ -65,7 +65,7 @@ function toLicenseUrl() {
6565
@change="emitMessage"
6666
autosize
6767
></mo-textarea>
68-
<div class="close-button" @click="$emit('close')">OK</div>
68+
<span class="close-button" @click="$emit('close')">OK</span>
6969
</div>
7070
</div>
7171
</template>
@@ -104,12 +104,4 @@ function toLicenseUrl() {
104104
.setting-content .close-button:focus-visible {
105105
outline: 4px auto -webkit-focus-ring-color;
106106
}
107-
108-
@media (min-width: 1024px) {
109-
.about {
110-
min-height: 100vh;
111-
display: flex;
112-
align-items: center;
113-
}
114-
}
115107
</style>

0 commit comments

Comments
 (0)