@tmagic/form 1.0.0-beta.6 → 1.0.0-rc.10
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/README.md +1 -0
- package/dist/style.css +9 -11
- package/dist/tmagic-form.es.js +240 -145
- package/dist/tmagic-form.es.js.map +1 -1
- package/dist/tmagic-form.umd.js +243 -149
- package/dist/tmagic-form.umd.js.map +1 -1
- package/dist/types/src/containers/Col.vue.d.ts +42 -0
- package/dist/types/src/containers/Container.vue.d.ts +1 -0
- package/dist/types/src/containers/Row.vue.d.ts +0 -1
- package/dist/types/src/fields/Checkbox.vue.d.ts +2 -2
- package/dist/types/src/fields/DynamicField.vue.d.ts +2 -2
- package/dist/types/src/index.d.ts +1 -1
- package/dist/types/src/schema.d.ts +10 -0
- package/package.json +17 -7
- package/src/Form.vue +7 -2
- package/src/FormDialog.vue +1 -1
- package/src/containers/Col.vue +56 -0
- package/src/containers/Container.vue +42 -12
- package/src/containers/GroupListItem.vue +4 -4
- package/src/containers/Row.vue +13 -17
- package/src/containers/Table.vue +15 -7
- package/src/containers/Tabs.vue +13 -5
- package/src/fields/Checkbox.vue +2 -2
- package/src/fields/Daterange.vue +8 -0
- package/src/fields/Link.vue +1 -1
- package/src/fields/Select.vue +11 -15
- package/src/fields/Text.vue +4 -4
- package/src/fields/Textarea.vue +11 -13
- package/src/schema.ts +10 -0
- package/src/theme/form.scss +24 -17
- package/src/utils/form.ts +7 -1
- package/dist/types/src/Form.vue.d.ts +0 -301
- package/dist/types/src/FormDialog.vue.d.ts +0 -638
- package/dist/types/src/containers/Table.vue.d.ts +0 -1403
- package/dist/types/src/fields/Cascader.vue.d.ts +0 -1748
- package/dist/types/src/fields/Link.vue.d.ts +0 -1358
- package/dist/types/src/fields/Select.vue.d.ts +0 -975
- package/tsconfig.json +0 -9
- package/vite.config.ts +0 -27
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
import type { DefineComponent, ComputedRef, ComponentOptionsMixin, VNodeProps, AllowedComponentProps, ComponentCustomProps, ExtractPropTypes, PropType } from 'vue';
|
|
2
|
+
import { ChildConfig, FormState } from '../schema';
|
|
3
|
+
declare const _default: DefineComponent<{
|
|
4
|
+
labelWidth: StringConstructor;
|
|
5
|
+
expandMore: BooleanConstructor;
|
|
6
|
+
span: NumberConstructor;
|
|
7
|
+
model: {
|
|
8
|
+
type: ObjectConstructor;
|
|
9
|
+
default: () => {};
|
|
10
|
+
};
|
|
11
|
+
config: {
|
|
12
|
+
type: PropType<ChildConfig>;
|
|
13
|
+
default: () => {};
|
|
14
|
+
};
|
|
15
|
+
prop: StringConstructor;
|
|
16
|
+
size: StringConstructor;
|
|
17
|
+
}, {
|
|
18
|
+
mForm: FormState | undefined;
|
|
19
|
+
display: ComputedRef<any>;
|
|
20
|
+
changeHandler: () => void;
|
|
21
|
+
}, unknown, {}, {}, ComponentOptionsMixin, ComponentOptionsMixin, "change"[], "change", VNodeProps & AllowedComponentProps & ComponentCustomProps, Readonly<ExtractPropTypes<{
|
|
22
|
+
labelWidth: StringConstructor;
|
|
23
|
+
expandMore: BooleanConstructor;
|
|
24
|
+
span: NumberConstructor;
|
|
25
|
+
model: {
|
|
26
|
+
type: ObjectConstructor;
|
|
27
|
+
default: () => {};
|
|
28
|
+
};
|
|
29
|
+
config: {
|
|
30
|
+
type: PropType<ChildConfig>;
|
|
31
|
+
default: () => {};
|
|
32
|
+
};
|
|
33
|
+
prop: StringConstructor;
|
|
34
|
+
size: StringConstructor;
|
|
35
|
+
}>> & {
|
|
36
|
+
onChange?: ((...args: any[]) => any) | undefined;
|
|
37
|
+
}, {
|
|
38
|
+
config: ChildConfig;
|
|
39
|
+
model: Record<string, any>;
|
|
40
|
+
expandMore: boolean;
|
|
41
|
+
}>;
|
|
42
|
+
export default _default;
|
|
@@ -30,6 +30,7 @@ declare const _default: DefineComponent<{
|
|
|
30
30
|
itemProp: ComputedRef<string>;
|
|
31
31
|
items: ComputedRef<FormConfig>;
|
|
32
32
|
display: ComputedRef<boolean>;
|
|
33
|
+
itemLabelWidth: ComputedRef<string | undefined>;
|
|
33
34
|
tagName: ComputedRef<ConcreteComponent<{}, any, any, ComputedOptions, MethodOptions> | "m-fields-text">;
|
|
34
35
|
rule: ComputedRef<Rule[]>;
|
|
35
36
|
tooltip: ComputedRef<any>;
|
|
@@ -16,7 +16,6 @@ declare const _default: DefineComponent<{
|
|
|
16
16
|
size: StringConstructor;
|
|
17
17
|
}, {
|
|
18
18
|
mForm: FormState | undefined;
|
|
19
|
-
display(config: any): any;
|
|
20
19
|
changeHandler: () => void;
|
|
21
20
|
}, unknown, {}, {}, ComponentOptionsMixin, ComponentOptionsMixin, "change"[], "change", VNodeProps & AllowedComponentProps & ComponentCustomProps, Readonly<ExtractPropTypes<{
|
|
22
21
|
labelWidth: StringConstructor;
|
|
@@ -23,8 +23,8 @@ declare const _default: DefineComponent<{
|
|
|
23
23
|
initValues: ObjectConstructor;
|
|
24
24
|
values: ObjectConstructor;
|
|
25
25
|
}, {
|
|
26
|
-
activeValue: ComputedRef<string | number | boolean>;
|
|
27
|
-
inactiveValue: ComputedRef<string | number | boolean>;
|
|
26
|
+
activeValue: ComputedRef<string | number | boolean | undefined>;
|
|
27
|
+
inactiveValue: ComputedRef<string | number | boolean | undefined>;
|
|
28
28
|
changeHandler(value: number | boolean): void;
|
|
29
29
|
}, unknown, {}, {}, ComponentOptionsMixin, ComponentOptionsMixin, ("change" | "input")[], "change" | "input", VNodeProps & AllowedComponentProps & ComponentCustomProps, Readonly<ExtractPropTypes<{
|
|
30
30
|
config: {
|
|
@@ -34,10 +34,10 @@ declare const _default: DefineComponent<{
|
|
|
34
34
|
}, {
|
|
35
35
|
request: Function;
|
|
36
36
|
fieldMap: {
|
|
37
|
-
[
|
|
37
|
+
[key: string]: any;
|
|
38
38
|
};
|
|
39
39
|
fieldLabelMap: {
|
|
40
|
-
[
|
|
40
|
+
[key: string]: any;
|
|
41
41
|
};
|
|
42
42
|
unwatch: WatchStopHandle;
|
|
43
43
|
changeFieldMap: () => Promise<void>;
|
|
@@ -31,6 +31,6 @@ export { default as MSelect } from './fields/Select.vue';
|
|
|
31
31
|
export { default as MCascader } from './fields/Cascader.vue';
|
|
32
32
|
export { default as MDynamicField } from './fields/DynamicField.vue';
|
|
33
33
|
declare const _default: {
|
|
34
|
-
install: (app: App
|
|
34
|
+
install: (app: App, opt: any) => void;
|
|
35
35
|
};
|
|
36
36
|
export default _default;
|
|
@@ -3,6 +3,7 @@
|
|
|
3
3
|
*/
|
|
4
4
|
export declare type FormState = {
|
|
5
5
|
config: FormConfig;
|
|
6
|
+
popperClass?: string;
|
|
6
7
|
initValues: FormValue;
|
|
7
8
|
values: FormValue;
|
|
8
9
|
$emit: (event: string, ...args: any[]) => void;
|
|
@@ -91,6 +92,7 @@ export interface Rule {
|
|
|
91
92
|
/** 整个表单的值 */
|
|
92
93
|
formValue: FormValue;
|
|
93
94
|
prop: string;
|
|
95
|
+
config: any;
|
|
94
96
|
}, mForm: FormState | undefined) => void;
|
|
95
97
|
}
|
|
96
98
|
export interface Input {
|
|
@@ -106,12 +108,14 @@ declare type FilterFunction = (mForm: FormState | undefined, data: {
|
|
|
106
108
|
parent?: Record<any, any>;
|
|
107
109
|
formValue: Record<any, any>;
|
|
108
110
|
prop: string;
|
|
111
|
+
config: any;
|
|
109
112
|
}) => boolean;
|
|
110
113
|
declare type OnChangeHandler = (mForm: FormState | undefined, value: any, data: {
|
|
111
114
|
model: Record<any, any>;
|
|
112
115
|
values: Record<any, any>;
|
|
113
116
|
parent?: Record<any, any>;
|
|
114
117
|
formValue: Record<any, any>;
|
|
118
|
+
config: any;
|
|
115
119
|
}) => any;
|
|
116
120
|
declare type DefaultValueFunction = (mForm: FormState | undefined) => any;
|
|
117
121
|
/**
|
|
@@ -137,18 +141,22 @@ export interface SelectGroupOption {
|
|
|
137
141
|
}
|
|
138
142
|
declare type SelectOptionFunction = (mForm: FormState | undefined, data: {
|
|
139
143
|
model: any;
|
|
144
|
+
prop?: string;
|
|
140
145
|
formValues: any;
|
|
141
146
|
formValue: any;
|
|
147
|
+
config: any;
|
|
142
148
|
}) => SelectOption[] | SelectGroupOption[];
|
|
143
149
|
declare type RemoteSelectOptionBodyFunction = (mForm: FormState | undefined, data: {
|
|
144
150
|
model: any;
|
|
145
151
|
formValue: any;
|
|
146
152
|
formValues: any;
|
|
153
|
+
config: any;
|
|
147
154
|
}) => Record<string, any>;
|
|
148
155
|
declare type RemoteSelectOptionRequestFunction = (mForm: FormState | undefined, res: any, data: {
|
|
149
156
|
model: any;
|
|
150
157
|
formValue: any;
|
|
151
158
|
formValues: any;
|
|
159
|
+
config: any;
|
|
152
160
|
}) => any;
|
|
153
161
|
declare type RemoteSelectOptionItemFunction = (optionsData: Record<string, any>) => SelectOption[];
|
|
154
162
|
declare type SelectOptionValueFunction = (item: Record<string, any>) => any;
|
|
@@ -394,6 +402,7 @@ export interface TabPaneConfig {
|
|
|
394
402
|
lazy?: boolean;
|
|
395
403
|
labelWidth?: string;
|
|
396
404
|
items: FormConfig;
|
|
405
|
+
[key: string]: any;
|
|
397
406
|
}
|
|
398
407
|
export interface TabConfig extends FormItem, ContainerCommonConfig {
|
|
399
408
|
type: 'tab' | 'dynamic-tab';
|
|
@@ -431,6 +440,7 @@ export interface ColumnConfig extends FormItem, ContainerCommonConfig {
|
|
|
431
440
|
label: string;
|
|
432
441
|
width: string | number;
|
|
433
442
|
sortable: boolean;
|
|
443
|
+
[key: string]: any;
|
|
434
444
|
}
|
|
435
445
|
/**
|
|
436
446
|
* 表格容器
|
package/package.json
CHANGED
|
@@ -1,7 +1,10 @@
|
|
|
1
1
|
{
|
|
2
|
-
"version": "1.0.0-
|
|
2
|
+
"version": "1.0.0-rc.10",
|
|
3
3
|
"name": "@tmagic/form",
|
|
4
|
-
"sideEffects":
|
|
4
|
+
"sideEffects": [
|
|
5
|
+
"dist/*",
|
|
6
|
+
"src/theme/*"
|
|
7
|
+
],
|
|
5
8
|
"main": "dist/tmagic-form.umd.js",
|
|
6
9
|
"module": "dist/tmagic-form.es.js",
|
|
7
10
|
"style": "dist/style.css",
|
|
@@ -14,8 +17,10 @@
|
|
|
14
17
|
"./dist/style.css": {
|
|
15
18
|
"import": "./dist/style.css",
|
|
16
19
|
"require": "./dist/style.css"
|
|
17
|
-
}
|
|
20
|
+
},
|
|
21
|
+
"./*": "./*"
|
|
18
22
|
},
|
|
23
|
+
"license": "Apache-2.0",
|
|
19
24
|
"scripts": {
|
|
20
25
|
"build": "vite build"
|
|
21
26
|
},
|
|
@@ -28,21 +33,26 @@
|
|
|
28
33
|
},
|
|
29
34
|
"dependencies": {
|
|
30
35
|
"@element-plus/icons": "0.0.11",
|
|
31
|
-
"@tmagic/utils": "
|
|
32
|
-
"element-plus": "^2.0
|
|
36
|
+
"@tmagic/utils": "1.0.0-rc.10",
|
|
37
|
+
"element-plus": "^2.2.0",
|
|
33
38
|
"lodash-es": "^4.17.21",
|
|
34
|
-
"moment": "^2.29.
|
|
39
|
+
"moment": "^2.29.2",
|
|
35
40
|
"sortablejs": "^1.14.0",
|
|
36
41
|
"vue": "^3.2.0"
|
|
37
42
|
},
|
|
43
|
+
"peerDependencies": {
|
|
44
|
+
"element-plus": "^2.2.0",
|
|
45
|
+
"vue": "^3.2.0"
|
|
46
|
+
},
|
|
38
47
|
"devDependencies": {
|
|
48
|
+
"@babel/core": "^7.18.0",
|
|
39
49
|
"@types/lodash-es": "^4.17.4",
|
|
40
50
|
"@types/node": "^15.12.4",
|
|
41
51
|
"@types/sortablejs": "^1.10.7",
|
|
42
52
|
"@vitejs/plugin-vue": "^1.2.3",
|
|
43
53
|
"@vitejs/plugin-vue-jsx": "^1.1.6",
|
|
44
54
|
"@vue/compiler-sfc": "^3.2.0",
|
|
45
|
-
"@vue/test-utils": "^2.0.0
|
|
55
|
+
"@vue/test-utils": "^2.0.0",
|
|
46
56
|
"sass": "^1.35.1",
|
|
47
57
|
"typescript": "^4.3.4",
|
|
48
58
|
"vite": "^2.3.7",
|
package/src/Form.vue
CHANGED
|
@@ -86,7 +86,7 @@ export default defineComponent({
|
|
|
86
86
|
},
|
|
87
87
|
|
|
88
88
|
size: {
|
|
89
|
-
type: String
|
|
89
|
+
type: String as PropType<'small' | 'default' | 'large'>,
|
|
90
90
|
},
|
|
91
91
|
|
|
92
92
|
inline: {
|
|
@@ -103,6 +103,10 @@ export default defineComponent({
|
|
|
103
103
|
type: String,
|
|
104
104
|
default: '__key',
|
|
105
105
|
},
|
|
106
|
+
|
|
107
|
+
popperClass: {
|
|
108
|
+
type: String,
|
|
109
|
+
},
|
|
106
110
|
},
|
|
107
111
|
|
|
108
112
|
emits: ['change', 'field-input', 'field-change'],
|
|
@@ -117,6 +121,7 @@ export default defineComponent({
|
|
|
117
121
|
|
|
118
122
|
const formState: FormState = reactive<FormState>({
|
|
119
123
|
keyProp: props.keyProp,
|
|
124
|
+
popperClass: props.popperClass,
|
|
120
125
|
config: props.config,
|
|
121
126
|
initValues: props.initValues,
|
|
122
127
|
parentValues: props.parentValues,
|
|
@@ -172,7 +177,7 @@ export default defineComponent({
|
|
|
172
177
|
submitForm: async (native?: boolean): Promise<any> => {
|
|
173
178
|
try {
|
|
174
179
|
await elForm.value?.validate();
|
|
175
|
-
return native ? values.value : cloneDeep(values.value);
|
|
180
|
+
return native ? values.value : cloneDeep(toRaw(values.value));
|
|
176
181
|
} catch (invalidFields: any) {
|
|
177
182
|
const error: string[] = [];
|
|
178
183
|
|
package/src/FormDialog.vue
CHANGED
|
@@ -0,0 +1,56 @@
|
|
|
1
|
+
<template>
|
|
2
|
+
<el-col v-show="display && config.type !== 'hidden'" :span="span">
|
|
3
|
+
<m-form-container
|
|
4
|
+
:model="model"
|
|
5
|
+
:config="config"
|
|
6
|
+
:prop="prop"
|
|
7
|
+
:label-width="config.labelWidth || labelWidth"
|
|
8
|
+
:expand-more="expandMore"
|
|
9
|
+
:size="size"
|
|
10
|
+
@change="changeHandler"
|
|
11
|
+
></m-form-container>
|
|
12
|
+
</el-col>
|
|
13
|
+
</template>
|
|
14
|
+
|
|
15
|
+
<script lang="ts">
|
|
16
|
+
import { computed, defineComponent, inject, PropType } from 'vue';
|
|
17
|
+
|
|
18
|
+
import { ChildConfig, FormState } from '../schema';
|
|
19
|
+
import { display as displayFunction } from '../utils/form';
|
|
20
|
+
|
|
21
|
+
export default defineComponent({
|
|
22
|
+
props: {
|
|
23
|
+
labelWidth: String,
|
|
24
|
+
expandMore: Boolean,
|
|
25
|
+
span: Number,
|
|
26
|
+
|
|
27
|
+
model: {
|
|
28
|
+
type: Object,
|
|
29
|
+
default: () => ({}),
|
|
30
|
+
},
|
|
31
|
+
|
|
32
|
+
config: {
|
|
33
|
+
type: Object as PropType<ChildConfig>,
|
|
34
|
+
default: () => ({}),
|
|
35
|
+
},
|
|
36
|
+
|
|
37
|
+
prop: String,
|
|
38
|
+
|
|
39
|
+
size: String,
|
|
40
|
+
},
|
|
41
|
+
|
|
42
|
+
emits: ['change'],
|
|
43
|
+
|
|
44
|
+
setup(props, { emit }) {
|
|
45
|
+
const mForm = inject<FormState | undefined>('mForm');
|
|
46
|
+
|
|
47
|
+
const changeHandler = () => emit('change', props.model);
|
|
48
|
+
|
|
49
|
+
return {
|
|
50
|
+
mForm,
|
|
51
|
+
display: computed(() => displayFunction(mForm, props.config.display, props)),
|
|
52
|
+
changeHandler,
|
|
53
|
+
};
|
|
54
|
+
},
|
|
55
|
+
});
|
|
56
|
+
</script>
|
|
@@ -1,5 +1,10 @@
|
|
|
1
1
|
<template>
|
|
2
|
-
<div
|
|
2
|
+
<div
|
|
3
|
+
v-if="config"
|
|
4
|
+
:style="config.tip ? 'display: flex;align-items: baseline;' : ''"
|
|
5
|
+
:class="config.className"
|
|
6
|
+
class="m-form-container"
|
|
7
|
+
>
|
|
3
8
|
<m-fields-hidden
|
|
4
9
|
v-if="type === 'hidden'"
|
|
5
10
|
:model="model"
|
|
@@ -20,15 +25,16 @@
|
|
|
20
25
|
:prop="itemProp"
|
|
21
26
|
:step-active="stepActive"
|
|
22
27
|
:expand-more="expand"
|
|
23
|
-
:label-width="
|
|
28
|
+
:label-width="itemLabelWidth"
|
|
24
29
|
@change="onChangeHandler"
|
|
25
30
|
></component>
|
|
26
31
|
|
|
27
32
|
<template v-else-if="type && display">
|
|
28
33
|
<el-form-item
|
|
29
34
|
:style="config.tip ? 'flex: 1' : ''"
|
|
35
|
+
:class="{ hidden: `${itemLabelWidth}` === '0' || !config.text }"
|
|
30
36
|
:prop="itemProp"
|
|
31
|
-
:label-width="
|
|
37
|
+
:label-width="itemLabelWidth"
|
|
32
38
|
:rules="rule"
|
|
33
39
|
>
|
|
34
40
|
<template #label><span v-html="type === 'checkbox' ? '' : config.text"></span></template>
|
|
@@ -65,8 +71,8 @@
|
|
|
65
71
|
<div v-if="extra" v-html="extra" class="m-form-tip"></div>
|
|
66
72
|
</el-form-item>
|
|
67
73
|
|
|
68
|
-
<el-tooltip v-if="config.tip" placement="
|
|
69
|
-
<
|
|
74
|
+
<el-tooltip v-if="config.tip" placement="left">
|
|
75
|
+
<el-icon style="line-height: 40px; margin-left: 5px"><warning-filled /></el-icon>
|
|
70
76
|
<template #content>
|
|
71
77
|
<div v-html="config.tip"></div>
|
|
72
78
|
</template>
|
|
@@ -83,7 +89,7 @@
|
|
|
83
89
|
:size="size"
|
|
84
90
|
:step-active="stepActive"
|
|
85
91
|
:expand-more="expand"
|
|
86
|
-
:label-width="
|
|
92
|
+
:label-width="itemLabelWidth"
|
|
87
93
|
:prop="itemProp"
|
|
88
94
|
@change="onChangeHandler"
|
|
89
95
|
></m-form-container>
|
|
@@ -91,13 +97,14 @@
|
|
|
91
97
|
</template>
|
|
92
98
|
|
|
93
99
|
<div style="text-align: center" v-if="config.expand && type !== 'fieldset'">
|
|
94
|
-
<el-button
|
|
100
|
+
<el-button text @click="expandHandler">{{ expand ? '收起配置' : '展开更多配置' }}</el-button>
|
|
95
101
|
</div>
|
|
96
102
|
</div>
|
|
97
103
|
</template>
|
|
98
104
|
|
|
99
105
|
<script lang="ts">
|
|
100
106
|
import { computed, defineComponent, inject, PropType, ref, resolveComponent, watchEffect } from 'vue';
|
|
107
|
+
import { WarningFilled } from '@element-plus/icons';
|
|
101
108
|
|
|
102
109
|
import { ChildConfig, ContainerCommonConfig, FormState, FormValue } from '../schema';
|
|
103
110
|
import { display as displayFunction, filterFunction, getRules } from '../utils/form';
|
|
@@ -105,6 +112,8 @@ import { display as displayFunction, filterFunction, getRules } from '../utils/f
|
|
|
105
112
|
export default defineComponent({
|
|
106
113
|
name: 'm-form-container',
|
|
107
114
|
|
|
115
|
+
components: { WarningFilled },
|
|
116
|
+
|
|
108
117
|
props: {
|
|
109
118
|
labelWidth: String,
|
|
110
119
|
expandMore: Boolean,
|
|
@@ -145,7 +154,18 @@ export default defineComponent({
|
|
|
145
154
|
|
|
146
155
|
const items = computed(() => (props.config as ContainerCommonConfig).items);
|
|
147
156
|
|
|
148
|
-
const itemProp = computed(() =>
|
|
157
|
+
const itemProp = computed(() => {
|
|
158
|
+
let n: string | number = '';
|
|
159
|
+
const { names } = props.config as any;
|
|
160
|
+
if (names?.[0]) {
|
|
161
|
+
[n] = names;
|
|
162
|
+
} else if (name.value) {
|
|
163
|
+
n = name.value;
|
|
164
|
+
} else {
|
|
165
|
+
return props.prop;
|
|
166
|
+
}
|
|
167
|
+
return `${props.prop}${props.prop ? '.' : ''}${n}`;
|
|
168
|
+
});
|
|
149
169
|
|
|
150
170
|
const tagName = computed(() => {
|
|
151
171
|
const component = resolveComponent(`m-${items.value ? 'form' : 'fields'}-${type.value}`);
|
|
@@ -180,6 +200,8 @@ export default defineComponent({
|
|
|
180
200
|
return displayFunction(mForm, props.config.display, props);
|
|
181
201
|
});
|
|
182
202
|
|
|
203
|
+
const itemLabelWidth = computed(() => props.config.labelWidth || props.labelWidth);
|
|
204
|
+
|
|
183
205
|
watchEffect(() => {
|
|
184
206
|
expand.value = props.expandMore;
|
|
185
207
|
});
|
|
@@ -195,6 +217,7 @@ export default defineComponent({
|
|
|
195
217
|
values: mForm?.initValues,
|
|
196
218
|
formValue: mForm?.values,
|
|
197
219
|
prop: itemProp.value,
|
|
220
|
+
config: props.config,
|
|
198
221
|
});
|
|
199
222
|
}
|
|
200
223
|
|
|
@@ -212,6 +235,7 @@ export default defineComponent({
|
|
|
212
235
|
values: mForm?.initValues,
|
|
213
236
|
formValue: mForm?.values,
|
|
214
237
|
prop: itemProp.value,
|
|
238
|
+
config: props.config,
|
|
215
239
|
});
|
|
216
240
|
}
|
|
217
241
|
};
|
|
@@ -224,10 +248,15 @@ export default defineComponent({
|
|
|
224
248
|
|
|
225
249
|
const onChangeHandler = async function (v: FormValue, key?: string) {
|
|
226
250
|
const { filter, onChange, trim, name, dynamicKey } = props.config as any;
|
|
227
|
-
let value: FormValue | number | string =
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
|
|
251
|
+
let value: FormValue | number | string = v;
|
|
252
|
+
|
|
253
|
+
try {
|
|
254
|
+
value = filterHandler(filter, v);
|
|
255
|
+
value = (await changeHandler(onChange, value)) ?? value;
|
|
256
|
+
value = trimHandler(trim, value) ?? value;
|
|
257
|
+
} catch (e) {
|
|
258
|
+
console.error(e);
|
|
259
|
+
}
|
|
231
260
|
|
|
232
261
|
// field内容下包含field-link时,model===value, 这里避免循环引用
|
|
233
262
|
if ((name || name === 0) && props.model !== value && (v !== value || props.model[name] !== value)) {
|
|
@@ -250,6 +279,7 @@ export default defineComponent({
|
|
|
250
279
|
itemProp,
|
|
251
280
|
items,
|
|
252
281
|
display,
|
|
282
|
+
itemLabelWidth,
|
|
253
283
|
tagName,
|
|
254
284
|
rule,
|
|
255
285
|
tooltip,
|
|
@@ -5,21 +5,21 @@
|
|
|
5
5
|
><caret-bottom v-if="expand" /><caret-right v-else
|
|
6
6
|
/></el-icon>
|
|
7
7
|
|
|
8
|
-
<el-button
|
|
8
|
+
<el-button text @click="expandHandler">{{ title }}</el-button>
|
|
9
9
|
|
|
10
10
|
<el-button
|
|
11
11
|
v-show="showDelete(parseInt(String(index)))"
|
|
12
|
-
|
|
12
|
+
text
|
|
13
13
|
:icon="Delete"
|
|
14
14
|
style="color: #f56c6c"
|
|
15
15
|
@click="removeHandler"
|
|
16
16
|
></el-button>
|
|
17
17
|
|
|
18
18
|
<template v-if="movable()">
|
|
19
|
-
<el-button v-show="index !== 0"
|
|
19
|
+
<el-button v-show="index !== 0" text size="small" @click="changeOrder(-1)"
|
|
20
20
|
>上移<el-icon><CaretRight /></el-icon
|
|
21
21
|
></el-button>
|
|
22
|
-
<el-button v-show="index !== length - 1"
|
|
22
|
+
<el-button v-show="index !== length - 1" text size="small" @click="changeOrder(1)"
|
|
23
23
|
>下移<el-icon><CaretBottom /></el-icon
|
|
24
24
|
></el-button>
|
|
25
25
|
</template>
|
package/src/containers/Row.vue
CHANGED
|
@@ -1,21 +1,17 @@
|
|
|
1
1
|
<template>
|
|
2
2
|
<el-row :gutter="10">
|
|
3
|
-
<
|
|
3
|
+
<Col
|
|
4
4
|
v-for="(col, index) in config.items"
|
|
5
|
-
:style="!display(col) || col.type === 'hidden' ? 'display: none' : ''"
|
|
6
5
|
:key="col[mForm?.keyProp || '__key'] ?? index"
|
|
7
6
|
:span="col.span || config.span || 24 / config.items.length"
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
@change="changeHandler"
|
|
17
|
-
></m-form-container>
|
|
18
|
-
</el-col>
|
|
7
|
+
:config="col"
|
|
8
|
+
:labelWidth="config.labelWidth || labelWidth"
|
|
9
|
+
:expandMore="expandMore"
|
|
10
|
+
:model="name ? model[name] : model"
|
|
11
|
+
:prop="prop"
|
|
12
|
+
:size="size"
|
|
13
|
+
@change="changeHandler"
|
|
14
|
+
/>
|
|
19
15
|
</el-row>
|
|
20
16
|
</template>
|
|
21
17
|
|
|
@@ -23,11 +19,14 @@
|
|
|
23
19
|
import { defineComponent, inject, PropType } from 'vue';
|
|
24
20
|
|
|
25
21
|
import { FormState, RowConfig } from '../schema';
|
|
26
|
-
|
|
22
|
+
|
|
23
|
+
import Col from './Col.vue';
|
|
27
24
|
|
|
28
25
|
export default defineComponent({
|
|
29
26
|
name: 'm-form-row',
|
|
30
27
|
|
|
28
|
+
components: { Col },
|
|
29
|
+
|
|
31
30
|
props: {
|
|
32
31
|
labelWidth: String,
|
|
33
32
|
expandMore: Boolean,
|
|
@@ -58,9 +57,6 @@ export default defineComponent({
|
|
|
58
57
|
|
|
59
58
|
return {
|
|
60
59
|
mForm,
|
|
61
|
-
display(config: any) {
|
|
62
|
-
return displayFunction(mForm, config.display, props);
|
|
63
|
-
},
|
|
64
60
|
changeHandler,
|
|
65
61
|
};
|
|
66
62
|
},
|
package/src/containers/Table.vue
CHANGED
|
@@ -25,8 +25,8 @@
|
|
|
25
25
|
<template v-slot="scope">
|
|
26
26
|
<el-button
|
|
27
27
|
v-show="showDelete(scope.$index + 1 + pagecontext * pagesize - 1)"
|
|
28
|
-
|
|
29
|
-
|
|
28
|
+
type="danger"
|
|
29
|
+
text
|
|
30
30
|
:icon="Delete"
|
|
31
31
|
@click="removeHandler(scope.$index + 1 + pagecontext * pagesize - 1)"
|
|
32
32
|
></el-button>
|
|
@@ -43,8 +43,9 @@
|
|
|
43
43
|
<el-button
|
|
44
44
|
plain
|
|
45
45
|
size="small"
|
|
46
|
+
type="primary"
|
|
46
47
|
:icon="ArrowUp"
|
|
47
|
-
|
|
48
|
+
text
|
|
48
49
|
@click="upHandler(scope.$index + 1 + pagecontext * pagesize - 1)"
|
|
49
50
|
@dblclick="topHandler(scope.$index + 1 + pagecontext * pagesize - 1)"
|
|
50
51
|
></el-button>
|
|
@@ -57,8 +58,9 @@
|
|
|
57
58
|
<el-button
|
|
58
59
|
plain
|
|
59
60
|
size="small"
|
|
61
|
+
type="primary"
|
|
60
62
|
:icon="ArrowDown"
|
|
61
|
-
|
|
63
|
+
text
|
|
62
64
|
@click="downHandler(scope.$index + 1 + pagecontext * pagesize - 1)"
|
|
63
65
|
@dblclick="bottomHandler(scope.$index + 1 + pagecontext * pagesize - 1)"
|
|
64
66
|
></el-button>
|
|
@@ -107,10 +109,16 @@
|
|
|
107
109
|
</el-tooltip>
|
|
108
110
|
<slot></slot>
|
|
109
111
|
<el-button v-if="addable" size="small" type="primary" plain @click="newHandler()">添加</el-button>
|
|
110
|
-
<el-button :icon="Grid" size="small" @click="toggleMode" v-if="enableToggleMode && !isFullscreen"
|
|
112
|
+
<el-button :icon="Grid" size="small" type="primary" @click="toggleMode" v-if="enableToggleMode && !isFullscreen"
|
|
111
113
|
>展开配置</el-button
|
|
112
114
|
>
|
|
113
|
-
<el-button
|
|
115
|
+
<el-button
|
|
116
|
+
:icon="FullScreen"
|
|
117
|
+
size="small"
|
|
118
|
+
type="primary"
|
|
119
|
+
@click="toggleFullscreen"
|
|
120
|
+
v-if="config.enableFullscreen !== false"
|
|
121
|
+
>
|
|
114
122
|
{{ isFullscreen ? '退出全屏' : '全屏编辑' }}
|
|
115
123
|
</el-button>
|
|
116
124
|
<el-upload
|
|
@@ -468,7 +476,7 @@ export default defineComponent({
|
|
|
468
476
|
}
|
|
469
477
|
emit('select', selection, row);
|
|
470
478
|
if (typeof props.config.onSelect === 'function') {
|
|
471
|
-
props.config.onSelect(mForm, { selection, row });
|
|
479
|
+
props.config.onSelect(mForm, { selection, row, config: props.config });
|
|
472
480
|
}
|
|
473
481
|
},
|
|
474
482
|
|
package/src/containers/Tabs.vue
CHANGED
|
@@ -59,12 +59,12 @@ const tabClickHandler = (mForm: FormState | undefined, tab: any, props: any) =>
|
|
|
59
59
|
tab.name = tab.paneName;
|
|
60
60
|
|
|
61
61
|
if (typeof config.onTabClick === 'function') {
|
|
62
|
-
config.onTabClick(mForm, tab, { model, formValue: mForm?.values, prop });
|
|
62
|
+
config.onTabClick(mForm, tab, { model, formValue: mForm?.values, prop, config });
|
|
63
63
|
}
|
|
64
64
|
|
|
65
65
|
const tabConfig = config.items.find((item: TabPaneConfig) => tab.name === item.status);
|
|
66
66
|
if (tabConfig && typeof tabConfig.onTabClick === 'function') {
|
|
67
|
-
tabConfig.onTabClick(mForm, tab, { model, formValue: mForm?.values, prop });
|
|
67
|
+
tabConfig.onTabClick(mForm, tab, { model, formValue: mForm?.values, prop, config });
|
|
68
68
|
}
|
|
69
69
|
};
|
|
70
70
|
|
|
@@ -136,7 +136,11 @@ const Tab = defineComponent({
|
|
|
136
136
|
if (!props.config.name) throw new Error('dynamic tab 必须配置name');
|
|
137
137
|
|
|
138
138
|
if (typeof props.config.onTabAdd === 'function') {
|
|
139
|
-
props.config.onTabAdd(mForm, {
|
|
139
|
+
props.config.onTabAdd(mForm, {
|
|
140
|
+
model: props.model,
|
|
141
|
+
prop: props.prop,
|
|
142
|
+
config: props.config,
|
|
143
|
+
});
|
|
140
144
|
} else if (tabs.value.length > 0) {
|
|
141
145
|
const newObj = cloneDeep(tabs.value[0]);
|
|
142
146
|
newObj.title = `标签${tabs.value.length + 1}`;
|
|
@@ -150,7 +154,11 @@ const Tab = defineComponent({
|
|
|
150
154
|
if (!props.config.name) throw new Error('dynamic tab 必须配置name');
|
|
151
155
|
|
|
152
156
|
if (typeof props.config.onTabRemove === 'function') {
|
|
153
|
-
props.config.onTabRemove(mForm, tabName, {
|
|
157
|
+
props.config.onTabRemove(mForm, tabName, {
|
|
158
|
+
model: props.model,
|
|
159
|
+
prop: props.prop,
|
|
160
|
+
config: props.config,
|
|
161
|
+
});
|
|
154
162
|
} else {
|
|
155
163
|
props.model[props.config.name].splice(+tabName, 1);
|
|
156
164
|
|
|
@@ -169,7 +177,7 @@ const Tab = defineComponent({
|
|
|
169
177
|
changeHandler: () => {
|
|
170
178
|
emit('change', props.model);
|
|
171
179
|
if (typeof props.config.onChange === 'function') {
|
|
172
|
-
props.config.onChange(mForm, { model: props.model });
|
|
180
|
+
props.config.onChange(mForm, { model: props.model, prop: props.prop, config: props.config });
|
|
173
181
|
}
|
|
174
182
|
},
|
|
175
183
|
};
|