riku
2025-03-28 cca8d423c4805665bbd48a47e4d9218b16d14ebb
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
<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>
    <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'
  }
});
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>