flame-plus 0.1.25 → 0.1.27
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.
package/package.json
CHANGED
|
@@ -1,303 +1,237 @@
|
|
|
1
|
-
<script lang="tsx">
|
|
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
|
-
const updateFormModel = (model: FormModel) => {
|
|
130
|
-
Object.entries(model).forEach(([key, value]: Array < any > ) => formModel[key] = value)
|
|
131
|
-
}
|
|
132
|
-
|
|
133
|
-
/**
|
|
134
|
-
* 表单修改
|
|
135
|
-
* @date 2022-04-14
|
|
136
|
-
* @param {any} value 修改值
|
|
137
|
-
* @param {string} prop 修改键名
|
|
138
|
-
*/
|
|
139
|
-
const formChange = (value: any, prop: string) => formModel[prop] = value
|
|
140
|
-
|
|
141
|
-
/**
|
|
142
|
-
* 表单方法调用
|
|
143
|
-
* @date 2022-04-14
|
|
144
|
-
* @param {'submit' | 'cancel' | 'reset' | string} event 方法名(默认方法直接调用;自定义方法回传方法名及表单数据)
|
|
145
|
-
*/
|
|
146
|
-
const formEvent = (event: FormButtonConfig['event']) => {
|
|
147
|
-
const defaultEvent: Record < FormButtonConfig['event'], Function > = {
|
|
148
|
-
submit,
|
|
149
|
-
cancel,
|
|
150
|
-
reset
|
|
151
|
-
}
|
|
152
|
-
isValidKey(event, defaultEvent) ?
|
|
153
|
-
defaultEvent[event]() :
|
|
154
|
-
emit('customEvent', {
|
|
155
|
-
event,
|
|
156
|
-
formModel
|
|
157
|
-
})
|
|
158
|
-
}
|
|
159
|
-
|
|
160
|
-
// 提交
|
|
161
|
-
const submit = () => {
|
|
162
|
-
const formRef: any = instance?.refs['formRef']
|
|
163
|
-
if (!formRef) return
|
|
164
|
-
formRef.validate((valid: boolean) => {
|
|
165
|
-
valid && emit('submit', formModel)
|
|
166
|
-
})
|
|
167
|
-
}
|
|
168
|
-
|
|
169
|
-
// 取消
|
|
170
|
-
const cancel = () => {
|
|
171
|
-
emit('cancel', formModel)
|
|
172
|
-
}
|
|
173
|
-
|
|
174
|
-
// 重置
|
|
175
|
-
const reset = () => {
|
|
176
|
-
const formRef: any = instance?.refs['formRef']
|
|
177
|
-
if (!formRef) return
|
|
178
|
-
formRef.resetFields()
|
|
179
|
-
emit('reset', formModel)
|
|
180
|
-
}
|
|
181
|
-
|
|
182
|
-
/**
|
|
183
|
-
* 表单元素
|
|
184
|
-
* @date 2022-04-14
|
|
185
|
-
* @param {Array} items 表单项配置
|
|
186
|
-
* @returns {any} 表单项dom
|
|
187
|
-
*/
|
|
188
|
-
const formItemsDom = (items: FormConfig['items'] = []) => {
|
|
189
|
-
const controlDom = (prop: string, controlType: ControlTypes, controlConfig: ControlConfig) => {
|
|
190
|
-
const config: FormModel = {
|
|
191
|
-
...controlConfig
|
|
192
|
-
}
|
|
193
|
-
const event = controlType === ControlTypes['flmInput'] ? 'onInput' : 'onChange'
|
|
194
|
-
config[event] = (value: any) => formChange(value, prop)
|
|
195
|
-
return h(resolveComponent(controlType), {
|
|
196
|
-
config
|
|
197
|
-
})
|
|
198
|
-
}
|
|
199
|
-
return items.map((item: FormItemConfig) => {
|
|
200
|
-
if (typeof(item.prop) === 'string') {
|
|
201
|
-
if (isValidKey('isSlot', item)) {
|
|
202
|
-
const {
|
|
203
|
-
isSlot,
|
|
204
|
-
...itemConfig
|
|
205
|
-
} = item
|
|
206
|
-
return ( <
|
|
207
|
-
el - form - item class = {
|
|
208
|
-
`form-${item.prop}`
|
|
209
|
-
} {
|
|
210
|
-
...itemConfig
|
|
211
|
-
} > {
|
|
212
|
-
(slots[item.prop]?.({
|
|
213
|
-
prop: item.prop,
|
|
214
|
-
formModel
|
|
215
|
-
}))
|
|
216
|
-
} <
|
|
217
|
-
/el-form-item>
|
|
218
|
-
)
|
|
219
|
-
} else {
|
|
220
|
-
const {
|
|
221
|
-
controlType,
|
|
222
|
-
controlConfig,
|
|
223
|
-
...itemConfig
|
|
224
|
-
} = item
|
|
225
|
-
if (controlType && controlConfig) {
|
|
226
|
-
return ( <
|
|
227
|
-
el - form - item class = {
|
|
228
|
-
`form-${item.prop}`
|
|
229
|
-
} {
|
|
230
|
-
...itemConfig
|
|
231
|
-
} > {
|
|
232
|
-
controlDom(item.prop, controlType, controlConfig)
|
|
233
|
-
} <
|
|
234
|
-
/el-form-item>
|
|
235
|
-
)
|
|
236
|
-
}
|
|
237
|
-
}
|
|
238
|
-
}
|
|
239
|
-
})
|
|
240
|
-
}
|
|
241
|
-
|
|
242
|
-
/**
|
|
243
|
-
* 表单按钮
|
|
244
|
-
* @date 2022-04-14
|
|
245
|
-
* @param {Array} buttons 表单按钮配置
|
|
246
|
-
* @returns {any} 表单按钮dom
|
|
247
|
-
*/
|
|
248
|
-
const buttonsDom = (buttons: FormConfig['buttons'] = []) => {
|
|
249
|
-
if (buttons.length) {
|
|
250
|
-
return ( <
|
|
251
|
-
el - form - item class = "form-buttons" > {
|
|
252
|
-
buttons.map(({
|
|
253
|
-
event,
|
|
254
|
-
...config
|
|
255
|
-
}: FormButtonConfig) =>
|
|
256
|
-
<
|
|
257
|
-
flm - button config = {
|
|
258
|
-
config
|
|
259
|
-
}
|
|
260
|
-
onButtonClick = {
|
|
261
|
-
() => formEvent(event)
|
|
262
|
-
}
|
|
263
|
-
/>
|
|
264
|
-
)
|
|
265
|
-
} <
|
|
266
|
-
/el-form-item>
|
|
267
|
-
)
|
|
268
|
-
}
|
|
269
|
-
}
|
|
270
|
-
|
|
271
|
-
expose({
|
|
272
|
-
formModel,
|
|
273
|
-
reset
|
|
274
|
-
})
|
|
275
|
-
|
|
276
|
-
// 表单设置
|
|
277
|
-
const formConfig = computed((): FormConfig => filterConfig(formDefaultConfig, props.config))
|
|
278
|
-
const formDom = () => {
|
|
279
|
-
const {
|
|
280
|
-
items = [], buttons = [], model, ...defaultConfig
|
|
281
|
-
} = formConfig.value
|
|
282
|
-
return ( <
|
|
283
|
-
el - form ref = 'formRef' {
|
|
284
|
-
...defaultConfig
|
|
285
|
-
}
|
|
286
|
-
model = {
|
|
287
|
-
formModel
|
|
288
|
-
} > {
|
|
289
|
-
formItemsDom(items)
|
|
290
|
-
} {
|
|
291
|
-
buttonsDom(buttons)
|
|
292
|
-
} <
|
|
293
|
-
/el-form>
|
|
294
|
-
)
|
|
295
|
-
}
|
|
296
|
-
return () => (formDom())
|
|
297
|
-
},
|
|
298
|
-
})
|
|
299
|
-
</script>
|
|
1
|
+
<script lang="tsx">
|
|
2
|
+
import {
|
|
3
|
+
defineComponent,
|
|
4
|
+
getCurrentInstance,
|
|
5
|
+
PropType,
|
|
6
|
+
reactive,
|
|
7
|
+
computed,
|
|
8
|
+
watch,
|
|
9
|
+
h,
|
|
10
|
+
resolveComponent,
|
|
11
|
+
onMounted
|
|
12
|
+
} from 'vue'
|
|
13
|
+
import {
|
|
14
|
+
flmButton,
|
|
15
|
+
flmCascader,
|
|
16
|
+
flmCheckbox,
|
|
17
|
+
flmColorPicker,
|
|
18
|
+
flmDatePicker,
|
|
19
|
+
flmInput,
|
|
20
|
+
flmInputNumber,
|
|
21
|
+
flmRadio,
|
|
22
|
+
flmRate,
|
|
23
|
+
flmRead,
|
|
24
|
+
flmSelect,
|
|
25
|
+
flmSlider,
|
|
26
|
+
flmSwitch,
|
|
27
|
+
flmTimePicker,
|
|
28
|
+
flmTimeSelect,
|
|
29
|
+
flmTransfer,
|
|
30
|
+
} from '../../index'
|
|
31
|
+
import {
|
|
32
|
+
ControlTypes,
|
|
33
|
+
ControlConfig,
|
|
34
|
+
isInputControl,
|
|
35
|
+
FormModel,
|
|
36
|
+
FormConfig,
|
|
37
|
+
FormItemConfig,
|
|
38
|
+
FormButtonConfig,
|
|
39
|
+
formDefaultConfig
|
|
40
|
+
} from '../../../model/flmComponentConfig'
|
|
41
|
+
import { filterConfig, isValidKey } from '../../../utils'
|
|
42
|
+
|
|
43
|
+
export default defineComponent({
|
|
44
|
+
components: {
|
|
45
|
+
flmButton,
|
|
46
|
+
flmCascader,
|
|
47
|
+
flmCheckbox,
|
|
48
|
+
flmColorPicker,
|
|
49
|
+
flmDatePicker,
|
|
50
|
+
flmInput,
|
|
51
|
+
flmInputNumber,
|
|
52
|
+
flmRadio,
|
|
53
|
+
flmRate,
|
|
54
|
+
flmRead,
|
|
55
|
+
flmSelect,
|
|
56
|
+
flmSlider,
|
|
57
|
+
flmSwitch,
|
|
58
|
+
flmTimePicker,
|
|
59
|
+
flmTimeSelect,
|
|
60
|
+
flmTransfer,
|
|
61
|
+
},
|
|
62
|
+
emits: ['submit', 'cancel', 'reset', 'customEvent'],
|
|
63
|
+
props: {
|
|
64
|
+
// 默认设置
|
|
65
|
+
config: {
|
|
66
|
+
type: Object as PropType<FormConfig>,
|
|
67
|
+
default: {}
|
|
68
|
+
},
|
|
69
|
+
},
|
|
70
|
+
computed: {
|
|
71
|
+
columnNumber(): number | boolean {
|
|
72
|
+
const { inline = false, columnNumber = 0 } = this.config
|
|
73
|
+
return inline && columnNumber > 1
|
|
74
|
+
? columnNumber
|
|
75
|
+
: false
|
|
76
|
+
}
|
|
77
|
+
},
|
|
78
|
+
setup(props, { slots, emit, expose }) {
|
|
79
|
+
const instance = getCurrentInstance() // 实例,必须在最外层声明
|
|
80
|
+
let formModel: FormModel = reactive({}) // 表单数据
|
|
81
|
+
|
|
82
|
+
// 监听表单配置的 model,变化后更新组件内部 formModel
|
|
83
|
+
watch(() => props.config.model, (newModel: FormModel) => updateFormModel(newModel))
|
|
84
|
+
|
|
85
|
+
// 监听组件内部 formModel,变化后更新控件 value
|
|
86
|
+
watch(formModel, (newModel: FormModel) => updateControl(newModel))
|
|
87
|
+
|
|
88
|
+
onMounted(() => {
|
|
89
|
+
if (props.config?.model && Object.keys(props.config?.model).length) {
|
|
90
|
+
updateControl(props.config.model)
|
|
91
|
+
updateFormModel(props.config.model)
|
|
92
|
+
}
|
|
93
|
+
})
|
|
94
|
+
|
|
95
|
+
/**
|
|
96
|
+
* 更新控件值
|
|
97
|
+
* @date 2022-05-09
|
|
98
|
+
* @param {FormModel} model
|
|
99
|
+
*/
|
|
100
|
+
const updateControl = (model: FormModel) => {
|
|
101
|
+
props.config.items?.forEach((formItem: FormItemConfig) => {
|
|
102
|
+
if (!isValidKey('isSlot', formItem) && typeof(formItem.prop) === 'string') {
|
|
103
|
+
const { controlConfig } = formItem
|
|
104
|
+
controlConfig && (
|
|
105
|
+
isInputControl(controlConfig)
|
|
106
|
+
? controlConfig['modelValue'] = model[formItem.prop]
|
|
107
|
+
: controlConfig['model-value'] = model[formItem.prop]
|
|
108
|
+
)
|
|
109
|
+
}
|
|
110
|
+
})
|
|
111
|
+
}
|
|
112
|
+
|
|
113
|
+
/**
|
|
114
|
+
* 更新表单值
|
|
115
|
+
* @date 2022-05-09
|
|
116
|
+
* @param {FormModel} model
|
|
117
|
+
*/
|
|
118
|
+
const updateFormModel = (model: FormModel) => {
|
|
119
|
+
Object.entries(model).forEach(([key, value]: Array<any>) => formModel[key] = value)
|
|
120
|
+
}
|
|
121
|
+
|
|
122
|
+
/**
|
|
123
|
+
* 表单修改
|
|
124
|
+
* @date 2022-04-14
|
|
125
|
+
* @param {any} value 修改值
|
|
126
|
+
* @param {string} prop 修改键名
|
|
127
|
+
*/
|
|
128
|
+
const formChange = (value: any, prop: string) => formModel[prop] = value
|
|
300
129
|
|
|
130
|
+
/**
|
|
131
|
+
* 表单方法调用
|
|
132
|
+
* @date 2022-04-14
|
|
133
|
+
* @param {'submit' | 'cancel' | 'reset' | string} event 方法名(默认方法直接调用;自定义方法回传方法名及表单数据)
|
|
134
|
+
*/
|
|
135
|
+
const formEvent = (event: FormButtonConfig['event']) => {
|
|
136
|
+
const defaultEvent: Record<FormButtonConfig['event'], Function> = { submit, cancel, reset }
|
|
137
|
+
isValidKey(event, defaultEvent)
|
|
138
|
+
? defaultEvent[event]()
|
|
139
|
+
: emit('customEvent', { event, formModel })
|
|
140
|
+
}
|
|
141
|
+
|
|
142
|
+
// 提交
|
|
143
|
+
const submit = () => {
|
|
144
|
+
const formRef: any = instance?.refs['formRef']
|
|
145
|
+
if (!formRef) return
|
|
146
|
+
formRef.validate((valid: boolean) => {
|
|
147
|
+
valid && emit('submit', formModel)
|
|
148
|
+
})
|
|
149
|
+
}
|
|
150
|
+
|
|
151
|
+
// 取消
|
|
152
|
+
const cancel = () => {
|
|
153
|
+
emit('cancel', formModel)
|
|
154
|
+
}
|
|
155
|
+
|
|
156
|
+
// 重置
|
|
157
|
+
const reset = () => {
|
|
158
|
+
const formRef: any = instance?.refs['formRef']
|
|
159
|
+
if (!formRef) return
|
|
160
|
+
formRef.resetFields()
|
|
161
|
+
emit('reset', formModel)
|
|
162
|
+
}
|
|
163
|
+
|
|
164
|
+
/**
|
|
165
|
+
* 表单元素
|
|
166
|
+
* @date 2022-04-14
|
|
167
|
+
* @param {Array} items 表单项配置
|
|
168
|
+
* @returns {any} 表单项dom
|
|
169
|
+
*/
|
|
170
|
+
const formItemsDom = (items: FormConfig['items'] = []) => {
|
|
171
|
+
const controlDom = (prop: string, controlType: ControlTypes, controlConfig: ControlConfig) => {
|
|
172
|
+
const config: FormModel = { ...controlConfig }
|
|
173
|
+
const event = controlType === ControlTypes['flmInput'] ? 'onInput' : 'onChange'
|
|
174
|
+
config[event] = (value: any) => formChange(value, prop)
|
|
175
|
+
return h(resolveComponent(controlType), { config })
|
|
176
|
+
}
|
|
177
|
+
return items.map((item: FormItemConfig) => {
|
|
178
|
+
if (typeof(item.prop) === 'string') {
|
|
179
|
+
if (isValidKey('isSlot', item)) {
|
|
180
|
+
const { isSlot, ...itemConfig } = item
|
|
181
|
+
return (
|
|
182
|
+
<el-form-item class={`form-${item.prop}`} {...itemConfig}>
|
|
183
|
+
{(slots[item.prop]?.({ prop: item.prop, formModel }))}
|
|
184
|
+
</el-form-item>
|
|
185
|
+
)
|
|
186
|
+
} else {
|
|
187
|
+
const { controlType, controlConfig, ...itemConfig } = item
|
|
188
|
+
if (controlType && controlConfig) {
|
|
189
|
+
return (
|
|
190
|
+
<el-form-item class={`form-${item.prop}`} {...itemConfig}>
|
|
191
|
+
{controlDom(item.prop, controlType, controlConfig)}
|
|
192
|
+
</el-form-item>
|
|
193
|
+
)
|
|
194
|
+
}
|
|
195
|
+
}
|
|
196
|
+
}
|
|
197
|
+
})
|
|
198
|
+
}
|
|
199
|
+
|
|
200
|
+
/**
|
|
201
|
+
* 表单按钮
|
|
202
|
+
* @date 2022-04-14
|
|
203
|
+
* @param {Array} buttons 表单按钮配置
|
|
204
|
+
* @returns {any} 表单按钮dom
|
|
205
|
+
*/
|
|
206
|
+
const buttonsDom = (buttons: FormConfig['buttons'] = []) => {
|
|
207
|
+
if (buttons.length) {
|
|
208
|
+
return (
|
|
209
|
+
<el-form-item class="form-buttons">
|
|
210
|
+
{buttons.map(({ event, ...config }: FormButtonConfig) =>
|
|
211
|
+
<flm-button config={config} onButtonClick={() => formEvent(event)} />
|
|
212
|
+
)}
|
|
213
|
+
</el-form-item>
|
|
214
|
+
)
|
|
215
|
+
}
|
|
216
|
+
}
|
|
217
|
+
|
|
218
|
+
expose({ formModel, reset })
|
|
219
|
+
|
|
220
|
+
// 表单设置
|
|
221
|
+
const formConfig = computed((): FormConfig => filterConfig(formDefaultConfig, props.config))
|
|
222
|
+
const formDom = () => {
|
|
223
|
+
const { items = [], buttons = [], model, ...defaultConfig } = formConfig.value
|
|
224
|
+
return (
|
|
225
|
+
<el-form ref='formRef' {...defaultConfig} model={formModel}>
|
|
226
|
+
{formItemsDom(items)}
|
|
227
|
+
{buttonsDom(buttons)}
|
|
228
|
+
</el-form>
|
|
229
|
+
)
|
|
230
|
+
}
|
|
231
|
+
return () => (formDom())
|
|
232
|
+
},
|
|
233
|
+
})
|
|
234
|
+
</script>
|
|
301
235
|
<style lang="scss" scoped>
|
|
302
236
|
$columnNumber: v-bind(columnNumber);
|
|
303
237
|
:deep(.el-form-item) {
|
|
@@ -305,4 +239,4 @@ $columnNumber: v-bind(columnNumber);
|
|
|
305
239
|
width: calc((100% - 32px * $columnNumber) / $columnNumber);
|
|
306
240
|
}
|
|
307
241
|
}
|
|
308
|
-
</style>
|
|
242
|
+
</style>
|
|
@@ -1,11 +1,3 @@
|
|
|
1
|
-
/*
|
|
2
|
-
* @Author: 关羽 xiaobing525@163.com
|
|
3
|
-
* @Date: 2023-01-04 22:32:16
|
|
4
|
-
* @LastEditors: 关羽 xiaobing525@163.com
|
|
5
|
-
* @LastEditTime: 2023-01-05 19:54:43
|
|
6
|
-
* @FilePath: /flame-components/packages/model/flmComponentConfig/complex/flmSearch.ts
|
|
7
|
-
* @Description: 这是默认设置,请设置`customMade`, 打开koroFileHeader查看配置 进行设置: https://github.com/OBKoro1/koro1FileHeader/wiki/%E9%85%8D%E7%BD%AE
|
|
8
|
-
*/
|
|
9
1
|
import { FormConfig } from '../../../model/flmComponentConfig'
|
|
10
2
|
|
|
11
3
|
export interface SearchConfig extends FormConfig {
|