@tmagic/form 1.3.16 → 1.4.0-beta.2

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 (50) hide show
  1. package/dist/style.css +3 -8
  2. package/dist/tmagic-form.js +132 -123
  3. package/dist/tmagic-form.umd.cjs +131 -122
  4. package/package.json +12 -11
  5. package/src/FormBox.vue +48 -34
  6. package/src/containers/Container.vue +3 -3
  7. package/src/containers/Fieldset.vue +2 -2
  8. package/src/fields/Cascader.vue +1 -0
  9. package/src/fields/Checkbox.vue +2 -2
  10. package/src/fields/CheckboxGroup.vue +1 -6
  11. package/src/fields/RadioGroup.vue +3 -7
  12. package/src/schema.ts +6 -2
  13. package/src/theme/form-box.scss +3 -8
  14. package/types/Form.vue.d.ts +12 -12
  15. package/types/FormBox.vue.d.ts +195 -244
  16. package/types/FormDialog.vue.d.ts +191 -241
  17. package/types/FormDrawer.vue.d.ts +192 -242
  18. package/types/containers/Col.vue.d.ts +3 -3
  19. package/types/containers/Container.vue.d.ts +12 -12
  20. package/types/containers/Fieldset.vue.d.ts +11 -11
  21. package/types/containers/GroupList.vue.d.ts +3 -3
  22. package/types/containers/GroupListItem.vue.d.ts +3 -3
  23. package/types/containers/Panel.vue.d.ts +8 -8
  24. package/types/containers/Row.vue.d.ts +3 -3
  25. package/types/containers/Step.vue.d.ts +11 -11
  26. package/types/containers/Table.vue.d.ts +11 -11
  27. package/types/containers/Tabs.vue.d.ts +11 -11
  28. package/types/fields/Cascader.vue.d.ts +3 -3
  29. package/types/fields/Checkbox.vue.d.ts +3 -3
  30. package/types/fields/CheckboxGroup.vue.d.ts +3 -3
  31. package/types/fields/ColorPicker.vue.d.ts +3 -3
  32. package/types/fields/Date.vue.d.ts +3 -3
  33. package/types/fields/DateTime.vue.d.ts +3 -3
  34. package/types/fields/Daterange.vue.d.ts +3 -3
  35. package/types/fields/Display.vue.d.ts +2 -2
  36. package/types/fields/DynamicField.vue.d.ts +3 -3
  37. package/types/fields/Hidden.vue.d.ts +2 -2
  38. package/types/fields/Link.vue.d.ts +3 -3
  39. package/types/fields/Number.vue.d.ts +3 -3
  40. package/types/fields/NumberRange.vue.d.ts +3 -3
  41. package/types/fields/RadioGroup.vue.d.ts +3 -3
  42. package/types/fields/Select.vue.d.ts +3 -3
  43. package/types/fields/SelectOptionGroups.vue.d.ts +3 -3
  44. package/types/fields/SelectOptions.vue.d.ts +3 -3
  45. package/types/fields/Switch.vue.d.ts +3 -3
  46. package/types/fields/Text.vue.d.ts +3 -3
  47. package/types/fields/Textarea.vue.d.ts +3 -3
  48. package/types/fields/Time.vue.d.ts +3 -3
  49. package/types/fields/Timerange.vue.d.ts +3 -3
  50. package/types/schema.d.ts +6 -2
package/src/FormBox.vue CHANGED
@@ -1,56 +1,57 @@
1
1
  <template>
2
- <div class="m-form-box">
3
- <div ref="boxBody" class="m-box-body">
4
- <Form
5
- ref="form"
6
- :size="size"
7
- :disabled="disabled"
8
- :config="config"
9
- :init-values="values"
10
- :parent-values="parentValues"
11
- :label-width="labelWidth"
12
- :label-position="labelPosition"
13
- :inline="inline"
14
- @change="changeHandler"
15
- ></Form>
16
- <slot></slot>
2
+ <div class="m-form-box" :style="style">
3
+ <div class="m-box-body" :style="bodyHeight ? { height: `${bodyHeight}px` } : {}">
4
+ <TMagicScrollbar>
5
+ <Form
6
+ ref="form"
7
+ :size="size"
8
+ :disabled="disabled"
9
+ :config="config"
10
+ :init-values="values"
11
+ :parent-values="parentValues"
12
+ :label-width="labelWidth"
13
+ :label-position="labelPosition"
14
+ :inline="inline"
15
+ @change="changeHandler"
16
+ ></Form>
17
+ <slot></slot>
18
+ </TMagicScrollbar>
17
19
  </div>
18
20
 
19
- <TMagicRow class="dialog-footer">
20
- <TMagicCol :span="12" style="text-align: left">
21
- <div style="min-height: 1px">
22
- <slot name="left"></slot>
23
- </div>
24
- </TMagicCol>
25
- <TMagicCol :span="12">
21
+ <div class="dialog-footer" :style="`height: ${footerHeight}px`">
22
+ <div>
23
+ <slot name="left"></slot>
24
+ </div>
25
+ <div>
26
26
  <slot name="footer">
27
- <TMagicButton type="primary" :disabled="disabled" :loading="saveFetch" @click="submitHandler">{{
27
+ <TMagicButton type="primary" :size="size" :disabled="disabled" :loading="saveFetch" @click="submitHandler">{{
28
28
  confirmText
29
29
  }}</TMagicButton>
30
30
  </slot>
31
- </TMagicCol>
32
- </TMagicRow>
31
+ </div>
32
+ </div>
33
33
  </div>
34
34
  </template>
35
35
 
36
36
  <script setup lang="ts">
37
- import { ref, watchEffect } from 'vue';
37
+ import { computed, ref, watchEffect } from 'vue';
38
38
 
39
- import { TMagicButton, TMagicCol, TMagicRow } from '@tmagic/design';
39
+ import { TMagicButton, TMagicScrollbar } from '@tmagic/design';
40
40
 
41
41
  import Form from './Form.vue';
42
42
  import type { FormConfig } from './schema';
43
43
 
44
44
  defineOptions({
45
- name: 'MFormDialog',
45
+ name: 'MFormBox',
46
46
  });
47
47
 
48
- withDefaults(
48
+ const props = withDefaults(
49
49
  defineProps<{
50
50
  config?: FormConfig;
51
51
  values?: Object;
52
52
  parentValues?: Object;
53
- width?: string | number;
53
+ width?: number;
54
+ height?: number;
54
55
  labelWidth?: string;
55
56
  disabled?: boolean;
56
57
  size?: 'small' | 'default' | 'large';
@@ -67,15 +68,29 @@ withDefaults(
67
68
 
68
69
  const emit = defineEmits(['submit', 'change', 'error']);
69
70
 
71
+ const footerHeight = 60;
72
+
73
+ const style = computed(() => {
74
+ const style: { width?: string; height?: string } = {};
75
+ if (typeof props.width === 'number') {
76
+ style.width = `${props.width}px`;
77
+ }
78
+ if (typeof props.height === 'number') {
79
+ style.height = `${props.height}px`;
80
+ }
81
+ return style;
82
+ });
83
+
70
84
  const form = ref<InstanceType<typeof Form>>();
71
- const boxBody = ref<HTMLDivElement>();
72
85
  const saveFetch = ref(false);
86
+
73
87
  const bodyHeight = ref(0);
74
88
 
75
89
  watchEffect(() => {
76
- if (boxBody.value) {
77
- bodyHeight.value = boxBody.value.clientHeight;
90
+ if (!props.height) {
91
+ return;
78
92
  }
93
+ bodyHeight.value = props.height - footerHeight;
79
94
  });
80
95
 
81
96
  const submitHandler = async () => {
@@ -98,7 +113,6 @@ const hide = () => {};
98
113
  defineExpose({
99
114
  form,
100
115
  saveFetch,
101
- bodyHeight,
102
116
 
103
117
  show,
104
118
  hide,
@@ -42,7 +42,7 @@
42
42
  :label-width="itemLabelWidth"
43
43
  :rules="rule"
44
44
  >
45
- <template #label><span v-html="type === 'checkbox' ? '' : text"></span></template>
45
+ <template #label><span v-html="type === 'checkbox' ? '' : text" :title="config.labelTitle"></span></template>
46
46
  <TMagicTooltip v-if="tooltip">
47
47
  <component
48
48
  :key="key(config)"
@@ -99,7 +99,7 @@
99
99
  :rules="rule"
100
100
  style="background: #f7dadd"
101
101
  >
102
- <template #label><span v-html="type === 'checkbox' ? '' : text"></span></template>
102
+ <template #label><span v-html="type === 'checkbox' ? '' : text" :title="config.labelTitle"></span></template>
103
103
  <TMagicTooltip v-if="tooltip">
104
104
  <component
105
105
  :key="key(config)"
@@ -148,7 +148,7 @@
148
148
  :rules="rule"
149
149
  style="background: #def7da"
150
150
  >
151
- <template #label><span v-html="type === 'checkbox' ? '' : text"></span></template>
151
+ <template #label><span v-html="type === 'checkbox' ? '' : text" :title="config.labelTitle"></span></template>
152
152
  <TMagicTooltip v-if="tooltip">
153
153
  <component
154
154
  :key="key(config)"
@@ -8,8 +8,8 @@
8
8
  <TMagicCheckbox
9
9
  v-model="model[name].value"
10
10
  :prop="`${prop}${prop ? '.' : ''}${config.name}.value`"
11
- :true-label="1"
12
- :false-label="0"
11
+ :true-value="1"
12
+ :false-value="0"
13
13
  @update:modelValue="change"
14
14
  ><span v-html="config.legend"></span><span v-if="config.extra" v-html="config.extra" class="m-form-tip"></span
15
15
  ></TMagicCheckbox>
@@ -9,6 +9,7 @@
9
9
  :placeholder="config.placeholder"
10
10
  :disabled="disabled"
11
11
  :options="options"
12
+ :popper-class="config.popperClass"
12
13
  :props="{
13
14
  multiple: config.multiple ?? false,
14
15
  emitPath: config.emitPath ?? true,
@@ -2,8 +2,8 @@
2
2
  <TMagicCheckbox
3
3
  v-model="model[name]"
4
4
  :size="size"
5
- :trueLabel="activeValue"
6
- :falseLabel="inactiveValue"
5
+ :trueValue="activeValue"
6
+ :falseValue="inactiveValue"
7
7
  :disabled="disabled"
8
8
  @change="changeHandler"
9
9
  >{{ config.text }}</TMagicCheckbox
@@ -1,11 +1,6 @@
1
1
  <template>
2
2
  <TMagicCheckboxGroup v-model="model[name]" :size="size" :disabled="disabled" @change="changeHandler">
3
- <TMagicCheckbox
4
- v-for="option in options"
5
- :label="option.value"
6
- :value="option.value"
7
- :key="option.value"
8
- :disabled="option.disabled"
3
+ <TMagicCheckbox v-for="option in options" :value="option.value" :key="option.value" :disabled="option.disabled"
9
4
  >{{ option.text }}
10
5
  </TMagicCheckbox>
11
6
  </TMagicCheckboxGroup>
@@ -1,12 +1,8 @@
1
1
  <template>
2
2
  <TMagicRadioGroup v-if="model" v-model="model[name]" :size="size" :disabled="disabled" @change="changeHandler">
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
- >
3
+ <TMagicRadio v-for="option in config.options" :value="option.value" :key="`${option.value}`">{{
4
+ option.text
5
+ }}</TMagicRadio>
10
6
  </TMagicRadioGroup>
11
7
  </template>
12
8
 
package/src/schema.ts CHANGED
@@ -66,6 +66,8 @@ export interface FormItem {
66
66
  __key?: string | number;
67
67
  /** 表单域标签的的宽度,例如 '50px'。支持 auto。 */
68
68
  labelWidth?: string;
69
+ /** label 标签的title属性 */
70
+ labelTitle?: string;
69
71
  className?: string;
70
72
  /** 表单组件类型 */
71
73
  type?: string | TypeFunction;
@@ -399,8 +401,8 @@ export interface TimeConfig extends FormItem, Input {
399
401
  */
400
402
  export interface CheckboxConfig extends FormItem {
401
403
  type: 'checkbox';
402
- activeValue?: boolean | number | string;
403
- inactiveValue?: boolean | number | string;
404
+ activeValue?: number | string;
405
+ inactiveValue?: number | string;
404
406
  }
405
407
 
406
408
  /**
@@ -534,6 +536,8 @@ export interface CascaderConfig extends FormItem, Input {
534
536
  multiple?: boolean;
535
537
  /** 是否严格的遵守父子节点不互相关联,默认 false */
536
538
  checkStrictly?: boolean;
539
+ /** 弹出内容的自定义类名 */
540
+ popperClass?: string;
537
541
  options?:
538
542
  | ((
539
543
  mForm: FormState | undefined,
@@ -1,18 +1,13 @@
1
1
  .m-form-box {
2
2
  display: flex;
3
3
  flex-direction: column;
4
- padding: 16px;
5
- width: 100%;
6
4
  .el-box__header {
7
5
  margin: 0;
8
6
  }
9
7
 
10
- .m-box-body {
11
- flex: 1;
12
- overflow-y: auto;
13
- overflow-x: hidden;
14
- }
15
8
  .dialog-footer {
16
- margin-top: 16px;
9
+ display: flex;
10
+ align-items: center;
11
+ justify-content: space-between;
17
12
  }
18
13
  }
@@ -1,5 +1,5 @@
1
1
  import type { FormConfig, FormState, FormValue } from './schema';
2
- declare const _default: import("vue").DefineComponent<__VLS_WithDefaults<__VLS_TypePropsToRuntimeProps<{
2
+ declare const _default: import("vue").DefineComponent<__VLS_WithDefaults<__VLS_TypePropsToOption<{
3
3
  /** 表单配置 */
4
4
  config: FormConfig;
5
5
  /** 表单值 */
@@ -45,7 +45,7 @@ declare const _default: import("vue").DefineComponent<__VLS_WithDefaults<__VLS_T
45
45
  error: (...args: any[]) => void;
46
46
  "field-input": (...args: any[]) => void;
47
47
  "field-change": (...args: any[]) => void;
48
- }, string, import("vue").VNodeProps & import("vue").AllowedComponentProps & import("vue").ComponentCustomProps, Readonly<import("vue").ExtractPropTypes<__VLS_WithDefaults<__VLS_TypePropsToRuntimeProps<{
48
+ }, string, import("vue").PublicProps, Readonly<import("vue").ExtractPropTypes<__VLS_WithDefaults<__VLS_TypePropsToOption<{
49
49
  /** 表单配置 */
50
50
  config: FormConfig;
51
51
  /** 表单值 */
@@ -92,21 +92,12 @@ declare const _default: import("vue").DefineComponent<__VLS_WithDefaults<__VLS_T
92
92
  parentValues: Record<string, any>;
93
93
  labelWidth: string;
94
94
  disabled: boolean;
95
- stepActive: string | number;
96
95
  height: string;
96
+ stepActive: string | number;
97
97
  inline: boolean;
98
98
  labelPosition: string;
99
99
  }, {}>;
100
100
  export default _default;
101
- type __VLS_NonUndefinedable<T> = T extends undefined ? never : T;
102
- type __VLS_TypePropsToRuntimeProps<T> = {
103
- [K in keyof T]-?: {} extends Pick<T, K> ? {
104
- type: import('vue').PropType<__VLS_NonUndefinedable<T[K]>>;
105
- } : {
106
- type: import('vue').PropType<T[K]>;
107
- required: true;
108
- };
109
- };
110
101
  type __VLS_WithDefaults<P, D> = {
111
102
  [K in keyof Pick<P, keyof P>]: K extends keyof D ? __VLS_Prettify<P[K] & {
112
103
  default: D[K];
@@ -115,3 +106,12 @@ type __VLS_WithDefaults<P, D> = {
115
106
  type __VLS_Prettify<T> = {
116
107
  [K in keyof T]: T[K];
117
108
  } & {};
109
+ type __VLS_NonUndefinedable<T> = T extends undefined ? never : T;
110
+ type __VLS_TypePropsToOption<T> = {
111
+ [K in keyof T]-?: {} extends Pick<T, K> ? {
112
+ type: import('vue').PropType<__VLS_NonUndefinedable<T[K]>>;
113
+ } : {
114
+ type: import('vue').PropType<T[K]>;
115
+ required: true;
116
+ };
117
+ };