@tmagic/form 1.0.0-beta.8 → 1.0.0-rc.11

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.
@@ -15,20 +15,15 @@
15
15
  :value-key="config.valueKey || 'value'"
16
16
  :allow-create="config.allowCreate"
17
17
  :disabled="disabled"
18
- :remote-method="remoteMethod"
18
+ :remote-method="config.remote && remoteMethod"
19
19
  @change="changeHandler"
20
20
  @visible-change="visibleHandler"
21
21
  >
22
22
  <template v-if="config.group">
23
- <el-option-group
24
- v-for="(group, index) in options"
25
- :key="group.label + index"
26
- :label="group.label"
27
- :disabled="group.disabled"
28
- >
23
+ <el-option-group v-for="(group, index) in options" :key="index" :label="group.label" :disabled="group.disabled">
29
24
  <el-option
30
25
  v-for="(item, index) in group.options"
31
- :key="item.label + index"
26
+ :key="index"
32
27
  :label="item.label"
33
28
  :value="item.value"
34
29
  :disabled="item.disabled"
@@ -139,6 +134,7 @@ export default defineComponent({
139
134
  model: props.model,
140
135
  formValue: mForm?.values,
141
136
  formValues: mForm?.values,
137
+ config: props.config,
142
138
  }) as Record<string, any>;
143
139
  }
144
140
 
@@ -168,6 +164,7 @@ export default defineComponent({
168
164
  model: props.model,
169
165
  formValue: mForm?.values,
170
166
  formValues: mForm?.values,
167
+ config: props.config,
171
168
  });
172
169
  }
173
170
 
@@ -289,8 +286,10 @@ export default defineComponent({
289
286
  Promise.resolve(
290
287
  props.config.options(mForm, {
291
288
  model: props.model,
289
+ prop: props.prop,
292
290
  formValues: mForm?.values,
293
291
  formValue: mForm?.values,
292
+ config: props.config,
294
293
  }),
295
294
  ).then((data) => {
296
295
  options.value = data;
@@ -349,12 +348,12 @@ export default defineComponent({
349
348
  moreLoadingVisible,
350
349
  popperClass: mForm?.popperClass,
351
350
 
351
+ getOptions,
352
+
352
353
  getRequestFuc() {
353
354
  return getConfig('request');
354
355
  },
355
356
 
356
- async getInitOption() {},
357
-
358
357
  changeHandler(value: any) {
359
358
  emit('change', value);
360
359
  },
@@ -372,11 +371,6 @@ export default defineComponent({
372
371
  }
373
372
  },
374
373
 
375
- async editAfterAction() {
376
- pgIndex.value = 0;
377
- options.value = await getOptions();
378
- },
379
-
380
374
  async remoteMethod(q: string) {
381
375
  if (!localOptions.value.length) {
382
376
  query.value = q;
@@ -14,7 +14,8 @@
14
14
  <el-button
15
15
  v-if="typeof config.append === 'object' && config.append.type === 'button'"
16
16
  style="color: #409eff"
17
- @click="buttonClickHandler"
17
+ :size="size"
18
+ @click.prevent="buttonClickHandler"
18
19
  >
19
20
  {{ config.append.text }}
20
21
  </el-button>
@@ -43,6 +44,8 @@ export default defineComponent({
43
44
  emits: ['change', 'input'],
44
45
 
45
46
  setup(props, { emit }) {
47
+ const mForm = inject<FormState | undefined>('mForm');
48
+
46
49
  useAddField(props.prop);
47
50
 
48
51
  const modelName = computed(() => props.name || props.config.name || '');
@@ -54,14 +57,11 @@ export default defineComponent({
54
57
  },
55
58
 
56
59
  inputHandler(v: string | number) {
57
- const mForm = inject<FormState | undefined>('mForm');
58
60
  emit('input', v);
59
61
  mForm?.$emit('field-input', props.prop, v);
60
62
  },
61
63
 
62
64
  buttonClickHandler() {
63
- const mForm = inject<FormState | undefined>('mForm');
64
-
65
65
  if (typeof props.config.append === 'string') return;
66
66
 
67
67
  if (props.config.append?.handler) {
@@ -1,17 +1,15 @@
1
1
  <template>
2
- <div v-if="model">
3
- <el-input
4
- v-model="model[name]"
5
- type="textarea"
6
- :size="size"
7
- clearable
8
- :placeholder="config.placeholder"
9
- :disabled="disabled"
10
- @change="changeHandler"
11
- @input="inputHandler"
12
- >
13
- </el-input>
14
- </div>
2
+ <el-input
3
+ v-model="model[name]"
4
+ type="textarea"
5
+ :size="size"
6
+ clearable
7
+ :placeholder="config.placeholder"
8
+ :disabled="disabled"
9
+ @change="changeHandler"
10
+ @input="inputHandler"
11
+ >
12
+ </el-input>
15
13
  </template>
16
14
 
17
15
  <script lang="ts">
package/src/schema.ts CHANGED
@@ -120,6 +120,7 @@ export interface Rule {
120
120
  /** 整个表单的值 */
121
121
  formValue: FormValue;
122
122
  prop: string;
123
+ config: any;
123
124
  },
124
125
  mForm: FormState | undefined,
125
126
  ) => void;
@@ -145,6 +146,7 @@ type FilterFunction = (
145
146
  parent?: Record<any, any>;
146
147
  formValue: Record<any, any>;
147
148
  prop: string;
149
+ config: any;
148
150
  },
149
151
  ) => boolean;
150
152
 
@@ -156,6 +158,7 @@ type OnChangeHandler = (
156
158
  values: Record<any, any>;
157
159
  parent?: Record<any, any>;
158
160
  formValue: Record<any, any>;
161
+ config: any;
159
162
  },
160
163
  ) => any;
161
164
 
@@ -188,8 +191,10 @@ type SelectOptionFunction = (
188
191
  mForm: FormState | undefined,
189
192
  data: {
190
193
  model: any;
194
+ prop?: string;
191
195
  formValues: any;
192
196
  formValue: any;
197
+ config: any;
193
198
  },
194
199
  ) => SelectOption[] | SelectGroupOption[];
195
200
 
@@ -199,6 +204,7 @@ type RemoteSelectOptionBodyFunction = (
199
204
  model: any;
200
205
  formValue: any;
201
206
  formValues: any;
207
+ config: any;
202
208
  },
203
209
  ) => Record<string, any>;
204
210
 
@@ -209,6 +215,7 @@ type RemoteSelectOptionRequestFunction = (
209
215
  model: any;
210
216
  formValue: any;
211
217
  formValues: any;
218
+ config: any;
212
219
  },
213
220
  ) => any;
214
221
 
@@ -499,6 +506,7 @@ export interface TabPaneConfig {
499
506
  lazy?: boolean;
500
507
  labelWidth?: string;
501
508
  items: FormConfig;
509
+ [key: string]: any;
502
510
  }
503
511
  export interface TabConfig extends FormItem, ContainerCommonConfig {
504
512
  type: 'tab' | 'dynamic-tab';
@@ -539,6 +547,7 @@ export interface ColumnConfig extends FormItem, ContainerCommonConfig {
539
547
  label: string;
540
548
  width: string | number;
541
549
  sortable: boolean;
550
+ [key: string]: any;
542
551
  }
543
552
 
544
553
  /**
@@ -2,29 +2,36 @@
2
2
  .fade-leave-active {
3
3
  transition: opacity 0.5s;
4
4
  }
5
+
5
6
  .fade-enter, .fade-leave-to /* .fade-leave-active below version 2.1.8 */ {
6
7
  opacity: 0;
7
8
  }
8
9
 
9
- .m-form,
10
- .m-form-panel.el-card .el-card__body {
11
- color: #333;
12
- background-color: #fff;
13
- }
10
+ .m-form {
11
+ .m-form-tip {
12
+ color: rgba(0, 0, 0, 0.45);
13
+ font-size: 12px;
14
+ transition: color 0.3s cubic-bezier(0.215, 0.61, 0.355, 1);
15
+ }
14
16
 
15
- .m-form .m-form-tip {
16
- color: rgba(0, 0, 0, 0.45);
17
- font-size: 12px;
18
- transition: color 0.3s cubic-bezier(0.215, 0.61, 0.355, 1);
19
- }
17
+ .m-form-schematic {
18
+ max-width: 50%;
19
+ height: 100%;
20
+ }
20
21
 
21
- .m-form .m-form-schematic {
22
- max-width: 50%;
23
- height: 100%;
24
- }
22
+ .el-table {
23
+ .cell > div.m-form-container {
24
+ display: block;
25
+ }
26
+ }
27
+
28
+ .el-tabs {
29
+ margin-bottom: 10px;
30
+ }
25
31
 
26
- .el-table {
27
- .cell > div.m-form-container {
28
- display: block;
32
+ .el-form-item.hidden {
33
+ .el-form-item__label {
34
+ display: none;
35
+ }
29
36
  }
30
37
  }
package/src/utils/form.ts CHANGED
@@ -122,7 +122,11 @@ const initValueItem = function (
122
122
  // 这种情况比较多,提前结束
123
123
  if (name && !items && typeof initValue[name] !== 'undefined') {
124
124
  if (typeof value[name] === 'undefined') {
125
- value[name] = typeof initValue[name] === 'object' ? cloneDeep(initValue[name]) : initValue[name];
125
+ if (type === 'number') {
126
+ value[name] = Number(initValue[name]);
127
+ } else {
128
+ value[name] = typeof initValue[name] === 'object' ? cloneDeep(initValue[name]) : initValue[name];
129
+ }
126
130
  }
127
131
 
128
132
  return value;
@@ -197,6 +201,7 @@ export const filterFunction = (mForm: FormState | undefined, config: any, props:
197
201
  parent: mForm?.parentValues || {},
198
202
  formValue: mForm?.values || props.model,
199
203
  prop: props.prop,
204
+ config: props.config,
200
205
  });
201
206
  };
202
207
 
@@ -238,6 +243,7 @@ export const getRules = function (mForm: FormState | undefined, rules: Rule[] |
238
243
  parent: mForm?.parentValues || {},
239
244
  formValue: mForm?.values || props.model,
240
245
  prop: props.prop,
246
+ config: props.config,
241
247
  },
242
248
  mForm,
243
249
  );