gyyg-components 0.1.13 → 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,332 +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 = null
135
- if(this.dialogClass){
136
- db=document.getElementsByClassName(this.dialogClass)[0].getElementsByClassName('el-dialog__body')
137
- }else{
138
- db=document.getElementsByClassName('el-dialog__body')
139
- }
140
- //表单清空显示
141
- if (db && db[0] && db[0].getElementsByClassName('el-form') && db[0].getElementsByClassName('el-form').length > 0) {
142
- let arr = Array.prototype.slice.call(db[0].getElementsByClassName('el-form'))
143
- arr.forEach(item => {
144
- if (item.__vue__) {
145
- let obj = item.__vue__.$options.propsData.model
146
- for (let key in obj) {
147
- if (obj.hasOwnProperty(key)) {
148
- if (obj[key] instanceof Array) {
149
- obj[key] = []
150
- } else if (obj[key] instanceof Object) {
151
- obj[key] = {}
152
- } else {
153
- obj[key] = ''
154
- }
155
- }
156
- }
157
- }
158
- })
159
- }
160
- //组件清空显示(组件里必须要加class='subcomponents',才能找到,清空)
161
- if (db && db[0] && db[0].getElementsByClassName('subcomponents') && db[0].getElementsByClassName('subcomponents').length > 0) {
162
- let arr = Array.prototype.slice.call(db[0].getElementsByClassName('subcomponents'))
163
- arr.forEach(item => {
164
- if (item.__vue__) {
165
- //组件清空数据的方法
166
- if (item.__vue__.clearHandle) {
167
- item.__vue__.clearHandle()
168
- } else if (item.__vue__.clearInput) {
169
- item.__vue__.clearInput()
170
- }
171
- }
172
- })
173
- }
174
- this.visible = false
175
- },
176
- closed() {
177
- this.close()
178
- this.$emit('closed')
179
- },
180
- //弹框关闭
181
- closeMethod() {
182
- this.close()
183
- this.$emit('close')
184
- },
185
- },
186
- }
187
- </script>
188
-
189
- <style lang="less">
190
- .el-dialog__wrapper {
191
- overflow: hidden;
192
- display: flex;
193
- justify-content: center;
194
- align-items: center;
195
- .el-dialog {
196
- display: flex;
197
- flex-direction: column;
198
- border-radius: 8px;
199
- margin: 0;
200
- margin-top: 0 !important;
201
- max-height: 95%;
202
- .el-dialog__header {
203
- text-align: left;
204
- background-color: #efefef;
205
- height: 48px;
206
- line-height: 48px;
207
- padding: 0 20px;
208
- color: #fff;
209
- border-top-left-radius: 8px;
210
- border-top-right-radius: 8px;
211
- font-weight: bold;
212
-
213
- .el-dialog__title {
214
- font-size: 16px;
215
- }
216
-
217
- .el-dialog__headerbtn {
218
- top: 12px;
219
- }
220
- }
221
-
222
- .el-dialog__body {
223
- flex: 1;
224
- overflow: auto;
225
- }
226
-
227
- .el-dialog__footer {
228
- padding: 10px;
229
- border: none;
230
- background-color: #efefef;
231
- border-bottom-left-radius: 8px;
232
- border-bottom-right-radius: 8px;
233
- }
234
- }
235
-
236
- .gyyg-modal-form {
237
- height: auto;
238
-
239
- .el-dialog__body {
240
- padding: 20px 20px 0 20px;
241
- }
242
-
243
- .el-dialog__footer {
244
- border: none;
245
- background-color: #efefef;
246
- border-bottom-left-radius: 8px;
247
- border-bottom-right-radius: 8px;
248
- }
249
-
250
- .custom-table {
251
- // 取消表格下边线
252
- tbody tr:last-child td {
253
- border-bottom: none !important;
254
- }
255
- }
256
- }
257
-
258
- .gyyg-modal-table {
259
- height: 90vh;
260
- margin-top: 5vh !important;
261
- }
262
-
263
- .gyyg-modal-fullscreen {
264
- height: 100vh;
265
- width: 100vw;
266
-
267
- .el-dialog__body {
268
- padding: 10px;
269
- }
270
- .el-dialog__footer {
271
- padding: 10px;
272
- border: none;
273
- background-color: #efefef;
274
- border-bottom-left-radius: 8px;
275
- border-bottom-right-radius: 8px;
276
- }
277
- }
278
- }
279
-
280
- .gyyg-modal {
281
- text-align: left;
282
- }
283
- ::v-deep .gyyg-modal .el-dialog__wrapper {
284
- overflow: hidden;
285
- display: flex !important;
286
- justify-content: center;
287
- align-items: center;
288
- .el-dialog {
289
- display: flex;
290
- flex-direction: column;
291
- border-radius: 8px;
292
- margin: 0;
293
- margin-top: 0 !important;
294
- .el-dialog__header {
295
- text-align: left;
296
- background-color: #efefef;
297
- height: 48px;
298
- line-height: 48px;
299
- padding: 0 20px;
300
- color: #fff;
301
- border-top-left-radius: 8px;
302
- border-top-right-radius: 8px;
303
- font-weight: bold;
304
-
305
- .el-dialog__title {
306
- font-size: 16px;
307
- // font-weight: bold;
308
- }
309
-
310
- .el-dialog__headerbtn {
311
- top: 12px;
312
- }
313
- }
314
-
315
- .el-dialog__body {
316
- flex: 1;
317
- overflow: auto;
318
- }
319
-
320
- .el-dialog__footer {
321
- flex-shrink: 0;
322
- box-sizing: content-box;
323
- height: 32px;
324
- padding: 10px;
325
- border: none;
326
- background-color: #efefef;
327
- border-bottom-left-radius: 8px;
328
- border-bottom-right-radius: 8px;
329
- }
330
- }
331
- }
332
- </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>