zhuoyuan.wang
2024-06-19 15ebe96f28cadec6a726c5324593a40bbf56205f
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
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
<template>
  <el-dialog
    v-model="visible"
    v-bind="$props"
    :draggable="true"
    :fullscreen="fullscreen"
    :modal-class="footerDom ? '' : 'dialog-no-footer'"
  >
    <template #title>
      <div class="header">
        <app-svg-icon
          class="icon"
          :icon-class="fullscreen ? 'exit-fullscreen' : 'fullscreen'"
          @click="fullscreen = !fullscreen"
        />
        <div class="title">{{ $props.title }}</div>
      </div>
    </template>
    <slot/>
    <template #footer>
      <div class="dialog-footer" v-if="footerDom">
        <el-button @click="onClose()" icon="Close">{{ $t('components.dialog.DialogForm.cancel') }}
        </el-button>
        <el-button @click="onReset()" icon="RefreshRight">{{ $t('components.dialog.DialogForm.reset') }}</el-button>
        <el-button type="primary" @click="onSubmit()" icon="DocumentAdd" v-loading="loading">
          {{ $t('components.dialog.DialogForm.save') }}
        </el-button>
      </div>
    </template>
  </el-dialog>
</template>
 
<script setup>
 
import {context} from '@/hooks';
 
const {useForceUpdate} = context;
 
const props = defineProps({
  title: {
    type: String,
    default: ''
  },
  width: {
    type: Number,
    default: 750
  },
  subClose: {
    type: Function,
    default: () => {
    }
  },
  overflow: {
    type: Boolean,
    default: true
  },
  subReset: {
    type: Function,
    default: () => {
    }
  },
  subSubmit: {
    type: Function,
    default: () => {
    }
  },
  footerDom: {
    type: Boolean,
    default: true
  }
});
 
const [$props, forceUpdate] = useForceUpdate(props);
 
const $forceUpdate = forceUpdate;
 
const fullscreen = ref(false)
 
const visible = ref(false);
 
const loading = ref(false);
 
const onClose = async () => {
  props.subClose();
  visible.value = false;
}
 
const onReset = async () => {
  await props.subReset();
}
 
const onSubmit = async () => {
  loading.value = true;
  try {
    await props.subSubmit();
    visible.value = false;
  } catch (e) {
 
  } finally {
    loading.value = false;
  }
}
 
const onOpen = async () => {
  fullscreen.value = false;
  visible.value = true;
};
 
/**
 * 暴露给父组件的参数和方法 (外部需要什么,都可以从这里暴露出去)
 */
defineExpose({
  onOpen,
  onClose,
  $forceUpdate
});
 
</script>
 
<style lang='scss'>
.dialog-no-footer {
  .el-dialog__footer {
    display: none;
  }
 
  .el-dialog {
    .el-dialog__footer {
      height: 45px
    }
 
    .el-dialog__body {
      max-height: calc(100vh - 170px) !important;;
      overflow-y: auto;
    }
  }
 
  .is-fullscreen {
    --el-dialog-margin-top: 0 !important;
 
    .el-dialog__body {
      max-height: calc(100vh - 100px) !important;
    }
 
  }
}
</style>
 
 
<style lang='scss' scoped>
.header {
  .title {
    padding-left: 20px;
    font-size: var(--el-font-size-extra-large);
    color: var(--el-text-color-primary);
    font-weight: 500;
  }
 
  display: flex;
  align-items: center;
 
  .icon {
    font-size: 10px;
    cursor: pointer;
    position: absolute;
    top: 15px;
    left: 15px;
  }
}
 
.dialog-footer {
  position: absolute;
  bottom: 15px;
  right: 15px;
}
</style>