@tmagic/form 1.0.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.
Files changed (94) hide show
  1. package/dist/style.css +161 -0
  2. package/dist/tmagic-form.es.js +3749 -0
  3. package/dist/tmagic-form.es.js.map +1 -0
  4. package/dist/tmagic-form.umd.js +3790 -0
  5. package/dist/tmagic-form.umd.js.map +1 -0
  6. package/dist/types/src/Form.vue.d.ts +304 -0
  7. package/dist/types/src/FormDialog.vue.d.ts +641 -0
  8. package/dist/types/src/containers/Container.vue.d.ts +69 -0
  9. package/dist/types/src/containers/Fieldset.vue.d.ts +56 -0
  10. package/dist/types/src/containers/GroupList.vue.d.ts +56 -0
  11. package/dist/types/src/containers/GroupListItem.vue.d.ts +72 -0
  12. package/dist/types/src/containers/Panel.vue.d.ts +41 -0
  13. package/dist/types/src/containers/Row.vue.d.ts +42 -0
  14. package/dist/types/src/containers/Step.vue.d.ts +45 -0
  15. package/dist/types/src/containers/Table.vue.d.ts +1401 -0
  16. package/dist/types/src/containers/Tabs.vue.d.ts +45 -0
  17. package/dist/types/src/fields/Cascader.vue.d.ts +1748 -0
  18. package/dist/types/src/fields/Checkbox.vue.d.ts +59 -0
  19. package/dist/types/src/fields/CheckboxGroup.vue.d.ts +56 -0
  20. package/dist/types/src/fields/Date.vue.d.ts +58 -0
  21. package/dist/types/src/fields/DateTime.vue.d.ts +57 -0
  22. package/dist/types/src/fields/Daterange.vue.d.ts +57 -0
  23. package/dist/types/src/fields/Display.vue.d.ts +3 -0
  24. package/dist/types/src/fields/DynamicField.vue.d.ts +76 -0
  25. package/dist/types/src/fields/Hidden.vue.d.ts +3 -0
  26. package/dist/types/src/fields/Link.vue.d.ts +1365 -0
  27. package/dist/types/src/fields/Number.vue.d.ts +59 -0
  28. package/dist/types/src/fields/RadioGroup.vue.d.ts +55 -0
  29. package/dist/types/src/fields/Select.vue.d.ts +975 -0
  30. package/dist/types/src/fields/Switch.vue.d.ts +59 -0
  31. package/dist/types/src/fields/Text.vue.d.ts +61 -0
  32. package/dist/types/src/fields/Textarea.vue.d.ts +56 -0
  33. package/dist/types/src/fields/Time.vue.d.ts +54 -0
  34. package/dist/types/src/index.d.ts +36 -0
  35. package/dist/types/src/schema.d.ts +495 -0
  36. package/dist/types/src/shims-vue.d.ts +6 -0
  37. package/dist/types/src/utils/config.d.ts +3 -0
  38. package/dist/types/src/utils/fieldProps.d.ts +21 -0
  39. package/dist/types/src/utils/form.d.ts +8 -0
  40. package/dist/types/src/utils/useAddField.d.ts +1 -0
  41. package/dist/types/src/vite-env.d.ts +1 -0
  42. package/package.json +51 -0
  43. package/src/Form.vue +188 -0
  44. package/src/FormDialog.vue +163 -0
  45. package/src/containers/Container.vue +263 -0
  46. package/src/containers/Fieldset.vue +138 -0
  47. package/src/containers/GroupList.vue +152 -0
  48. package/src/containers/GroupListItem.vue +159 -0
  49. package/src/containers/Panel.vue +106 -0
  50. package/src/containers/Row.vue +68 -0
  51. package/src/containers/Step.vue +82 -0
  52. package/src/containers/Table.vue +624 -0
  53. package/src/containers/Tabs.vue +176 -0
  54. package/src/fields/Cascader.vue +147 -0
  55. package/src/fields/Checkbox.vue +67 -0
  56. package/src/fields/CheckboxGroup.vue +44 -0
  57. package/src/fields/ColorPicker.vue +38 -0
  58. package/src/fields/Date.vue +51 -0
  59. package/src/fields/DateTime.vue +59 -0
  60. package/src/fields/Daterange.vue +75 -0
  61. package/src/fields/Display.vue +34 -0
  62. package/src/fields/DynamicField.vue +109 -0
  63. package/src/fields/Hidden.vue +29 -0
  64. package/src/fields/Link.vue +112 -0
  65. package/src/fields/Number.vue +53 -0
  66. package/src/fields/RadioGroup.vue +33 -0
  67. package/src/fields/Select.vue +393 -0
  68. package/src/fields/Switch.vue +65 -0
  69. package/src/fields/Text.vue +134 -0
  70. package/src/fields/Textarea.vue +62 -0
  71. package/src/fields/Time.vue +48 -0
  72. package/src/index.ts +127 -0
  73. package/src/schema.ts +638 -0
  74. package/src/shims-vue.d.ts +6 -0
  75. package/src/theme/date-time.scss +7 -0
  76. package/src/theme/fieldset.scss +24 -0
  77. package/src/theme/form-dialog.scss +13 -0
  78. package/src/theme/form.scss +30 -0
  79. package/src/theme/group-list.scss +23 -0
  80. package/src/theme/index.scss +9 -0
  81. package/src/theme/link.scss +3 -0
  82. package/src/theme/panel.scss +18 -0
  83. package/src/theme/select.scss +3 -0
  84. package/src/theme/table.scss +69 -0
  85. package/src/theme/tabs.scss +25 -0
  86. package/src/utils/config.ts +27 -0
  87. package/src/utils/containerProps.ts +50 -0
  88. package/src/utils/createForm.ts +25 -0
  89. package/src/utils/fieldProps.ts +39 -0
  90. package/src/utils/form.ts +266 -0
  91. package/src/utils/useAddField.ts +40 -0
  92. package/src/vite-env.d.ts +1 -0
  93. package/tsconfig.json +9 -0
  94. package/vite.config.ts +27 -0
@@ -0,0 +1,176 @@
1
+ <template>
2
+ <el-tabs
3
+ v-model="activeTabName"
4
+ :class="config.dynamic ? 'magic-form-dynamic-tab' : 'magic-form-tab'"
5
+ :type="config.tabType"
6
+ :editable="config.editable || false"
7
+ :tab-position="config.tabPosition || 'top'"
8
+ @tab-click="tabClickHandler"
9
+ @tab-add="onTabAdd"
10
+ @tab-remove="onTabRemove"
11
+ >
12
+ <template v-for="(tab, tabIndex) in tabs">
13
+ <el-tab-pane
14
+ v-if="display(tab.display) && tabItems(tab).length"
15
+ :key="tab[mForm?.keyProp || '__key'] ?? tabIndex"
16
+ :name="filter(tab.status) || tabIndex.toString()"
17
+ :label="filter(tab.title)"
18
+ :lazy="tab.lazy || false"
19
+ >
20
+ <m-form-container
21
+ v-for="item in tabItems(tab)"
22
+ :key="item[mForm?.keyProp || '__key']"
23
+ :config="item"
24
+ :model="config.dynamic ? model[config.name || ''][tabIndex] : tab.name ? model[tab.name] : model"
25
+ :prop="config.dynamic ? `${prop}${prop ? '.' : ''}${String(tabIndex)}` : prop"
26
+ :size="size"
27
+ :label-width="tab.labelWidth || labelWidth"
28
+ :expand-more="expandMore"
29
+ @change="changeHandler"
30
+ ></m-form-container>
31
+ </el-tab-pane>
32
+ </template>
33
+ </el-tabs>
34
+ </template>
35
+
36
+ <script lang="ts">
37
+ /* eslint-disable vue/no-mutating-props */
38
+ import { computed, defineComponent, inject, PropType, ref, watchEffect } from 'vue';
39
+ import { cloneDeep } from 'lodash-es';
40
+
41
+ import { FormState, FormValue, TabConfig, TabPaneConfig } from '../schema';
42
+ import { display, filterFunction } from '../utils/form';
43
+
44
+ const getActive = (mForm: FormState | undefined, props: any, activeTabName: string) => {
45
+ const { config, model, prop } = props;
46
+ const { active } = config;
47
+
48
+ if (typeof active === 'function') return active(mForm, { model, formValue: mForm?.values, prop });
49
+ if (+activeTabName >= props.config.items.length) return '0';
50
+ if (typeof active !== 'undefined') return active;
51
+
52
+ return '0';
53
+ };
54
+
55
+ const tabClickHandler = (mForm: FormState | undefined, tab: any, props: any) => {
56
+ const { config, model, prop } = props;
57
+ if (typeof config.onTabClick === 'function') {
58
+ config.onTabClick(mForm, tab, { model, formValue: mForm?.values, prop });
59
+ }
60
+
61
+ const tabConfig = config.items.find((item: TabPaneConfig) => tab.name === item.status);
62
+ if (tabConfig && typeof tabConfig.onTabClick === 'function') {
63
+ tabConfig.onTabClick(mForm, tab, { model, formValue: mForm?.values, prop });
64
+ }
65
+ };
66
+
67
+ const Tab = defineComponent({
68
+ name: 'm-form-tab',
69
+
70
+ props: {
71
+ labelWidth: String,
72
+ expandMore: Boolean,
73
+
74
+ model: {
75
+ type: Object,
76
+ default: () => ({}),
77
+ },
78
+
79
+ config: {
80
+ type: Object as PropType<TabConfig>,
81
+ default: () => ({}),
82
+ },
83
+
84
+ prop: String,
85
+
86
+ size: String,
87
+ },
88
+
89
+ emits: {
90
+ change(values: FormValue) {
91
+ return values;
92
+ },
93
+ },
94
+
95
+ setup(props, { emit }) {
96
+ const mForm = inject<FormState | undefined>('mForm');
97
+ const activeTabName = ref(getActive(mForm, props, ''));
98
+
99
+ const tabs = computed(() => {
100
+ if (props.config.dynamic) {
101
+ if (!props.config.name) throw new Error('dynamic tab 必须配置name');
102
+ return props.model[props.config.name] || [];
103
+ }
104
+ return props.config.items;
105
+ });
106
+
107
+ const filter = (config: any) => filterFunction(mForm, config, props);
108
+
109
+ watchEffect(() => {
110
+ if (typeof props.config.activeChange === 'function') {
111
+ props.config.activeChange(mForm, activeTabName.value, {
112
+ model: props.model,
113
+ prop: props.prop,
114
+ });
115
+ }
116
+ });
117
+
118
+ return {
119
+ mForm,
120
+
121
+ activeTabName,
122
+
123
+ tabs,
124
+
125
+ filter,
126
+
127
+ tabItems: (tab: TabPaneConfig) => (props.config.dynamic ? props.config.items : tab.items),
128
+
129
+ tabClickHandler: (tab: any) => tabClickHandler(mForm, tab, props),
130
+
131
+ onTabAdd: () => {
132
+ if (!props.config.name) throw new Error('dynamic tab 必须配置name');
133
+
134
+ if (typeof props.config.onTabAdd === 'function') {
135
+ props.config.onTabAdd(mForm, { model: props.model });
136
+ } else if (tabs.value.length > 0) {
137
+ const newObj = cloneDeep(tabs.value[0]);
138
+ newObj.title = `标签${tabs.value.length + 1}`;
139
+ props.model[props.config.name].push(newObj);
140
+ }
141
+ emit('change', props.model);
142
+ mForm?.$emit('field-change', props.prop, props.model[props.config.name]);
143
+ },
144
+
145
+ onTabRemove: (tabName: string) => {
146
+ if (!props.config.name) throw new Error('dynamic tab 必须配置name');
147
+
148
+ if (typeof props.config.onTabRemove === 'function') {
149
+ props.config.onTabRemove(mForm, tabName, { model: props.model });
150
+ } else {
151
+ props.model[props.config.name].splice(+tabName, 1);
152
+
153
+ // 防止删除后没有选中的问题
154
+ if (tabName < activeTabName.value || activeTabName.value >= props.model[props.config.name].length) {
155
+ activeTabName.value = (+activeTabName.value - 1).toString();
156
+ tabClickHandler(mForm, { name: activeTabName.value }, props);
157
+ }
158
+ }
159
+ emit('change', props.model);
160
+ mForm?.$emit('field-change', props.prop, props.model[props.config.name]);
161
+ },
162
+
163
+ display: (displayConfig: any) => display(mForm, displayConfig, props),
164
+
165
+ changeHandler: () => {
166
+ emit('change', props.model);
167
+ if (typeof props.config.onChange === 'function') {
168
+ props.config.onChange(mForm, { model: props.model });
169
+ }
170
+ },
171
+ };
172
+ },
173
+ });
174
+
175
+ export default Tab;
176
+ </script>
@@ -0,0 +1,147 @@
1
+ <template>
2
+ <div class="m-cascader" style="width: 100%">
3
+ <el-cascader
4
+ v-model="model[name]"
5
+ ref="cascader"
6
+ style="width: 100%"
7
+ clearable
8
+ filterable
9
+ :size="size"
10
+ :placeholder="config.placeholder"
11
+ :disabled="disabled"
12
+ :options="options"
13
+ :props="{ multiple: config.multiple }"
14
+ @change="changeHandler"
15
+ ></el-cascader>
16
+ </div>
17
+ </template>
18
+
19
+ <script lang="ts">
20
+ import {
21
+ ComponentInternalInstance,
22
+ computed,
23
+ defineComponent,
24
+ getCurrentInstance,
25
+ inject,
26
+ PropType,
27
+ Ref,
28
+ ref,
29
+ watchEffect,
30
+ } from 'vue';
31
+ import { ElCascader, ElDialog } from 'element-plus';
32
+
33
+ import { CascaderConfig, FormState } from '../schema';
34
+ import { getConfig } from '../utils/config';
35
+ import fieldProps from '../utils/fieldProps';
36
+ import { useAddField } from '../utils/useAddField';
37
+
38
+ export default defineComponent({
39
+ name: 'm-fields-cascader',
40
+
41
+ props: {
42
+ ...fieldProps,
43
+ config: {
44
+ type: Object as PropType<CascaderConfig>,
45
+ required: true,
46
+ },
47
+ },
48
+
49
+ emits: ['change'],
50
+
51
+ setup(props, { emit }) {
52
+ const mForm = inject<FormState | null>('mForm');
53
+ const vm = getCurrentInstance() as ComponentInternalInstance;
54
+
55
+ useAddField(props.prop);
56
+
57
+ const requestFunc = getConfig('request') as Function;
58
+
59
+ const cascader: Ref<null | typeof ElCascader> = ref(null);
60
+ const dialog: Ref<null | typeof ElDialog> = ref(null);
61
+
62
+ const options = Array.isArray(props.config.options) ? ref(props.config.options) : ref([]);
63
+ const remoteData: Ref<any> = ref(null);
64
+
65
+ const setRemoteOptions = async function () {
66
+ const { config } = props;
67
+ const { option } = config;
68
+ if (!option) return;
69
+ let { body } = option;
70
+
71
+ const postOptions: Record<string, any> = {
72
+ url: option.url,
73
+ cache: option.cache,
74
+ timeout: option.timeout,
75
+ data: {},
76
+ };
77
+
78
+ if (body && mForm) {
79
+ if (typeof body === 'function' && props.model && mForm) {
80
+ body = body(mForm, {
81
+ model: props.model,
82
+ formValue: null,
83
+ formValues: mForm.values,
84
+ });
85
+ }
86
+ postOptions.data = body;
87
+ }
88
+
89
+ const res = await requestFunc(postOptions);
90
+
91
+ remoteData.value = res[option.root];
92
+ if (remoteData.value && typeof option?.item === 'function') {
93
+ options.value = option.item(res[option.root]);
94
+ }
95
+ };
96
+
97
+ // 初始化
98
+ if (typeof props.config.options === 'function' && props.model && mForm) {
99
+ watchEffect(
100
+ () =>
101
+ (options.value = (props.config.options as Function)(vm, { model: props.model, formValues: mForm.values })),
102
+ );
103
+ } else if (!props.config.options || !props.config.options.length || props.config.remote) {
104
+ Promise.resolve(setRemoteOptions());
105
+ }
106
+
107
+ const action = computed(() => {
108
+ if (props.config.add?.action.method === 'post') {
109
+ return (options: any) =>
110
+ requestFunc({
111
+ ...props.config?.add?.action.body,
112
+ ...options,
113
+ });
114
+ }
115
+ return null;
116
+ });
117
+
118
+ return {
119
+ options,
120
+ remoteData,
121
+ addButtonStyle: {
122
+ top: 0,
123
+ left: 0,
124
+ width: 'auto',
125
+ },
126
+ dialogVisible: false,
127
+ cascader,
128
+ dialog,
129
+ action,
130
+ setRemoteOptions,
131
+ changeHandler: (value: any) => {
132
+ if (!cascader.value) return;
133
+ cascader.value.query = '';
134
+ cascader.value.previousQuery = null;
135
+ emit('change', value);
136
+ },
137
+ addHandler: () => {
138
+ if (!dialog.value) return;
139
+ dialog.value.dialogVisible = true;
140
+ },
141
+ editAfterAction: () => {
142
+ setRemoteOptions();
143
+ },
144
+ };
145
+ },
146
+ });
147
+ </script>
@@ -0,0 +1,67 @@
1
+ <template>
2
+ <el-checkbox
3
+ v-model="model[name]"
4
+ :size="size"
5
+ :trueLabel="activeValue"
6
+ :falseLabel="inactiveValue"
7
+ :disabled="disabled"
8
+ :label="config.text"
9
+ @change="changeHandler"
10
+ ></el-checkbox>
11
+ </template>
12
+
13
+ <script lang="ts">
14
+ import { computed, defineComponent, PropType } from 'vue';
15
+
16
+ import { CheckboxConfig } from '../schema';
17
+ import fieldProps from '../utils/fieldProps';
18
+ import { useAddField } from '../utils/useAddField';
19
+
20
+ export default defineComponent({
21
+ name: 'm-fields-checkbox',
22
+
23
+ props: {
24
+ ...fieldProps,
25
+ config: {
26
+ type: Object as PropType<CheckboxConfig>,
27
+ required: true,
28
+ },
29
+ },
30
+
31
+ emits: ['change', 'input'],
32
+
33
+ setup(props, { emit }) {
34
+ useAddField(props.prop);
35
+
36
+ return {
37
+ activeValue: computed(() => {
38
+ if (typeof props.config.activeValue === 'undefined') {
39
+ if (props.config.filter === 'number') {
40
+ return 1;
41
+ }
42
+ } else {
43
+ return props.config.activeValue;
44
+ }
45
+
46
+ return 'true';
47
+ }),
48
+
49
+ inactiveValue: computed(() => {
50
+ if (typeof props.config.inactiveValue === 'undefined') {
51
+ if (props.config.filter === 'number') {
52
+ return 0;
53
+ }
54
+ } else {
55
+ return props.config.inactiveValue;
56
+ }
57
+
58
+ return 'false';
59
+ }),
60
+
61
+ changeHandler(value: number | boolean) {
62
+ emit('change', value);
63
+ },
64
+ };
65
+ },
66
+ });
67
+ </script>
@@ -0,0 +1,44 @@
1
+ <template>
2
+ <el-checkbox-group v-model="model[name]" :size="size" :disabled="disabled" @change="changeHandler">
3
+ <el-checkbox v-for="option in config.options" :label="option.value" :key="option.value"
4
+ >{{ option.text }}
5
+ </el-checkbox>
6
+ </el-checkbox-group>
7
+ </template>
8
+
9
+ <script lang="ts">
10
+ import { defineComponent, PropType } from 'vue';
11
+
12
+ import { CheckboxGroupConfig } from '../schema';
13
+ import fieldProps from '../utils/fieldProps';
14
+ import { useAddField } from '../utils/useAddField';
15
+
16
+ export default defineComponent({
17
+ name: 'm-fields-checkbox-group',
18
+
19
+ props: {
20
+ ...fieldProps,
21
+ config: {
22
+ type: Object as PropType<CheckboxGroupConfig>,
23
+ required: true,
24
+ },
25
+ },
26
+
27
+ emits: ['change'],
28
+
29
+ setup(props, { emit }) {
30
+ useAddField(props.prop);
31
+
32
+ // 初始化选项
33
+ if (props.model && !props.model[props.name]) {
34
+ // eslint-disable-next-line no-param-reassign
35
+ props.model[props.name] = [];
36
+ }
37
+ return {
38
+ changeHandler: (v: Array<string | number | boolean>) => {
39
+ emit('change', v);
40
+ },
41
+ };
42
+ },
43
+ });
44
+ </script>
@@ -0,0 +1,38 @@
1
+ <template>
2
+ <div v-if="model">
3
+ <el-color-picker
4
+ v-model="model[name]"
5
+ :size="size"
6
+ :disabled="disabled"
7
+ :showAlpha="true"
8
+ @change="changeHandler"
9
+ ></el-color-picker>
10
+ </div>
11
+ </template>
12
+
13
+ <script lang="ts">
14
+ import { defineComponent, PropType } from 'vue';
15
+
16
+ import { ColorPickConfig } from '../schema';
17
+ import fieldProps from '../utils/fieldProps';
18
+ import { useAddField } from '../utils/useAddField';
19
+ export default defineComponent({
20
+ name: 'm-fields-color-picker',
21
+ });
22
+ </script>
23
+
24
+ <script lang="ts" setup>
25
+ const emit = defineEmits(['change']);
26
+
27
+ const props = defineProps({
28
+ ...fieldProps,
29
+ config: {
30
+ type: Object as PropType<ColorPickConfig>,
31
+ required: true,
32
+ },
33
+ });
34
+
35
+ useAddField(props.prop);
36
+
37
+ const changeHandler = (value: string) => emit('change', value);
38
+ </script>
@@ -0,0 +1,51 @@
1
+ <template>
2
+ <div v-if="model">
3
+ <el-date-picker
4
+ v-model="model[modelName]"
5
+ type="date"
6
+ :size="size"
7
+ :placeholder="config.placeholder"
8
+ :disabled="disabled"
9
+ :format="config.format"
10
+ :value-format="config.format || 'YYYY-MM-DD HH:mm:ss'"
11
+ @change="changeHandler"
12
+ ></el-date-picker>
13
+ </div>
14
+ </template>
15
+
16
+ <script lang="ts">
17
+ import { computed, defineComponent, PropType } from 'vue';
18
+
19
+ import { datetimeFormatter } from '@tmagic/utils';
20
+
21
+ import { DateConfig } from '../schema';
22
+ import fieldProps from '../utils/fieldProps';
23
+ import { useAddField } from '../utils/useAddField';
24
+
25
+ export default defineComponent({
26
+ name: 'm-fields-date',
27
+
28
+ props: {
29
+ ...fieldProps,
30
+ config: {
31
+ type: Object as PropType<DateConfig>,
32
+ required: true,
33
+ },
34
+ },
35
+
36
+ emits: ['change', 'input'],
37
+
38
+ setup(props, { emit }) {
39
+ useAddField(props.prop);
40
+
41
+ const modelName = computed(() => props.prop || props.config.name || '');
42
+ props.model[modelName.value] = datetimeFormatter(props.model[modelName.value], '');
43
+ return {
44
+ modelName,
45
+ changeHandler(v: string) {
46
+ emit('change', v);
47
+ },
48
+ };
49
+ },
50
+ });
51
+ </script>
@@ -0,0 +1,59 @@
1
+ <template>
2
+ <div v-if="model">
3
+ <el-date-picker
4
+ v-model="model[name]"
5
+ popper-class="magic-datetime-picker-popper"
6
+ type="datetime"
7
+ :size="size"
8
+ :placeholder="config.placeholder"
9
+ :disabled="disabled"
10
+ :format="config.format || 'YYYY-MM-DD HH:mm:ss'"
11
+ :value-format="config.valueFormat || 'YYYY-MM-DD HH:mm:ss'"
12
+ @change="changeHandler"
13
+ ></el-date-picker>
14
+ </div>
15
+ </template>
16
+
17
+ <script lang="ts">
18
+ import { defineComponent, PropType } from 'vue';
19
+
20
+ import { datetimeFormatter } from '@tmagic/utils';
21
+
22
+ import { DateTimeConfig } from '../schema';
23
+ import fieldProps from '../utils/fieldProps';
24
+ import { useAddField } from '../utils/useAddField';
25
+
26
+ export default defineComponent({
27
+ name: 'm-fields-datetime',
28
+
29
+ props: {
30
+ ...fieldProps,
31
+ config: {
32
+ type: Object as PropType<DateTimeConfig>,
33
+ required: true,
34
+ },
35
+ },
36
+
37
+ emits: ['change'],
38
+
39
+ setup(props, { emit }) {
40
+ useAddField(props.prop);
41
+
42
+ const value = props.model?.[props.name].toString();
43
+ if (props.model) {
44
+ if (value === 'Invalid Date') {
45
+ props.model[props.name] = '';
46
+ } else {
47
+ props.model[props.name] = datetimeFormatter(props.model[props.name], '', props.config.valueFormat);
48
+ }
49
+ }
50
+
51
+ return {
52
+ value,
53
+ changeHandler: (v: Date) => {
54
+ emit('change', v);
55
+ },
56
+ };
57
+ },
58
+ });
59
+ </script>
@@ -0,0 +1,75 @@
1
+ <template>
2
+ <div>
3
+ <el-date-picker
4
+ v-model="value"
5
+ type="datetimerange"
6
+ range-separator="-"
7
+ start-placeholder="开始日期"
8
+ end-placeholder="结束日期"
9
+ :size="size"
10
+ :unlink-panels="true"
11
+ :disabled="disabled"
12
+ @change="changeHandler"
13
+ ></el-date-picker>
14
+ </div>
15
+ </template>
16
+
17
+ <script lang="ts">
18
+ import { defineComponent, PropType, ref } from 'vue';
19
+
20
+ import { datetimeFormatter } from '@tmagic/utils';
21
+
22
+ import { DaterangeConfig } from '../schema';
23
+ import fieldProps from '../utils/fieldProps';
24
+ import { useAddField } from '../utils/useAddField';
25
+
26
+ export default defineComponent({
27
+ name: 'm-fields-daterange',
28
+
29
+ props: {
30
+ ...fieldProps,
31
+ config: {
32
+ type: Object as PropType<DaterangeConfig>,
33
+ required: true,
34
+ },
35
+ },
36
+
37
+ emits: ['change'],
38
+
39
+ setup(props, { emit }) {
40
+ useAddField(props.prop);
41
+
42
+ // eslint-disable-next-line vue/no-setup-props-destructure
43
+ const { names } = props.config;
44
+ const value = ref<(string | number)[]>([]);
45
+
46
+ if (props.model !== undefined) {
47
+ if (names?.length) {
48
+ value.value = names.map((item) => datetimeFormatter(props.model?.[item], ''));
49
+ } else if (props.name && props.model[props.name]) {
50
+ value.value = props.model[props.name].map((item: string) => datetimeFormatter(item, ''));
51
+ }
52
+ }
53
+
54
+ const setValue = (v: Date[] | Date) => {
55
+ if (names?.length && v instanceof Array) {
56
+ names.forEach((item, index) => {
57
+ if (props.model) {
58
+ props.model[item] = datetimeFormatter(v[index].toString(), '');
59
+ }
60
+ });
61
+ } else if (props.model && props.name && v instanceof Date) {
62
+ props.model[props.name] = datetimeFormatter(v.toString(), '');
63
+ }
64
+ };
65
+
66
+ return {
67
+ value,
68
+ changeHandler(v: Date[]) {
69
+ setValue(v);
70
+ emit('change', v);
71
+ },
72
+ };
73
+ },
74
+ });
75
+ </script>
@@ -0,0 +1,34 @@
1
+ <template>
2
+ <span v-if="model">{{ model[n] }}</span>
3
+ </template>
4
+
5
+ <script lang="ts">
6
+ import { computed, defineComponent, PropType } from 'vue';
7
+
8
+ import { DisplayConfig } from '../schema';
9
+ import fieldProps from '../utils/fieldProps';
10
+ import { useAddField } from '../utils/useAddField';
11
+
12
+ export default defineComponent({
13
+ name: 'm-fields-display',
14
+ });
15
+ </script>
16
+
17
+ <script setup lang="ts">
18
+ const props = defineProps({
19
+ ...fieldProps,
20
+ config: {
21
+ type: Object as PropType<DisplayConfig>,
22
+ required: true,
23
+ },
24
+ });
25
+
26
+ const n = computed(() => props.name || props.config.name || '');
27
+
28
+ if (props.config.initValue && n.value && props.model) {
29
+ // eslint-disable-next-line no-param-reassign,vue/no-setup-props-destructure
30
+ props.model[n.value] = props.config.initValue;
31
+ }
32
+
33
+ useAddField(props.prop);
34
+ </script>