-
Notifications
You must be signed in to change notification settings - Fork 6
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
11 changed files
with
233 additions
and
7 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
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
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
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,92 @@ | ||
<script lang="ts" setup> | ||
import Shadow from './Shadow.vue' | ||
import { CloseBold } from '@element-plus/icons-vue' | ||
import isMobile from '@/composables/isMobile' | ||
import Loading from './Loading.vue' | ||
const props = withDefaults(defineProps<{ | ||
show: boolean | ||
width?: string | ||
height?: string | ||
maxWidth?: string | ||
minHeight?: string | ||
maxHeight?: string | ||
loading?: boolean | ||
preventShadowEvent?: boolean | ||
showClose?: boolean | ||
transition?: transitionType | ||
}>(), { | ||
width: '40rem', | ||
height: 'auto', | ||
maxWidth: '90vw', | ||
minHeight: '25rem', | ||
maxHeight: '90vh', | ||
loading: false, | ||
preventShadowEvent: true, | ||
showClose: true, | ||
transition: 'fade-scale' | ||
}) | ||
const _isMobile = isMobile() | ||
const emit = defineEmits<{ | ||
(e: 'update:show', value: boolean): void | ||
}>() | ||
function shadowClick() { | ||
// 如果显示关闭按钮(手机端会自动隐藏关闭按钮,关闭劝流转到点击阴影) | ||
if (props.showClose) { | ||
// 且不是在手机端,则把关闭权交给关闭按钮 | ||
if (!_isMobile.value && props.preventShadowEvent) return | ||
} | ||
emit('update:show', false) | ||
} | ||
</script> | ||
<template> | ||
<Teleport to="body"> | ||
<Transition :name="props.transition" mode="out-in" appear> | ||
<Shadow v-if="props.show" contentCenter @shadowClick="shadowClick"> | ||
<div :style="{ position: 'relative', maxHeight: props.maxHeight }"> | ||
<div class="block shadow modal" | ||
:style="{ width: props.width, height: props.height, maxWidth: props.maxWidth, minHeight: props.minHeight, maxHeight: props.maxHeight }"> | ||
<Loading v-if="props.loading"></Loading> | ||
<template v-else> | ||
<slot name="modalHeader"></slot> | ||
<main class="modal-main"> | ||
<slot></slot> | ||
</main> | ||
<slot name="modalFooter"></slot> | ||
</template> | ||
</div> | ||
<el-icon v-if="!_isMobile && props.showClose" class="icon-close" @click="emit('update:show', false)"> | ||
<CloseBold /> | ||
</el-icon> | ||
</div> | ||
</Shadow> | ||
</Transition> | ||
</Teleport> | ||
</template> | ||
<style scoped> | ||
.modal { | ||
position: relative; | ||
display: flex; | ||
flex-direction: column; | ||
background-color: white; | ||
} | ||
.modal-main { | ||
flex: 1; | ||
overflow: auto; | ||
width: 100%; | ||
height: 100%; | ||
} | ||
.icon-close { | ||
position: absolute; | ||
top: .3rem; | ||
right: -2rem; | ||
cursor: pointer; | ||
font-size: 1.5rem; | ||
color: white; | ||
} | ||
</style> |
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,26 @@ | ||
<script lang="ts" setup> | ||
import loadingGif from '@/assets/loading.gif' | ||
</script> | ||
|
||
<template> | ||
<div class="loading-wrapper"> | ||
<img class="loading-gif" :src="loadingGif" alt="加载中..."> | ||
</div> | ||
</template> | ||
|
||
<style scoped> | ||
.loading-wrapper { | ||
width: 100%; | ||
height: 100%; | ||
display: flex; | ||
justify-content: center; | ||
align-items: center; | ||
flex: 1; | ||
} | ||
.loading-gif { | ||
width: 5rem; | ||
height: auto; | ||
object-fit: contain; | ||
} | ||
</style> |
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 |
---|---|---|
|
@@ -63,6 +63,7 @@ header { | |
} | ||
.icon-sidebar-trigger { | ||
cursor: pointer; | ||
margin-right: 1.2rem; | ||
font-size: 1.2rem; | ||
|
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,48 @@ | ||
<script setup lang="ts"> | ||
import Dialog from '@/components/Dialog.vue' | ||
import { reactive } from 'vue' | ||
const dialogs = reactive({ | ||
dialog1: { | ||
show: false, | ||
loading: false, | ||
timeout: <NodeJS.Timeout | null>null, | ||
transition: <transitionType>'slide-down' | ||
} | ||
}) | ||
function showDialog(transition: transitionType) { | ||
dialogs.dialog1.timeout && clearTimeout(dialogs.dialog1.timeout) | ||
dialogs.dialog1.loading = true | ||
dialogs.dialog1.transition = transition | ||
dialogs.dialog1.show = true | ||
dialogs.dialog1.timeout = setTimeout(() => { | ||
dialogs.dialog1.loading = false | ||
}, 2000) | ||
} | ||
</script> | ||
|
||
<template> | ||
<div> | ||
<Dialog v-model:show="dialogs.dialog1.show" :loading="dialogs.dialog1.loading" | ||
:transition="dialogs.dialog1.transition"> | ||
<template #modalHeader> | ||
<div style="height: 3rem; background-color: aquamarine;">模态框头部</div> | ||
</template> | ||
<div style="width: 100%; height: 50rem; background-color: lightblue;"> | ||
模态框内容 | ||
</div> | ||
<template #modalFooter> | ||
<div style="height: 3rem; background-color: bisque;">模态框底部</div> | ||
</template> | ||
</Dialog> | ||
<ElButton @click="showDialog('fade')">fade模态框</ElButton> | ||
<ElButton @click="showDialog('fade-scale')">fade-scale模态框</ElButton> | ||
<ElButton @click="showDialog('slide-up')">slide-up模态框</ElButton> | ||
<ElButton @click="showDialog('slide-down')">slide-down模态框</ElButton> | ||
<ElButton @click="showDialog('slide-left')">slide-left模态框</ElButton> | ||
<ElButton @click="showDialog('slide-right')">slide-right模态框</ElButton> | ||
</div> | ||
</template> | ||
|
||
<style> | ||
</style> |