1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
| <template>
| <!-- dialog包裹 -->
| <el-dialog
| v-if="currType == 'dialog'"
| :title="title"
| :model-value="visible"
| @opened="$emit('update:visible', true)"
| @closed="$emit('update:visible', false)"
| destroy-on-close
| :draggable="draggable"
| :modal="modal"
| :append-to-body="appendToBody"
| >
| <div v-if="visible">
| <slot name="content"></slot>
| </div>
| </el-dialog>
| <!-- drawer包裹 -->
| <el-drawer
| v-if="currType == 'drawer'"
| :title="title"
| size="45%"
| direction="ltr"
| :model-value="visible"
| @opened="$emit('update:visible', true)"
| @closed="$emit('update:visible', false)"
| destroy-on-close
| >
| <slot name="content"></slot>
| </el-drawer>
| <!-- 默认无包裹 -->
| <div v-if="currType == 'normal'">
| <slot></slot>
| </div>
| </template>
| <script setup>
| import { ref, defineEmits, watch } from 'vue';
| const props = defineProps({
| visible: Boolean,
| title: String,
| type: {
| type: String,
| default: 'normal'
| },
| draggable: Boolean,
| modal: {
| type: Boolean,
| default: true
| },
| appendToBody: {
| type: Boolean,
| default: true
| }
| });
| const typeOptions = ref([
| { id: '0', label: 'dialog' },
| { id: '1', label: 'drawer' },
| { id: '10', label: '' }
| ]);
| const currType = ref('');
| const emit = defineEmits(['update:visible']);
| watch(
| () => props.type,
| (nValue) => {
| currType.value = nValue;
| },
| { immediate: true }
| );
| </script>
| <style scoped>
| ::v-deep .el-drawer__body {
| padding-top: 0;
| }
|
| ::v-deep .el-drawer__header {
| margin-bottom: 16px;
| }
| </style>
|
|