@tmagic/form 1.2.0-beta.8 → 1.2.0

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 (77) hide show
  1. package/dist/style.css +1 -1
  2. package/dist/{tmagic-form.mjs → tmagic-form.js} +322 -126
  3. package/dist/tmagic-form.js.map +1 -0
  4. package/dist/{tmagic-form.umd.js → tmagic-form.umd.cjs} +321 -124
  5. package/dist/tmagic-form.umd.cjs.map +1 -0
  6. package/package.json +10 -8
  7. package/src/Form.vue +11 -3
  8. package/src/FormDialog.vue +3 -1
  9. package/src/containers/Col.vue +3 -1
  10. package/src/containers/Container.vue +12 -6
  11. package/src/containers/Fieldset.vue +4 -1
  12. package/src/containers/GroupList.vue +4 -2
  13. package/src/containers/GroupListItem.vue +8 -5
  14. package/src/containers/Panel.vue +4 -1
  15. package/src/containers/Row.vue +3 -1
  16. package/src/containers/Step.vue +3 -1
  17. package/src/containers/Table.vue +44 -18
  18. package/src/containers/Tabs.vue +9 -4
  19. package/src/fields/Cascader.vue +2 -2
  20. package/src/fields/Checkbox.vue +2 -2
  21. package/src/fields/CheckboxGroup.vue +8 -3
  22. package/src/fields/ColorPicker.vue +2 -2
  23. package/src/fields/Date.vue +3 -3
  24. package/src/fields/DateTime.vue +2 -2
  25. package/src/fields/Daterange.vue +2 -2
  26. package/src/fields/Display.vue +1 -1
  27. package/src/fields/DynamicField.vue +2 -2
  28. package/src/fields/Hidden.vue +1 -1
  29. package/src/fields/Link.vue +2 -2
  30. package/src/fields/Number.vue +2 -2
  31. package/src/fields/RadioGroup.vue +9 -5
  32. package/src/fields/Select.vue +63 -24
  33. package/src/fields/SelectOptionGroups.vue +1 -1
  34. package/src/fields/SelectOptions.vue +1 -1
  35. package/src/fields/Switch.vue +2 -2
  36. package/src/fields/Text.vue +2 -2
  37. package/src/fields/Textarea.vue +2 -2
  38. package/src/fields/Time.vue +4 -2
  39. package/src/schema.ts +18 -4
  40. package/src/theme/form.scss +1 -1
  41. package/src/utils/form.ts +9 -5
  42. package/types/Form.vue.d.ts +32 -170
  43. package/types/FormDialog.vue.d.ts +4 -0
  44. package/types/containers/Col.vue.d.ts +12 -74
  45. package/types/containers/Container.vue.d.ts +17 -95
  46. package/types/containers/Fieldset.vue.d.ts +15 -87
  47. package/types/containers/GroupList.vue.d.ts +11 -71
  48. package/types/containers/GroupListItem.vue.d.ts +12 -80
  49. package/types/containers/Panel.vue.d.ts +4 -0
  50. package/types/containers/Row.vue.d.ts +12 -74
  51. package/types/containers/Step.vue.d.ts +13 -79
  52. package/types/containers/Table.vue.d.ts +4 -0
  53. package/types/containers/Tabs.vue.d.ts +12 -74
  54. package/types/fields/Cascader.vue.d.ts +12 -78
  55. package/types/fields/Checkbox.vue.d.ts +12 -78
  56. package/types/fields/CheckboxGroup.vue.d.ts +12 -78
  57. package/types/fields/ColorPicker.vue.d.ts +12 -78
  58. package/types/fields/Date.vue.d.ts +12 -78
  59. package/types/fields/DateTime.vue.d.ts +12 -78
  60. package/types/fields/Daterange.vue.d.ts +12 -78
  61. package/types/fields/Display.vue.d.ts +9 -65
  62. package/types/fields/DynamicField.vue.d.ts +12 -78
  63. package/types/fields/Hidden.vue.d.ts +9 -65
  64. package/types/fields/Link.vue.d.ts +12 -78
  65. package/types/fields/Number.vue.d.ts +12 -81
  66. package/types/fields/RadioGroup.vue.d.ts +12 -78
  67. package/types/fields/Select.vue.d.ts +12 -79
  68. package/types/fields/SelectOptionGroups.vue.d.ts +4 -50
  69. package/types/fields/SelectOptions.vue.d.ts +5 -53
  70. package/types/fields/Switch.vue.d.ts +12 -78
  71. package/types/fields/Text.vue.d.ts +12 -81
  72. package/types/fields/Textarea.vue.d.ts +12 -81
  73. package/types/fields/Time.vue.d.ts +12 -78
  74. package/types/schema.d.ts +17 -4
  75. package/types/utils/form.d.ts +2 -1
  76. package/dist/tmagic-form.mjs.map +0 -1
  77. package/dist/tmagic-form.umd.js.map +0 -1
@@ -12,7 +12,7 @@
12
12
  </div>
13
13
  </template>
14
14
 
15
- <script lang="ts" setup>
15
+ <script lang="ts" setup name="MFormDynamicField">
16
16
  /**
17
17
  * 动态表单,目前只支持input类型字段
18
18
  * inputType: 'dynamic-field',
@@ -39,7 +39,7 @@ const props = defineProps<{
39
39
  name: string;
40
40
  prop: string;
41
41
  disabled?: boolean;
42
- size: 'mini' | 'small' | 'medium';
42
+ size?: 'large' | 'default' | 'small';
43
43
  }>();
44
44
 
45
45
  const emit = defineEmits(['change']);
@@ -2,7 +2,7 @@
2
2
  <input v-if="model" v-model="model[name]" type="hidden" />
3
3
  </template>
4
4
 
5
- <script setup lang="ts">
5
+ <script setup lang="ts" name="MFormHidden">
6
6
  import { HiddenConfig } from '../schema';
7
7
  import { useAddField } from '../utils/useAddField';
8
8
 
@@ -16,7 +16,7 @@
16
16
  </div>
17
17
  </template>
18
18
 
19
- <script lang="ts" setup>
19
+ <script lang="ts" setup name="MFormLink">
20
20
  import { computed, inject, ref } from 'vue';
21
21
 
22
22
  import { TMagicButton } from '@tmagic/design';
@@ -33,7 +33,7 @@ const props = defineProps<{
33
33
  name: string;
34
34
  prop: string;
35
35
  disabled?: boolean;
36
- size: 'mini' | 'small' | 'medium';
36
+ size?: 'large' | 'default' | 'small';
37
37
  }>();
38
38
 
39
39
  const emit = defineEmits(['change']);
@@ -15,7 +15,7 @@
15
15
  ></TMagicInputNumber>
16
16
  </template>
17
17
 
18
- <script lang="ts" setup>
18
+ <script lang="ts" setup name="MFormNumber">
19
19
  import { inject } from 'vue';
20
20
 
21
21
  import { TMagicInputNumber } from '@tmagic/design';
@@ -31,7 +31,7 @@ const props = defineProps<{
31
31
  name: string;
32
32
  prop: string;
33
33
  disabled?: boolean;
34
- size: 'mini' | 'small' | 'medium';
34
+ size?: 'large' | 'default' | 'small';
35
35
  }>();
36
36
 
37
37
  const emit = defineEmits(['change', 'input']);
@@ -1,12 +1,16 @@
1
1
  <template>
2
2
  <TMagicRadioGroup v-if="model" v-model="model[name]" :size="size" :disabled="disabled" @change="changeHandler">
3
- <TMagicRadio v-for="option in config.options" :label="option.value" :key="`${option.value}`">{{
4
- option.text
5
- }}</TMagicRadio>
3
+ <TMagicRadio
4
+ v-for="option in config.options"
5
+ :label="option.value"
6
+ :value="option.value"
7
+ :key="`${option.value}`"
8
+ >{{ option.text }}</TMagicRadio
9
+ >
6
10
  </TMagicRadioGroup>
7
11
  </template>
8
12
 
9
- <script lang="ts" setup>
13
+ <script lang="ts" setup name="MFormRadioGroup">
10
14
  import { TMagicRadio, TMagicRadioGroup } from '@tmagic/design';
11
15
 
12
16
  import { RadioGroupConfig } from '../schema';
@@ -20,7 +24,7 @@ const props = defineProps<{
20
24
  name: string;
21
25
  prop: string;
22
26
  disabled?: boolean;
23
- size: 'mini' | 'small' | 'medium';
27
+ size?: 'large' | 'default' | 'small';
24
28
  }>();
25
29
 
26
30
  const emit = defineEmits(['change']);
@@ -25,7 +25,7 @@
25
25
  </TMagicSelect>
26
26
  </template>
27
27
 
28
- <script lang="ts" setup>
28
+ <script lang="ts" setup name="MFormSelect">
29
29
  import { inject, nextTick, onBeforeMount, onMounted, Ref, ref, watchEffect } from 'vue';
30
30
 
31
31
  import { TMagicSelect } from '@tmagic/design';
@@ -45,7 +45,7 @@ const props = defineProps<{
45
45
  name: string;
46
46
  prop: string;
47
47
  disabled?: boolean;
48
- size: 'mini' | 'small' | 'medium';
48
+ size?: 'large' | 'default' | 'small';
49
49
  }>();
50
50
 
51
51
  const emit = defineEmits(['change']);
@@ -99,11 +99,16 @@ const getOptions = async () => {
99
99
 
100
100
  const { config } = props;
101
101
  const { option } = config;
102
- let { body } = option;
102
+ const { root = '', totalKey = 'total' } = option;
103
+ let { body = {}, url } = option;
104
+
105
+ if (typeof url === 'function') {
106
+ url = await url(mForm, { model: props.model, formValue: mForm?.values });
107
+ }
103
108
 
104
109
  let postOptions: Record<string, any> = {
105
110
  method: option.method || 'POST',
106
- url: option.url,
111
+ url,
107
112
  cache: option.cache,
108
113
  timeout: option.timeout,
109
114
  mode: option.mode,
@@ -111,22 +116,21 @@ const getOptions = async () => {
111
116
  json: option.json || false,
112
117
  };
113
118
 
114
- if (body) {
115
- if (typeof body === 'function') {
116
- body = body(mForm, {
117
- model: props.model,
118
- formValue: mForm?.values,
119
- formValues: mForm?.values,
120
- config: props.config,
121
- }) as Record<string, any>;
122
- }
123
-
124
- body.query = query.value;
125
- body.pgSize = pgSize.value;
126
- body.pgIndex = pgIndex.value;
127
- postOptions.data = body;
119
+ if (typeof body === 'function') {
120
+ body = body(mForm, {
121
+ model: props.model,
122
+ formValue: mForm?.values,
123
+ formValues: mForm?.values,
124
+ config: props.config,
125
+ }) as Record<string, any>;
128
126
  }
129
127
 
128
+ body.query = query.value;
129
+ body.pgSize = pgSize.value;
130
+ body.pgIndex = pgIndex.value;
131
+
132
+ postOptions.data = body;
133
+
130
134
  const requestFuc = getConfig('request') as Function;
131
135
 
132
136
  if (typeof option.beforeRequest === 'function') {
@@ -151,10 +155,14 @@ const getOptions = async () => {
151
155
  });
152
156
  }
153
157
 
154
- const optionsData = res[option.root];
158
+ const optionsData = root.split('.').reduce((accumulator, currentValue: any) => accumulator[currentValue], res);
155
159
 
156
- if (res.total > 0) {
157
- total.value = res.total;
160
+ const resTotal = globalThis.parseInt(
161
+ totalKey.split('.').reduce((accumulator, currentValue: any) => accumulator[currentValue], res),
162
+ 10,
163
+ );
164
+ if (resTotal > 0) {
165
+ total.value = resTotal;
158
166
  }
159
167
 
160
168
  remoteData.value = remoteData.value.concat(optionsData);
@@ -214,6 +222,8 @@ const getInitOption = async () => {
214
222
 
215
223
  const { config } = props;
216
224
  const { option } = config;
225
+ const { root = '', initRoot = '' } = option;
226
+ let { initBody = {} } = option;
217
227
 
218
228
  let options: SelectOption[] | SelectGroupOption[] = [];
219
229
 
@@ -226,24 +236,53 @@ const getInitOption = async () => {
226
236
  url = await url(mForm, { model: props.model, formValue: mForm?.values });
227
237
  }
228
238
 
229
- const postOptions: Record<string, any> = {
239
+ if (typeof initBody === 'function') {
240
+ initBody = initBody(mForm, {
241
+ model: props.model,
242
+ formValue: mForm?.values,
243
+ formValues: mForm?.values,
244
+ config: props.config,
245
+ }) as Record<string, any>;
246
+ }
247
+
248
+ let postOptions: Record<string, any> = {
230
249
  method: option.method || 'POST',
231
250
  url,
232
251
  data: {
233
252
  id: props.model[props.name],
253
+ ...initBody,
234
254
  },
235
255
  mode: option.mode,
236
256
  headers: option.headers || {},
237
257
  json: option.json || false,
238
258
  };
259
+
260
+ if (typeof option.beforeInitRequest === 'function') {
261
+ postOptions = option.beforeInitRequest(mForm, postOptions, {
262
+ model: props.model,
263
+ formValue: mForm?.values,
264
+ });
265
+ }
266
+
239
267
  if (option.method?.toLocaleLowerCase() === 'jsonp') {
240
268
  postOptions.jsonpCallback = option.jsonpCallback || 'callback';
241
269
  }
242
270
 
243
271
  const requestFuc = getConfig('request') as Function;
244
- const res = await requestFuc(postOptions);
272
+ let res = await requestFuc(postOptions);
273
+
274
+ if (typeof option.afterRequest === 'function') {
275
+ res = option.afterRequest(mForm, res, {
276
+ model: props.model,
277
+ formValue: mForm?.values,
278
+ formValues: mForm?.values,
279
+ config: props.config,
280
+ });
281
+ }
245
282
 
246
- let initData = res[option.root];
283
+ let initData = (initRoot || root)
284
+ .split('.')
285
+ .reduce((accumulator, currentValue: any) => accumulator[currentValue], res);
247
286
  if (initData) {
248
287
  if (!Array.isArray(initData)) {
249
288
  initData = [initData];
@@ -12,7 +12,7 @@
12
12
  </TMagicOptionGroup>
13
13
  </template>
14
14
 
15
- <script lang="ts" setup>
15
+ <script lang="ts" setup name="MFormSelectOptionGroups">
16
16
  import { getConfig, TMagicOptionGroup } from '@tmagic/design';
17
17
 
18
18
  import { SelectGroupOption } from '../schema';
@@ -8,7 +8,7 @@
8
8
  ></TMagicOption>
9
9
  </template>
10
10
 
11
- <script lang="ts" setup>
11
+ <script lang="ts" setup name="MFormSelectOptions">
12
12
  import { TMagicOption } from '@tmagic/design';
13
13
 
14
14
  import { SelectOption } from '../schema';
@@ -9,7 +9,7 @@
9
9
  ></TMagicSwitch>
10
10
  </template>
11
11
 
12
- <script lang="ts" setup>
12
+ <script lang="ts" setup name="MFormSwitch">
13
13
  import { computed } from 'vue';
14
14
 
15
15
  import { TMagicSwitch } from '@tmagic/design';
@@ -25,7 +25,7 @@ const props = defineProps<{
25
25
  name: string;
26
26
  prop: string;
27
27
  disabled?: boolean;
28
- size: 'mini' | 'small' | 'medium';
28
+ size?: 'large' | 'default' | 'small';
29
29
  }>();
30
30
 
31
31
  const emit = defineEmits(['change']);
@@ -23,7 +23,7 @@
23
23
  </TMagicInput>
24
24
  </template>
25
25
 
26
- <script lang="ts" setup>
26
+ <script lang="ts" setup name="MFormText">
27
27
  import { inject } from 'vue';
28
28
 
29
29
  import { TMagicInput } from '@tmagic/design';
@@ -40,7 +40,7 @@ const props = defineProps<{
40
40
  name: string;
41
41
  prop: string;
42
42
  disabled?: boolean;
43
- size: 'mini' | 'small' | 'medium';
43
+ size?: 'large' | 'default' | 'small';
44
44
  }>();
45
45
 
46
46
  const emit = defineEmits(['change', 'input']);
@@ -12,7 +12,7 @@
12
12
  </TMagicInput>
13
13
  </template>
14
14
 
15
- <script lang="ts" setup>
15
+ <script lang="ts" setup name="MFormTextarea">
16
16
  import { inject } from 'vue';
17
17
 
18
18
  import { TMagicInput } from '@tmagic/design';
@@ -28,7 +28,7 @@ const props = defineProps<{
28
28
  name: string;
29
29
  prop: string;
30
30
  disabled?: boolean;
31
- size: 'mini' | 'small' | 'medium';
31
+ size?: 'large' | 'default' | 'small';
32
32
  }>();
33
33
 
34
34
  const emit = defineEmits(['change', 'input']);
@@ -1,6 +1,8 @@
1
1
  <template>
2
2
  <TMagicTimePicker
3
3
  v-model="model[name]"
4
+ :value-format="config.valueFormat || 'HH:mm:ss'"
5
+ :format="config.format || 'HH:mm:ss'"
4
6
  :size="size"
5
7
  :placeholder="config.placeholder"
6
8
  :disabled="disabled"
@@ -8,7 +10,7 @@
8
10
  ></TMagicTimePicker>
9
11
  </template>
10
12
 
11
- <script lang="ts" setup>
13
+ <script lang="ts" setup name="MFormTime">
12
14
  import { TMagicTimePicker } from '@tmagic/design';
13
15
 
14
16
  import { TimeConfig } from '../schema';
@@ -22,7 +24,7 @@ const props = defineProps<{
22
24
  name: string;
23
25
  prop: string;
24
26
  disabled?: boolean;
25
- size: 'mini' | 'small' | 'medium';
27
+ size?: 'large' | 'default' | 'small';
26
28
  }>();
27
29
 
28
30
  const emit = defineEmits(['change']);
package/src/schema.ts CHANGED
@@ -348,6 +348,7 @@ export interface HiddenConfig extends FormItem {
348
348
  export interface DateConfig extends FormItem, Input {
349
349
  type: 'date';
350
350
  format?: 'YYYY-MM-dd HH:mm:ss' | string;
351
+ valueFormat?: 'YYYY-MM-dd HH:mm:ss' | string;
351
352
  }
352
353
 
353
354
  /**
@@ -365,6 +366,8 @@ export interface DateTimeConfig extends FormItem, Input {
365
366
  */
366
367
  export interface TimeConfig extends FormItem, Input {
367
368
  type: 'time';
369
+ format?: 'HH:mm:ss' | string;
370
+ valueFormat?: 'HH:mm:ss' | string;
368
371
  }
369
372
 
370
373
  /**
@@ -430,7 +433,7 @@ export interface SelectConfig extends FormItem, Input {
430
433
  options: SelectConfigOption[] | SelectConfigGroupOption[] | SelectOptionFunction;
431
434
  remote: true;
432
435
  option: {
433
- url: string;
436
+ url: string | ((mForm: FormState | undefined, data: { model: any; formValue: any }) => string);
434
437
  initUrl?: string | ((mForm: FormState | undefined, data: { model: any; formValue: any }) => string);
435
438
  method?: 'jsonp' | string;
436
439
  cache?: boolean;
@@ -441,13 +444,22 @@ export interface SelectConfig extends FormItem, Input {
441
444
  };
442
445
  json?: false | boolean;
443
446
  body?: Record<string, any> | RemoteSelectOptionBodyFunction;
447
+ initBody?: Record<string, any> | RemoteSelectOptionBodyFunction;
444
448
  jsonpCallback?: 'callback' | string;
445
449
  afterRequest?: RemoteSelectOptionRequestFunction;
450
+ afterInitRequest?: RemoteSelectOptionRequestFunction;
446
451
  beforeRequest?: (mForm: FormState | undefined, postOptions: Record<string, any>, data: any) => Record<string, any>;
447
- root: string;
452
+ beforeInitRequest?: (
453
+ mForm: FormState | undefined,
454
+ postOptions: Record<string, any>,
455
+ data: any,
456
+ ) => Record<string, any>;
457
+ root?: string;
458
+ totalKey?: string;
459
+ initRoot?: string;
448
460
  item?: RemoteSelectOptionItemFunction;
449
- value: string | SelectOptionValueFunction;
450
- text: string | SelectOptionTextFunction;
461
+ value?: string | SelectOptionValueFunction;
462
+ text?: string | SelectOptionTextFunction;
451
463
  };
452
464
  }
453
465
 
@@ -610,6 +622,7 @@ export interface TableConfig extends FormItem {
610
622
  border?: boolean;
611
623
  /** 显示行号 */
612
624
  showIndex?: boolean;
625
+ pagination?: boolean;
613
626
  enum?: any[];
614
627
  /** 是否显示添加按钮 */
615
628
  addable?: (mForm: FormState | undefined, data: any) => boolean | 'undefined' | boolean;
@@ -629,6 +642,7 @@ export interface TableConfig extends FormItem {
629
642
  enableFullscreen?: boolean;
630
643
  fixed?: boolean;
631
644
  itemExtra?: string | FilterFunction;
645
+ rowKey: string;
632
646
  }
633
647
 
634
648
  export interface GroupListConfig extends FormItem {
@@ -30,7 +30,7 @@
30
30
  }
31
31
 
32
32
  .el-form-item.hidden {
33
- .el-form-item__label {
33
+ > .el-form-item__label {
34
34
  display: none;
35
35
  }
36
36
  }
package/src/utils/form.ts CHANGED
@@ -62,9 +62,9 @@ const initItemsValue = (
62
62
  { items, name, extensible }: any,
63
63
  ) => {
64
64
  if (Array.isArray(initValue[name])) {
65
- value[name] = initValue[name].map((v: any, index: number) => init(mForm, items, v, value[name]?.[index]));
65
+ value[name] = initValue[name].map((v: any, index: number) => createValues(mForm, items, v, value[name]?.[index]));
66
66
  } else {
67
- value[name] = init(mForm, items, initValue[name], value[name]);
67
+ value[name] = createValues(mForm, items, initValue[name], value[name]);
68
68
  if (extensible) {
69
69
  value[name] = Object.assign({}, initValue[name], value[name]);
70
70
  }
@@ -129,7 +129,7 @@ const initValueItem = function (
129
129
 
130
130
  if (!name) {
131
131
  // 没有配置name,直接跳过
132
- return init(mForm, items, initValue, value);
132
+ return createValues(mForm, items, initValue, value);
133
133
  }
134
134
 
135
135
  setValue(mForm, value, initValue, item);
@@ -137,7 +137,7 @@ const initValueItem = function (
137
137
  return value;
138
138
  };
139
139
 
140
- const init = function (
140
+ export const createValues = function (
141
141
  mForm: FormState | undefined,
142
142
  config: FormConfig | TabPaneConfig[] = [],
143
143
  initValue: FormValue = {},
@@ -197,6 +197,10 @@ export const filterFunction = (mForm: FormState | undefined, config: any, props:
197
197
  };
198
198
 
199
199
  export const display = function (mForm: FormState | undefined, config: any, props: any) {
200
+ if (config === 'expand') {
201
+ return config;
202
+ }
203
+
200
204
  if (typeof config === 'function') {
201
205
  return filterFunction(mForm, config, props);
202
206
  }
@@ -249,7 +253,7 @@ export const initValue = async (
249
253
  ) => {
250
254
  if (!Array.isArray(config)) throw new Error('config应该为数组');
251
255
 
252
- let valuesTmp = init(mForm, config, toRaw(initValues), {});
256
+ let valuesTmp = createValues(mForm, config, toRaw(initValues), {});
253
257
 
254
258
  const [firstForm] = config as [ContainerCommonConfig];
255
259
  if (firstForm && typeof firstForm.onInitValue === 'function') {