@tmagic/form 1.5.12 → 1.5.14

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.
package/package.json CHANGED
@@ -1,5 +1,5 @@
1
1
  {
2
- "version": "1.5.12",
2
+ "version": "1.5.14",
3
3
  "name": "@tmagic/form",
4
4
  "type": "module",
5
5
  "sideEffects": [
@@ -51,8 +51,8 @@
51
51
  "peerDependencies": {
52
52
  "vue": ">=3.5.0",
53
53
  "typescript": "*",
54
- "@tmagic/design": "1.5.12",
55
- "@tmagic/utils": "1.5.12"
54
+ "@tmagic/design": "1.5.14",
55
+ "@tmagic/utils": "1.5.14"
56
56
  },
57
57
  "peerDependenciesMeta": {
58
58
  "typescript": {
package/src/Form.vue CHANGED
@@ -63,7 +63,7 @@ const props = withDefaults(
63
63
  keyProp?: string;
64
64
  popperClass?: string;
65
65
  preventSubmitDefault?: boolean;
66
- extendState?: (state: FormState) => Record<string, any> | Promise<Record<string, any>>;
66
+ extendState?: (_state: FormState) => Record<string, any> | Promise<Record<string, any>>;
67
67
  }>(),
68
68
  {
69
69
  config: () => [],
@@ -101,7 +101,7 @@ const formState: FormState = reactive<FormState>({
101
101
  parentValues: props.parentValues,
102
102
  values,
103
103
  lastValuesProcessed,
104
- $emit: emit as (event: string, ...args: any[]) => void,
104
+ $emit: emit as (_event: string, ..._args: any[]) => void,
105
105
  fields,
106
106
  setField: (prop: string, field: any) => fields.set(prop, field),
107
107
  getField: (prop: string) => fields.get(prop),
@@ -82,7 +82,7 @@ withDefaults(
82
82
  labelPosition?: string;
83
83
  preventSubmitDefault?: boolean;
84
84
  /** 关闭前的回调,会暂停 Drawer 的关闭; done 是个 function type 接受一个 boolean 参数, 执行 done 使用 true 参数或不提供参数将会终止关闭 */
85
- beforeClose?: (done: (cancel?: boolean) => void) => void;
85
+ beforeClose?: (_done: (_cancel?: boolean) => void) => void;
86
86
  }>(),
87
87
  {
88
88
  closeOnPressEscape: true,
@@ -228,6 +228,7 @@ import { WarningFilled } from '@element-plus/icons-vue';
228
228
  import { isEqual } from 'lodash-es';
229
229
 
230
230
  import { TMagicButton, TMagicFormItem, TMagicIcon, TMagicTooltip } from '@tmagic/design';
231
+ import { setValueByKeyPath } from '@tmagic/utils';
231
232
 
232
233
  import type { ChildConfig, ContainerChangeEventData, ContainerCommonConfig, FormState, FormValue } from '../schema';
233
234
  import { display as displayFunction, filterFunction, getRules } from '../utils/form';
@@ -423,6 +424,12 @@ const onChangeHandler = async function (v: any, eventData: ContainerChangeEventD
423
424
  prop: itemProp.value,
424
425
  config: props.config,
425
426
  changeRecords: newChangeRecords,
427
+ setModel: (key: string, value: any) => {
428
+ setValueByKeyPath(key, value, props.model);
429
+ if (props.config.name) {
430
+ newChangeRecords.push({ propPath: itemProp.value.replace(`${props.config.name}`, key), value });
431
+ }
432
+ },
426
433
  })) ?? value;
427
434
  }
428
435
  value = trimHandler(trim, value) ?? value;
@@ -445,7 +452,6 @@ const onChangeHandler = async function (v: any, eventData: ContainerChangeEventD
445
452
  delete eventData.modifyKey;
446
453
  } else if (isValidName() && props.model !== value && (v !== value || props.model[name.value] !== value)) {
447
454
  // field内容下包含field-link时,model===value, 这里避免循环引用
448
- // eslint-disable-next-line vue/no-mutating-props
449
455
  props.model[name.value] = value;
450
456
  }
451
457
 
@@ -273,22 +273,18 @@ const isFullscreen = ref(false);
273
273
 
274
274
  const modelName = computed(() => props.name || props.config.name || '');
275
275
 
276
- const data = computed(() =>
277
- props.config.pagination
278
- ? (props.model[modelName.value] || []).filter(
279
- (item: any, index: number) =>
280
- index >= pagecontext.value * pagesize.value && index + 1 <= (pagecontext.value + 1) * pagesize.value,
281
- )
282
- : props.model[modelName.value],
283
- );
276
+ const getDataByPage = (data: any[] = []) =>
277
+ data.filter(
278
+ (item: any, index: number) =>
279
+ index >= pagecontext.value * pagesize.value && index + 1 <= (pagecontext.value + 1) * pagesize.value,
280
+ );
281
+
282
+ const pageinationData = computed(() => getDataByPage(props.model[modelName.value]));
283
+
284
+ const data = computed(() => (props.config.pagination ? pageinationData.value : props.model[modelName.value]));
284
285
 
285
286
  const lastData = computed(() =>
286
- props.config.pagination
287
- ? (props.lastValues[modelName.value] || []).filter(
288
- (item: any, index: number) =>
289
- index >= pagecontext.value * pagesize.value && index + 1 <= (pagecontext.value + 1) * pagesize.value,
290
- )
291
- : props.lastValues[modelName.value] || [],
287
+ props.config.pagination ? getDataByPage(props.lastValues[modelName.value]) : props.lastValues[modelName.value] || [],
292
288
  );
293
289
 
294
290
  const sortChange = ({ prop, order }: SortProp) => {
@@ -320,6 +316,8 @@ const rowDrop = () => {
320
316
  }
321
317
  sortable = Sortable.create(tBodyEl, {
322
318
  draggable: '.tmagic-design-table-row',
319
+ filter: 'input', // 表单组件选字操作和触发拖拽会冲突,优先保证选字操作
320
+ preventOnFilter: false, // 允许选字
323
321
  direction: 'vertical',
324
322
  onEnd: ({ newIndex, oldIndex }: SortableEvent) => {
325
323
  if (typeof newIndex === 'undefined') return;
@@ -41,21 +41,21 @@
41
41
  config.dynamic
42
42
  ? (name ? model[name] : model)[tabIndex]
43
43
  : tab.name
44
- ? (name ? model[name] : model)[tab.name]
45
- : name
46
- ? model[name]
47
- : model
44
+ ? (name ? model[name] : model)[tab.name]
45
+ : name
46
+ ? model[name]
47
+ : model
48
48
  "
49
49
  :last-values="
50
50
  isEmpty(lastValues)
51
51
  ? {}
52
52
  : config.dynamic
53
- ? (name ? lastValues[name] : lastValues)[tabIndex]
54
- : tab.name
55
- ? (name ? lastValues[name] : lastValues)[tab.name]
56
- : name
57
- ? lastValues[name]
58
- : lastValues
53
+ ? (name ? lastValues[name] : lastValues)[tabIndex]
54
+ : tab.name
55
+ ? (name ? lastValues[name] : lastValues)[tab.name]
56
+ : name
57
+ ? lastValues[name]
58
+ : lastValues
59
59
  "
60
60
  :is-compare="isCompare"
61
61
  :prop="config.dynamic ? `${prop}${prop ? '.' : ''}${String(tabIndex)}` : prop"
@@ -13,7 +13,6 @@ defineOptions({
13
13
  const props = defineProps<FieldProps<DisplayConfig>>();
14
14
 
15
15
  if (props.config.initValue && props.model) {
16
- // eslint-disable-next-line vue/no-setup-props-destructure
17
16
  props.model[props.name] = props.config.initValue;
18
17
  }
19
18
 
@@ -21,7 +21,7 @@
21
21
  >
22
22
  <template v-if="config.group">
23
23
  <component
24
- v-for="(group, index) in (options as SelectGroupOption[])"
24
+ v-for="(group, index) in options as SelectGroupOption[]"
25
25
  :key="index"
26
26
  :is="optionGroupComponent?.component || 'el-option-group'"
27
27
  v-bind="
@@ -55,7 +55,7 @@
55
55
  </template>
56
56
  <template v-else>
57
57
  <component
58
- v-for="option in (options as SelectOption[])"
58
+ v-for="option in options as SelectOption[]"
59
59
  class="tmagic-design-option"
60
60
  :key="config.valueKey ? option.value[config.valueKey] : option.value"
61
61
  :is="optionComponent?.component || 'el-option'"
@@ -31,7 +31,6 @@ const emit = defineEmits(['change']);
31
31
 
32
32
  useAddField(props.prop);
33
33
 
34
- // eslint-disable-next-line vue/no-setup-props-destructure
35
34
  const { names } = props.config;
36
35
  const value = ref<(Date | undefined)[] | null>([]);
37
36
 
package/src/index.ts CHANGED
@@ -101,7 +101,6 @@ export default {
101
101
  install(app: App, opt: FormInstallOptions = {}) {
102
102
  const option = Object.assign(defaultInstallOpt, opt);
103
103
 
104
- // eslint-disable-next-line no-param-reassign
105
104
  app.config.globalProperties.$MAGIC_FORM = option;
106
105
  setConfig(option);
107
106
 
package/src/schema.ts CHANGED
@@ -196,6 +196,7 @@ export interface OnChangeHandlerData {
196
196
  config: any;
197
197
  prop: string;
198
198
  changeRecords: ChangeRecord[];
199
+ setModel: (prop: string, value: any) => void;
199
200
  }
200
201
 
201
202
  export type OnChangeHandler = (mForm: FormState | undefined, value: any, data: OnChangeHandlerData) => any;
package/src/utils/form.ts CHANGED
@@ -16,7 +16,6 @@
16
16
  * limitations under the License.
17
17
  */
18
18
 
19
- /* eslint-disable no-param-reassign */
20
19
  import { toRaw } from 'vue';
21
20
  import dayjs from 'dayjs';
22
21
  import utc from 'dayjs/plugin/utc';