@tmagic/form 1.3.0-alpha.9 → 1.3.0-beta.1
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/style.css +21 -0
- package/dist/tmagic-form.js +716 -388
- package/dist/tmagic-form.js.map +1 -1
- package/dist/tmagic-form.umd.cjs +744 -413
- package/dist/tmagic-form.umd.cjs.map +1 -1
- package/package.json +4 -4
- package/src/Form.vue +12 -4
- package/src/FormDialog.vue +19 -5
- package/src/FormDrawer.vue +159 -0
- package/src/containers/Container.vue +11 -10
- package/src/containers/GroupList.vue +1 -0
- package/src/containers/GroupListItem.vue +8 -2
- package/src/containers/Table.vue +148 -150
- package/src/fields/Cascader.vue +2 -12
- package/src/fields/Checkbox.vue +2 -12
- package/src/fields/CheckboxGroup.vue +2 -12
- package/src/fields/ColorPicker.vue +5 -13
- package/src/fields/Date.vue +6 -14
- package/src/fields/DateTime.vue +7 -15
- package/src/fields/Daterange.vue +2 -12
- package/src/fields/Display.vue +2 -10
- package/src/fields/DynamicField.vue +3 -13
- package/src/fields/Hidden.vue +2 -10
- package/src/fields/Link.vue +2 -12
- package/src/fields/Number.vue +7 -14
- package/src/fields/NumberRange.vue +50 -0
- package/src/fields/RadioGroup.vue +2 -12
- package/src/fields/Select.vue +2 -12
- package/src/fields/Switch.vue +6 -14
- package/src/fields/Text.vue +7 -14
- package/src/fields/Textarea.vue +7 -14
- package/src/fields/Time.vue +5 -13
- package/src/fields/Timerange.vue +76 -0
- package/src/index.ts +7 -0
- package/src/schema.ts +23 -2
- package/src/theme/form-drawer.scss +11 -0
- package/src/theme/index.scss +2 -0
- package/src/theme/number-range.scss +8 -0
- package/src/theme/panel.scss +6 -0
- package/src/utils/config.ts +1 -1
- package/src/utils/form.ts +2 -1
- package/types/Form.vue.d.ts +13 -11
- package/types/FormDialog.vue.d.ts +30 -17
- package/types/FormDrawer.vue.d.ts +348 -0
- package/types/fields/Cascader.vue.d.ts +2 -22
- package/types/fields/Checkbox.vue.d.ts +2 -22
- package/types/fields/CheckboxGroup.vue.d.ts +2 -22
- package/types/fields/ColorPicker.vue.d.ts +2 -24
- package/types/fields/Date.vue.d.ts +2 -24
- package/types/fields/DateTime.vue.d.ts +2 -24
- package/types/fields/Daterange.vue.d.ts +2 -22
- package/types/fields/Display.vue.d.ts +2 -18
- package/types/fields/DynamicField.vue.d.ts +2 -22
- package/types/fields/Hidden.vue.d.ts +2 -18
- package/types/fields/Link.vue.d.ts +2 -22
- package/types/fields/Number.vue.d.ts +2 -25
- package/types/fields/NumberRange.vue.d.ts +12 -0
- package/types/fields/RadioGroup.vue.d.ts +2 -22
- package/types/fields/Select.vue.d.ts +2 -22
- package/types/fields/Switch.vue.d.ts +2 -24
- package/types/fields/Text.vue.d.ts +2 -25
- package/types/fields/Textarea.vue.d.ts +2 -25
- package/types/fields/Time.vue.d.ts +2 -24
- package/types/fields/Timerange.vue.d.ts +14 -0
- package/types/index.d.ts +3 -0
- package/types/schema.d.ts +21 -2
- package/types/utils/config.d.ts +1 -1
package/src/fields/Number.vue
CHANGED
|
@@ -20,26 +20,19 @@ import { inject } from 'vue';
|
|
|
20
20
|
|
|
21
21
|
import { TMagicInputNumber } from '@tmagic/design';
|
|
22
22
|
|
|
23
|
-
import { FormState, NumberConfig } from '../schema';
|
|
23
|
+
import type { FieldProps, FormState, NumberConfig } from '../schema';
|
|
24
24
|
import { useAddField } from '../utils/useAddField';
|
|
25
25
|
|
|
26
26
|
defineOptions({
|
|
27
27
|
name: 'MFormNumber',
|
|
28
28
|
});
|
|
29
29
|
|
|
30
|
-
const props = defineProps<
|
|
31
|
-
config: NumberConfig;
|
|
32
|
-
model: any;
|
|
33
|
-
initValues?: any;
|
|
34
|
-
values?: any;
|
|
35
|
-
name: string;
|
|
36
|
-
prop: string;
|
|
37
|
-
disabled?: boolean;
|
|
38
|
-
size?: 'large' | 'default' | 'small';
|
|
39
|
-
lastValues?: Record<string, any>;
|
|
40
|
-
}>();
|
|
30
|
+
const props = defineProps<FieldProps<NumberConfig>>();
|
|
41
31
|
|
|
42
|
-
const emit = defineEmits
|
|
32
|
+
const emit = defineEmits<{
|
|
33
|
+
change: [values: number];
|
|
34
|
+
input: [values: number];
|
|
35
|
+
}>();
|
|
43
36
|
|
|
44
37
|
useAddField(props.prop);
|
|
45
38
|
|
|
@@ -49,7 +42,7 @@ const changeHandler = (value: number) => {
|
|
|
49
42
|
emit('change', value);
|
|
50
43
|
};
|
|
51
44
|
|
|
52
|
-
const inputHandler = (v:
|
|
45
|
+
const inputHandler = (v: number) => {
|
|
53
46
|
emit('input', v);
|
|
54
47
|
mForm?.$emit('field-input', props.prop, v);
|
|
55
48
|
};
|
|
@@ -0,0 +1,50 @@
|
|
|
1
|
+
<template>
|
|
2
|
+
<div class="m-fields-number-range">
|
|
3
|
+
<TMagicInput
|
|
4
|
+
v-model="model[name][0]"
|
|
5
|
+
clearable
|
|
6
|
+
:size="size"
|
|
7
|
+
:disabled="disabled"
|
|
8
|
+
@change="minChangeHandler"
|
|
9
|
+
></TMagicInput>
|
|
10
|
+
<span class="split-tag">-</span>
|
|
11
|
+
<TMagicInput
|
|
12
|
+
v-model="model[name][1]"
|
|
13
|
+
clearable
|
|
14
|
+
:size="size"
|
|
15
|
+
:disabled="disabled"
|
|
16
|
+
@change="maxChangeHandler"
|
|
17
|
+
></TMagicInput>
|
|
18
|
+
</div>
|
|
19
|
+
</template>
|
|
20
|
+
|
|
21
|
+
<script lang="ts" setup>
|
|
22
|
+
import { TMagicInput } from '@tmagic/design';
|
|
23
|
+
|
|
24
|
+
import type { FieldProps, NumberRangeConfig } from '../schema';
|
|
25
|
+
import { useAddField } from '../utils/useAddField';
|
|
26
|
+
|
|
27
|
+
defineOptions({
|
|
28
|
+
name: 'MFormNumberRange',
|
|
29
|
+
});
|
|
30
|
+
|
|
31
|
+
const props = defineProps<FieldProps<NumberRangeConfig>>();
|
|
32
|
+
|
|
33
|
+
const emit = defineEmits<{
|
|
34
|
+
change: [values: [number, number]];
|
|
35
|
+
}>();
|
|
36
|
+
|
|
37
|
+
useAddField(props.prop);
|
|
38
|
+
|
|
39
|
+
if (!Array.isArray(props.model[props.name])) {
|
|
40
|
+
props.model[props.name] = [];
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
const minChangeHandler = (v: string) => {
|
|
44
|
+
emit('change', [Number(v), props.model[props.name][1]]);
|
|
45
|
+
};
|
|
46
|
+
|
|
47
|
+
const maxChangeHandler = (v: string) => {
|
|
48
|
+
emit('change', [props.model[props.name][0], Number(v)]);
|
|
49
|
+
};
|
|
50
|
+
</script>
|
|
@@ -13,24 +13,14 @@
|
|
|
13
13
|
<script lang="ts" setup>
|
|
14
14
|
import { TMagicRadio, TMagicRadioGroup } from '@tmagic/design';
|
|
15
15
|
|
|
16
|
-
import { RadioGroupConfig } from '../schema';
|
|
16
|
+
import type { FieldProps, RadioGroupConfig } from '../schema';
|
|
17
17
|
import { useAddField } from '../utils/useAddField';
|
|
18
18
|
|
|
19
19
|
defineOptions({
|
|
20
20
|
name: 'MFormRadioGroup',
|
|
21
21
|
});
|
|
22
22
|
|
|
23
|
-
const props = defineProps<
|
|
24
|
-
config: RadioGroupConfig;
|
|
25
|
-
model: any;
|
|
26
|
-
initValues?: any;
|
|
27
|
-
values?: any;
|
|
28
|
-
name: string;
|
|
29
|
-
prop: string;
|
|
30
|
-
disabled?: boolean;
|
|
31
|
-
size?: 'large' | 'default' | 'small';
|
|
32
|
-
lastValues?: Record<string, any>;
|
|
33
|
-
}>();
|
|
23
|
+
const props = defineProps<FieldProps<RadioGroupConfig>>();
|
|
34
24
|
|
|
35
25
|
const emit = defineEmits(['change']);
|
|
36
26
|
|
package/src/fields/Select.vue
CHANGED
|
@@ -31,7 +31,7 @@ import { inject, onBeforeMount, Ref, ref, watch, watchEffect } from 'vue';
|
|
|
31
31
|
import { TMagicSelect } from '@tmagic/design';
|
|
32
32
|
import { getValueByKeyPath } from '@tmagic/utils';
|
|
33
33
|
|
|
34
|
-
import { FormState, SelectConfig, SelectGroupOption, SelectOption } from '../schema';
|
|
34
|
+
import type { FieldProps, FormState, SelectConfig, SelectGroupOption, SelectOption } from '../schema';
|
|
35
35
|
import { getConfig } from '../utils/config';
|
|
36
36
|
import { useAddField } from '../utils/useAddField';
|
|
37
37
|
|
|
@@ -42,17 +42,7 @@ defineOptions({
|
|
|
42
42
|
name: 'MFormSelect',
|
|
43
43
|
});
|
|
44
44
|
|
|
45
|
-
const props = defineProps<
|
|
46
|
-
config: SelectConfig;
|
|
47
|
-
model: any;
|
|
48
|
-
initValues?: any;
|
|
49
|
-
values?: any;
|
|
50
|
-
name: string;
|
|
51
|
-
prop: string;
|
|
52
|
-
disabled?: boolean;
|
|
53
|
-
size?: 'large' | 'default' | 'small';
|
|
54
|
-
lastValues?: Record<string, any>;
|
|
55
|
-
}>();
|
|
45
|
+
const props = defineProps<FieldProps<SelectConfig>>();
|
|
56
46
|
|
|
57
47
|
const emit = defineEmits(['change']);
|
|
58
48
|
|
package/src/fields/Switch.vue
CHANGED
|
@@ -14,30 +14,22 @@ import { computed } from 'vue';
|
|
|
14
14
|
|
|
15
15
|
import { TMagicSwitch } from '@tmagic/design';
|
|
16
16
|
|
|
17
|
-
import { SwitchConfig } from '../schema';
|
|
17
|
+
import type { FieldProps, SwitchConfig } from '../schema';
|
|
18
18
|
import { useAddField } from '../utils/useAddField';
|
|
19
19
|
|
|
20
20
|
defineOptions({
|
|
21
21
|
name: 'MFormSwitch',
|
|
22
22
|
});
|
|
23
23
|
|
|
24
|
-
const props = defineProps<
|
|
25
|
-
config: SwitchConfig;
|
|
26
|
-
model: any;
|
|
27
|
-
initValues?: any;
|
|
28
|
-
values?: any;
|
|
29
|
-
name: string;
|
|
30
|
-
prop: string;
|
|
31
|
-
disabled?: boolean;
|
|
32
|
-
size?: 'large' | 'default' | 'small';
|
|
33
|
-
lastValues?: Record<string, any>;
|
|
34
|
-
}>();
|
|
24
|
+
const props = defineProps<FieldProps<SwitchConfig>>();
|
|
35
25
|
|
|
36
|
-
const emit = defineEmits
|
|
26
|
+
const emit = defineEmits<{
|
|
27
|
+
change: [value: any];
|
|
28
|
+
}>();
|
|
37
29
|
|
|
38
30
|
useAddField(props.prop);
|
|
39
31
|
|
|
40
|
-
const changeHandler = (value:
|
|
32
|
+
const changeHandler = (value: any) => {
|
|
41
33
|
emit('change', value);
|
|
42
34
|
};
|
|
43
35
|
|
package/src/fields/Text.vue
CHANGED
|
@@ -29,32 +29,25 @@ import { inject } from 'vue';
|
|
|
29
29
|
import { TMagicButton, TMagicInput } from '@tmagic/design';
|
|
30
30
|
import { isNumber } from '@tmagic/utils';
|
|
31
31
|
|
|
32
|
-
import { FormState, TextConfig } from '../schema';
|
|
32
|
+
import type { FieldProps, FormState, TextConfig } from '../schema';
|
|
33
33
|
import { useAddField } from '../utils/useAddField';
|
|
34
34
|
|
|
35
35
|
defineOptions({
|
|
36
36
|
name: 'MFormText',
|
|
37
37
|
});
|
|
38
38
|
|
|
39
|
-
const props = defineProps<
|
|
40
|
-
config: TextConfig;
|
|
41
|
-
model: any;
|
|
42
|
-
initValues?: any;
|
|
43
|
-
values?: any;
|
|
44
|
-
name: string;
|
|
45
|
-
prop: string;
|
|
46
|
-
disabled?: boolean;
|
|
47
|
-
size?: 'large' | 'default' | 'small';
|
|
48
|
-
lastValues?: Record<string, any>;
|
|
49
|
-
}>();
|
|
39
|
+
const props = defineProps<FieldProps<TextConfig>>();
|
|
50
40
|
|
|
51
|
-
const emit = defineEmits
|
|
41
|
+
const emit = defineEmits<{
|
|
42
|
+
change: [value: string];
|
|
43
|
+
input: [value: string];
|
|
44
|
+
}>();
|
|
52
45
|
|
|
53
46
|
useAddField(props.prop);
|
|
54
47
|
|
|
55
48
|
const mForm = inject<FormState | undefined>('mForm');
|
|
56
49
|
|
|
57
|
-
const changeHandler = (value:
|
|
50
|
+
const changeHandler = (value: string) => {
|
|
58
51
|
emit('change', value);
|
|
59
52
|
};
|
|
60
53
|
|
package/src/fields/Textarea.vue
CHANGED
|
@@ -17,32 +17,25 @@ import { inject } from 'vue';
|
|
|
17
17
|
|
|
18
18
|
import { TMagicInput } from '@tmagic/design';
|
|
19
19
|
|
|
20
|
-
import { FormState, TextareaConfig } from '../schema';
|
|
20
|
+
import type { FieldProps, FormState, TextareaConfig } from '../schema';
|
|
21
21
|
import { useAddField } from '../utils/useAddField';
|
|
22
22
|
|
|
23
23
|
defineOptions({
|
|
24
24
|
name: 'MFormTextarea',
|
|
25
25
|
});
|
|
26
26
|
|
|
27
|
-
const props = defineProps<
|
|
28
|
-
config: TextareaConfig;
|
|
29
|
-
model: any;
|
|
30
|
-
initValues?: any;
|
|
31
|
-
values?: any;
|
|
32
|
-
name: string;
|
|
33
|
-
prop: string;
|
|
34
|
-
disabled?: boolean;
|
|
35
|
-
size?: 'large' | 'default' | 'small';
|
|
36
|
-
lastValues?: Record<string, any>;
|
|
37
|
-
}>();
|
|
27
|
+
const props = defineProps<FieldProps<TextareaConfig>>();
|
|
38
28
|
|
|
39
|
-
const emit = defineEmits
|
|
29
|
+
const emit = defineEmits<{
|
|
30
|
+
change: [value: string];
|
|
31
|
+
input: [value: string];
|
|
32
|
+
}>();
|
|
40
33
|
|
|
41
34
|
useAddField(props.prop);
|
|
42
35
|
|
|
43
36
|
const mForm = inject<FormState | null>('mForm');
|
|
44
37
|
|
|
45
|
-
const changeHandler = (value:
|
|
38
|
+
const changeHandler = (value: string) => {
|
|
46
39
|
emit('change', value);
|
|
47
40
|
};
|
|
48
41
|
|
package/src/fields/Time.vue
CHANGED
|
@@ -13,26 +13,18 @@
|
|
|
13
13
|
<script lang="ts" setup>
|
|
14
14
|
import { TMagicTimePicker } from '@tmagic/design';
|
|
15
15
|
|
|
16
|
-
import { TimeConfig } from '../schema';
|
|
16
|
+
import type { FieldProps, TimeConfig } from '../schema';
|
|
17
17
|
import { useAddField } from '../utils/useAddField';
|
|
18
18
|
|
|
19
19
|
defineOptions({
|
|
20
20
|
name: 'MFormTime',
|
|
21
21
|
});
|
|
22
22
|
|
|
23
|
-
const props = defineProps<
|
|
24
|
-
config: TimeConfig;
|
|
25
|
-
model: any;
|
|
26
|
-
initValues?: any;
|
|
27
|
-
values?: any;
|
|
28
|
-
name: string;
|
|
29
|
-
prop: string;
|
|
30
|
-
disabled?: boolean;
|
|
31
|
-
size?: 'large' | 'default' | 'small';
|
|
32
|
-
lastValues?: Record<string, any>;
|
|
33
|
-
}>();
|
|
23
|
+
const props = defineProps<FieldProps<TimeConfig>>();
|
|
34
24
|
|
|
35
|
-
const emit = defineEmits
|
|
25
|
+
const emit = defineEmits<{
|
|
26
|
+
change: [value: string];
|
|
27
|
+
}>();
|
|
36
28
|
|
|
37
29
|
useAddField(props.prop);
|
|
38
30
|
|
|
@@ -0,0 +1,76 @@
|
|
|
1
|
+
<template>
|
|
2
|
+
<TMagicTimePicker
|
|
3
|
+
v-model="value"
|
|
4
|
+
is-range
|
|
5
|
+
range-separator="-"
|
|
6
|
+
start-placeholder="开始时间"
|
|
7
|
+
end-placeholder="结束时间"
|
|
8
|
+
:size="size"
|
|
9
|
+
:unlink-panels="true"
|
|
10
|
+
:disabled="disabled"
|
|
11
|
+
:default-time="config.defaultTime"
|
|
12
|
+
@change="changeHandler"
|
|
13
|
+
></TMagicTimePicker>
|
|
14
|
+
</template>
|
|
15
|
+
|
|
16
|
+
<script lang="ts" setup>
|
|
17
|
+
import { ref, watch } from 'vue';
|
|
18
|
+
|
|
19
|
+
import { TMagicTimePicker } from '@tmagic/design';
|
|
20
|
+
import { datetimeFormatter } from '@tmagic/utils';
|
|
21
|
+
|
|
22
|
+
import type { DaterangeConfig, FieldProps } from '../schema';
|
|
23
|
+
import { useAddField } from '../utils/useAddField';
|
|
24
|
+
|
|
25
|
+
defineOptions({
|
|
26
|
+
name: 'MFormTimeRange',
|
|
27
|
+
});
|
|
28
|
+
|
|
29
|
+
const props = defineProps<FieldProps<DaterangeConfig>>();
|
|
30
|
+
|
|
31
|
+
const emit = defineEmits(['change']);
|
|
32
|
+
|
|
33
|
+
useAddField(props.prop);
|
|
34
|
+
|
|
35
|
+
// eslint-disable-next-line vue/no-setup-props-destructure
|
|
36
|
+
const { names } = props.config;
|
|
37
|
+
const value = ref<(Date | undefined)[] | null>([]);
|
|
38
|
+
|
|
39
|
+
if (props.model !== undefined && names?.length) {
|
|
40
|
+
watch(
|
|
41
|
+
[() => props.model[names[0]], () => props.model[names[1]]],
|
|
42
|
+
([start, end], [preStart, preEnd]) => {
|
|
43
|
+
if (!value.value) {
|
|
44
|
+
value.value = [];
|
|
45
|
+
}
|
|
46
|
+
if (!start || !end) value.value = [];
|
|
47
|
+
if (start !== preStart) value.value[0] = start;
|
|
48
|
+
if (end !== preEnd) value.value[1] = end;
|
|
49
|
+
},
|
|
50
|
+
{
|
|
51
|
+
immediate: true,
|
|
52
|
+
},
|
|
53
|
+
);
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
const setValue = (v: Date[] | Date) => {
|
|
57
|
+
names?.forEach((item, index) => {
|
|
58
|
+
if (!props.model) {
|
|
59
|
+
return;
|
|
60
|
+
}
|
|
61
|
+
if (Array.isArray(v)) {
|
|
62
|
+
props.model[item] = datetimeFormatter(v[index]?.toString(), '');
|
|
63
|
+
} else {
|
|
64
|
+
props.model[item] = undefined;
|
|
65
|
+
}
|
|
66
|
+
});
|
|
67
|
+
};
|
|
68
|
+
|
|
69
|
+
const changeHandler = (v: Date[]) => {
|
|
70
|
+
const value = v || [];
|
|
71
|
+
if (names?.length) {
|
|
72
|
+
setValue(value);
|
|
73
|
+
}
|
|
74
|
+
emit('change', value);
|
|
75
|
+
};
|
|
76
|
+
</script>
|
package/src/index.ts
CHANGED
|
@@ -38,12 +38,14 @@ import DynamicField from './fields/DynamicField.vue';
|
|
|
38
38
|
import Hidden from './fields/Hidden.vue';
|
|
39
39
|
import Link from './fields/Link.vue';
|
|
40
40
|
import Number from './fields/Number.vue';
|
|
41
|
+
import NumberRange from './fields/NumberRange.vue';
|
|
41
42
|
import RadioGroup from './fields/RadioGroup.vue';
|
|
42
43
|
import Select from './fields/Select.vue';
|
|
43
44
|
import Switch from './fields/Switch.vue';
|
|
44
45
|
import Text from './fields/Text.vue';
|
|
45
46
|
import Textarea from './fields/Textarea.vue';
|
|
46
47
|
import Time from './fields/Time.vue';
|
|
48
|
+
import Timerange from './fields/Timerange.vue';
|
|
47
49
|
import { setConfig } from './utils/config';
|
|
48
50
|
import Form from './Form.vue';
|
|
49
51
|
import FormDialog from './FormDialog.vue';
|
|
@@ -56,6 +58,7 @@ export * from './utils/useAddField';
|
|
|
56
58
|
|
|
57
59
|
export { default as MForm } from './Form.vue';
|
|
58
60
|
export { default as MFormDialog } from './FormDialog.vue';
|
|
61
|
+
export { default as MFormDrawer } from './FormDrawer.vue';
|
|
59
62
|
export { default as MContainer } from './containers/Container.vue';
|
|
60
63
|
export { default as MFieldset } from './containers/Fieldset.vue';
|
|
61
64
|
export { default as MPanel } from './containers/Panel.vue';
|
|
@@ -65,6 +68,7 @@ export { default as MTable } from './containers/Table.vue';
|
|
|
65
68
|
export { default as MGroupList } from './containers/GroupList.vue';
|
|
66
69
|
export { default as MText } from './fields/Text.vue';
|
|
67
70
|
export { default as MNumber } from './fields/Number.vue';
|
|
71
|
+
export { default as MNumberRange } from './fields/NumberRange.vue';
|
|
68
72
|
export { default as MTextarea } from './fields/Textarea.vue';
|
|
69
73
|
export { default as MHidden } from './fields/Hidden.vue';
|
|
70
74
|
export { default as MDate } from './fields/Date.vue';
|
|
@@ -73,6 +77,7 @@ export { default as MTime } from './fields/Time.vue';
|
|
|
73
77
|
export { default as MCheckbox } from './fields/Checkbox.vue';
|
|
74
78
|
export { default as MSwitch } from './fields/Switch.vue';
|
|
75
79
|
export { default as MDaterange } from './fields/Daterange.vue';
|
|
80
|
+
export { default as MTimerange } from './fields/Timerange.vue';
|
|
76
81
|
export { default as MColorPicker } from './fields/ColorPicker.vue';
|
|
77
82
|
export { default as MCheckboxGroup } from './fields/CheckboxGroup.vue';
|
|
78
83
|
export { default as MRadioGroup } from './fields/RadioGroup.vue';
|
|
@@ -108,11 +113,13 @@ export default {
|
|
|
108
113
|
app.component('m-form-tab', Tabs);
|
|
109
114
|
app.component('m-fields-text', Text);
|
|
110
115
|
app.component('m-fields-number', Number);
|
|
116
|
+
app.component('m-fields-number-range', NumberRange);
|
|
111
117
|
app.component('m-fields-textarea', Textarea);
|
|
112
118
|
app.component('m-fields-hidden', Hidden);
|
|
113
119
|
app.component('m-fields-date', Date);
|
|
114
120
|
app.component('m-fields-datetime', DateTime);
|
|
115
121
|
app.component('m-fields-daterange', Daterange);
|
|
122
|
+
app.component('m-fields-timerange', Timerange);
|
|
116
123
|
app.component('m-fields-time', Time);
|
|
117
124
|
app.component('m-fields-checkbox', Checkbox);
|
|
118
125
|
app.component('m-fields-switch', Switch);
|
package/src/schema.ts
CHANGED
|
@@ -21,6 +21,18 @@ export interface ValidateError {
|
|
|
21
21
|
field: string;
|
|
22
22
|
}
|
|
23
23
|
|
|
24
|
+
export interface FieldProps<T = any> {
|
|
25
|
+
config: T;
|
|
26
|
+
model: any;
|
|
27
|
+
initValues?: any;
|
|
28
|
+
values?: any;
|
|
29
|
+
name: string;
|
|
30
|
+
prop: string;
|
|
31
|
+
disabled?: boolean;
|
|
32
|
+
size?: 'large' | 'default' | 'small';
|
|
33
|
+
lastValues?: Record<string, any>;
|
|
34
|
+
}
|
|
35
|
+
|
|
24
36
|
/**
|
|
25
37
|
* 整个表单的数据,会注入到各个组件中去
|
|
26
38
|
*/
|
|
@@ -72,7 +84,7 @@ export interface FormItem {
|
|
|
72
84
|
/** 值发生改变时调用的方法 */
|
|
73
85
|
onChange?: OnChangeHandler;
|
|
74
86
|
/** label 标签的文本 */
|
|
75
|
-
text?: string;
|
|
87
|
+
text?: string | FilterFunction;
|
|
76
88
|
/** 右侧感叹号 */
|
|
77
89
|
tip?: string;
|
|
78
90
|
|
|
@@ -146,7 +158,7 @@ export type TypeFunction = (
|
|
|
146
158
|
},
|
|
147
159
|
) => string;
|
|
148
160
|
|
|
149
|
-
type FilterFunction = (
|
|
161
|
+
export type FilterFunction = (
|
|
150
162
|
mForm: FormState | undefined,
|
|
151
163
|
data: {
|
|
152
164
|
model: Record<any, any>;
|
|
@@ -339,6 +351,13 @@ export interface NumberConfig extends FormItem {
|
|
|
339
351
|
placeholder?: string;
|
|
340
352
|
}
|
|
341
353
|
|
|
354
|
+
/**
|
|
355
|
+
* 数值范围
|
|
356
|
+
*/
|
|
357
|
+
export interface NumberRangeConfig extends FormItem {
|
|
358
|
+
type?: 'number-range';
|
|
359
|
+
}
|
|
360
|
+
|
|
342
361
|
/**
|
|
343
362
|
* 隐藏域
|
|
344
363
|
*/
|
|
@@ -661,6 +680,8 @@ export interface GroupListConfig extends FormItem {
|
|
|
661
680
|
groupItems?: FormConfig;
|
|
662
681
|
tableItems?: FormConfig;
|
|
663
682
|
titleKey?: string;
|
|
683
|
+
titlePrefix?: string;
|
|
684
|
+
title?: string | FilterFunction;
|
|
664
685
|
itemExtra?: string | FilterFunction;
|
|
665
686
|
expandAll?: boolean;
|
|
666
687
|
addable?: (mForm: FormState | undefined, data: any) => boolean | 'undefined' | boolean;
|
package/src/theme/index.scss
CHANGED
package/src/theme/panel.scss
CHANGED
package/src/utils/config.ts
CHANGED
package/src/utils/form.ts
CHANGED
|
@@ -174,7 +174,7 @@ const getDefaultValue = function (mForm: FormState | undefined, { defaultValue,
|
|
|
174
174
|
return false;
|
|
175
175
|
}
|
|
176
176
|
|
|
177
|
-
if (multiple) {
|
|
177
|
+
if (multiple || type === 'number-range') {
|
|
178
178
|
return [];
|
|
179
179
|
}
|
|
180
180
|
|
|
@@ -193,6 +193,7 @@ export const filterFunction = (mForm: FormState | undefined, config: any, props:
|
|
|
193
193
|
formValue: mForm?.values || props.model,
|
|
194
194
|
prop: props.prop,
|
|
195
195
|
config: props.config,
|
|
196
|
+
index: props.index,
|
|
196
197
|
});
|
|
197
198
|
};
|
|
198
199
|
|
package/types/Form.vue.d.ts
CHANGED
|
@@ -3,21 +3,22 @@ declare const _default: import("vue").DefineComponent<__VLS_WithDefaults<__VLS_T
|
|
|
3
3
|
/** 表单配置 */
|
|
4
4
|
config: FormConfig;
|
|
5
5
|
/** 表单值 */
|
|
6
|
-
initValues:
|
|
6
|
+
initValues: Record<string, any>;
|
|
7
7
|
/** 需对比的值(开启对比模式时传入) */
|
|
8
|
-
lastValues?:
|
|
8
|
+
lastValues?: Record<string, any> | undefined;
|
|
9
9
|
/** 是否开启对比模式 */
|
|
10
10
|
isCompare?: boolean | undefined;
|
|
11
|
-
parentValues?:
|
|
11
|
+
parentValues?: Record<string, any> | undefined;
|
|
12
12
|
labelWidth?: string | undefined;
|
|
13
13
|
disabled?: boolean | undefined;
|
|
14
14
|
height?: string | undefined;
|
|
15
15
|
stepActive?: string | number | undefined;
|
|
16
|
-
size?: "
|
|
16
|
+
size?: "large" | "default" | "small" | undefined;
|
|
17
17
|
inline?: boolean | undefined;
|
|
18
18
|
labelPosition?: string | undefined;
|
|
19
19
|
keyProp?: string | undefined;
|
|
20
20
|
popperClass?: string | undefined;
|
|
21
|
+
extendState?: ((state: FormState) => Record<string, any> | Promise<Record<string, any>>) | undefined;
|
|
21
22
|
}>, {
|
|
22
23
|
config: () => never[];
|
|
23
24
|
initValues: () => {};
|
|
@@ -43,21 +44,22 @@ declare const _default: import("vue").DefineComponent<__VLS_WithDefaults<__VLS_T
|
|
|
43
44
|
/** 表单配置 */
|
|
44
45
|
config: FormConfig;
|
|
45
46
|
/** 表单值 */
|
|
46
|
-
initValues:
|
|
47
|
+
initValues: Record<string, any>;
|
|
47
48
|
/** 需对比的值(开启对比模式时传入) */
|
|
48
|
-
lastValues?:
|
|
49
|
+
lastValues?: Record<string, any> | undefined;
|
|
49
50
|
/** 是否开启对比模式 */
|
|
50
51
|
isCompare?: boolean | undefined;
|
|
51
|
-
parentValues?:
|
|
52
|
+
parentValues?: Record<string, any> | undefined;
|
|
52
53
|
labelWidth?: string | undefined;
|
|
53
54
|
disabled?: boolean | undefined;
|
|
54
55
|
height?: string | undefined;
|
|
55
56
|
stepActive?: string | number | undefined;
|
|
56
|
-
size?: "
|
|
57
|
+
size?: "large" | "default" | "small" | undefined;
|
|
57
58
|
inline?: boolean | undefined;
|
|
58
59
|
labelPosition?: string | undefined;
|
|
59
60
|
keyProp?: string | undefined;
|
|
60
61
|
popperClass?: string | undefined;
|
|
62
|
+
extendState?: ((state: FormState) => Record<string, any> | Promise<Record<string, any>>) | undefined;
|
|
61
63
|
}>, {
|
|
62
64
|
config: () => never[];
|
|
63
65
|
initValues: () => {};
|
|
@@ -77,11 +79,11 @@ declare const _default: import("vue").DefineComponent<__VLS_WithDefaults<__VLS_T
|
|
|
77
79
|
"onField-change"?: ((...args: any[]) => any) | undefined;
|
|
78
80
|
}, {
|
|
79
81
|
config: FormConfig;
|
|
80
|
-
initValues:
|
|
81
|
-
lastValues:
|
|
82
|
+
initValues: Record<string, any>;
|
|
83
|
+
lastValues: Record<string, any>;
|
|
82
84
|
isCompare: boolean;
|
|
83
85
|
keyProp: string;
|
|
84
|
-
parentValues:
|
|
86
|
+
parentValues: Record<string, any>;
|
|
85
87
|
labelWidth: string;
|
|
86
88
|
disabled: boolean;
|
|
87
89
|
stepActive: string | number;
|