@tmagic/form 1.0.0-rc.9 → 1.0.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.
@@ -92,6 +92,7 @@ export interface Rule {
92
92
  /** 整个表单的值 */
93
93
  formValue: FormValue;
94
94
  prop: string;
95
+ config: any;
95
96
  }, mForm: FormState | undefined) => void;
96
97
  }
97
98
  export interface Input {
@@ -107,12 +108,14 @@ declare type FilterFunction = (mForm: FormState | undefined, data: {
107
108
  parent?: Record<any, any>;
108
109
  formValue: Record<any, any>;
109
110
  prop: string;
111
+ config: any;
110
112
  }) => boolean;
111
113
  declare type OnChangeHandler = (mForm: FormState | undefined, value: any, data: {
112
114
  model: Record<any, any>;
113
115
  values: Record<any, any>;
114
116
  parent?: Record<any, any>;
115
117
  formValue: Record<any, any>;
118
+ config: any;
116
119
  }) => any;
117
120
  declare type DefaultValueFunction = (mForm: FormState | undefined) => any;
118
121
  /**
@@ -141,16 +144,19 @@ declare type SelectOptionFunction = (mForm: FormState | undefined, data: {
141
144
  prop?: string;
142
145
  formValues: any;
143
146
  formValue: any;
147
+ config: any;
144
148
  }) => SelectOption[] | SelectGroupOption[];
145
149
  declare type RemoteSelectOptionBodyFunction = (mForm: FormState | undefined, data: {
146
150
  model: any;
147
151
  formValue: any;
148
152
  formValues: any;
153
+ config: any;
149
154
  }) => Record<string, any>;
150
155
  declare type RemoteSelectOptionRequestFunction = (mForm: FormState | undefined, res: any, data: {
151
156
  model: any;
152
157
  formValue: any;
153
158
  formValues: any;
159
+ config: any;
154
160
  }) => any;
155
161
  declare type RemoteSelectOptionItemFunction = (optionsData: Record<string, any>) => SelectOption[];
156
162
  declare type SelectOptionValueFunction = (item: Record<string, any>) => any;
@@ -168,6 +174,7 @@ interface CascaderOption {
168
174
  */
169
175
  export interface DaterangeConfig extends FormItem {
170
176
  type: 'daterange';
177
+ defaultTime?: Date[];
171
178
  names?: string[];
172
179
  }
173
180
  /**
@@ -235,6 +242,7 @@ export interface DateConfig extends FormItem, Input {
235
242
  */
236
243
  export interface DateTimeConfig extends FormItem, Input {
237
244
  type: 'datetime';
245
+ defaultTime?: Date[];
238
246
  format?: 'YYYY-MM-dd HH:mm:ss' | string;
239
247
  valueFormat?: 'YYYY-MM-dd HH:mm:ss' | string;
240
248
  }
@@ -396,6 +404,7 @@ export interface TabPaneConfig {
396
404
  lazy?: boolean;
397
405
  labelWidth?: string;
398
406
  items: FormConfig;
407
+ [key: string]: any;
399
408
  }
400
409
  export interface TabConfig extends FormItem, ContainerCommonConfig {
401
410
  type: 'tab' | 'dynamic-tab';
@@ -433,6 +442,7 @@ export interface ColumnConfig extends FormItem, ContainerCommonConfig {
433
442
  label: string;
434
443
  width: string | number;
435
444
  sortable: boolean;
445
+ [key: string]: any;
436
446
  }
437
447
  /**
438
448
  * 表格容器
package/package.json CHANGED
@@ -1,5 +1,5 @@
1
1
  {
2
- "version": "1.0.0-rc.9",
2
+ "version": "1.0.2",
3
3
  "name": "@tmagic/form",
4
4
  "sideEffects": [
5
5
  "dist/*",
@@ -33,7 +33,7 @@
33
33
  },
34
34
  "dependencies": {
35
35
  "@element-plus/icons": "0.0.11",
36
- "@tmagic/utils": "1.0.0-rc.9",
36
+ "@tmagic/utils": "1.0.2",
37
37
  "element-plus": "^2.2.0",
38
38
  "lodash-es": "^4.17.21",
39
39
  "moment": "^2.29.2",
@@ -217,6 +217,7 @@ export default defineComponent({
217
217
  values: mForm?.initValues,
218
218
  formValue: mForm?.values,
219
219
  prop: itemProp.value,
220
+ config: props.config,
220
221
  });
221
222
  }
222
223
 
@@ -234,6 +235,7 @@ export default defineComponent({
234
235
  values: mForm?.initValues,
235
236
  formValue: mForm?.values,
236
237
  prop: itemProp.value,
238
+ config: props.config,
237
239
  });
238
240
  }
239
241
  };
@@ -80,6 +80,8 @@ export default defineComponent({
80
80
  return props.config.addable(mForm, {
81
81
  model: props.model[props.name],
82
82
  formValue: mForm?.values,
83
+ prop: props.prop,
84
+ config: props.config,
83
85
  });
84
86
  }
85
87
 
@@ -101,6 +103,8 @@ export default defineComponent({
101
103
  initValues = await props.config.defaultAdd(mForm, {
102
104
  model: props.model[props.name],
103
105
  formValue: mForm?.values,
106
+ prop: props.prop,
107
+ config: props.config,
104
108
  });
105
109
  } else if (props.config.defaultAdd) {
106
110
  initValues = props.config.defaultAdd;
@@ -154,7 +154,7 @@
154
154
  /* eslint-disable no-param-reassign */
155
155
  import { computed, defineComponent, inject, onMounted, PropType, ref, toRefs } from 'vue';
156
156
  import { ArrowDown, ArrowUp, Delete, FullScreen, Grid } from '@element-plus/icons';
157
- import { ElMessage, ElTable, ElUpload } from 'element-plus';
157
+ import { ElMessage, ElTable, UploadFile } from 'element-plus';
158
158
  import { cloneDeep } from 'lodash-es';
159
159
  import Sortable, { SortableEvent } from 'sortablejs';
160
160
 
@@ -163,23 +163,6 @@ import { asyncLoadJs, sleep } from '@tmagic/utils';
163
163
  import { ColumnConfig, FormState, SortProp, TableConfig } from '../schema';
164
164
  import { display, initValue } from '../utils/form';
165
165
 
166
- export type UploadStatus = 'ready' | 'uploading' | 'success' | 'fail';
167
-
168
- export interface ElFile extends File {
169
- uid: number;
170
- }
171
-
172
- export type UploadFile = {
173
- name: string;
174
- percentage?: number;
175
- status: UploadStatus;
176
- size: number;
177
- response?: unknown;
178
- uid: number;
179
- url?: string;
180
- raw: ElFile;
181
- };
182
-
183
166
  let loadedAMapJS = false; // 是否加载完js
184
167
  let firstLoadingAMapJS = true; // 否是第一次请求
185
168
 
@@ -241,7 +224,7 @@ export default defineComponent({
241
224
  const mForm = inject<FormState | undefined>('mForm');
242
225
 
243
226
  const elTable = ref<InstanceType<typeof ElTable>>();
244
- const excelBtn = ref<InstanceType<typeof ElUpload>>();
227
+ const excelBtn = ref<any>();
245
228
  const mTable = ref<HTMLDivElement>();
246
229
 
247
230
  const pagesize = ref(10);
@@ -476,7 +459,7 @@ export default defineComponent({
476
459
  }
477
460
  emit('select', selection, row);
478
461
  if (typeof props.config.onSelect === 'function') {
479
- props.config.onSelect(mForm, { selection, row });
462
+ props.config.onSelect(mForm, { selection, row, config: props.config });
480
463
  }
481
464
  },
482
465
 
@@ -59,12 +59,12 @@ const tabClickHandler = (mForm: FormState | undefined, tab: any, props: any) =>
59
59
  tab.name = tab.paneName;
60
60
 
61
61
  if (typeof config.onTabClick === 'function') {
62
- config.onTabClick(mForm, tab, { model, formValue: mForm?.values, prop });
62
+ config.onTabClick(mForm, tab, { model, formValue: mForm?.values, prop, config });
63
63
  }
64
64
 
65
65
  const tabConfig = config.items.find((item: TabPaneConfig) => tab.name === item.status);
66
66
  if (tabConfig && typeof tabConfig.onTabClick === 'function') {
67
- tabConfig.onTabClick(mForm, tab, { model, formValue: mForm?.values, prop });
67
+ tabConfig.onTabClick(mForm, tab, { model, formValue: mForm?.values, prop, config });
68
68
  }
69
69
  };
70
70
 
@@ -136,7 +136,11 @@ const Tab = defineComponent({
136
136
  if (!props.config.name) throw new Error('dynamic tab 必须配置name');
137
137
 
138
138
  if (typeof props.config.onTabAdd === 'function') {
139
- props.config.onTabAdd(mForm, { model: props.model });
139
+ props.config.onTabAdd(mForm, {
140
+ model: props.model,
141
+ prop: props.prop,
142
+ config: props.config,
143
+ });
140
144
  } else if (tabs.value.length > 0) {
141
145
  const newObj = cloneDeep(tabs.value[0]);
142
146
  newObj.title = `标签${tabs.value.length + 1}`;
@@ -150,7 +154,11 @@ const Tab = defineComponent({
150
154
  if (!props.config.name) throw new Error('dynamic tab 必须配置name');
151
155
 
152
156
  if (typeof props.config.onTabRemove === 'function') {
153
- props.config.onTabRemove(mForm, tabName, { model: props.model });
157
+ props.config.onTabRemove(mForm, tabName, {
158
+ model: props.model,
159
+ prop: props.prop,
160
+ config: props.config,
161
+ });
154
162
  } else {
155
163
  props.model[props.config.name].splice(+tabName, 1);
156
164
 
@@ -169,7 +177,7 @@ const Tab = defineComponent({
169
177
  changeHandler: () => {
170
178
  emit('change', props.model);
171
179
  if (typeof props.config.onChange === 'function') {
172
- props.config.onChange(mForm, { model: props.model });
180
+ props.config.onChange(mForm, { model: props.model, prop: props.prop, config: props.config });
173
181
  }
174
182
  },
175
183
  };
@@ -1,17 +1,16 @@
1
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>
2
+ <el-date-picker
3
+ v-model="model[name]"
4
+ popper-class="magic-datetime-picker-popper"
5
+ type="datetime"
6
+ :size="size"
7
+ :placeholder="config.placeholder"
8
+ :disabled="disabled"
9
+ :format="config.format || 'YYYY-MM-DD HH:mm:ss'"
10
+ :value-format="config.valueFormat || 'YYYY-MM-DD HH:mm:ss'"
11
+ :default-time="config.defaultTime || [new Date(2000, 1, 1, 23, 59, 59)]"
12
+ @change="changeHandler"
13
+ ></el-date-picker>
15
14
  </template>
16
15
 
17
16
  <script lang="ts">
@@ -1,17 +1,16 @@
1
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>
2
+ <el-date-picker
3
+ v-model="value"
4
+ type="datetimerange"
5
+ range-separator="-"
6
+ start-placeholder="开始日期"
7
+ end-placeholder="结束日期"
8
+ :size="size"
9
+ :unlink-panels="true"
10
+ :disabled="disabled"
11
+ :default-time="config.defaultTime || [new Date(2000, 1, 1, 23, 59, 59)]"
12
+ @change="changeHandler"
13
+ ></el-date-picker>
15
14
  </template>
16
15
 
17
16
  <script lang="ts">
@@ -134,6 +134,7 @@ export default defineComponent({
134
134
  model: props.model,
135
135
  formValue: mForm?.values,
136
136
  formValues: mForm?.values,
137
+ config: props.config,
137
138
  }) as Record<string, any>;
138
139
  }
139
140
 
@@ -163,6 +164,7 @@ export default defineComponent({
163
164
  model: props.model,
164
165
  formValue: mForm?.values,
165
166
  formValues: mForm?.values,
167
+ config: props.config,
166
168
  });
167
169
  }
168
170
 
@@ -287,6 +289,7 @@ export default defineComponent({
287
289
  prop: props.prop,
288
290
  formValues: mForm?.values,
289
291
  formValue: mForm?.values,
292
+ config: props.config,
290
293
  }),
291
294
  ).then((data) => {
292
295
  options.value = data;
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
 
@@ -191,6 +194,7 @@ type SelectOptionFunction = (
191
194
  prop?: string;
192
195
  formValues: any;
193
196
  formValue: any;
197
+ config: any;
194
198
  },
195
199
  ) => SelectOption[] | SelectGroupOption[];
196
200
 
@@ -200,6 +204,7 @@ type RemoteSelectOptionBodyFunction = (
200
204
  model: any;
201
205
  formValue: any;
202
206
  formValues: any;
207
+ config: any;
203
208
  },
204
209
  ) => Record<string, any>;
205
210
 
@@ -210,6 +215,7 @@ type RemoteSelectOptionRequestFunction = (
210
215
  model: any;
211
216
  formValue: any;
212
217
  formValues: any;
218
+ config: any;
213
219
  },
214
220
  ) => any;
215
221
 
@@ -231,6 +237,7 @@ interface CascaderOption {
231
237
  */
232
238
  export interface DaterangeConfig extends FormItem {
233
239
  type: 'daterange';
240
+ defaultTime?: Date[];
234
241
  names?: string[];
235
242
  }
236
243
 
@@ -311,6 +318,7 @@ export interface DateConfig extends FormItem, Input {
311
318
  */
312
319
  export interface DateTimeConfig extends FormItem, Input {
313
320
  type: 'datetime';
321
+ defaultTime?: Date[];
314
322
  format?: 'YYYY-MM-dd HH:mm:ss' | string;
315
323
  valueFormat?: 'YYYY-MM-dd HH:mm:ss' | string;
316
324
  }
@@ -500,6 +508,7 @@ export interface TabPaneConfig {
500
508
  lazy?: boolean;
501
509
  labelWidth?: string;
502
510
  items: FormConfig;
511
+ [key: string]: any;
503
512
  }
504
513
  export interface TabConfig extends FormItem, ContainerCommonConfig {
505
514
  type: 'tab' | 'dynamic-tab';
@@ -540,6 +549,7 @@ export interface ColumnConfig extends FormItem, ContainerCommonConfig {
540
549
  label: string;
541
550
  width: string | number;
542
551
  sortable: boolean;
552
+ [key: string]: any;
543
553
  }
544
554
 
545
555
  /**
package/src/utils/form.ts CHANGED
@@ -71,7 +71,7 @@ const initItemsValue = (
71
71
  { items, name, extensible }: any,
72
72
  ) => {
73
73
  if (Array.isArray(initValue[name])) {
74
- value[name] = initValue[name].map((v: any) => init(mForm, items, v));
74
+ value[name] = initValue[name].map((v: any, index: number) => init(mForm, items, v, value[name]?.[index]));
75
75
  } else {
76
76
  value[name] = init(mForm, items, initValue[name], value[name]);
77
77
  if (extensible) {
@@ -201,6 +201,7 @@ export const filterFunction = (mForm: FormState | undefined, config: any, props:
201
201
  parent: mForm?.parentValues || {},
202
202
  formValue: mForm?.values || props.model,
203
203
  prop: props.prop,
204
+ config: props.config,
204
205
  });
205
206
  };
206
207
 
@@ -242,6 +243,7 @@ export const getRules = function (mForm: FormState | undefined, rules: Rule[] |
242
243
  parent: mForm?.parentValues || {},
243
244
  formValue: mForm?.values || props.model,
244
245
  prop: props.prop,
246
+ config: props.config,
245
247
  },
246
248
  mForm,
247
249
  );