@tmagic/form 1.0.6 → 1.1.0-beta.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/dist/{tmagic-form.es.js → tmagic-form.mjs} +225 -190
- package/dist/tmagic-form.mjs.map +1 -0
- package/dist/tmagic-form.umd.js +239 -204
- package/dist/tmagic-form.umd.js.map +1 -1
- package/package.json +17 -16
- package/src/Form.vue +3 -7
- package/src/containers/Container.vue +1 -1
- package/src/containers/GroupListItem.vue +4 -4
- package/src/containers/Panel.vue +1 -1
- package/src/containers/Table.vue +1 -1
- package/src/fields/Cascader.vue +3 -5
- package/src/fields/ColorPicker.vue +19 -26
- package/src/fields/Daterange.vue +73 -52
- package/src/fields/Display.vue +13 -23
- package/src/fields/Hidden.vue +10 -20
- package/src/fields/Select.vue +1 -2
- package/src/fields/Text.vue +6 -4
- package/src/index.ts +4 -4
- package/tsconfig.build.json +13 -0
- package/types/Form.vue.d.ts +125 -0
- package/types/FormDialog.vue.d.ts +300 -0
- package/{dist/types/src → types}/containers/Col.vue.d.ts +4 -4
- package/types/containers/Container.vue.d.ts +70 -0
- package/types/containers/Fieldset.vue.d.ts +118 -0
- package/{dist/types/src → types}/containers/GroupList.vue.d.ts +6 -6
- package/{dist/types/src → types}/containers/GroupListItem.vue.d.ts +15 -15
- package/{dist/types/src → types}/containers/Panel.vue.d.ts +6 -6
- package/{dist/types/src → types}/containers/Row.vue.d.ts +3 -3
- package/{dist/types/src → types}/containers/Step.vue.d.ts +4 -4
- package/types/containers/Table.vue.d.ts +128 -0
- package/{dist/types/src → types}/containers/Tabs.vue.d.ts +11 -7
- package/types/fields/Cascader.vue.d.ts +74 -0
- package/{dist/types/src → types}/fields/Checkbox.vue.d.ts +5 -5
- package/{dist/types/src → types}/fields/CheckboxGroup.vue.d.ts +3 -3
- package/types/fields/ColorPicker.vue.d.ts +100 -0
- package/{dist/types/src → types}/fields/Date.vue.d.ts +3 -3
- package/{dist/types/src → types}/fields/DateTime.vue.d.ts +3 -3
- package/types/fields/Daterange.vue.d.ts +100 -0
- package/types/fields/Display.vue.d.ts +84 -0
- package/{dist/types/src → types}/fields/DynamicField.vue.d.ts +4 -4
- package/types/fields/Hidden.vue.d.ts +84 -0
- package/types/fields/Link.vue.d.ts +686 -0
- package/{dist/types/src → types}/fields/Number.vue.d.ts +3 -3
- package/{dist/types/src → types}/fields/RadioGroup.vue.d.ts +4 -5
- package/types/fields/Select.vue.d.ts +67 -0
- package/types/fields/SelectOptionGroups.vue.d.ts +64 -0
- package/types/fields/SelectOptions.vue.d.ts +68 -0
- package/{dist/types/src → types}/fields/Switch.vue.d.ts +6 -6
- package/{dist/types/src → types}/fields/Text.vue.d.ts +4 -4
- package/{dist/types/src → types}/fields/Textarea.vue.d.ts +10 -4
- package/{dist/types/src → types}/fields/Time.vue.d.ts +8 -4
- package/{dist/types/src → types}/index.d.ts +1 -0
- package/{dist/types/src → types}/schema.d.ts +0 -0
- package/{dist/types/src → types}/utils/config.d.ts +0 -0
- package/types/utils/containerProps.d.ts +26 -0
- package/types/utils/createForm.d.ts +3 -0
- package/{dist/types/src → types}/utils/fieldProps.d.ts +0 -0
- package/{dist/types/src → types}/utils/form.d.ts +0 -0
- package/types/utils/useAddField.d.ts +1 -0
- package/dist/tmagic-form.es.js.map +0 -1
- package/dist/types/src/containers/Container.vue.d.ts +0 -70
- package/dist/types/src/containers/Fieldset.vue.d.ts +0 -79
- package/dist/types/src/containers/Table.vue.d.ts +0 -128
- package/dist/types/src/fields/Daterange.vue.d.ts +0 -57
- package/dist/types/src/fields/Display.vue.d.ts +0 -3
- package/dist/types/src/fields/Hidden.vue.d.ts +0 -3
- package/dist/types/src/fields/SelectOptionGroups.vue.d.ts +0 -13
- package/dist/types/src/fields/SelectOptions.vue.d.ts +0 -21
- package/dist/types/src/shims-vue.d.ts +0 -6
- package/dist/types/src/utils/useAddField.d.ts +0 -1
- package/dist/types/src/vite-env.d.ts +0 -1
- package/src/vite-env.d.ts +0 -1
package/package.json
CHANGED
|
@@ -1,17 +1,17 @@
|
|
|
1
1
|
{
|
|
2
|
-
"version": "1.0.
|
|
2
|
+
"version": "1.1.0-beta.10",
|
|
3
3
|
"name": "@tmagic/form",
|
|
4
4
|
"sideEffects": [
|
|
5
5
|
"dist/*",
|
|
6
6
|
"src/theme/*"
|
|
7
7
|
],
|
|
8
8
|
"main": "dist/tmagic-form.umd.js",
|
|
9
|
-
"module": "dist/tmagic-form.
|
|
9
|
+
"module": "dist/tmagic-form.mjs",
|
|
10
10
|
"style": "dist/style.css",
|
|
11
|
-
"types": "
|
|
11
|
+
"types": "types/index.d.ts",
|
|
12
12
|
"exports": {
|
|
13
13
|
".": {
|
|
14
|
-
"import": "./dist/tmagic-form.
|
|
14
|
+
"import": "./dist/tmagic-form.mjs",
|
|
15
15
|
"require": "./dist/tmagic-form.umd.js"
|
|
16
16
|
},
|
|
17
17
|
"./dist/style.css": {
|
|
@@ -22,7 +22,9 @@
|
|
|
22
22
|
},
|
|
23
23
|
"license": "Apache-2.0",
|
|
24
24
|
"scripts": {
|
|
25
|
-
"build": "
|
|
25
|
+
"build": "npm run build:type && vite build",
|
|
26
|
+
"build:type": "npm run clear:type && vue-tsc --declaration --emitDeclarationOnly --project tsconfig.build.json",
|
|
27
|
+
"clear:type": "rimraf ./types"
|
|
26
28
|
},
|
|
27
29
|
"engines": {
|
|
28
30
|
"node": ">=14"
|
|
@@ -32,30 +34,29 @@
|
|
|
32
34
|
"url": "https://github.com/Tencent/tmagic-editor.git"
|
|
33
35
|
},
|
|
34
36
|
"dependencies": {
|
|
35
|
-
"@element-plus/icons": "
|
|
36
|
-
"@tmagic/utils": "1.0.
|
|
37
|
+
"@element-plus/icons-vue": "^2.0.6",
|
|
38
|
+
"@tmagic/utils": "1.1.0-beta.10",
|
|
37
39
|
"element-plus": "^2.2.6",
|
|
38
40
|
"lodash-es": "^4.17.21",
|
|
39
|
-
"moment": "^2.29.2",
|
|
40
41
|
"sortablejs": "^1.14.0",
|
|
41
|
-
"vue": "^3.2.
|
|
42
|
+
"vue": "^3.2.37"
|
|
42
43
|
},
|
|
43
44
|
"peerDependencies": {
|
|
44
45
|
"element-plus": "^2.2.6",
|
|
45
|
-
"vue": "^3.2.
|
|
46
|
+
"vue": "^3.2.37"
|
|
46
47
|
},
|
|
47
48
|
"devDependencies": {
|
|
48
49
|
"@babel/core": "^7.18.0",
|
|
49
50
|
"@types/lodash-es": "^4.17.4",
|
|
50
51
|
"@types/node": "^15.12.4",
|
|
51
52
|
"@types/sortablejs": "^1.10.7",
|
|
52
|
-
"@vitejs/plugin-vue": "^
|
|
53
|
-
"@vue/compiler-sfc": "^3.2.
|
|
53
|
+
"@vitejs/plugin-vue": "^3.0.1",
|
|
54
|
+
"@vue/compiler-sfc": "^3.2.37",
|
|
54
55
|
"@vue/test-utils": "^2.0.0",
|
|
56
|
+
"rimraf": "^3.0.2",
|
|
55
57
|
"sass": "^1.35.1",
|
|
56
|
-
"typescript": "^4.
|
|
57
|
-
"vite": "^
|
|
58
|
-
"
|
|
59
|
-
"vue-tsc": "^0.38.2"
|
|
58
|
+
"typescript": "^4.7.4",
|
|
59
|
+
"vite": "^3.0.4",
|
|
60
|
+
"vue-tsc": "^0.39.4"
|
|
60
61
|
}
|
|
61
62
|
}
|
package/src/Form.vue
CHANGED
|
@@ -26,22 +26,17 @@
|
|
|
26
26
|
|
|
27
27
|
<script lang="ts">
|
|
28
28
|
import { defineComponent, PropType, provide, reactive, ref, toRaw, watch } from 'vue';
|
|
29
|
-
import { ElForm } from 'element-plus';
|
|
30
29
|
import { cloneDeep, isEqual } from 'lodash-es';
|
|
31
30
|
|
|
32
31
|
import { getConfig } from './utils/config';
|
|
33
32
|
import { initValue } from './utils/form';
|
|
34
33
|
import { FormConfig, FormState, FormValue } from './schema';
|
|
35
34
|
|
|
36
|
-
|
|
35
|
+
interface ValidateError {
|
|
37
36
|
message: string;
|
|
38
37
|
field: string;
|
|
39
38
|
}
|
|
40
39
|
|
|
41
|
-
export interface FieldErrorList {
|
|
42
|
-
[field: string]: ValidateError[];
|
|
43
|
-
}
|
|
44
|
-
|
|
45
40
|
export default defineComponent({
|
|
46
41
|
name: 'm-form',
|
|
47
42
|
|
|
@@ -112,7 +107,8 @@ export default defineComponent({
|
|
|
112
107
|
emits: ['change', 'field-input', 'field-change'],
|
|
113
108
|
|
|
114
109
|
setup(props, { emit }) {
|
|
115
|
-
|
|
110
|
+
// InstanceType<typeof ElForm>,构建types的时候会出错
|
|
111
|
+
const elForm = ref<any>();
|
|
116
112
|
const initialized = ref(false);
|
|
117
113
|
const values = ref<FormValue>({});
|
|
118
114
|
const fields = new Map<string, any>();
|
|
@@ -104,7 +104,7 @@
|
|
|
104
104
|
|
|
105
105
|
<script lang="ts">
|
|
106
106
|
import { computed, defineComponent, inject, PropType, ref, resolveComponent, watchEffect } from 'vue';
|
|
107
|
-
import { WarningFilled } from '@element-plus/icons';
|
|
107
|
+
import { WarningFilled } from '@element-plus/icons-vue';
|
|
108
108
|
|
|
109
109
|
import { ChildConfig, ContainerCommonConfig, FormState, FormValue } from '../schema';
|
|
110
110
|
import { display as displayFunction, filterFunction, getRules } from '../utils/form';
|
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
<div class="m-fields-group-list-item">
|
|
3
3
|
<div>
|
|
4
4
|
<el-icon style="margin-right: 7px" @click="expandHandler"
|
|
5
|
-
><
|
|
5
|
+
><CaretBottom v-if="expand" /><CaretRight v-else
|
|
6
6
|
/></el-icon>
|
|
7
7
|
|
|
8
8
|
<el-button text @click="expandHandler">{{ title }}</el-button>
|
|
@@ -17,7 +17,7 @@
|
|
|
17
17
|
|
|
18
18
|
<template v-if="movable()">
|
|
19
19
|
<el-button v-show="index !== 0" text size="small" @click="changeOrder(-1)"
|
|
20
|
-
>上移<el-icon><
|
|
20
|
+
>上移<el-icon><CaretTop /></el-icon
|
|
21
21
|
></el-button>
|
|
22
22
|
<el-button v-show="index !== length - 1" text size="small" @click="changeOrder(1)"
|
|
23
23
|
>下移<el-icon><CaretBottom /></el-icon
|
|
@@ -41,7 +41,7 @@
|
|
|
41
41
|
|
|
42
42
|
<script lang="ts">
|
|
43
43
|
import { computed, defineComponent, inject, PropType, ref, watchEffect } from 'vue';
|
|
44
|
-
import { CaretBottom, CaretRight, Delete } from '@element-plus/icons';
|
|
44
|
+
import { CaretBottom, CaretRight, CaretTop, Delete } from '@element-plus/icons-vue';
|
|
45
45
|
|
|
46
46
|
import { FormState, GroupListConfig } from '../schema';
|
|
47
47
|
import { filterFunction } from '../utils/form';
|
|
@@ -49,7 +49,7 @@ import { filterFunction } from '../utils/form';
|
|
|
49
49
|
export default defineComponent({
|
|
50
50
|
name: 'm-form-group-list-item',
|
|
51
51
|
|
|
52
|
-
components: { CaretRight,
|
|
52
|
+
components: { CaretBottom, CaretRight, CaretTop },
|
|
53
53
|
|
|
54
54
|
props: {
|
|
55
55
|
labelWidth: String,
|
package/src/containers/Panel.vue
CHANGED
|
@@ -51,7 +51,7 @@
|
|
|
51
51
|
|
|
52
52
|
<script lang="ts">
|
|
53
53
|
import { computed, defineComponent, inject, PropType, ref } from 'vue';
|
|
54
|
-
import { CaretBottom, CaretRight } from '@element-plus/icons';
|
|
54
|
+
import { CaretBottom, CaretRight } from '@element-plus/icons-vue';
|
|
55
55
|
|
|
56
56
|
import { FormState, PanelConfig } from '../schema';
|
|
57
57
|
import { filterFunction } from '../utils/form';
|
package/src/containers/Table.vue
CHANGED
|
@@ -153,7 +153,7 @@
|
|
|
153
153
|
<script lang="ts">
|
|
154
154
|
/* eslint-disable no-param-reassign */
|
|
155
155
|
import { computed, defineComponent, inject, onMounted, PropType, ref, toRefs } from 'vue';
|
|
156
|
-
import { ArrowDown, ArrowUp, Delete, FullScreen, Grid } from '@element-plus/icons';
|
|
156
|
+
import { ArrowDown, ArrowUp, Delete, FullScreen, Grid } from '@element-plus/icons-vue';
|
|
157
157
|
import { ElMessage, UploadFile } from 'element-plus';
|
|
158
158
|
import { cloneDeep } from 'lodash-es';
|
|
159
159
|
import Sortable, { SortableEvent } from 'sortablejs';
|
package/src/fields/Cascader.vue
CHANGED
|
@@ -24,11 +24,9 @@ import {
|
|
|
24
24
|
getCurrentInstance,
|
|
25
25
|
inject,
|
|
26
26
|
PropType,
|
|
27
|
-
Ref,
|
|
28
27
|
ref,
|
|
29
28
|
watchEffect,
|
|
30
29
|
} from 'vue';
|
|
31
|
-
import { ElCascader, ElDialog } from 'element-plus';
|
|
32
30
|
|
|
33
31
|
import { CascaderConfig, FormState } from '../schema';
|
|
34
32
|
import { getConfig } from '../utils/config';
|
|
@@ -56,11 +54,11 @@ export default defineComponent({
|
|
|
56
54
|
|
|
57
55
|
const requestFunc = getConfig('request') as Function;
|
|
58
56
|
|
|
59
|
-
const cascader
|
|
60
|
-
const dialog
|
|
57
|
+
const cascader = ref<any>();
|
|
58
|
+
const dialog = ref<any>();
|
|
61
59
|
|
|
62
60
|
const options = Array.isArray(props.config.options) ? ref(props.config.options) : ref([]);
|
|
63
|
-
const remoteData
|
|
61
|
+
const remoteData = ref<any>(null);
|
|
64
62
|
|
|
65
63
|
const setRemoteOptions = async function () {
|
|
66
64
|
const { config } = props;
|
|
@@ -1,36 +1,29 @@
|
|
|
1
1
|
<template>
|
|
2
|
-
<
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
></el-color-picker>
|
|
10
|
-
</div>
|
|
2
|
+
<el-color-picker
|
|
3
|
+
v-model="model[name]"
|
|
4
|
+
:size="size"
|
|
5
|
+
:disabled="disabled"
|
|
6
|
+
:showAlpha="true"
|
|
7
|
+
@change="changeHandler"
|
|
8
|
+
></el-color-picker>
|
|
11
9
|
</template>
|
|
12
10
|
|
|
13
|
-
<script lang="ts">
|
|
14
|
-
import { defineComponent, PropType } from 'vue';
|
|
15
|
-
|
|
11
|
+
<script lang="ts" setup>
|
|
16
12
|
import { ColorPickConfig } from '../schema';
|
|
17
|
-
import fieldProps from '../utils/fieldProps';
|
|
18
13
|
import { useAddField } from '../utils/useAddField';
|
|
19
|
-
export default defineComponent({
|
|
20
|
-
name: 'm-fields-color-picker',
|
|
21
|
-
});
|
|
22
|
-
</script>
|
|
23
14
|
|
|
24
|
-
|
|
25
|
-
|
|
15
|
+
const props = defineProps<{
|
|
16
|
+
config: ColorPickConfig;
|
|
17
|
+
model: any;
|
|
18
|
+
initValues?: any;
|
|
19
|
+
values?: any;
|
|
20
|
+
name: string;
|
|
21
|
+
prop: string;
|
|
22
|
+
disabled?: boolean;
|
|
23
|
+
size: 'mini' | 'small' | 'medium';
|
|
24
|
+
}>();
|
|
26
25
|
|
|
27
|
-
const
|
|
28
|
-
...fieldProps,
|
|
29
|
-
config: {
|
|
30
|
-
type: Object as PropType<ColorPickConfig>,
|
|
31
|
-
required: true,
|
|
32
|
-
},
|
|
33
|
-
});
|
|
26
|
+
const emit = defineEmits(['change']);
|
|
34
27
|
|
|
35
28
|
useAddField(props.prop);
|
|
36
29
|
|
package/src/fields/Daterange.vue
CHANGED
|
@@ -13,70 +13,91 @@
|
|
|
13
13
|
></el-date-picker>
|
|
14
14
|
</template>
|
|
15
15
|
|
|
16
|
-
<script lang="ts">
|
|
17
|
-
import {
|
|
16
|
+
<script lang="ts" setup>
|
|
17
|
+
import { ref, watch } from 'vue';
|
|
18
18
|
|
|
19
19
|
import { datetimeFormatter } from '@tmagic/utils';
|
|
20
20
|
|
|
21
21
|
import { DaterangeConfig } from '../schema';
|
|
22
|
-
import fieldProps from '../utils/fieldProps';
|
|
23
22
|
import { useAddField } from '../utils/useAddField';
|
|
24
23
|
|
|
25
|
-
|
|
26
|
-
|
|
24
|
+
const props = defineProps<{
|
|
25
|
+
config: DaterangeConfig;
|
|
26
|
+
model: any;
|
|
27
|
+
initValues?: any;
|
|
28
|
+
values?: any;
|
|
29
|
+
name: string;
|
|
30
|
+
prop: string;
|
|
31
|
+
disabled?: boolean;
|
|
32
|
+
size: 'mini' | 'small' | 'medium';
|
|
33
|
+
}>();
|
|
27
34
|
|
|
28
|
-
|
|
29
|
-
...fieldProps,
|
|
30
|
-
config: {
|
|
31
|
-
type: Object as PropType<DaterangeConfig>,
|
|
32
|
-
required: true,
|
|
33
|
-
},
|
|
34
|
-
},
|
|
35
|
+
const emit = defineEmits(['change']);
|
|
35
36
|
|
|
36
|
-
|
|
37
|
+
useAddField(props.prop);
|
|
37
38
|
|
|
38
|
-
|
|
39
|
-
|
|
39
|
+
// eslint-disable-next-line vue/no-setup-props-destructure
|
|
40
|
+
const { names } = props.config;
|
|
41
|
+
const value = ref<(Date | undefined)[] | null>([]);
|
|
40
42
|
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
43
|
+
if (props.model !== undefined) {
|
|
44
|
+
if (names?.length) {
|
|
45
|
+
watch(
|
|
46
|
+
[() => props.model[names[0]], () => props.model[names[1]]],
|
|
47
|
+
([start, end], [preStart, preEnd]) => {
|
|
48
|
+
if (!value.value) {
|
|
49
|
+
value.value = [];
|
|
50
|
+
}
|
|
51
|
+
if (!start || !end) value.value = [];
|
|
52
|
+
if (start !== preStart) value.value[0] = new Date(start);
|
|
53
|
+
if (end !== preEnd) value.value[1] = new Date(end);
|
|
54
|
+
},
|
|
55
|
+
{
|
|
56
|
+
immediate: true,
|
|
57
|
+
},
|
|
58
|
+
);
|
|
59
|
+
} else if (props.name && props.model[props.name]) {
|
|
60
|
+
watch(
|
|
61
|
+
() => props.model[props.name],
|
|
62
|
+
(start, preStart) => {
|
|
63
|
+
if (start !== preStart) value.value = start.map((item: string) => (item ? new Date(item) : undefined));
|
|
64
|
+
},
|
|
65
|
+
{
|
|
66
|
+
immediate: true,
|
|
67
|
+
},
|
|
68
|
+
);
|
|
69
|
+
}
|
|
70
|
+
}
|
|
44
71
|
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
value.value = props.model[props.name].map((item: string) => datetimeFormatter(item, ''));
|
|
50
|
-
}
|
|
72
|
+
const setValue = (v: Date[] | Date) => {
|
|
73
|
+
names?.forEach((item, index) => {
|
|
74
|
+
if (!props.model) {
|
|
75
|
+
return;
|
|
51
76
|
}
|
|
77
|
+
if (Array.isArray(v)) {
|
|
78
|
+
props.model[item] = datetimeFormatter(v[index]?.toString(), '');
|
|
79
|
+
} else {
|
|
80
|
+
props.model[item] = undefined;
|
|
81
|
+
}
|
|
82
|
+
});
|
|
83
|
+
};
|
|
52
84
|
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
names.forEach((item, index) => {
|
|
56
|
-
if (props.model) {
|
|
57
|
-
props.model[item] = datetimeFormatter(v[index].toString(), '');
|
|
58
|
-
}
|
|
59
|
-
});
|
|
60
|
-
} else if (props.model && props.name && v instanceof Date) {
|
|
61
|
-
props.model[props.name] = datetimeFormatter(v.toString(), '');
|
|
62
|
-
} else if (names?.length) {
|
|
63
|
-
names.forEach((item) => {
|
|
64
|
-
if (props.model) {
|
|
65
|
-
props.model[item] = undefined;
|
|
66
|
-
}
|
|
67
|
-
});
|
|
68
|
-
} else if (props.name) {
|
|
69
|
-
props.model[props.name] = undefined;
|
|
70
|
-
}
|
|
71
|
-
};
|
|
85
|
+
const changeHandler = (v: Date[]) => {
|
|
86
|
+
const value = v || [];
|
|
72
87
|
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
}
|
|
88
|
+
if (props.name) {
|
|
89
|
+
emit(
|
|
90
|
+
'change',
|
|
91
|
+
value.map((item?: Date) => {
|
|
92
|
+
if (item) return datetimeFormatter(item, '');
|
|
93
|
+
return undefined;
|
|
94
|
+
}),
|
|
95
|
+
);
|
|
96
|
+
} else {
|
|
97
|
+
if (names?.length) {
|
|
98
|
+
setValue(value);
|
|
99
|
+
}
|
|
100
|
+
emit('change', value);
|
|
101
|
+
}
|
|
102
|
+
};
|
|
82
103
|
</script>
|
package/src/fields/Display.vue
CHANGED
|
@@ -1,33 +1,23 @@
|
|
|
1
1
|
<template>
|
|
2
|
-
<span v-if="model">{{ model[
|
|
2
|
+
<span v-if="model">{{ model[name] }}</span>
|
|
3
3
|
</template>
|
|
4
4
|
|
|
5
|
-
<script lang="ts">
|
|
6
|
-
import { computed, defineComponent, PropType } from 'vue';
|
|
7
|
-
|
|
5
|
+
<script setup lang="ts">
|
|
8
6
|
import { DisplayConfig } from '../schema';
|
|
9
|
-
import fieldProps from '../utils/fieldProps';
|
|
10
7
|
import { useAddField } from '../utils/useAddField';
|
|
11
8
|
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
config: {
|
|
21
|
-
type: Object as PropType<DisplayConfig>,
|
|
22
|
-
required: true,
|
|
23
|
-
},
|
|
24
|
-
});
|
|
25
|
-
|
|
26
|
-
const n = computed(() => props.name || props.config.name || '');
|
|
9
|
+
const props = defineProps<{
|
|
10
|
+
config: DisplayConfig;
|
|
11
|
+
model: any;
|
|
12
|
+
initValues?: any;
|
|
13
|
+
values?: any;
|
|
14
|
+
name: string;
|
|
15
|
+
prop: string;
|
|
16
|
+
}>();
|
|
27
17
|
|
|
28
|
-
if (props.config.initValue &&
|
|
29
|
-
// eslint-disable-next-line
|
|
30
|
-
props.model[
|
|
18
|
+
if (props.config.initValue && props.model) {
|
|
19
|
+
// eslint-disable-next-line vue/no-setup-props-destructure
|
|
20
|
+
props.model[props.name] = props.config.initValue;
|
|
31
21
|
}
|
|
32
22
|
|
|
33
23
|
useAddField(props.prop);
|
package/src/fields/Hidden.vue
CHANGED
|
@@ -1,29 +1,19 @@
|
|
|
1
1
|
<template>
|
|
2
|
-
<input v-if="model" v-model="model[
|
|
2
|
+
<input v-if="model" v-model="model[name]" type="hidden" />
|
|
3
3
|
</template>
|
|
4
4
|
|
|
5
|
-
<script lang="ts">
|
|
6
|
-
import { computed, defineComponent, PropType } from 'vue';
|
|
7
|
-
|
|
5
|
+
<script setup lang="ts">
|
|
8
6
|
import { HiddenConfig } from '../schema';
|
|
9
|
-
import fieldProps from '../utils/fieldProps';
|
|
10
7
|
import { useAddField } from '../utils/useAddField';
|
|
11
8
|
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
config: {
|
|
21
|
-
type: Object as PropType<HiddenConfig>,
|
|
22
|
-
required: true,
|
|
23
|
-
},
|
|
24
|
-
});
|
|
25
|
-
|
|
26
|
-
const n = computed(() => props.name || props.config.name || '');
|
|
9
|
+
const props = defineProps<{
|
|
10
|
+
config: HiddenConfig;
|
|
11
|
+
model: any;
|
|
12
|
+
initValues?: any;
|
|
13
|
+
values?: any;
|
|
14
|
+
name: string;
|
|
15
|
+
prop: string;
|
|
16
|
+
}>();
|
|
27
17
|
|
|
28
18
|
useAddField(props.prop);
|
|
29
19
|
</script>
|
package/src/fields/Select.vue
CHANGED
|
@@ -27,7 +27,6 @@
|
|
|
27
27
|
|
|
28
28
|
<script lang="ts">
|
|
29
29
|
import { defineComponent, inject, onBeforeMount, onMounted, PropType, Ref, ref, watch } from 'vue';
|
|
30
|
-
import { ElSelect } from 'element-plus';
|
|
31
30
|
|
|
32
31
|
import { FormState, SelectConfig, SelectGroupOption, SelectOption } from '../schema';
|
|
33
32
|
import { getConfig } from '../utils/config';
|
|
@@ -56,7 +55,7 @@ export default defineComponent({
|
|
|
56
55
|
if (!props.model) throw new Error('不能没有model');
|
|
57
56
|
useAddField(props.prop);
|
|
58
57
|
|
|
59
|
-
const select = ref<
|
|
58
|
+
const select = ref<any>();
|
|
60
59
|
const mForm = inject<FormState | undefined>('mForm');
|
|
61
60
|
const options = ref<SelectOption[] | SelectGroupOption[]>([]);
|
|
62
61
|
const localOptions = ref<SelectOption[] | SelectGroupOption[]>([]);
|
package/src/fields/Text.vue
CHANGED
|
@@ -26,6 +26,8 @@
|
|
|
26
26
|
<script lang="ts">
|
|
27
27
|
import { computed, defineComponent, inject, PropType } from 'vue';
|
|
28
28
|
|
|
29
|
+
import { isNumber } from '@tmagic/utils';
|
|
30
|
+
|
|
29
31
|
import { FormState, TextConfig } from '../schema';
|
|
30
32
|
import fieldProps from '../utils/fieldProps';
|
|
31
33
|
import { useAddField } from '../utils/useAddField';
|
|
@@ -86,7 +88,7 @@ export default defineComponent({
|
|
|
86
88
|
const value = props.model[modelName.value];
|
|
87
89
|
let num;
|
|
88
90
|
let unit;
|
|
89
|
-
if (
|
|
91
|
+
if (isNumber(value)) {
|
|
90
92
|
num = +value;
|
|
91
93
|
} else {
|
|
92
94
|
value.replace(/^([0-9.]+)([a-z%]+)$/, ($0: string, $1: string, $2: string) => {
|
|
@@ -100,7 +102,7 @@ export default defineComponent({
|
|
|
100
102
|
}
|
|
101
103
|
|
|
102
104
|
const ctrl = navigator.platform.match('Mac') ? $event.metaKey : $event.ctrlKey;
|
|
103
|
-
const
|
|
105
|
+
const shift = $event.shiftKey;
|
|
104
106
|
const alt = $event.altKey;
|
|
105
107
|
|
|
106
108
|
if (arrowUp) {
|
|
@@ -108,7 +110,7 @@ export default defineComponent({
|
|
|
108
110
|
num += 100;
|
|
109
111
|
} else if (alt) {
|
|
110
112
|
num = (num * 10000 + 1000) / 10000;
|
|
111
|
-
} else if (
|
|
113
|
+
} else if (shift) {
|
|
112
114
|
num = num + 10;
|
|
113
115
|
} else {
|
|
114
116
|
num += 1;
|
|
@@ -118,7 +120,7 @@ export default defineComponent({
|
|
|
118
120
|
num -= 100;
|
|
119
121
|
} else if (alt) {
|
|
120
122
|
num = (num * 10000 - 1000) / 10000;
|
|
121
|
-
} else if (
|
|
123
|
+
} else if (shift) {
|
|
122
124
|
num -= 10;
|
|
123
125
|
} else {
|
|
124
126
|
num -= 1;
|
package/src/index.ts
CHANGED
|
@@ -105,17 +105,17 @@ const install = (app: App, opt: any) => {
|
|
|
105
105
|
app.component(Text.name, Text);
|
|
106
106
|
app.component(Number.name, Number);
|
|
107
107
|
app.component(Textarea.name, Textarea);
|
|
108
|
-
app.component(
|
|
108
|
+
app.component('m-fields-hidden', Hidden);
|
|
109
109
|
app.component(Date.name, Date);
|
|
110
110
|
app.component(DateTime.name, DateTime);
|
|
111
111
|
app.component(Time.name, Time);
|
|
112
112
|
app.component(Checkbox.name, Checkbox);
|
|
113
113
|
app.component(Switch.name, Switch);
|
|
114
|
-
app.component(
|
|
115
|
-
app.component(
|
|
114
|
+
app.component('m-fields-daterange', Daterange);
|
|
115
|
+
app.component('m-fields-color-picker', ColorPicker);
|
|
116
116
|
app.component(CheckboxGroup.name, CheckboxGroup);
|
|
117
117
|
app.component(RadioGroup.name, RadioGroup);
|
|
118
|
-
app.component(
|
|
118
|
+
app.component('m-fields-display', Display);
|
|
119
119
|
app.component(Link.name, Link);
|
|
120
120
|
app.component(Select.name, Select);
|
|
121
121
|
app.component(Cascader.name, Cascader);
|