@tmagic/form 1.5.12 → 1.5.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.
- package/dist/tmagic-form.js +37 -29
- package/dist/tmagic-form.umd.cjs +79 -301
- package/package.json +3 -3
- package/src/Form.vue +2 -2
- package/src/FormDrawer.vue +1 -1
- package/src/containers/Container.vue +7 -1
- package/src/containers/Table.vue +12 -14
- package/src/containers/Tabs.vue +10 -10
- package/src/fields/Display.vue +0 -1
- package/src/fields/Select.vue +2 -2
- package/src/fields/Timerange.vue +0 -1
- package/src/index.ts +0 -1
- package/src/schema.ts +1 -0
- package/src/utils/form.ts +0 -1
- package/types/index.d.ts +1386 -3050
package/package.json
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
{
|
|
2
|
-
"version": "1.5.
|
|
2
|
+
"version": "1.5.14",
|
|
3
3
|
"name": "@tmagic/form",
|
|
4
4
|
"type": "module",
|
|
5
5
|
"sideEffects": [
|
|
@@ -51,8 +51,8 @@
|
|
|
51
51
|
"peerDependencies": {
|
|
52
52
|
"vue": ">=3.5.0",
|
|
53
53
|
"typescript": "*",
|
|
54
|
-
"@tmagic/design": "1.5.
|
|
55
|
-
"@tmagic/utils": "1.5.
|
|
54
|
+
"@tmagic/design": "1.5.14",
|
|
55
|
+
"@tmagic/utils": "1.5.14"
|
|
56
56
|
},
|
|
57
57
|
"peerDependenciesMeta": {
|
|
58
58
|
"typescript": {
|
package/src/Form.vue
CHANGED
|
@@ -63,7 +63,7 @@ const props = withDefaults(
|
|
|
63
63
|
keyProp?: string;
|
|
64
64
|
popperClass?: string;
|
|
65
65
|
preventSubmitDefault?: boolean;
|
|
66
|
-
extendState?: (
|
|
66
|
+
extendState?: (_state: FormState) => Record<string, any> | Promise<Record<string, any>>;
|
|
67
67
|
}>(),
|
|
68
68
|
{
|
|
69
69
|
config: () => [],
|
|
@@ -101,7 +101,7 @@ const formState: FormState = reactive<FormState>({
|
|
|
101
101
|
parentValues: props.parentValues,
|
|
102
102
|
values,
|
|
103
103
|
lastValuesProcessed,
|
|
104
|
-
$emit: emit as (
|
|
104
|
+
$emit: emit as (_event: string, ..._args: any[]) => void,
|
|
105
105
|
fields,
|
|
106
106
|
setField: (prop: string, field: any) => fields.set(prop, field),
|
|
107
107
|
getField: (prop: string) => fields.get(prop),
|
package/src/FormDrawer.vue
CHANGED
|
@@ -82,7 +82,7 @@ withDefaults(
|
|
|
82
82
|
labelPosition?: string;
|
|
83
83
|
preventSubmitDefault?: boolean;
|
|
84
84
|
/** 关闭前的回调,会暂停 Drawer 的关闭; done 是个 function type 接受一个 boolean 参数, 执行 done 使用 true 参数或不提供参数将会终止关闭 */
|
|
85
|
-
beforeClose?: (
|
|
85
|
+
beforeClose?: (_done: (_cancel?: boolean) => void) => void;
|
|
86
86
|
}>(),
|
|
87
87
|
{
|
|
88
88
|
closeOnPressEscape: true,
|
|
@@ -228,6 +228,7 @@ import { WarningFilled } from '@element-plus/icons-vue';
|
|
|
228
228
|
import { isEqual } from 'lodash-es';
|
|
229
229
|
|
|
230
230
|
import { TMagicButton, TMagicFormItem, TMagicIcon, TMagicTooltip } from '@tmagic/design';
|
|
231
|
+
import { setValueByKeyPath } from '@tmagic/utils';
|
|
231
232
|
|
|
232
233
|
import type { ChildConfig, ContainerChangeEventData, ContainerCommonConfig, FormState, FormValue } from '../schema';
|
|
233
234
|
import { display as displayFunction, filterFunction, getRules } from '../utils/form';
|
|
@@ -423,6 +424,12 @@ const onChangeHandler = async function (v: any, eventData: ContainerChangeEventD
|
|
|
423
424
|
prop: itemProp.value,
|
|
424
425
|
config: props.config,
|
|
425
426
|
changeRecords: newChangeRecords,
|
|
427
|
+
setModel: (key: string, value: any) => {
|
|
428
|
+
setValueByKeyPath(key, value, props.model);
|
|
429
|
+
if (props.config.name) {
|
|
430
|
+
newChangeRecords.push({ propPath: itemProp.value.replace(`${props.config.name}`, key), value });
|
|
431
|
+
}
|
|
432
|
+
},
|
|
426
433
|
})) ?? value;
|
|
427
434
|
}
|
|
428
435
|
value = trimHandler(trim, value) ?? value;
|
|
@@ -445,7 +452,6 @@ const onChangeHandler = async function (v: any, eventData: ContainerChangeEventD
|
|
|
445
452
|
delete eventData.modifyKey;
|
|
446
453
|
} else if (isValidName() && props.model !== value && (v !== value || props.model[name.value] !== value)) {
|
|
447
454
|
// field内容下包含field-link时,model===value, 这里避免循环引用
|
|
448
|
-
// eslint-disable-next-line vue/no-mutating-props
|
|
449
455
|
props.model[name.value] = value;
|
|
450
456
|
}
|
|
451
457
|
|
package/src/containers/Table.vue
CHANGED
|
@@ -273,22 +273,18 @@ const isFullscreen = ref(false);
|
|
|
273
273
|
|
|
274
274
|
const modelName = computed(() => props.name || props.config.name || '');
|
|
275
275
|
|
|
276
|
-
const data =
|
|
277
|
-
|
|
278
|
-
|
|
279
|
-
|
|
280
|
-
|
|
281
|
-
|
|
282
|
-
|
|
283
|
-
|
|
276
|
+
const getDataByPage = (data: any[] = []) =>
|
|
277
|
+
data.filter(
|
|
278
|
+
(item: any, index: number) =>
|
|
279
|
+
index >= pagecontext.value * pagesize.value && index + 1 <= (pagecontext.value + 1) * pagesize.value,
|
|
280
|
+
);
|
|
281
|
+
|
|
282
|
+
const pageinationData = computed(() => getDataByPage(props.model[modelName.value]));
|
|
283
|
+
|
|
284
|
+
const data = computed(() => (props.config.pagination ? pageinationData.value : props.model[modelName.value]));
|
|
284
285
|
|
|
285
286
|
const lastData = computed(() =>
|
|
286
|
-
props.config.pagination
|
|
287
|
-
? (props.lastValues[modelName.value] || []).filter(
|
|
288
|
-
(item: any, index: number) =>
|
|
289
|
-
index >= pagecontext.value * pagesize.value && index + 1 <= (pagecontext.value + 1) * pagesize.value,
|
|
290
|
-
)
|
|
291
|
-
: props.lastValues[modelName.value] || [],
|
|
287
|
+
props.config.pagination ? getDataByPage(props.lastValues[modelName.value]) : props.lastValues[modelName.value] || [],
|
|
292
288
|
);
|
|
293
289
|
|
|
294
290
|
const sortChange = ({ prop, order }: SortProp) => {
|
|
@@ -320,6 +316,8 @@ const rowDrop = () => {
|
|
|
320
316
|
}
|
|
321
317
|
sortable = Sortable.create(tBodyEl, {
|
|
322
318
|
draggable: '.tmagic-design-table-row',
|
|
319
|
+
filter: 'input', // 表单组件选字操作和触发拖拽会冲突,优先保证选字操作
|
|
320
|
+
preventOnFilter: false, // 允许选字
|
|
323
321
|
direction: 'vertical',
|
|
324
322
|
onEnd: ({ newIndex, oldIndex }: SortableEvent) => {
|
|
325
323
|
if (typeof newIndex === 'undefined') return;
|
package/src/containers/Tabs.vue
CHANGED
|
@@ -41,21 +41,21 @@
|
|
|
41
41
|
config.dynamic
|
|
42
42
|
? (name ? model[name] : model)[tabIndex]
|
|
43
43
|
: tab.name
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
44
|
+
? (name ? model[name] : model)[tab.name]
|
|
45
|
+
: name
|
|
46
|
+
? model[name]
|
|
47
|
+
: model
|
|
48
48
|
"
|
|
49
49
|
:last-values="
|
|
50
50
|
isEmpty(lastValues)
|
|
51
51
|
? {}
|
|
52
52
|
: config.dynamic
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
53
|
+
? (name ? lastValues[name] : lastValues)[tabIndex]
|
|
54
|
+
: tab.name
|
|
55
|
+
? (name ? lastValues[name] : lastValues)[tab.name]
|
|
56
|
+
: name
|
|
57
|
+
? lastValues[name]
|
|
58
|
+
: lastValues
|
|
59
59
|
"
|
|
60
60
|
:is-compare="isCompare"
|
|
61
61
|
:prop="config.dynamic ? `${prop}${prop ? '.' : ''}${String(tabIndex)}` : prop"
|
package/src/fields/Display.vue
CHANGED
package/src/fields/Select.vue
CHANGED
|
@@ -21,7 +21,7 @@
|
|
|
21
21
|
>
|
|
22
22
|
<template v-if="config.group">
|
|
23
23
|
<component
|
|
24
|
-
v-for="(group, index) in
|
|
24
|
+
v-for="(group, index) in options as SelectGroupOption[]"
|
|
25
25
|
:key="index"
|
|
26
26
|
:is="optionGroupComponent?.component || 'el-option-group'"
|
|
27
27
|
v-bind="
|
|
@@ -55,7 +55,7 @@
|
|
|
55
55
|
</template>
|
|
56
56
|
<template v-else>
|
|
57
57
|
<component
|
|
58
|
-
v-for="option in
|
|
58
|
+
v-for="option in options as SelectOption[]"
|
|
59
59
|
class="tmagic-design-option"
|
|
60
60
|
:key="config.valueKey ? option.value[config.valueKey] : option.value"
|
|
61
61
|
:is="optionComponent?.component || 'el-option'"
|
package/src/fields/Timerange.vue
CHANGED
package/src/index.ts
CHANGED
|
@@ -101,7 +101,6 @@ export default {
|
|
|
101
101
|
install(app: App, opt: FormInstallOptions = {}) {
|
|
102
102
|
const option = Object.assign(defaultInstallOpt, opt);
|
|
103
103
|
|
|
104
|
-
// eslint-disable-next-line no-param-reassign
|
|
105
104
|
app.config.globalProperties.$MAGIC_FORM = option;
|
|
106
105
|
setConfig(option);
|
|
107
106
|
|
package/src/schema.ts
CHANGED
|
@@ -196,6 +196,7 @@ export interface OnChangeHandlerData {
|
|
|
196
196
|
config: any;
|
|
197
197
|
prop: string;
|
|
198
198
|
changeRecords: ChangeRecord[];
|
|
199
|
+
setModel: (prop: string, value: any) => void;
|
|
199
200
|
}
|
|
200
201
|
|
|
201
202
|
export type OnChangeHandler = (mForm: FormState | undefined, value: any, data: OnChangeHandlerData) => any;
|