gyyg-components 0.1.12 → 0.1.14

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,327 +1,333 @@
1
- /** * 公共模态框组件 author:lijihao Date:2024.11 支持关闭时,el-form表单清空 **/
2
- <template>
3
- <div class="gyyg-modal">
4
- <el-dialog
5
- :class="dialogClass"
6
- v-el-drag-dialog
7
- :type="type"
8
- :width="width"
9
- :custom-class="customClass"
10
- :fullscreen="fullscreen"
11
- :title="title"
12
- :close-on-click-modal="closeOnClickModal"
13
- :append-to-body="appendToBody"
14
- :visible.sync="visible"
15
- :before-close="beforeClose"
16
- :show-close="showClose"
17
- v-if="visible"
18
- @closed="closed"
19
- @close="closeMethod"
20
- :destroy-on-close="destroyOnClose"
21
- :modal="modal"
22
- >
23
- <div>
24
- <slot name="body" class="gyyg-modal-body" />
25
- </div>
26
-
27
- <div v-if="footer" slot="footer" class="dialog-footer">
28
- <slot name="footer" />
29
- </div>
30
- </el-dialog>
31
- </div>
32
- </template>
33
-
34
- <script>
35
- import elDragDialog from '@/directive/el-drag-dialog' // 引入拖拽指令
36
- export default {
37
- name: 'GyygModal',
38
- directives: { elDragDialog },
39
- props: {
40
- // 是否嵌套
41
- appendToBody: {
42
- type: Boolean,
43
- default: false,
44
- },
45
- // 是否可以点击关闭
46
- closeOnClickModal: {
47
- type: Boolean,
48
- default: false,
49
- },
50
- // 是否显示底部
51
- footer: {
52
- type: Boolean,
53
- default: true,
54
- },
55
- // title
56
- title: {
57
- type: String,
58
- default: '',
59
- },
60
- type: {
61
- type: [String,Number],
62
- default: "",
63
- }, // 对话框类型:1.基础表单[gyyg-modal-form] 2.表格[gyyg-modal-table] 3.全屏 [gyyg-modal-fullscreen]
64
- // 对话框宽度(默认50%)
65
- width: {
66
- type: [String,Number],
67
- default: '',
68
- },
69
- //对话框高度(默认90%)
70
- height: {
71
- type: [String,Number],
72
- default: '',
73
- },
74
- //关闭后销毁
75
- destroyOnClose: {
76
- type: Boolean,
77
- default: true,
78
- },
79
- // 关闭回调函数
80
- beforeClose: Function,
81
- //弹框class
82
- dialogClass: {
83
- type: String,
84
- default: '',
85
- },
86
- // 是否显示叉号
87
- showClose: {
88
- default: true,
89
- type: Boolean,
90
- },
91
- //是否需要遮罩层
92
- modal: {
93
- default: true,
94
- type: Boolean,
95
- },
96
- },
97
- data() {
98
- return {
99
- visible: false,
100
- fullscreen: false,
101
- }
102
- },
103
- computed: {
104
- customClass() {
105
- let className = "";
106
- switch (this.type) {
107
- case "form":
108
- className = "gyyg-modal-form";
109
- break;
110
- case "table":
111
- className = "gyyg-modal-table";
112
- break;
113
- case "fullscreen":
114
- className = "gyyg-modal-fullscreen";
115
- break;
116
- }
117
- return className;
118
- },
119
- },
120
- created() {
121
- this.type === "fullscreen" && (this.fullscreen = true);
122
- },
123
- methods: {
124
- //弹框打开
125
- open() {
126
- this.visible = true
127
- if (this.height) {
128
- this.$nextTick(() => {
129
- document.getElementsByClassName('gyyg-modal')[0].getElementsByClassName('el-dialog')[0].style.height = this.height
130
- })
131
- }
132
- },
133
- close() {
134
- let db = document.getElementsByClassName('el-dialog__body')
135
- //表单清空显示
136
- if (db && db[0] && db[0].getElementsByClassName('el-form') && db[0].getElementsByClassName('el-form').length > 0) {
137
- let arr = Array.prototype.slice.call(db[0].getElementsByClassName('el-form'))
138
- arr.forEach(item => {
139
- if (item.__vue__) {
140
- let obj = item.__vue__.$options.propsData.model
141
- for (let key in obj) {
142
- if (obj.hasOwnProperty(key)) {
143
- if (obj[key] instanceof Array) {
144
- obj[key] = []
145
- } else if (obj[key] instanceof Object) {
146
- obj[key] = {}
147
- } else {
148
- obj[key] = ''
149
- }
150
- }
151
- }
152
- }
153
- })
154
- }
155
- //组件清空显示(组件里必须要加class='subcomponents',才能找到,清空)
156
- if (db && db[0] && db[0].getElementsByClassName('subcomponents') && db[0].getElementsByClassName('subcomponents').length > 0) {
157
- let arr = Array.prototype.slice.call(db[0].getElementsByClassName('subcomponents'))
158
- arr.forEach(item => {
159
- if (item.__vue__) {
160
- //组件清空数据的方法
161
- if (item.__vue__.clearHandle) {
162
- item.__vue__.clearHandle()
163
- } else if (item.__vue__.clearInput) {
164
- item.__vue__.clearInput()
165
- }
166
- }
167
- })
168
- }
169
- this.visible = false
170
- },
171
- closed() {
172
- this.close()
173
- this.$emit('closed')
174
- },
175
- //弹框关闭
176
- closeMethod() {
177
- this.close()
178
- this.$emit('close')
179
- },
180
- },
181
- }
182
- </script>
183
-
184
- <style lang="less">
185
- .el-dialog__wrapper {
186
- overflow: hidden;
187
- display: flex;
188
- justify-content: center;
189
- align-items: center;
190
- .el-dialog {
191
- display: flex;
192
- flex-direction: column;
193
- border-radius: 8px;
194
- margin: 0;
195
- margin-top: 0 !important;
196
- max-height: 95%;
197
- .el-dialog__header {
198
- text-align: left;
199
- background-color: #efefef;
200
- height: 48px;
201
- line-height: 48px;
202
- padding: 0 20px;
203
- color: #fff;
204
- border-top-left-radius: 8px;
205
- border-top-right-radius: 8px;
206
- font-weight: bold;
207
-
208
- .el-dialog__title {
209
- font-size: 16px;
210
- }
211
-
212
- .el-dialog__headerbtn {
213
- top: 12px;
214
- }
215
- }
216
-
217
- .el-dialog__body {
218
- flex: 1;
219
- overflow: auto;
220
- }
221
-
222
- .el-dialog__footer {
223
- padding: 10px;
224
- border: none;
225
- background-color: #efefef;
226
- border-bottom-left-radius: 8px;
227
- border-bottom-right-radius: 8px;
228
- }
229
- }
230
-
231
- .gyyg-modal-form {
232
- height: auto;
233
-
234
- .el-dialog__body {
235
- padding: 20px 20px 0 20px;
236
- }
237
-
238
- .el-dialog__footer {
239
- border: none;
240
- background-color: #efefef;
241
- border-bottom-left-radius: 8px;
242
- border-bottom-right-radius: 8px;
243
- }
244
-
245
- .custom-table {
246
- // 取消表格下边线
247
- tbody tr:last-child td {
248
- border-bottom: none !important;
249
- }
250
- }
251
- }
252
-
253
- .gyyg-modal-table {
254
- height: 90vh;
255
- margin-top: 5vh !important;
256
- }
257
-
258
- .gyyg-modal-fullscreen {
259
- height: 100vh;
260
- width: 100vw;
261
-
262
- .el-dialog__body {
263
- padding: 10px;
264
- }
265
- .el-dialog__footer {
266
- padding: 10px;
267
- border: none;
268
- background-color: #efefef;
269
- border-bottom-left-radius: 8px;
270
- border-bottom-right-radius: 8px;
271
- }
272
- }
273
- }
274
-
275
- .gyyg-modal {
276
- text-align: left;
277
- }
278
- ::v-deep .gyyg-modal .el-dialog__wrapper {
279
- overflow: hidden;
280
- display: flex !important;
281
- justify-content: center;
282
- align-items: center;
283
- .el-dialog {
284
- display: flex;
285
- flex-direction: column;
286
- border-radius: 8px;
287
- margin: 0;
288
- margin-top: 0 !important;
289
- .el-dialog__header {
290
- text-align: left;
291
- background-color: #efefef;
292
- height: 48px;
293
- line-height: 48px;
294
- padding: 0 20px;
295
- color: #fff;
296
- border-top-left-radius: 8px;
297
- border-top-right-radius: 8px;
298
- font-weight: bold;
299
-
300
- .el-dialog__title {
301
- font-size: 16px;
302
- // font-weight: bold;
303
- }
304
-
305
- .el-dialog__headerbtn {
306
- top: 12px;
307
- }
308
- }
309
-
310
- .el-dialog__body {
311
- flex: 1;
312
- overflow: auto;
313
- }
314
-
315
- .el-dialog__footer {
316
- flex-shrink: 0;
317
- box-sizing: content-box;
318
- height: 32px;
319
- padding: 10px;
320
- border: none;
321
- background-color: #efefef;
322
- border-bottom-left-radius: 8px;
323
- border-bottom-right-radius: 8px;
324
- }
325
- }
326
- }
327
- </style>
1
+ /** * 公共模态框组件 author:lijihao Date:2024.11 支持关闭时,el-form表单清空 **/
2
+ <template>
3
+ <div class="gyyg-modal">
4
+ <el-dialog
5
+ :class="dialogClass"
6
+ v-el-drag-dialog
7
+ :type="type"
8
+ :width="width"
9
+ :custom-class="customClass"
10
+ :fullscreen="fullscreen"
11
+ :title="title"
12
+ :close-on-click-modal="closeOnClickModal"
13
+ :append-to-body="appendToBody"
14
+ :visible.sync="visible"
15
+ :before-close="beforeClose"
16
+ :show-close="showClose"
17
+ v-if="visible"
18
+ @closed="closed"
19
+ @close="closeMethod"
20
+ :destroy-on-close="destroyOnClose"
21
+ :modal="modal"
22
+ >
23
+ <div>
24
+ <slot name="body" class="gyyg-modal-body" />
25
+ </div>
26
+
27
+ <div v-if="footer" slot="footer" class="dialog-footer">
28
+ <slot name="footer" />
29
+ </div>
30
+ </el-dialog>
31
+ </div>
32
+ </template>
33
+
34
+ <script>
35
+ import elDragDialog from '@/directive/el-drag-dialog' // 引入拖拽指令
36
+ export default {
37
+ name: 'GyygModal',
38
+ directives: { elDragDialog },
39
+ props: {
40
+ // 是否嵌套
41
+ appendToBody: {
42
+ type: Boolean,
43
+ default: false,
44
+ },
45
+ // 是否可以点击关闭
46
+ closeOnClickModal: {
47
+ type: Boolean,
48
+ default: false,
49
+ },
50
+ // 是否显示底部
51
+ footer: {
52
+ type: Boolean,
53
+ default: true,
54
+ },
55
+ // title
56
+ title: {
57
+ type: String,
58
+ default: '',
59
+ },
60
+ type: {
61
+ type: [String,Number],
62
+ default: "",
63
+ }, // 对话框类型:1.基础表单[gyyg-modal-form] 2.表格[gyyg-modal-table] 3.全屏 [gyyg-modal-fullscreen]
64
+ // 对话框宽度(默认50%)
65
+ width: {
66
+ type: [String,Number],
67
+ default: '',
68
+ },
69
+ //对话框高度(默认90%)
70
+ height: {
71
+ type: [String,Number],
72
+ default: '',
73
+ },
74
+ //关闭后销毁
75
+ destroyOnClose: {
76
+ type: Boolean,
77
+ default: true,
78
+ },
79
+ // 关闭回调函数
80
+ beforeClose: Function,
81
+ //弹框class
82
+ dialogClass: {
83
+ type: String,
84
+ default: '',
85
+ },
86
+ // 是否显示叉号
87
+ showClose: {
88
+ default: true,
89
+ type: Boolean,
90
+ },
91
+ //是否需要遮罩层
92
+ modal: {
93
+ default: true,
94
+ type: Boolean,
95
+ },
96
+ },
97
+ data() {
98
+ return {
99
+ visible: false,
100
+ fullscreen: false,
101
+ }
102
+ },
103
+ computed: {
104
+ customClass() {
105
+ let className = "";
106
+ switch (this.type) {
107
+ case "form":
108
+ className = "gyyg-modal-form";
109
+ break;
110
+ case "table":
111
+ className = "gyyg-modal-table";
112
+ break;
113
+ case "fullscreen":
114
+ className = "gyyg-modal-fullscreen";
115
+ break;
116
+ }
117
+ return className;
118
+ },
119
+ },
120
+ created() {
121
+ this.type === "fullscreen" && (this.fullscreen = true);
122
+ },
123
+ methods: {
124
+ //弹框打开
125
+ open() {
126
+ this.visible = true
127
+ if (this.height) {
128
+ this.$nextTick(() => {
129
+ document.getElementsByClassName('gyyg-modal')[0].getElementsByClassName('el-dialog')[0].style.height = this.height
130
+ })
131
+ }
132
+ },
133
+ close() {
134
+ let db = null
135
+ //子弹框需要加dialogClass,否则父弹框的form也会清空
136
+ if(this.dialogClass){
137
+ db=document.getElementsByClassName(this.dialogClass)[0].getElementsByClassName('el-dialog__body')
138
+ }else{
139
+ db=document.getElementsByClassName('el-dialog__body')
140
+ }
141
+ //表单清空显示
142
+ if (db && db[0] && db[0].getElementsByClassName('el-form') && db[0].getElementsByClassName('el-form').length > 0) {
143
+ let arr = Array.prototype.slice.call(db[0].getElementsByClassName('el-form'))
144
+ arr.forEach(item => {
145
+ if (item.__vue__) {
146
+ let obj = item.__vue__.$options.propsData.model
147
+ for (let key in obj) {
148
+ if (obj.hasOwnProperty(key)) {
149
+ if (obj[key] instanceof Array) {
150
+ obj[key] = []
151
+ } else if (obj[key] instanceof Object) {
152
+ obj[key] = {}
153
+ } else {
154
+ obj[key] = ''
155
+ }
156
+ }
157
+ }
158
+ }
159
+ })
160
+ }
161
+ //组件清空显示(组件里必须要加class='subcomponents',才能找到,清空)
162
+ if (db && db[0] && db[0].getElementsByClassName('subcomponents') && db[0].getElementsByClassName('subcomponents').length > 0) {
163
+ let arr = Array.prototype.slice.call(db[0].getElementsByClassName('subcomponents'))
164
+ arr.forEach(item => {
165
+ if (item.__vue__) {
166
+ //组件清空数据的方法
167
+ if (item.__vue__.clearHandle) {
168
+ item.__vue__.clearHandle()
169
+ } else if (item.__vue__.clearInput) {
170
+ item.__vue__.clearInput()
171
+ }
172
+ }
173
+ })
174
+ }
175
+ this.visible = false
176
+ },
177
+ closed() {
178
+ this.close()
179
+ this.$emit('closed')
180
+ },
181
+ //弹框关闭
182
+ closeMethod() {
183
+ this.close()
184
+ this.$emit('close')
185
+ },
186
+ },
187
+ }
188
+ </script>
189
+
190
+ <style lang="less">
191
+ .el-dialog__wrapper {
192
+ overflow: hidden;
193
+ display: flex;
194
+ justify-content: center;
195
+ align-items: center;
196
+ .el-dialog {
197
+ display: flex;
198
+ flex-direction: column;
199
+ border-radius: 8px;
200
+ margin: 0;
201
+ margin-top: 0 !important;
202
+ max-height: 95%;
203
+ .el-dialog__header {
204
+ text-align: left;
205
+ background-color: #efefef;
206
+ height: 48px;
207
+ line-height: 48px;
208
+ padding: 0 20px;
209
+ color: #fff;
210
+ border-top-left-radius: 8px;
211
+ border-top-right-radius: 8px;
212
+ font-weight: bold;
213
+
214
+ .el-dialog__title {
215
+ font-size: 16px;
216
+ }
217
+
218
+ .el-dialog__headerbtn {
219
+ top: 12px;
220
+ }
221
+ }
222
+
223
+ .el-dialog__body {
224
+ flex: 1;
225
+ overflow: auto;
226
+ }
227
+
228
+ .el-dialog__footer {
229
+ padding: 10px;
230
+ border: none;
231
+ background-color: #efefef;
232
+ border-bottom-left-radius: 8px;
233
+ border-bottom-right-radius: 8px;
234
+ }
235
+ }
236
+
237
+ .gyyg-modal-form {
238
+ height: auto;
239
+
240
+ .el-dialog__body {
241
+ padding: 20px 20px 0 20px;
242
+ }
243
+
244
+ .el-dialog__footer {
245
+ border: none;
246
+ background-color: #efefef;
247
+ border-bottom-left-radius: 8px;
248
+ border-bottom-right-radius: 8px;
249
+ }
250
+
251
+ .custom-table {
252
+ // 取消表格下边线
253
+ tbody tr:last-child td {
254
+ border-bottom: none !important;
255
+ }
256
+ }
257
+ }
258
+
259
+ .gyyg-modal-table {
260
+ height: 90vh;
261
+ margin-top: 5vh !important;
262
+ }
263
+
264
+ .gyyg-modal-fullscreen {
265
+ height: 100vh;
266
+ width: 100vw;
267
+
268
+ .el-dialog__body {
269
+ padding: 10px;
270
+ }
271
+ .el-dialog__footer {
272
+ padding: 10px;
273
+ border: none;
274
+ background-color: #efefef;
275
+ border-bottom-left-radius: 8px;
276
+ border-bottom-right-radius: 8px;
277
+ }
278
+ }
279
+ }
280
+
281
+ .gyyg-modal {
282
+ text-align: left;
283
+ }
284
+ ::v-deep .gyyg-modal .el-dialog__wrapper {
285
+ overflow: hidden;
286
+ display: flex !important;
287
+ justify-content: center;
288
+ align-items: center;
289
+ .el-dialog {
290
+ display: flex;
291
+ flex-direction: column;
292
+ border-radius: 8px;
293
+ margin: 0;
294
+ margin-top: 0 !important;
295
+ .el-dialog__header {
296
+ text-align: left;
297
+ background-color: #efefef;
298
+ height: 48px;
299
+ line-height: 48px;
300
+ padding: 0 20px;
301
+ color: #fff;
302
+ border-top-left-radius: 8px;
303
+ border-top-right-radius: 8px;
304
+ font-weight: bold;
305
+
306
+ .el-dialog__title {
307
+ font-size: 16px;
308
+ // font-weight: bold;
309
+ }
310
+
311
+ .el-dialog__headerbtn {
312
+ top: 12px;
313
+ }
314
+ }
315
+
316
+ .el-dialog__body {
317
+ flex: 1;
318
+ overflow: auto;
319
+ }
320
+
321
+ .el-dialog__footer {
322
+ flex-shrink: 0;
323
+ box-sizing: content-box;
324
+ height: 32px;
325
+ padding: 10px;
326
+ border: none;
327
+ background-color: #efefef;
328
+ border-bottom-left-radius: 8px;
329
+ border-bottom-right-radius: 8px;
330
+ }
331
+ }
332
+ }
333
+ </style>