Skip to content

Commit f4510b6

Browse files
committed
feat(FormDialog): add fullscreen func
1 parent 309ebbe commit f4510b6

File tree

3 files changed

+218
-100
lines changed

3 files changed

+218
-100
lines changed

src/components/FormDialog/FormDialog.js

Lines changed: 105 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
import { cloneDeep, merge, isFunction, isBoolean } from 'lodash'
22
import { renderVNode } from './vnode'
3+
import styles from './formdialog.module.scss'
34

45
export default {
56
provide() {
@@ -30,6 +31,8 @@ export default {
3031
dialogProps: {
3132
'close-on-click-modal': false,
3233
'append-to-body': true,
34+
// 默认不全屏
35+
fullscreen: false,
3336
center: true
3437
},
3538
op: {
@@ -107,6 +110,9 @@ export default {
107110
this.$refs.form.clearValidate()
108111
}
109112
},
113+
toggleFullScreen() {
114+
this.conf.dialogProps.fullscreen = !this.conf.dialogProps.fullscreen
115+
},
110116
_create(options) {
111117
// 合并配置
112118
for (const name in this.conf) {
@@ -133,7 +139,11 @@ export default {
133139
// 表单默认值
134140
this.conf.items.forEach(e => {
135141
if (e.prop) {
136-
this.$set(this.form, e.prop, this.form[e.prop] ? this.form[e.prop] : cloneDeep(e.value))
142+
this.$set(
143+
this.form,
144+
e.prop,
145+
this.form[e.prop] ? this.form[e.prop] : cloneDeep(e.value)
146+
)
137147
}
138148
})
139149

@@ -222,34 +232,49 @@ export default {
222232
return (
223233
<el-form
224234
ref='form'
225-
{
226-
...{
227-
props: {
228-
...formProps,
229-
disabled: this.saving,
230-
model: this.form
231-
}
235+
{...{
236+
props: {
237+
...formProps,
238+
disabled: this.saving,
239+
model: this.form
232240
}
233-
}
241+
}}
234242
>
235-
<el-row gutter={10} { ...{ directives: [{ name: 'loading', value: this.loading }] } }>
243+
<el-row
244+
gutter={10}
245+
{...{ directives: [{ name: 'loading', value: this.loading }] }}
246+
>
236247
{/* 渲染表单列表 */}
237248
{items.map(e => {
238249
return (
239250
<el-col
240251
key={`form-item-${e.prop}`}
241-
{
242-
...{
243-
props: {
244-
span: e.span || 24
245-
}
252+
{...{
253+
props: {
254+
span: e.span || 24
246255
}
247-
}
256+
}}
248257
>
249-
{e.component && !this._parseHidden({ value: e.hidden, scope: this.form }) && (
250-
<el-form-item { ...{ props: { label: e.label, prop: e.prop, rules: e.rules }} }>
258+
{e.component &&
259+
!this._parseHidden({
260+
value: e.hidden,
261+
scope: this.form
262+
}) && (
263+
<el-form-item
264+
{...{
265+
props: {
266+
label: e.label,
267+
prop: e.prop,
268+
rules: e.rules
269+
}
270+
}}
271+
>
251272
{/* 将函数this绑定当前组件树实例。如果当前实例没有父实例,此实例将会是其自己。 */}
252-
{renderVNode.call(this, e.component, { scope: this.form, $scopedSlots: this.$scopedSlots, prop: e.prop })}
273+
{renderVNode.call(this, e.component, {
274+
scope: this.form,
275+
$scopedSlots: this.$scopedSlots,
276+
prop: e.prop
277+
})}
253278
</el-form-item>
254279
)}
255280
</el-col>
@@ -259,17 +284,57 @@ export default {
259284
</el-form>
260285
)
261286
},
287+
/**
288+
* 渲染标题区域
289+
*/
290+
renderHeader() {
291+
return (
292+
<div class={styles['s-formdialog__header']}>
293+
<span>{this.conf.title}</span>
294+
<i
295+
class={[
296+
this.conf.dialogProps.fullscreen ? 'el-icon-minus' : 'el-icon-full-screen',
297+
styles['s-formdialog__header-icon'],
298+
styles['s-formdialog__header-icon--fullscreen']
299+
]}
300+
{...{ on: { click: this.toggleFullScreen }}}
301+
></i>
302+
<i
303+
class={['el-icon-close', styles['s-formdialog__header-icon']]}
304+
{...{ on: { click: this._beforeClose }}}
305+
></i>
306+
</div>
307+
)
308+
},
262309
/**
263310
* 渲染底部按钮
264311
*/
265312
renderFooter() {
266313
return (
267314
<el-row type='flex' justify='end'>
268-
<el-button { ...{ props: { size: 'mini' }, on: { click: () => { this._beforeClose() } }} }>
269-
{ this.conf.op.cancelButtonText }
315+
<el-button
316+
{...{
317+
props: { size: 'mini' },
318+
on: {
319+
click: () => {
320+
this._beforeClose()
321+
}
322+
}
323+
}}
324+
>
325+
{this.conf.op.cancelButtonText}
270326
</el-button>
271-
<el-button { ...{ props: { size: 'mini', type: 'success', loading: this.saving }, on: { click: () => { this._submit() } }} }>
272-
{ this.conf.op.saveButtonText }
327+
<el-button
328+
{...{
329+
props: { size: 'mini', type: 'success', loading: this.saving },
330+
on: {
331+
click: () => {
332+
this._submit()
333+
}
334+
}
335+
}}
336+
>
337+
{this.conf.op.saveButtonText}
273338
</el-button>
274339
</el-row>
275340
)
@@ -279,31 +344,31 @@ export default {
279344
* render
280345
*/
281346
render() {
282-
const { title, width, dialogProps } = this.conf
347+
const { width, dialogProps } = this.conf
283348
return (
284349
<el-dialog
285-
title={title}
286350
width={width}
287351
visible={this.visible}
288-
{
289-
...{
290-
props: {
291-
...dialogProps,
292-
'before-close': this._beforeClose
352+
{...{
353+
props: {
354+
...dialogProps,
355+
'show-close': false,
356+
'before-close': this._beforeClose,
357+
'custom-class': styles['s-formdialog']
358+
},
359+
on: {
360+
'update:visible': v => {
361+
this.visible = v
293362
},
294-
on: {
295-
'update:visible': (v) => { this.visible = v },
296-
closed: this._onClosed
297-
},
298-
directives: [{ name: 'el-drag-dialog' }]
299-
}
300-
}
363+
closed: this._onClosed
364+
},
365+
directives: [{ name: 'el-drag-dialog', arg: dialogProps.fullscreen ? 'fullscreen' : null }]
366+
}}
301367
>
368+
<template slot='title'>{this.renderHeader()}</template>
302369
{this.renderForm()}
303370
{/* footer */}
304-
<div slot='footer'>
305-
{this.renderFooter()}
306-
</div>
371+
<template slot='footer'>{this.renderFooter()}</template>
307372
</el-dialog>
308373
)
309374
}
Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
.s-formdialog {
2+
display: flex;
3+
flex-direction: column;
4+
5+
&__header {
6+
position: relative;
7+
display: flex;
8+
justify-content: center;
9+
align-items: center;
10+
11+
&-icon {
12+
display: inline-block;
13+
cursor: pointer;
14+
position: absolute;
15+
top: 0;
16+
right: 0;
17+
color: #909399;
18+
19+
&--fullscreen {
20+
right: 16px;
21+
margin-right: 10px;
22+
}
23+
}
24+
}
25+
26+
& :global(.el-dialog__body) {
27+
flex: 1;
28+
}
29+
}

0 commit comments

Comments
 (0)