2023-03-27 05:22:18 +08:00
|
|
|
<script lang="ts">
|
|
|
|
import { defineComponent, onMounted } from "vue";
|
|
|
|
export default defineComponent({
|
|
|
|
name: "simple-modal",
|
|
|
|
props: {
|
|
|
|
contentWidth: String,
|
|
|
|
},
|
|
|
|
setup(props, { emit }) {
|
|
|
|
onMounted(() => {
|
|
|
|
document.addEventListener("keydown", (e) => {
|
|
|
|
if (e.keyCode == 27) {
|
|
|
|
emit("close");
|
|
|
|
}
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
return {};
|
|
|
|
},
|
|
|
|
});
|
|
|
|
</script>
|
|
|
|
|
|
|
|
|
2021-01-22 03:38:17 +08:00
|
|
|
<template>
|
2023-01-02 00:04:52 +08:00
|
|
|
<div class="modal-mask">
|
|
|
|
<div class="modal-wrapper" @click="$emit('close')">
|
2023-04-09 04:28:39 +08:00
|
|
|
<div @click.stop :class="[
|
|
|
|
'modal-container max-h-screen overflow-y-scroll',
|
|
|
|
contentWidth ? contentWidth : 'w-1/2',
|
|
|
|
]">
|
2023-01-02 00:04:52 +08:00
|
|
|
<div class="modal-header">
|
|
|
|
<div class="flex justify-between">
|
|
|
|
<slot name="header">default header</slot>
|
2023-04-09 04:28:39 +08:00
|
|
|
<button @click="$emit('close')"
|
|
|
|
class="ml-4 inline-flex items-center justify-center w-8 h-8 mr-2 text-red-500 transition-colors duration-150 bg-white rounded-full border-red-200 border focus:outline-none hover:border-red-500">
|
2023-01-02 00:04:52 +08:00
|
|
|
<font-awesome-icon icon="times" />
|
|
|
|
</button>
|
2021-01-22 03:38:17 +08:00
|
|
|
</div>
|
2023-01-02 00:04:52 +08:00
|
|
|
</div>
|
|
|
|
<hr />
|
2021-01-22 03:38:17 +08:00
|
|
|
|
2023-01-02 00:04:52 +08:00
|
|
|
<div class="modal-body">
|
|
|
|
<slot name="body">default body</slot>
|
|
|
|
</div>
|
|
|
|
|
|
|
|
<hr />
|
|
|
|
<div class="modal-footer">
|
|
|
|
<slot name="footer">
|
|
|
|
<div class="flex justify-end">
|
|
|
|
<button
|
|
|
|
class="modal-default-button text-red-500 border-red-200 border rounded py-1 px-2 transition-colors hover:outline-none hover:border-red-500"
|
2023-04-09 04:28:39 +08:00
|
|
|
@click="$emit('close')">
|
2023-01-02 00:04:52 +08:00
|
|
|
Cancel
|
|
|
|
</button>
|
|
|
|
</div>
|
|
|
|
</slot>
|
2021-01-22 03:38:17 +08:00
|
|
|
</div>
|
|
|
|
</div>
|
|
|
|
</div>
|
2023-01-02 00:04:52 +08:00
|
|
|
</div>
|
2021-01-22 03:38:17 +08:00
|
|
|
</template>
|
|
|
|
|
2023-01-02 00:04:52 +08:00
|
|
|
|
2021-05-27 23:56:40 +08:00
|
|
|
|
2022-04-04 02:54:31 +08:00
|
|
|
<style lang="postcss" scoped>
|
2021-01-22 03:38:17 +08:00
|
|
|
.modal-mask {
|
|
|
|
position: fixed;
|
|
|
|
z-index: 9998;
|
|
|
|
top: 0;
|
|
|
|
left: 0;
|
|
|
|
width: 100%;
|
|
|
|
height: 100%;
|
|
|
|
background-color: rgba(0, 0, 0, 0.5);
|
|
|
|
display: table;
|
2021-10-23 18:51:28 +08:00
|
|
|
transition: opacity 0.6s ease;
|
2021-01-22 03:38:17 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
.modal-wrapper {
|
|
|
|
display: table-cell;
|
|
|
|
vertical-align: middle;
|
|
|
|
}
|
|
|
|
|
|
|
|
.modal-container {
|
2021-05-27 23:56:40 +08:00
|
|
|
/* max-width: 70%; */
|
2021-01-22 03:38:17 +08:00
|
|
|
margin: 0px auto;
|
|
|
|
padding: 20px 30px;
|
|
|
|
background-color: #fff;
|
|
|
|
border-radius: 2px;
|
|
|
|
box-shadow: 0 2px 8px rgba(0, 0, 0, 0.33);
|
2021-10-23 18:51:28 +08:00
|
|
|
transition: all 0.6s ease;
|
2021-01-22 03:38:17 +08:00
|
|
|
font-family: Helvetica, Arial, sans-serif;
|
|
|
|
}
|
|
|
|
|
|
|
|
.modal-header h3 {
|
|
|
|
margin-top: 0;
|
|
|
|
color: #42b983;
|
|
|
|
}
|
|
|
|
|
|
|
|
.modal-body {
|
|
|
|
margin: 20px 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
.modal-default-button {
|
|
|
|
display: block;
|
|
|
|
margin-top: 1rem;
|
|
|
|
}
|
|
|
|
|
|
|
|
.modal-enter {
|
|
|
|
opacity: 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
.modal-leave-active {
|
|
|
|
opacity: 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
.modal-enter .modal-container,
|
|
|
|
.modal-leave-active .modal-container {
|
|
|
|
-webkit-transform: scale(1.1);
|
|
|
|
transform: scale(1.1);
|
|
|
|
}
|
|
|
|
</style>
|