@veltra/desktop 1.2.1 → 1.2.3
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/action/action.vue.d.ts +1 -1
- package/dist/components/cascade/cascade.vue.d.ts +1 -1
- package/dist/components/checkbox/checkbox-button.vue.d.ts +1 -1
- package/dist/components/date-panel/date-panel.vue.d.ts +1 -1
- package/dist/components/date-picker/date-picker.vue.d.ts +1 -1
- package/dist/components/date-range-picker/date-range-picker.vue.d.ts +1 -1
- package/dist/components/form/form.js.map +1 -1
- package/dist/components/form/form.vue_vue_type_script_setup_true_lang.js +13 -5
- package/dist/components/form/form.vue_vue_type_script_setup_true_lang.js.map +1 -1
- package/dist/components/pop-confirm/pop-confirm.vue.d.ts +1 -1
- package/dist/components/tip/tip.vue.d.ts +1 -1
- package/dist/components/watermark/watermark.vue.d.ts +1 -1
- package/package.json +6 -6
- package/src/components/form/form.vue +24 -6
|
@@ -6,9 +6,9 @@ type __VLS_Slots = {
|
|
|
6
6
|
default?: () => VNode[];
|
|
7
7
|
};
|
|
8
8
|
declare const __VLS_base: import("vue").DefineComponent<ActionGroupProps, _ActionGroupExposed, {}, {}, {}, import("vue").ComponentOptionsMixin, import("vue").ComponentOptionsMixin, {}, string, import("vue").PublicProps, Readonly<ActionGroupProps> & Readonly<{}>, {
|
|
9
|
-
type: import("@veltra/utils").ColorType;
|
|
10
9
|
text: boolean;
|
|
11
10
|
size: "small" | "default" | "large";
|
|
11
|
+
type: import("@veltra/utils").ColorType;
|
|
12
12
|
max: number;
|
|
13
13
|
circle: boolean;
|
|
14
14
|
loading: boolean;
|
|
@@ -12,9 +12,9 @@ declare const __VLS_base: import("vue").DefineComponent<ActionProps, {}, {}, {},
|
|
|
12
12
|
}, string, import("vue").PublicProps, Readonly<ActionProps> & Readonly<{
|
|
13
13
|
onRun?: (() => any) | undefined;
|
|
14
14
|
}>, {
|
|
15
|
-
type: ButtonType;
|
|
16
15
|
text: boolean;
|
|
17
16
|
size: import("@veltra/utils").ComponentSize;
|
|
17
|
+
type: ButtonType;
|
|
18
18
|
circle: boolean;
|
|
19
19
|
loading: boolean;
|
|
20
20
|
inDropdown: boolean;
|
|
@@ -18,8 +18,8 @@ declare const __VLS_export: import("vue").DefineComponent<CascadeProps, {}, {},
|
|
|
18
18
|
filterable: boolean;
|
|
19
19
|
disabled: boolean;
|
|
20
20
|
readonly: boolean;
|
|
21
|
-
separator: string;
|
|
22
21
|
visibilityLimit: number;
|
|
22
|
+
separator: string;
|
|
23
23
|
}, {}, {}, {}, string, import("vue").ComponentProvideOptions, false, {}, any>;
|
|
24
24
|
declare const _default: typeof __VLS_export;
|
|
25
25
|
//#endregion
|
|
@@ -17,9 +17,9 @@ declare const __VLS_base: import("vue").DefineComponent<__VLS_PublicProps, {}, {
|
|
|
17
17
|
"onUpdate:modelValue"?: ((checked: boolean) => any) | undefined;
|
|
18
18
|
onChange?: ((checked: boolean) => any) | undefined;
|
|
19
19
|
}>, {
|
|
20
|
-
type: import("@veltra/utils").ColorType;
|
|
21
20
|
disabled: boolean;
|
|
22
21
|
readonly: boolean;
|
|
22
|
+
type: import("@veltra/utils").ColorType;
|
|
23
23
|
round: boolean;
|
|
24
24
|
}, {}, {}, {}, string, import("vue").ComponentProvideOptions, false, {}, any>;
|
|
25
25
|
declare const __VLS_export: __VLS_WithSlots<typeof __VLS_base, __VLS_Slots>;
|
|
@@ -7,8 +7,8 @@ declare const __VLS_export: import("vue").DefineComponent<DatePanelProps, {}, {}
|
|
|
7
7
|
"onSelect:range-date"?: ((rangeDate?: [import("@cat-kit/core").Dater, import("@cat-kit/core").Dater] | undefined) => any) | undefined;
|
|
8
8
|
"onSelect:date"?: ((date: import("@cat-kit/core").Dater) => any) | undefined;
|
|
9
9
|
}>, {
|
|
10
|
-
type: "date" | "month" | "year";
|
|
11
10
|
size: import("@veltra/utils").ComponentSize;
|
|
11
|
+
type: "date" | "month" | "year";
|
|
12
12
|
}, {}, {}, {}, string, import("vue").ComponentProvideOptions, false, {}, any>;
|
|
13
13
|
declare const _default: typeof __VLS_export;
|
|
14
14
|
//#endregion
|
|
@@ -5,11 +5,11 @@ declare const __VLS_export: import("vue").DefineComponent<DatePickerProps, {}, {
|
|
|
5
5
|
}, string, import("vue").PublicProps, Readonly<DatePickerProps> & Readonly<{
|
|
6
6
|
"onUpdate:modelValue"?: ((value?: string | number | Date | undefined) => any) | undefined;
|
|
7
7
|
}>, {
|
|
8
|
-
type: "date" | "month" | "year";
|
|
9
8
|
placeholder: string;
|
|
10
9
|
clearable: boolean;
|
|
11
10
|
disabled: boolean;
|
|
12
11
|
readonly: boolean;
|
|
12
|
+
type: "date" | "month" | "year";
|
|
13
13
|
}, {}, {}, {}, string, import("vue").ComponentProvideOptions, false, {}, any>;
|
|
14
14
|
declare const _default: typeof __VLS_export;
|
|
15
15
|
//#endregion
|
|
@@ -5,11 +5,11 @@ declare const __VLS_export: import("vue").DefineComponent<DateRangePickerProps,
|
|
|
5
5
|
}, string, import("vue").PublicProps, Readonly<DateRangePickerProps> & Readonly<{
|
|
6
6
|
"onUpdate:modelValue"?: ((value?: [string, string] | undefined) => any) | undefined;
|
|
7
7
|
}>, {
|
|
8
|
-
type: "date" | "month" | "year";
|
|
9
8
|
placeholder: [string, string];
|
|
10
9
|
clearable: boolean;
|
|
11
10
|
disabled: boolean;
|
|
12
11
|
readonly: boolean;
|
|
12
|
+
type: "date" | "month" | "year";
|
|
13
13
|
}, {}, {}, {}, string, import("vue").ComponentProvideOptions, false, {}, any>;
|
|
14
14
|
declare const _default: typeof __VLS_export;
|
|
15
15
|
//#endregion
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"form.js","names":[],"sources":["../../../src/components/form/form.vue"],"sourcesContent":["<template>\n <u-grid\n tag=\"form\"\n ref=\"
|
|
1
|
+
{"version":3,"file":"form.js","names":[],"sources":["../../../src/components/form/form.vue"],"sourcesContent":["<template>\n <u-grid\n tag=\"form\"\n ref=\"grid\"\n @submit.prevent\n :cols=\"cols || breakpointCols\"\n :class=\"[cls.b, bem.is('readonly', readonly)]\"\n >\n <template\n v-for=\"{ node, isFormItem, formItemProps, field, modelValue } of getSlotsNodes()\"\n :key=\"node.key\"\n >\n <u-form-item v-if=\"!isFormItem && field\" v-bind=\"formItemProps\">\n <component\n :is=\"node\"\n :model-value=\"modelValue ?? o(model ?? {}).get(field)\"\n @update:model-value=\"handleUpdateValue(field, $event)\"\n />\n </u-form-item>\n\n <component v-else :is=\"node\" />\n </template>\n </u-grid>\n</template>\n\n<script lang=\"tsx\" setup>\nimport { o } from '@cat-kit/core'\nimport { bem } from '@veltra/utils'\nimport { provideFormContext } from '@veltra/utils'\nimport { nextTick, shallowRef, toRef, useTemplateRef } from 'vue'\n\nimport type { BreakCols, GridExposed, FormProps, _FormExposed } from '../../types'\nimport { UFormItem } from '../form-item'\nimport { UGrid } from '../grid'\nimport { useFormFields } from './use-form-fields'\nimport { useNodeInterceptor } from './use-node-interceptor'\n\ndefineOptions({ name: 'Form' })\n\nconst props = defineProps<FormProps>()\n\ndefineSlots<{ default(props?: { data: Record<string, any> | undefined }): any }>()\n\nconst cls = bem('form')\nconst formItemCls = bem('form-item')\nconst gridRef = useTemplateRef('grid')\n\nconst breakpointCols: BreakCols = { xs: 1, md: 2, lg: 3, xl: 4, default: 4 }\n\nconst {\n validate: runValidate,\n clearValidate,\n reset,\n registerField,\n unregisterField,\n shouldValidate\n} = useFormFields({ props })\n\nasync function validate(keys?: string[]) {\n const valid = await runValidate(keys)\n if (!valid) {\n await nextTick()\n\n gridRef.value?.el\n ?.querySelector(`.${formItemCls.e('error-text')}`)\n ?.scrollIntoView({ block: 'center' })\n }\n return valid\n}\n\nprovideFormContext({\n formProps: props,\n registerField,\n unregisterField,\n validateFields: validate,\n shouldValidate\n})\n\nconst { getSlotsNodes } = useNodeInterceptor()\n\nfunction handleUpdateValue(field: string, value: any) {\n if (!props.model) return\n o(props.model).set(field, value)\n}\n\ndefineExpose<_FormExposed>({ el: toRef(() => gridRef.value?.el), validate, clearValidate, reset })\n</script>\n"],"mappings":""}
|
|
@@ -2,7 +2,7 @@ import _sfc_main from "../grid/grid.js";
|
|
|
2
2
|
import form_item_default from "../form-item/form-item.js";
|
|
3
3
|
import { useFormFields } from "./use-form-fields.js";
|
|
4
4
|
import { useNodeInterceptor } from "./use-node-interceptor.js";
|
|
5
|
-
import { Fragment, createBlock, createElementBlock, defineComponent, mergeProps, normalizeClass, openBlock, renderList, resolveDynamicComponent,
|
|
5
|
+
import { Fragment, createBlock, createElementBlock, defineComponent, mergeProps, nextTick, normalizeClass, openBlock, renderList, resolveDynamicComponent, toRef, unref, useTemplateRef, withCtx, withModifiers } from "vue";
|
|
6
6
|
import { bem, provideFormContext } from "@veltra/utils";
|
|
7
7
|
import { o } from "@cat-kit/core";
|
|
8
8
|
//#region src/components/form/form.vue?vue&type=script&setup=true&lang.tsx
|
|
@@ -21,6 +21,8 @@ var form_vue_vue_type_script_setup_true_lang_default = /*@__PURE__*/ defineCompo
|
|
|
21
21
|
setup(__props, { expose: __expose }) {
|
|
22
22
|
const props = __props;
|
|
23
23
|
const cls = bem("form");
|
|
24
|
+
const formItemCls = bem("form-item");
|
|
25
|
+
const gridRef = useTemplateRef("grid");
|
|
24
26
|
const breakpointCols = {
|
|
25
27
|
xs: 1,
|
|
26
28
|
md: 2,
|
|
@@ -28,7 +30,15 @@ var form_vue_vue_type_script_setup_true_lang_default = /*@__PURE__*/ defineCompo
|
|
|
28
30
|
xl: 4,
|
|
29
31
|
default: 4
|
|
30
32
|
};
|
|
31
|
-
const { validate, clearValidate, reset, registerField, unregisterField, shouldValidate } = useFormFields({ props });
|
|
33
|
+
const { validate: runValidate, clearValidate, reset, registerField, unregisterField, shouldValidate } = useFormFields({ props });
|
|
34
|
+
async function validate(keys) {
|
|
35
|
+
const valid = await runValidate(keys);
|
|
36
|
+
if (!valid) {
|
|
37
|
+
await nextTick();
|
|
38
|
+
gridRef.value?.el?.querySelector(`.${formItemCls.e("error-text")}`)?.scrollIntoView({ block: "center" });
|
|
39
|
+
}
|
|
40
|
+
return valid;
|
|
41
|
+
}
|
|
32
42
|
provideFormContext({
|
|
33
43
|
formProps: props,
|
|
34
44
|
registerField,
|
|
@@ -41,7 +51,6 @@ var form_vue_vue_type_script_setup_true_lang_default = /*@__PURE__*/ defineCompo
|
|
|
41
51
|
if (!props.model) return;
|
|
42
52
|
o(props.model).set(field, value);
|
|
43
53
|
}
|
|
44
|
-
const gridRef = shallowRef();
|
|
45
54
|
__expose({
|
|
46
55
|
el: toRef(() => gridRef.value?.el),
|
|
47
56
|
validate,
|
|
@@ -51,8 +60,7 @@ var form_vue_vue_type_script_setup_true_lang_default = /*@__PURE__*/ defineCompo
|
|
|
51
60
|
return (_ctx, _cache) => {
|
|
52
61
|
return openBlock(), createBlock(unref(_sfc_main), {
|
|
53
62
|
tag: "form",
|
|
54
|
-
|
|
55
|
-
ref: gridRef,
|
|
63
|
+
ref: "grid",
|
|
56
64
|
onSubmit: _cache[0] || (_cache[0] = withModifiers(() => {}, ["prevent"])),
|
|
57
65
|
cols: __props.cols || breakpointCols,
|
|
58
66
|
class: normalizeClass([unref(cls).b, unref(bem).is("readonly", __props.readonly)])
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"form.vue_vue_type_script_setup_true_lang.js","names":[],"sources":["../../../src/components/form/form.vue"],"sourcesContent":["<template>\n <u-grid\n tag=\"form\"\n ref=\"
|
|
1
|
+
{"version":3,"file":"form.vue_vue_type_script_setup_true_lang.js","names":[],"sources":["../../../src/components/form/form.vue"],"sourcesContent":["<template>\n <u-grid\n tag=\"form\"\n ref=\"grid\"\n @submit.prevent\n :cols=\"cols || breakpointCols\"\n :class=\"[cls.b, bem.is('readonly', readonly)]\"\n >\n <template\n v-for=\"{ node, isFormItem, formItemProps, field, modelValue } of getSlotsNodes()\"\n :key=\"node.key\"\n >\n <u-form-item v-if=\"!isFormItem && field\" v-bind=\"formItemProps\">\n <component\n :is=\"node\"\n :model-value=\"modelValue ?? o(model ?? {}).get(field)\"\n @update:model-value=\"handleUpdateValue(field, $event)\"\n />\n </u-form-item>\n\n <component v-else :is=\"node\" />\n </template>\n </u-grid>\n</template>\n\n<script lang=\"tsx\" setup>\nimport { o } from '@cat-kit/core'\nimport { bem } from '@veltra/utils'\nimport { provideFormContext } from '@veltra/utils'\nimport { nextTick, shallowRef, toRef, useTemplateRef } from 'vue'\n\nimport type { BreakCols, GridExposed, FormProps, _FormExposed } from '../../types'\nimport { UFormItem } from '../form-item'\nimport { UGrid } from '../grid'\nimport { useFormFields } from './use-form-fields'\nimport { useNodeInterceptor } from './use-node-interceptor'\n\ndefineOptions({ name: 'Form' })\n\nconst props = defineProps<FormProps>()\n\ndefineSlots<{ default(props?: { data: Record<string, any> | undefined }): any }>()\n\nconst cls = bem('form')\nconst formItemCls = bem('form-item')\nconst gridRef = useTemplateRef('grid')\n\nconst breakpointCols: BreakCols = { xs: 1, md: 2, lg: 3, xl: 4, default: 4 }\n\nconst {\n validate: runValidate,\n clearValidate,\n reset,\n registerField,\n unregisterField,\n shouldValidate\n} = useFormFields({ props })\n\nasync function validate(keys?: string[]) {\n const valid = await runValidate(keys)\n if (!valid) {\n await nextTick()\n\n gridRef.value?.el\n ?.querySelector(`.${formItemCls.e('error-text')}`)\n ?.scrollIntoView({ block: 'center' })\n }\n return valid\n}\n\nprovideFormContext({\n formProps: props,\n registerField,\n unregisterField,\n validateFields: validate,\n shouldValidate\n})\n\nconst { getSlotsNodes } = useNodeInterceptor()\n\nfunction handleUpdateValue(field: string, value: any) {\n if (!props.model) return\n o(props.model).set(field, value)\n}\n\ndefineExpose<_FormExposed>({ el: toRef(() => gridRef.value?.el), validate, clearValidate, reset })\n</script>\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;EAuCA,MAAM,QAAQ;EAId,MAAM,MAAM,IAAI,MAAM;EACtB,MAAM,cAAc,IAAI,WAAW;EACnC,MAAM,UAAU,eAAe,MAAM;EAErC,MAAM,iBAA4B;GAAE,IAAI;GAAG,IAAI;GAAG,IAAI;GAAG,IAAI;GAAG,SAAS;EAAE;EAE3E,MAAM,EACJ,UAAU,aACV,eACA,OACA,eACA,iBACA,mBACE,cAAc,EAAE,MAAM,CAAC;EAE3B,eAAe,SAAS,MAAiB;GACvC,MAAM,QAAQ,MAAM,YAAY,IAAI;GACpC,IAAI,CAAC,OAAO;IACV,MAAM,SAAS;IAEf,QAAQ,OAAO,IACX,cAAc,IAAI,YAAY,EAAE,YAAY,GAAG,GAC/C,eAAe,EAAE,OAAO,SAAS,CAAC;GACxC;GACA,OAAO;EACT;EAEA,mBAAmB;GACjB,WAAW;GACX;GACA;GACA,gBAAgB;GAChB;EACF,CAAC;EAED,MAAM,EAAE,kBAAkB,mBAAmB;EAE7C,SAAS,kBAAkB,OAAe,OAAY;GACpD,IAAI,CAAC,MAAM,OAAO;GAClB,EAAE,MAAM,KAAK,EAAE,IAAI,OAAO,KAAK;EACjC;EAEA,SAA2B;GAAE,IAAI,YAAY,QAAQ,OAAO,EAAE;GAAG;GAAU;GAAe;EAAM,CAAC;;uBApF/F,YAqBS,MAAA,SAAA,GAAA;IApBP,KAAI;IACJ,KAAI;IACH,UAAM,OAAA,OAAA,OAAA,KAAA,oBAAP,CAAA,GAAe,CAAA,SAAA,CAAA;IACd,MAAM,QAAA,QAAQ;IACd,OAAK,eAAA,CAAG,MAAA,GAAA,EAAI,GAAG,MAAA,GAAA,EAAI,GAAE,YAAa,QAAA,QAAQ,CAAA,CAAA;;2BAGwC,EAAA,UAAA,IAAA,GADnF,mBAaW,UAAA,MAAA,WAZwD,MAAA,aAAA,EAAa,IAAA,EAArE,MAAM,YAAY,eAAe,OAAO,iBAAU;6DACrD,KAAK,IAAA,GAAA,CAAA,CAES,cAAc,SAAA,UAAA,GAAlC,YAMc,MAAA,iBAAA,GANd,WAMc;;;QANmC,aAAa,GAAA;6BAK1D,EAAA,UAAA,GAJF,YAIE,wBAHK,IAAI,GAAA;OACR,eAAa,cAAc,MAAA,CAAA,EAAE,QAAA,SAAK,CAAA,CAAA,EAAQ,IAAI,KAAK;OACnD,wBAAkB,WAAE,kBAAkB,OAAO,MAAM;;;+BAIxD,YAA+B,wBAAR,IAAI,GAAA,EAAA,KAAA,EAAA,CAAA,EAAA,GAAA,EAAA"}
|
|
@@ -12,8 +12,8 @@ declare const __VLS_base: import("vue").DefineComponent<PopConfirmProps, {}, {},
|
|
|
12
12
|
onConfirm?: (() => any) | undefined;
|
|
13
13
|
onCancel?: (() => any) | undefined;
|
|
14
14
|
}>, {
|
|
15
|
-
trigger: "hover" | "click";
|
|
16
15
|
direction: TipDirection;
|
|
16
|
+
trigger: "hover" | "click";
|
|
17
17
|
icon: import("vue").Component;
|
|
18
18
|
iconColor: string;
|
|
19
19
|
confirmText: string;
|
|
@@ -9,10 +9,10 @@ declare const __VLS_base: import("vue").DefineComponent<TipProps, {}, {}, {}, {}
|
|
|
9
9
|
}, string, import("vue").PublicProps, Readonly<TipProps> & Readonly<{
|
|
10
10
|
"onUpdate:visible"?: ((value: boolean) => any) | undefined;
|
|
11
11
|
}>, {
|
|
12
|
+
direction: TipDirection;
|
|
12
13
|
trigger: "hover" | "click";
|
|
13
14
|
contentTag: string;
|
|
14
15
|
visible: boolean;
|
|
15
|
-
direction: TipDirection;
|
|
16
16
|
content: string;
|
|
17
17
|
alignment: TipAlign;
|
|
18
18
|
}, {}, {}, {}, string, import("vue").ComponentProvideOptions, false, {}, any>;
|
|
@@ -5,8 +5,8 @@ type __VLS_Slots = {} & {
|
|
|
5
5
|
default?: (props: typeof __VLS_7) => any;
|
|
6
6
|
};
|
|
7
7
|
declare const __VLS_base: import("vue").DefineComponent<WatermarkProps, {}, {}, {}, {}, import("vue").ComponentOptionsMixin, import("vue").ComponentOptionsMixin, {}, string, import("vue").PublicProps, Readonly<WatermarkProps> & Readonly<{}>, {
|
|
8
|
-
route: number;
|
|
9
8
|
fontSize: number;
|
|
9
|
+
route: number;
|
|
10
10
|
}, {}, {}, {}, string, import("vue").ComponentProvideOptions, false, {}, any>;
|
|
11
11
|
declare const __VLS_export: __VLS_WithSlots<typeof __VLS_base, __VLS_Slots>;
|
|
12
12
|
declare const _default: typeof __VLS_export;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@veltra/desktop",
|
|
3
|
-
"version": "1.2.
|
|
3
|
+
"version": "1.2.3",
|
|
4
4
|
"files": [
|
|
5
5
|
"dist",
|
|
6
6
|
"src"
|
|
@@ -68,11 +68,11 @@
|
|
|
68
68
|
"@cat-kit/core": ">=1.1.6",
|
|
69
69
|
"@cat-kit/excel": ">=1.0.0",
|
|
70
70
|
"@cat-kit/fe": "^1.1.6",
|
|
71
|
-
"@veltra/compositions": "1.2.
|
|
72
|
-
"@veltra/directives": "1.2.
|
|
73
|
-
"@veltra/icons": "1.2.
|
|
74
|
-
"@veltra/styles": "1.2.
|
|
75
|
-
"@veltra/utils": "1.2.
|
|
71
|
+
"@veltra/compositions": "1.2.3",
|
|
72
|
+
"@veltra/directives": "1.2.3",
|
|
73
|
+
"@veltra/icons": "1.2.3",
|
|
74
|
+
"@veltra/styles": "1.2.3",
|
|
75
|
+
"@veltra/utils": "1.2.3",
|
|
76
76
|
"vue": ">=3.5.0"
|
|
77
77
|
}
|
|
78
78
|
}
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
<template>
|
|
2
2
|
<u-grid
|
|
3
3
|
tag="form"
|
|
4
|
-
ref="
|
|
4
|
+
ref="grid"
|
|
5
5
|
@submit.prevent
|
|
6
6
|
:cols="cols || breakpointCols"
|
|
7
7
|
:class="[cls.b, bem.is('readonly', readonly)]"
|
|
@@ -27,7 +27,7 @@
|
|
|
27
27
|
import { o } from '@cat-kit/core'
|
|
28
28
|
import { bem } from '@veltra/utils'
|
|
29
29
|
import { provideFormContext } from '@veltra/utils'
|
|
30
|
-
import { shallowRef, toRef } from 'vue'
|
|
30
|
+
import { nextTick, shallowRef, toRef, useTemplateRef } from 'vue'
|
|
31
31
|
|
|
32
32
|
import type { BreakCols, GridExposed, FormProps, _FormExposed } from '../../types'
|
|
33
33
|
import { UFormItem } from '../form-item'
|
|
@@ -42,11 +42,31 @@ const props = defineProps<FormProps>()
|
|
|
42
42
|
defineSlots<{ default(props?: { data: Record<string, any> | undefined }): any }>()
|
|
43
43
|
|
|
44
44
|
const cls = bem('form')
|
|
45
|
+
const formItemCls = bem('form-item')
|
|
46
|
+
const gridRef = useTemplateRef('grid')
|
|
45
47
|
|
|
46
48
|
const breakpointCols: BreakCols = { xs: 1, md: 2, lg: 3, xl: 4, default: 4 }
|
|
47
49
|
|
|
48
|
-
const {
|
|
49
|
-
|
|
50
|
+
const {
|
|
51
|
+
validate: runValidate,
|
|
52
|
+
clearValidate,
|
|
53
|
+
reset,
|
|
54
|
+
registerField,
|
|
55
|
+
unregisterField,
|
|
56
|
+
shouldValidate
|
|
57
|
+
} = useFormFields({ props })
|
|
58
|
+
|
|
59
|
+
async function validate(keys?: string[]) {
|
|
60
|
+
const valid = await runValidate(keys)
|
|
61
|
+
if (!valid) {
|
|
62
|
+
await nextTick()
|
|
63
|
+
|
|
64
|
+
gridRef.value?.el
|
|
65
|
+
?.querySelector(`.${formItemCls.e('error-text')}`)
|
|
66
|
+
?.scrollIntoView({ block: 'center' })
|
|
67
|
+
}
|
|
68
|
+
return valid
|
|
69
|
+
}
|
|
50
70
|
|
|
51
71
|
provideFormContext({
|
|
52
72
|
formProps: props,
|
|
@@ -63,7 +83,5 @@ function handleUpdateValue(field: string, value: any) {
|
|
|
63
83
|
o(props.model).set(field, value)
|
|
64
84
|
}
|
|
65
85
|
|
|
66
|
-
const gridRef = shallowRef<GridExposed>()
|
|
67
|
-
|
|
68
86
|
defineExpose<_FormExposed>({ el: toRef(() => gridRef.value?.el), validate, clearValidate, reset })
|
|
69
87
|
</script>
|