@veltra/desktop 1.1.26 → 1.1.28
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/dist/components/action/action-group.vue.d.ts +1 -1
- package/dist/components/batch-edit/batch-edit.js.map +1 -1
- package/dist/components/batch-edit/batch-edit.vue.d.ts +2 -2
- package/dist/components/batch-edit/di.js.map +1 -1
- package/dist/components/cascade/cascade.vue.d.ts +4 -4
- package/dist/components/checkbox-group/checkbox-group.vue.d.ts +2 -2
- package/dist/components/form/form-model.d.ts +9 -9
- package/dist/components/form/form-model.js +2 -2
- package/dist/components/form/form-model.js.map +1 -1
- package/dist/components/multi-select/multi-select.vue.d.ts +2 -2
- package/dist/components/multi-tree-select/multi-tree-select.vue.d.ts +4 -4
- package/dist/components/radio-group/radio-group.vue.d.ts +2 -2
- package/dist/components/select/select.vue.d.ts +2 -2
- package/dist/components/tabs/tabs-horizontal.vue.d.ts +2 -2
- package/dist/components/tabs/tabs-vertical.vue.d.ts +2 -2
- package/dist/components/tabs/tabs.vue.d.ts +2 -2
- package/dist/components/textarea/textarea.vue.d.ts +1 -1
- package/dist/components/tree-select/tree-select.vue.d.ts +4 -4
- package/dist/types/form.d.ts +7 -7
- package/package.json +6 -6
- package/src/components/batch-edit/batch-edit.vue +2 -2
- package/src/components/batch-edit/di.ts +2 -2
- package/src/components/form/form-model.ts +24 -21
- package/src/types/form.ts +7 -7
|
@@ -11,8 +11,8 @@ declare const __VLS_base: _$vue.DefineComponent<ActionGroupProps, _ActionGroupEx
|
|
|
11
11
|
type: _$_veltra_utils0.ColorType;
|
|
12
12
|
size: "small" | "default" | "large";
|
|
13
13
|
text: boolean;
|
|
14
|
-
circle: boolean;
|
|
15
14
|
max: number;
|
|
15
|
+
circle: boolean;
|
|
16
16
|
loading: boolean;
|
|
17
17
|
}, {}, {}, {}, string, _$vue.ComponentProvideOptions, false, {}, any>;
|
|
18
18
|
declare const __VLS_export: __VLS_WithSlots<typeof __VLS_base, __VLS_Slots>;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"batch-edit.js","names":[],"sources":["../../../src/components/batch-edit/batch-edit.vue"],"sourcesContent":["<template>\n <u-layout\n :class=\"cls.b\"\n :cols=\"cols\"\n rows=\"minmax(0, 1fr)\"\n gap=\"8px\"\n resizable\n @keydown=\"handleKeydown\"\n tabindex=\"-1\"\n >\n <!-- 编辑列表 -->\n <BatchEditList :slots=\"slots\" />\n\n <!-- 编辑表单 -->\n <BatchEditForm v-slot=\"scoped\">\n <!-- @vue-ignore -->\n <slot name=\"form\" v-bind=\"scoped\" />\n </BatchEditForm>\n </u-layout>\n</template>\n\n<script lang=\"ts\" setup generic=\"Model extends
|
|
1
|
+
{"version":3,"file":"batch-edit.js","names":[],"sources":["../../../src/components/batch-edit/batch-edit.vue"],"sourcesContent":["<template>\n <u-layout\n :class=\"cls.b\"\n :cols=\"cols\"\n rows=\"minmax(0, 1fr)\"\n gap=\"8px\"\n resizable\n @keydown=\"handleKeydown\"\n tabindex=\"-1\"\n >\n <!-- 编辑列表 -->\n <BatchEditList :slots=\"slots\" />\n\n <!-- 编辑表单 -->\n <BatchEditForm v-slot=\"scoped\">\n <!-- @vue-ignore -->\n <slot name=\"form\" v-bind=\"scoped\" />\n </BatchEditForm>\n </u-layout>\n</template>\n\n<script lang=\"ts\" setup generic=\"Model extends IFormModel\">\nimport { bem } from '@veltra/utils'\nimport { computed, inject, provide, shallowRef, watch } from 'vue'\n\nimport type {\n BatchEditEmits,\n BatchEditFeature,\n BatchEditProps,\n IFormModel,\n TableColumnSlotsScope,\n TableExposed,\n TableRow\n} from '../../types'\nimport { DialogDIKey } from '../dialog/di'\nimport { ULayout } from '../layout'\nimport BatchEditForm from './batch-edit-form.vue'\nimport BatchEditList from './batch-edit-list.vue'\nimport { BatchEditDIKey } from './di'\nimport { useEdit } from './use-edit'\n\ndefineOptions({ name: 'BatchEdit' })\n\nconst props = withDefaults(defineProps<BatchEditProps<Model>>(), {\n cols: () => ['1fr', '420px'],\n mode: 'normal'\n})\n\nconst emit = defineEmits<BatchEditEmits>()\n\nconst staticFeatures = computed(() => {\n const { features } = props\n\n if (Array.isArray(features)) {\n return new Set(features)\n }\n\n const defaultFeatures = new Set<BatchEditFeature>(['create', 'delete', 'update', 'createChild'])\n\n if (!features) {\n return defaultFeatures\n }\n\n // 函数与 false 的特性视为关闭;显式 true 视为开启(即便不在默认集合内)\n Object.entries(features).forEach(([key, value]) => {\n const k = key as BatchEditFeature\n if (typeof value === 'function' || value === false) {\n defaultFeatures.delete(k)\n } else if (value === true) {\n defaultFeatures.add(k)\n }\n })\n return defaultFeatures\n})\n\nconst dynamicFeatures = computed<\n Record<BatchEditFeature, ((row?: TableRow) => boolean) | undefined>\n>(() => {\n const { features } = props\n if (!Array.isArray(features) && typeof features === 'object') {\n const ret = Object.entries(features)\n .filter(([_, value]) => {\n return typeof value === 'function'\n })\n .reduce(\n (acc, [key, value]) => {\n acc[key] = value\n return acc\n },\n {} as Record<BatchEditFeature, (row?: TableRow) => boolean>\n )\n return ret\n }\n\n return {} as Record<BatchEditFeature, ((row?: TableRow) => boolean) | undefined>\n})\n\nconst slots = defineSlots<\n {\n form?: (props: {\n /** 表单数据 */\n data: Model['data']\n /** 表单模型 */\n model: Model\n /** 当前编辑的层级 */\n depth?: number\n /** 当前编辑的行 */\n row?: TableRow\n /** 当前编辑的行索引 */\n index?: number\n /** 操作的目标行索引路径 */\n indexes?: number[]\n }) => any\n\n header?: () => any\n } & Partial<{ [key: `column:${string}`]: (props: TableColumnSlotsScope) => any }>\n>()\n\nconst cls = bem('batch-edit')\n\nconst tableRef = shallowRef<TableExposed>()\n\nconst editCtx = useEdit({ props, emit, tableRef })\n\nconst { state, handleClose, handleSave, handleDelete, handleCreate } = editCtx\n\nprovide(BatchEditDIKey, { cls, props, emit, tableRef, staticFeatures, dynamicFeatures, ...editCtx })\n\nconst dialogCtx = inject(DialogDIKey, undefined)\n\ndialogCtx &&\n watch(dialogCtx.visible, (visible) => {\n !visible && editCtx.handleClose()\n })\n\nconst cols = computed(() => {\n return !!state.row || state.visible ? props.cols : undefined\n})\n\n/**\n * 键盘快捷键:\n * - Esc 关闭表单\n * - ⌘/Ctrl + S 保存\n * - ⌘/Ctrl + Backspace 删除当前编辑行\n * - ⌘/Ctrl + N 新增(仅在不在表单中时)\n */\nfunction handleKeydown(e: KeyboardEvent) {\n if (props.readonly && e.key !== 'Escape') return\n\n if (e.key === 'Escape') {\n if (state.visible) {\n e.preventDefault()\n handleClose()\n }\n return\n }\n\n const meta = e.metaKey || e.ctrlKey\n if (!meta) return\n\n const key = e.key.toLowerCase()\n\n if (key === 's' && state.visible) {\n e.preventDefault()\n handleSave()\n return\n }\n\n if (e.key === 'Backspace' && state.row && state.type === 'update') {\n e.preventDefault()\n handleDelete(state.row)\n return\n }\n\n if (key === 'n' && !state.visible) {\n e.preventDefault()\n handleCreate()\n }\n}\n</script>\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;EA2CA,MAAM,QAAQ;EAKd,MAAM,OAAO;EAEb,MAAM,iBAAiB,eAAe;GACpC,MAAM,EAAE,aAAa;GAErB,IAAI,MAAM,QAAQ,SAAQ,EACxB,OAAO,IAAI,IAAI,SAAQ;GAGzB,MAAM,kBAAkB,IAAI,IAAsB;IAAC;IAAU;IAAU;IAAU;IAAc,CAAA;GAE/F,IAAI,CAAC,UACH,OAAO;GAIT,OAAO,QAAQ,SAAQ,CAAE,SAAS,CAAC,KAAK,WAAW;IACjD,MAAM,IAAI;IACV,IAAI,OAAO,UAAU,cAAc,UAAU,OAC3C,gBAAgB,OAAO,EAAC;SACnB,IAAI,UAAU,MACnB,gBAAgB,IAAI,EAAC;KAExB;GACD,OAAO;IACR;EAED,MAAM,kBAAkB,eAEhB;GACN,MAAM,EAAE,aAAa;GACrB,IAAI,CAAC,MAAM,QAAQ,SAAQ,IAAK,OAAO,aAAa,UAYlD,OAXY,O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,eAAE,MAAA,IAAA,CAAI,EAAC;IACZ,MAAM,KAAA;IACP,MAAK;IACL,KAAI;IACJ,WAAA;IACC,WAAS;IACV,UAAS;;2BAEI;KAAb,mBAAA,SAAA;KACA,YAAgC,aAAA,EAAT,OAAK,CAAA;KAE5B,mBAAA,SAAA;KACA,YAGgB,aAAA,MAAA;wBAHO,WAAM,CAC3B,mBAAA,gBAAA,EACA,WAAoC,KAAA,QAAA,QAAA,eAAA,mBAAV,OAAM,CAAA,CAAA,CAAA,CAAA"}
|
|
@@ -1,11 +1,11 @@
|
|
|
1
|
+
import { IFormModel } from "../../types/form.js";
|
|
1
2
|
import { TableColumn, TableColumnSlotsScope, TableRow } from "../../types/table.js";
|
|
2
3
|
import { BatchEditEmits, BatchEditProps } from "../../types/batch-edit.js";
|
|
3
|
-
import { FormModel } from "../form/form-model.js";
|
|
4
4
|
import * as _$vue from "vue";
|
|
5
5
|
import * as _$_cat_kit_core0 from "@cat-kit/core";
|
|
6
6
|
|
|
7
7
|
//#region src/components/batch-edit/batch-edit.vue.d.ts
|
|
8
|
-
declare const __VLS_export: <Model extends
|
|
8
|
+
declare const __VLS_export: <Model extends IFormModel>(__VLS_props: NonNullable<Awaited<typeof __VLS_setup>>["props"], __VLS_ctx?: __VLS_PrettifyLocal<Pick<NonNullable<Awaited<typeof __VLS_setup>>, "attrs" | "emit" | "slots">>, __VLS_exposed?: NonNullable<Awaited<typeof __VLS_setup>>["expose"], __VLS_setup?: Promise<{
|
|
9
9
|
props: _$vue.PublicProps & __VLS_PrettifyLocal<BatchEditProps<Model> & {
|
|
10
10
|
"onUpdate:selected"?: ((value: Record<string, any> | undefined) => any) | undefined;
|
|
11
11
|
"onUpdate:checked"?: ((value: Record<string, any>[]) => any) | undefined;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"di.js","names":[],"sources":["../../../src/components/batch-edit/di.ts"],"sourcesContent":["import type { BEM } from '@veltra/utils'\nimport type { ComputedRef, InjectionKey, ShallowRef } from 'vue'\n\nimport type {\n BatchEditEmits,\n BatchEditFeature,\n BatchEditProps,\n TableExposed,\n TableRow\n} from '../../types'\nimport type {
|
|
1
|
+
{"version":3,"file":"di.js","names":[],"sources":["../../../src/components/batch-edit/di.ts"],"sourcesContent":["import type { BEM } from '@veltra/utils'\nimport type { ComputedRef, InjectionKey, ShallowRef } from 'vue'\n\nimport type {\n BatchEditEmits,\n BatchEditFeature,\n BatchEditProps,\n IFormModel,\n TableExposed,\n TableRow\n} from '../../types'\nimport type { EditReturned } from './use-edit'\nexport const BatchEditDIKey: InjectionKey<\n {\n cls: BEM<'batch-edit', 'u-'>\n props: BatchEditProps<IFormModel>\n emit: BatchEditEmits\n tableRef: ShallowRef<TableExposed | undefined>\n staticFeatures: ComputedRef<Set<BatchEditFeature>>\n dynamicFeatures: ComputedRef<\n Record<BatchEditFeature, ((row?: TableRow) => boolean) | undefined>\n >\n } & EditReturned\n> = Symbol('BatchEditDIKey')\n"],"mappings":";AAYA,MAAa,iBAWT,OAAO,iBAAiB"}
|
|
@@ -11,14 +11,14 @@ declare const __VLS_export: _$vue.DefineComponent<CascadeProps, {}, {}, {}, {},
|
|
|
11
11
|
onClear?: (() => any) | undefined;
|
|
12
12
|
onChange?: ((...args: [value?: string | undefined, label?: string | undefined, item?: Record<string, any> | undefined] | [value: string[], label: string[], data: Record<string, any>[]]) => any) | undefined;
|
|
13
13
|
}>, {
|
|
14
|
-
labelKey: string;
|
|
15
|
-
valueKey: string;
|
|
16
|
-
childrenKey: string;
|
|
17
|
-
data: Record<string, any>[];
|
|
18
14
|
disabled: boolean;
|
|
19
15
|
readonly: boolean;
|
|
20
16
|
placeholder: string;
|
|
21
17
|
clearable: boolean;
|
|
18
|
+
labelKey: string;
|
|
19
|
+
valueKey: string;
|
|
20
|
+
childrenKey: string;
|
|
21
|
+
data: Record<string, any>[];
|
|
22
22
|
filterable: boolean;
|
|
23
23
|
visibilityLimit: number;
|
|
24
24
|
separator: string;
|
|
@@ -14,10 +14,10 @@ declare const __VLS_export: _$vue.DefineComponent<__VLS_PublicProps, {}, {}, {},
|
|
|
14
14
|
}, string, _$vue.PublicProps, Readonly<__VLS_PublicProps> & Readonly<{
|
|
15
15
|
"onUpdate:modelValue"?: ((value: any[]) => any) | undefined;
|
|
16
16
|
}>, {
|
|
17
|
-
labelKey: string;
|
|
18
|
-
valueKey: string;
|
|
19
17
|
disabled: boolean;
|
|
20
18
|
readonly: boolean;
|
|
19
|
+
labelKey: string;
|
|
20
|
+
valueKey: string;
|
|
21
21
|
}, {}, {}, {}, string, _$vue.ComponentProvideOptions, false, {}, any>;
|
|
22
22
|
declare const _default: typeof __VLS_export;
|
|
23
23
|
//#endregion
|
|
@@ -1,11 +1,11 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { DataSettingConfig, FormModelField, IFormModel, ModelData } from "../../types/form.js";
|
|
2
2
|
import { Reactive } from "vue";
|
|
3
3
|
|
|
4
4
|
//#region src/components/form/form-model.d.ts
|
|
5
5
|
/**
|
|
6
6
|
* 表单模型
|
|
7
7
|
*/
|
|
8
|
-
declare class FormModel<Fields extends Record<string,
|
|
8
|
+
declare class FormModel<Fields extends Record<string, FormModelField> = Record<string, FormModelField>> implements IFormModel<Fields> {
|
|
9
9
|
/** 表单数据 */
|
|
10
10
|
data: ModelData<Fields>;
|
|
11
11
|
/** 表单规则 */
|
|
@@ -17,10 +17,10 @@ declare class FormModel<Fields extends Record<string, any> = Record<string, any>
|
|
|
17
17
|
* @description
|
|
18
18
|
* 这个值会在表单组件渲染时由表单设置,因为只有真正渲染的组件才应该被校验
|
|
19
19
|
*/
|
|
20
|
-
formKeys: Map<number,
|
|
20
|
+
formKeys: Map<number, string[]>;
|
|
21
21
|
/** 初始数据 */
|
|
22
22
|
readonly initialData: ModelData<Fields>;
|
|
23
|
-
readonly errors: Map<
|
|
23
|
+
readonly errors: Map<string, string[] | undefined>;
|
|
24
24
|
private validator;
|
|
25
25
|
/**
|
|
26
26
|
* 是否在表单值更新时校验
|
|
@@ -40,18 +40,18 @@ declare class FormModel<Fields extends Record<string, any> = Record<string, any>
|
|
|
40
40
|
* @param fields 需要校验的字段, 不传则校验所有字段
|
|
41
41
|
* @returns
|
|
42
42
|
*/
|
|
43
|
-
validate(fields?:
|
|
43
|
+
validate(fields?: string | string[]): Promise<boolean>;
|
|
44
44
|
/**
|
|
45
45
|
* 重置数据
|
|
46
46
|
* @param fields 需要重置的字段
|
|
47
47
|
*/
|
|
48
|
-
resetData(keys?:
|
|
48
|
+
resetData(keys?: string | string[]): void;
|
|
49
49
|
/**
|
|
50
50
|
* 设置值
|
|
51
51
|
* @param formData 表单值
|
|
52
52
|
* @param options 配置
|
|
53
53
|
*/
|
|
54
|
-
setData(formData: Partial<
|
|
54
|
+
setData(formData: Partial<Record<string, any>>, config?: DataSettingConfig): FormModel<Fields>;
|
|
55
55
|
/**
|
|
56
56
|
* 设置初始值
|
|
57
57
|
* @description 初始值在重置数据和查看原始数据时会用到
|
|
@@ -64,9 +64,9 @@ declare class FormModel<Fields extends Record<string, any> = Record<string, any>
|
|
|
64
64
|
* 监听值变更
|
|
65
65
|
* @param cb 回调
|
|
66
66
|
*/
|
|
67
|
-
onChange(cb: (field:
|
|
67
|
+
onChange(cb: (field: string, val: any) => void): void;
|
|
68
68
|
/** 关闭监听值变更 */
|
|
69
|
-
offChange(cb: (field:
|
|
69
|
+
offChange(cb: (field: string, val: any) => void): void;
|
|
70
70
|
}
|
|
71
71
|
//#endregion
|
|
72
72
|
export { FormModel };
|
|
@@ -87,8 +87,8 @@ var FormModel = class {
|
|
|
87
87
|
getValidateFields(fields) {
|
|
88
88
|
if (!fields) if (this.formKeys.size) {
|
|
89
89
|
let _fields = [];
|
|
90
|
-
this.formKeys.forEach((
|
|
91
|
-
_fields = _fields.concat(
|
|
90
|
+
this.formKeys.forEach((keys) => {
|
|
91
|
+
_fields = _fields.concat(keys);
|
|
92
92
|
});
|
|
93
93
|
return _fields;
|
|
94
94
|
} else return this.allKeys;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"form-model.js","names":[],"sources":["../../../src/components/form/form-model.ts"],"sourcesContent":["import { o } from '@cat-kit/core'\nimport { middleProxy, Validator } from '@veltra/utils'\nimport { nextTick, reactive, shallowReactive, watch, type Reactive } from 'vue'\n\nimport type {
|
|
1
|
+
{"version":3,"file":"form-model.js","names":[],"sources":["../../../src/components/form/form-model.ts"],"sourcesContent":["import { o } from '@cat-kit/core'\nimport { middleProxy, Validator } from '@veltra/utils'\nimport { nextTick, reactive, shallowReactive, watch, type Reactive } from 'vue'\n\nimport type {\n ModelData,\n DataSettingConfig,\n IFormModel,\n FormModelItem,\n FormModelField\n} from '../../types'\n\n/**\n * 递归展平字段逻辑\n */\nfunction flattenFields(fields: Record<string, any>, prefix = ''): Record<string, FormModelItem> {\n const result: Record<string, FormModelItem> = {}\n for (const key in fields) {\n const item = fields[key]\n const fullPath = prefix ? `${prefix}.${key}` : key\n if (item && typeof item === 'object' && '__isNested' in item && item.__isNested) {\n Object.assign(result, flattenFields((item as any).fields, fullPath))\n } else {\n result[fullPath] = item\n }\n }\n return result\n}\n\n/**\n * 表单模型\n */\nexport class FormModel<\n Fields extends Record<string, FormModelField> = Record<string, FormModelField>\n> implements IFormModel<Fields> {\n /** 表单数据 */\n data!: ModelData<Fields>\n\n /** 表单规则 */\n readonly fields: Fields\n\n /** 所有的键 */\n readonly allKeys: string[]\n\n /**\n * 不同表单所需要校验的字段\n * @description\n * 这个值会在表单组件渲染时由表单设置,因为只有真正渲染的组件才应该被校验\n */\n formKeys: Map<number, string[]> = new Map()\n\n /** 初始数据 */\n readonly initialData: ModelData<Fields>\n\n readonly errors: Map<string, string[] | undefined> = shallowReactive(new Map())\n\n private validator: Validator<Record<string, FormModelItem>>\n\n /**\n * 是否在表单值更新时校验\n */\n private validateOnFieldChange = true\n\n private modelChangeCallback: Set<(fields: string, val: any) => void> = new Set()\n\n constructor(fields: Fields) {\n this.fields = fields\n const flatFields = flattenFields(fields)\n const rawData = {} as ModelData<Fields>\n const allKeys: string[] = []\n\n for (const key in flatFields) {\n const fieldItem = flatFields[key]!\n allKeys.push(key)\n const { value } = fieldItem\n let v = value\n\n if (typeof value === 'function') {\n watch(value, (v) => {\n o(this.initialData).set(key, v)\n })\n v = value()\n }\n\n o(rawData).set(key, v)\n }\n\n this.allKeys = allKeys\n this.initialData = JSON.parse(JSON.stringify(rawData))\n\n this.setProxyData(reactive(rawData))\n\n this.validator = new Validator(flatFields)\n\n return shallowReactive(this)\n }\n\n /**\n * 设置响应式值, 替换掉原有的数据\n * @description 设置响应式值时,会自动监听值的变化,并进行校验\n * @param proxyData 响应式的值\n */\n setProxyData(proxyData: ModelData<Fields> | Reactive<ModelData<Fields>>): void {\n const data = middleProxy(proxyData, {\n set: (field, val) => {\n this.modelChangeCallback.forEach((cb) => cb(field, val))\n },\n\n changed: (fields) => {\n if (!this.validateOnFieldChange) {\n this.validateOnFieldChange = true\n return\n }\n this.validate(fields as any)\n }\n })\n\n this.data = data as ModelData<Fields>\n }\n\n private getValidateFields(fields?: string | string[]) {\n if (!fields) {\n if (this.formKeys.size) {\n let _fields: string[] = []\n this.formKeys.forEach((keys) => {\n _fields = _fields.concat(keys)\n })\n return _fields\n } else {\n return this.allKeys\n }\n }\n\n if (!Array.isArray(fields)) {\n return [fields]\n }\n return fields\n }\n\n /**\n * 模型校验\n * @param fields 需要校验的字段, 不传则校验所有字段\n * @returns\n */\n async validate(fields?: string | string[]): Promise<boolean> {\n const { errors, validator, data } = this\n\n const results = await validator.validate(data, this.getValidateFields(fields))\n\n // 全量校验\n if (!fields) {\n errors.clear()\n\n for (const field in results) {\n errors.set(field as any, results[field])\n }\n }\n // 局部校验\n else {\n ~(Array.isArray(fields) ? fields : [fields]).forEach((field) => {\n const errs = results[field as string]\n if (errs?.length) {\n errors.set(field, errs)\n } else {\n errors.delete(field)\n }\n })\n }\n\n if (errors.size > 0) {\n if (!fields) {\n nextTick(() => {\n document.querySelector('.u-form-item.is-error')?.scrollIntoView({ block: 'nearest' })\n })\n }\n return Promise.reject(false)\n }\n\n return true\n }\n\n /**\n * 重置数据\n * @param fields 需要重置的字段\n */\n resetData(keys?: string | string[]): void {\n if (typeof keys === 'string') {\n keys = [keys]\n } else if (Array.isArray(keys)) {\n } else {\n keys = this.allKeys\n }\n\n this.clearValidate()\n\n this.validateOnFieldChange = false\n\n keys.forEach((field) => {\n o(this.data).set(field as string, o(this.initialData).get(field as string))\n })\n }\n\n /**\n * 设置值\n * @param formData 表单值\n * @param options 配置\n */\n setData(formData: Partial<Record<string, any>>, config?: DataSettingConfig): FormModel<Fields> {\n const { validate = true } = config || {}\n\n if (!validate) {\n this.validateOnFieldChange = false\n }\n\n this.allKeys.forEach((key) => {\n const value = o(formData).get(key)\n if (value !== undefined) {\n o(this.data).set(key, value)\n }\n })\n\n return this\n }\n\n /**\n * 设置初始值\n * @description 初始值在重置数据和查看原始数据时会用到\n * @param data 初始值\n */\n setInitialData(data: Partial<ModelData<Fields>>): FormModel<Fields> {\n this.allKeys.forEach((key) => {\n o(this.initialData).set(key, o(data).get(key))\n })\n\n return this\n }\n\n /** 清除校验 */\n clearValidate(): void {\n this.errors.clear()\n }\n\n /**\n * 监听值变更\n * @param cb 回调\n */\n onChange(cb: (field: string, val: any) => void): void {\n this.modelChangeCallback.add(cb)\n }\n\n /** 关闭监听值变更 */\n offChange(cb: (field: string, val: any) => void): void {\n this.modelChangeCallback.delete(cb)\n }\n}\n"],"mappings":";;;;;;;AAeA,SAAS,cAAc,QAA6B,SAAS,IAAmC;CAC9F,MAAM,SAAwC,EAAE;CAChD,KAAK,MAAM,OAAO,QAAQ;EACxB,MAAM,OAAO,OAAO;EACpB,MAAM,WAAW,SAAS,GAAG,OAAO,GAAG,QAAQ;EAC/C,IAAI,QAAQ,OAAO,SAAS,YAAY,gBAAgB,QAAQ,KAAK,YACnE,OAAO,OAAO,QAAQ,cAAe,KAAa,QAAQ,SAAS,CAAC;OAEpE,OAAO,YAAY;;CAGvB,OA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K,KAAK,CAAC,IAAI,KAAK,MAAM;IAE9B;EAEF,OAAO;;;;;;;CAQT,eAAe,MAAqD;EAClE,KAAK,QAAQ,SAAS,QAAQ;GAC5B,EAAE,KAAK,YAAY,CAAC,IAAI,KAAK,EAAE,KAAK,CAAC,IAAI,IAAI,CAAC;IAC9C;EAEF,OAAO;;;CAIT,gBAAsB;EACpB,KAAK,OAAO,OAAO;;;;;;CAOrB,SAAS,IAA6C;EACpD,KAAK,oBAAoB,IAAI,GAAG;;;CAIlC,UAAU,IAA6C;EACrD,KAAK,oBAAoB,OAAO,GAAG"}
|
|
@@ -28,13 +28,13 @@ declare const __VLS_base: _$vue.DefineComponent<__VLS_PublicProps, {}, {}, {}, {
|
|
|
28
28
|
"onUpdate:modelValue"?: ((value: any[]) => any) | undefined;
|
|
29
29
|
onChange?: ((options: Record<string, any>[]) => any) | undefined;
|
|
30
30
|
}>, {
|
|
31
|
-
labelKey: string;
|
|
32
|
-
valueKey: string;
|
|
33
31
|
disabled: boolean;
|
|
34
32
|
readonly: boolean;
|
|
35
33
|
placeholder: string;
|
|
36
34
|
clearable: boolean;
|
|
37
35
|
minWidth: string;
|
|
36
|
+
labelKey: string;
|
|
37
|
+
valueKey: string;
|
|
38
38
|
visibilityLimit: number;
|
|
39
39
|
}, {}, {}, {}, string, _$vue.ComponentProvideOptions, false, {}, any>;
|
|
40
40
|
declare const __VLS_export: __VLS_WithSlots<typeof __VLS_base, __VLS_Slots>;
|
|
@@ -22,15 +22,15 @@ declare const __VLS_base: _$vue.DefineComponent<__VLS_PublicProps, {}, {}, {}, {
|
|
|
22
22
|
onClear?: (() => any) | undefined;
|
|
23
23
|
onChange?: ((checked: Record<string, any>[]) => any) | undefined;
|
|
24
24
|
}>, {
|
|
25
|
-
expandAll: boolean;
|
|
26
|
-
labelKey: string;
|
|
27
|
-
valueKey: string;
|
|
28
25
|
disabled: boolean;
|
|
29
26
|
readonly: boolean;
|
|
30
27
|
placeholder: string;
|
|
31
28
|
clearable: boolean;
|
|
32
|
-
filterable: boolean;
|
|
33
29
|
minWidth: string;
|
|
30
|
+
expandAll: boolean;
|
|
31
|
+
labelKey: string;
|
|
32
|
+
valueKey: string;
|
|
33
|
+
filterable: boolean;
|
|
34
34
|
visibilityLimit: number;
|
|
35
35
|
}, {}, {}, {}, string, _$vue.ComponentProvideOptions, false, {}, any>;
|
|
36
36
|
declare const __VLS_export: __VLS_WithSlots<typeof __VLS_base, __VLS_Slots>;
|
|
@@ -16,10 +16,10 @@ declare const __VLS_export: _$vue.DefineComponent<__VLS_PublicProps, {}, {}, {},
|
|
|
16
16
|
"onUpdate:modelValue"?: ((value: any) => any) | undefined;
|
|
17
17
|
onChange?: ((item: Record<string, any>) => any) | undefined;
|
|
18
18
|
}>, {
|
|
19
|
-
labelKey: string;
|
|
20
|
-
valueKey: string;
|
|
21
19
|
disabled: boolean;
|
|
22
20
|
readonly: boolean;
|
|
21
|
+
labelKey: string;
|
|
22
|
+
valueKey: string;
|
|
23
23
|
}, {}, {}, {}, string, _$vue.ComponentProvideOptions, false, {}, any>;
|
|
24
24
|
declare const _default: typeof __VLS_export;
|
|
25
25
|
//#endregion
|
|
@@ -26,12 +26,12 @@ declare const __VLS_base: _$vue.DefineComponent<__VLS_PublicProps, {}, {}, {}, {
|
|
|
26
26
|
"onUpdate:text"?: ((value: any) => any) | undefined;
|
|
27
27
|
"onUpdate:label"?: ((label?: string | undefined) => any) | undefined;
|
|
28
28
|
}>, {
|
|
29
|
-
labelKey: string;
|
|
30
|
-
valueKey: string;
|
|
31
29
|
disabled: boolean;
|
|
32
30
|
readonly: boolean;
|
|
33
31
|
placeholder: string;
|
|
34
32
|
clearable: boolean;
|
|
33
|
+
labelKey: string;
|
|
34
|
+
valueKey: string;
|
|
35
35
|
}, {}, {}, {}, string, _$vue.ComponentProvideOptions, false, {}, any>;
|
|
36
36
|
declare const __VLS_export: __VLS_WithSlots<typeof __VLS_base, __VLS_Slots>;
|
|
37
37
|
declare const _default: typeof __VLS_export;
|
|
@@ -16,12 +16,12 @@ declare const __VLS_base: _$vue.DefineComponent<__VLS_PublicProps, {}, {}, {}, {
|
|
|
16
16
|
"update:modelValue": (value: string | undefined) => any;
|
|
17
17
|
} & {
|
|
18
18
|
"update:modelValue": (value: string) => any;
|
|
19
|
-
click: (item: TabItem, index: number) => any;
|
|
20
19
|
close: (item: TabItem, index: number) => any;
|
|
20
|
+
click: (item: TabItem, index: number) => any;
|
|
21
21
|
}, string, _$vue.PublicProps, Readonly<__VLS_PublicProps> & Readonly<{
|
|
22
22
|
"onUpdate:modelValue"?: ((value: string) => any) | undefined;
|
|
23
|
-
onClick?: ((item: TabItem, index: number) => any) | undefined;
|
|
24
23
|
onClose?: ((item: TabItem, index: number) => any) | undefined;
|
|
24
|
+
onClick?: ((item: TabItem, index: number) => any) | undefined;
|
|
25
25
|
}>, {
|
|
26
26
|
closable: boolean;
|
|
27
27
|
rounded: boolean;
|
|
@@ -15,12 +15,12 @@ declare const __VLS_base: _$vue.DefineComponent<__VLS_PublicProps, {}, {}, {}, {
|
|
|
15
15
|
"update:modelValue": (value: string | undefined) => any;
|
|
16
16
|
} & {
|
|
17
17
|
"update:modelValue": (value: string) => any;
|
|
18
|
-
click: (item: TabItem, index: number) => any;
|
|
19
18
|
close: (item: TabItem, index: number) => any;
|
|
19
|
+
click: (item: TabItem, index: number) => any;
|
|
20
20
|
}, string, _$vue.PublicProps, Readonly<__VLS_PublicProps> & Readonly<{
|
|
21
21
|
"onUpdate:modelValue"?: ((value: string) => any) | undefined;
|
|
22
|
-
onClick?: ((item: TabItem, index: number) => any) | undefined;
|
|
23
22
|
onClose?: ((item: TabItem, index: number) => any) | undefined;
|
|
23
|
+
onClick?: ((item: TabItem, index: number) => any) | undefined;
|
|
24
24
|
}>, {
|
|
25
25
|
closable: boolean;
|
|
26
26
|
rounded: boolean;
|
|
@@ -11,12 +11,12 @@ declare const __VLS_export: _$vue.DefineComponent<__VLS_PublicProps, {}, {}, {},
|
|
|
11
11
|
"update:modelValue": (value: string | undefined) => any;
|
|
12
12
|
} & {
|
|
13
13
|
"update:modelValue": (value: string) => any;
|
|
14
|
-
click: (item: TabItem, index: number) => any;
|
|
15
14
|
close: (item: TabItem, index: number) => any;
|
|
15
|
+
click: (item: TabItem, index: number) => any;
|
|
16
16
|
}, string, _$vue.PublicProps, Readonly<__VLS_PublicProps> & Readonly<{
|
|
17
17
|
"onUpdate:modelValue"?: ((value: string) => any) | undefined;
|
|
18
|
-
onClick?: ((item: TabItem, index: number) => any) | undefined;
|
|
19
18
|
onClose?: ((item: TabItem, index: number) => any) | undefined;
|
|
19
|
+
onClick?: ((item: TabItem, index: number) => any) | undefined;
|
|
20
20
|
}>, {
|
|
21
21
|
closable: boolean;
|
|
22
22
|
rounded: boolean;
|
|
@@ -22,11 +22,11 @@ declare const __VLS_export: _$vue.DefineComponent<__VLS_PublicProps, {}, {}, {},
|
|
|
22
22
|
onFocus?: (() => any) | undefined;
|
|
23
23
|
onBlur?: (() => any) | undefined;
|
|
24
24
|
}>, {
|
|
25
|
+
resize: boolean;
|
|
25
26
|
disabled: boolean;
|
|
26
27
|
readonly: boolean;
|
|
27
28
|
placeholder: string;
|
|
28
29
|
clearable: boolean;
|
|
29
|
-
resize: boolean;
|
|
30
30
|
autosize: boolean;
|
|
31
31
|
}, {}, {}, {}, string, _$vue.ComponentProvideOptions, false, {}, any>;
|
|
32
32
|
declare const _default: typeof __VLS_export;
|
|
@@ -24,15 +24,15 @@ declare const __VLS_base: _$vue.DefineComponent<__VLS_PublicProps, {}, {}, {}, {
|
|
|
24
24
|
onChange?: ((value?: string | number | undefined, selectedData?: Record<string, any> | undefined) => any) | undefined;
|
|
25
25
|
"onUpdate:text"?: ((text?: string | undefined) => any) | undefined;
|
|
26
26
|
}>, {
|
|
27
|
-
expandAll: boolean;
|
|
28
|
-
labelKey: string;
|
|
29
|
-
valueKey: string;
|
|
30
27
|
disabled: boolean;
|
|
31
28
|
readonly: boolean;
|
|
32
29
|
placeholder: string;
|
|
33
30
|
clearable: boolean;
|
|
34
|
-
filterable: boolean;
|
|
35
31
|
minWidth: string;
|
|
32
|
+
expandAll: boolean;
|
|
33
|
+
labelKey: string;
|
|
34
|
+
valueKey: string;
|
|
35
|
+
filterable: boolean;
|
|
36
36
|
}, {}, {}, {}, string, _$vue.ComponentProvideOptions, false, {}, any>;
|
|
37
37
|
declare const __VLS_export: __VLS_WithSlots<typeof __VLS_base, __VLS_Slots>;
|
|
38
38
|
declare const _default: typeof __VLS_export;
|
package/dist/types/form.d.ts
CHANGED
|
@@ -25,23 +25,23 @@ type IFormModel<Fields extends Record<string, any> = Record<string, any>> = {
|
|
|
25
25
|
* 字段键
|
|
26
26
|
*/
|
|
27
27
|
readonly allKeys: string[]; /** 需要校验的key */
|
|
28
|
-
formKeys: Map<number,
|
|
29
|
-
readonly errors: Map<
|
|
28
|
+
formKeys: Map<number, string[]>; /** 错误 */
|
|
29
|
+
readonly errors: Map<string, string[] | undefined>;
|
|
30
30
|
/**
|
|
31
31
|
* 字段校验
|
|
32
32
|
* @param fields 字段, 如果不传入时将会使用keyFields来进行校验
|
|
33
33
|
*/
|
|
34
|
-
validate: (fields?:
|
|
35
|
-
resetData(fields?:
|
|
34
|
+
validate: (fields?: string | string[]) => Promise<boolean>; /** 重置数据 */
|
|
35
|
+
resetData(fields?: string | string[]): void;
|
|
36
36
|
/**
|
|
37
37
|
* 设置数据
|
|
38
38
|
* @param formData 表单值
|
|
39
39
|
* @param options 配置
|
|
40
40
|
*/
|
|
41
|
-
setData(formData: Partial<
|
|
41
|
+
setData(formData: Partial<Record<string, any>>, config?: DataSettingConfig): void; /** 清除校验 */
|
|
42
42
|
clearValidate(): void; /** 监听值变更 */
|
|
43
|
-
onChange(cb: (field:
|
|
44
|
-
offChange(cb: (field:
|
|
43
|
+
onChange(cb: (field: string, val: any) => void): void; /** 关闭监听值变更 */
|
|
44
|
+
offChange(cb: (field: string, val: any) => void): void;
|
|
45
45
|
};
|
|
46
46
|
/** 表单组件属性 */
|
|
47
47
|
interface FormProps<Model extends IFormModel = IFormModel> extends ComponentProps {
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@veltra/desktop",
|
|
3
|
-
"version": "1.1.
|
|
3
|
+
"version": "1.1.28",
|
|
4
4
|
"files": [
|
|
5
5
|
"dist",
|
|
6
6
|
"src"
|
|
@@ -68,11 +68,11 @@
|
|
|
68
68
|
"@cat-kit/core": ">=1.1.5",
|
|
69
69
|
"@cat-kit/excel": ">=1.0.0",
|
|
70
70
|
"@cat-kit/fe": "^1.1.5",
|
|
71
|
-
"@veltra/compositions": "1.1.
|
|
72
|
-
"@veltra/directives": "1.1.
|
|
73
|
-
"@veltra/icons": "1.1.
|
|
74
|
-
"@veltra/styles": "1.1.
|
|
75
|
-
"@veltra/utils": "1.1.
|
|
71
|
+
"@veltra/compositions": "1.1.28",
|
|
72
|
+
"@veltra/directives": "1.1.28",
|
|
73
|
+
"@veltra/icons": "1.1.28",
|
|
74
|
+
"@veltra/styles": "1.1.28",
|
|
75
|
+
"@veltra/utils": "1.1.28",
|
|
76
76
|
"vue": ">=3.5.0"
|
|
77
77
|
}
|
|
78
78
|
}
|
|
@@ -19,7 +19,7 @@
|
|
|
19
19
|
</u-layout>
|
|
20
20
|
</template>
|
|
21
21
|
|
|
22
|
-
<script lang="ts" setup generic="Model extends
|
|
22
|
+
<script lang="ts" setup generic="Model extends IFormModel">
|
|
23
23
|
import { bem } from '@veltra/utils'
|
|
24
24
|
import { computed, inject, provide, shallowRef, watch } from 'vue'
|
|
25
25
|
|
|
@@ -27,12 +27,12 @@ import type {
|
|
|
27
27
|
BatchEditEmits,
|
|
28
28
|
BatchEditFeature,
|
|
29
29
|
BatchEditProps,
|
|
30
|
+
IFormModel,
|
|
30
31
|
TableColumnSlotsScope,
|
|
31
32
|
TableExposed,
|
|
32
33
|
TableRow
|
|
33
34
|
} from '../../types'
|
|
34
35
|
import { DialogDIKey } from '../dialog/di'
|
|
35
|
-
import type { FormModel } from '../form'
|
|
36
36
|
import { ULayout } from '../layout'
|
|
37
37
|
import BatchEditForm from './batch-edit-form.vue'
|
|
38
38
|
import BatchEditList from './batch-edit-list.vue'
|
|
@@ -5,15 +5,15 @@ import type {
|
|
|
5
5
|
BatchEditEmits,
|
|
6
6
|
BatchEditFeature,
|
|
7
7
|
BatchEditProps,
|
|
8
|
+
IFormModel,
|
|
8
9
|
TableExposed,
|
|
9
10
|
TableRow
|
|
10
11
|
} from '../../types'
|
|
11
|
-
import type { FormModel } from '../form'
|
|
12
12
|
import type { EditReturned } from './use-edit'
|
|
13
13
|
export const BatchEditDIKey: InjectionKey<
|
|
14
14
|
{
|
|
15
15
|
cls: BEM<'batch-edit', 'u-'>
|
|
16
|
-
props: BatchEditProps<
|
|
16
|
+
props: BatchEditProps<IFormModel>
|
|
17
17
|
emit: BatchEditEmits
|
|
18
18
|
tableRef: ShallowRef<TableExposed | undefined>
|
|
19
19
|
staticFeatures: ComputedRef<Set<BatchEditFeature>>
|
|
@@ -2,7 +2,13 @@ import { o } from '@cat-kit/core'
|
|
|
2
2
|
import { middleProxy, Validator } from '@veltra/utils'
|
|
3
3
|
import { nextTick, reactive, shallowReactive, watch, type Reactive } from 'vue'
|
|
4
4
|
|
|
5
|
-
import type {
|
|
5
|
+
import type {
|
|
6
|
+
ModelData,
|
|
7
|
+
DataSettingConfig,
|
|
8
|
+
IFormModel,
|
|
9
|
+
FormModelItem,
|
|
10
|
+
FormModelField
|
|
11
|
+
} from '../../types'
|
|
6
12
|
|
|
7
13
|
/**
|
|
8
14
|
* 递归展平字段逻辑
|
|
@@ -25,7 +31,7 @@ function flattenFields(fields: Record<string, any>, prefix = ''): Record<string,
|
|
|
25
31
|
* 表单模型
|
|
26
32
|
*/
|
|
27
33
|
export class FormModel<
|
|
28
|
-
Fields extends Record<string,
|
|
34
|
+
Fields extends Record<string, FormModelField> = Record<string, FormModelField>
|
|
29
35
|
> implements IFormModel<Fields> {
|
|
30
36
|
/** 表单数据 */
|
|
31
37
|
data!: ModelData<Fields>
|
|
@@ -41,12 +47,12 @@ export class FormModel<
|
|
|
41
47
|
* @description
|
|
42
48
|
* 这个值会在表单组件渲染时由表单设置,因为只有真正渲染的组件才应该被校验
|
|
43
49
|
*/
|
|
44
|
-
formKeys: Map<number,
|
|
50
|
+
formKeys: Map<number, string[]> = new Map()
|
|
45
51
|
|
|
46
52
|
/** 初始数据 */
|
|
47
53
|
readonly initialData: ModelData<Fields>
|
|
48
54
|
|
|
49
|
-
readonly errors: Map<
|
|
55
|
+
readonly errors: Map<string, string[] | undefined> = shallowReactive(new Map())
|
|
50
56
|
|
|
51
57
|
private validator: Validator<Record<string, FormModelItem>>
|
|
52
58
|
|
|
@@ -112,16 +118,16 @@ export class FormModel<
|
|
|
112
118
|
this.data = data as ModelData<Fields>
|
|
113
119
|
}
|
|
114
120
|
|
|
115
|
-
private getValidateFields(fields?:
|
|
121
|
+
private getValidateFields(fields?: string | string[]) {
|
|
116
122
|
if (!fields) {
|
|
117
123
|
if (this.formKeys.size) {
|
|
118
|
-
let _fields:
|
|
119
|
-
this.formKeys.forEach((
|
|
120
|
-
_fields = _fields.concat(
|
|
124
|
+
let _fields: string[] = []
|
|
125
|
+
this.formKeys.forEach((keys) => {
|
|
126
|
+
_fields = _fields.concat(keys)
|
|
121
127
|
})
|
|
122
128
|
return _fields
|
|
123
129
|
} else {
|
|
124
|
-
return this.allKeys
|
|
130
|
+
return this.allKeys
|
|
125
131
|
}
|
|
126
132
|
}
|
|
127
133
|
|
|
@@ -136,10 +142,10 @@ export class FormModel<
|
|
|
136
142
|
* @param fields 需要校验的字段, 不传则校验所有字段
|
|
137
143
|
* @returns
|
|
138
144
|
*/
|
|
139
|
-
async validate(fields?:
|
|
145
|
+
async validate(fields?: string | string[]): Promise<boolean> {
|
|
140
146
|
const { errors, validator, data } = this
|
|
141
147
|
|
|
142
|
-
const results = await validator.validate(data, this.getValidateFields(fields)
|
|
148
|
+
const results = await validator.validate(data, this.getValidateFields(fields))
|
|
143
149
|
|
|
144
150
|
// 全量校验
|
|
145
151
|
if (!fields) {
|
|
@@ -177,12 +183,12 @@ export class FormModel<
|
|
|
177
183
|
* 重置数据
|
|
178
184
|
* @param fields 需要重置的字段
|
|
179
185
|
*/
|
|
180
|
-
resetData(keys?:
|
|
186
|
+
resetData(keys?: string | string[]): void {
|
|
181
187
|
if (typeof keys === 'string') {
|
|
182
188
|
keys = [keys]
|
|
183
189
|
} else if (Array.isArray(keys)) {
|
|
184
190
|
} else {
|
|
185
|
-
keys = this.allKeys
|
|
191
|
+
keys = this.allKeys
|
|
186
192
|
}
|
|
187
193
|
|
|
188
194
|
this.clearValidate()
|
|
@@ -199,10 +205,7 @@ export class FormModel<
|
|
|
199
205
|
* @param formData 表单值
|
|
200
206
|
* @param options 配置
|
|
201
207
|
*/
|
|
202
|
-
setData(
|
|
203
|
-
formData: Partial<ModelData<Fields> & Record<string, any>>,
|
|
204
|
-
config?: DataSettingConfig
|
|
205
|
-
): FormModel<Fields> {
|
|
208
|
+
setData(formData: Partial<Record<string, any>>, config?: DataSettingConfig): FormModel<Fields> {
|
|
206
209
|
const { validate = true } = config || {}
|
|
207
210
|
|
|
208
211
|
if (!validate) {
|
|
@@ -241,12 +244,12 @@ export class FormModel<
|
|
|
241
244
|
* 监听值变更
|
|
242
245
|
* @param cb 回调
|
|
243
246
|
*/
|
|
244
|
-
onChange(cb: (field:
|
|
245
|
-
this.modelChangeCallback.add(cb
|
|
247
|
+
onChange(cb: (field: string, val: any) => void): void {
|
|
248
|
+
this.modelChangeCallback.add(cb)
|
|
246
249
|
}
|
|
247
250
|
|
|
248
251
|
/** 关闭监听值变更 */
|
|
249
|
-
offChange(cb: (field:
|
|
250
|
-
this.modelChangeCallback.delete(cb
|
|
252
|
+
offChange(cb: (field: string, val: any) => void): void {
|
|
253
|
+
this.modelChangeCallback.delete(cb)
|
|
251
254
|
}
|
|
252
255
|
}
|
package/src/types/form.ts
CHANGED
|
@@ -52,29 +52,29 @@ export type IFormModel<Fields extends Record<string, any> = Record<string, any>>
|
|
|
52
52
|
*/
|
|
53
53
|
readonly allKeys: string[]
|
|
54
54
|
/** 需要校验的key */
|
|
55
|
-
formKeys: Map<number,
|
|
55
|
+
formKeys: Map<number, string[]>
|
|
56
56
|
/** 错误 */
|
|
57
|
-
readonly errors: Map<
|
|
57
|
+
readonly errors: Map<string, string[] | undefined>
|
|
58
58
|
/**
|
|
59
59
|
* 字段校验
|
|
60
60
|
* @param fields 字段, 如果不传入时将会使用keyFields来进行校验
|
|
61
61
|
*/
|
|
62
|
-
validate: (fields?:
|
|
62
|
+
validate: (fields?: string | string[]) => Promise<boolean>
|
|
63
63
|
/** 重置数据 */
|
|
64
|
-
resetData(fields?:
|
|
64
|
+
resetData(fields?: string | string[]): void
|
|
65
65
|
|
|
66
66
|
/**
|
|
67
67
|
* 设置数据
|
|
68
68
|
* @param formData 表单值
|
|
69
69
|
* @param options 配置
|
|
70
70
|
*/
|
|
71
|
-
setData(formData: Partial<
|
|
71
|
+
setData(formData: Partial<Record<string, any>>, config?: DataSettingConfig): void
|
|
72
72
|
/** 清除校验 */
|
|
73
73
|
clearValidate(): void
|
|
74
74
|
/** 监听值变更 */
|
|
75
|
-
onChange(cb: (field:
|
|
75
|
+
onChange(cb: (field: string, val: any) => void): void
|
|
76
76
|
/** 关闭监听值变更 */
|
|
77
|
-
offChange(cb: (field:
|
|
77
|
+
offChange(cb: (field: string, val: any) => void): void
|
|
78
78
|
}
|
|
79
79
|
|
|
80
80
|
/** 表单组件属性 */
|