@carefrees/form-utils-vue 0.0.8
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/README.md +3 -0
- package/assets/index.css +207 -0
- package/esm/component.d.ts +3 -0
- package/esm/component.mjs +12 -0
- package/esm/form/index.d.ts +37 -0
- package/esm/form/index.mjs +6 -0
- package/esm/form/index.vue.d.ts +19 -0
- package/esm/form/index.vue.mjs +110 -0
- package/esm/form/index.vue2.mjs +4 -0
- package/esm/formItem/form.Item.base.vue.d.ts +16 -0
- package/esm/formItem/form.Item.base.vue.mjs +114 -0
- package/esm/formItem/form.Item.base.vue2.mjs +4 -0
- package/esm/formItem/form.hide.item.vue.d.ts +16 -0
- package/esm/formItem/form.hide.item.vue.mjs +78 -0
- package/esm/formItem/form.hide.item.vue2.mjs +4 -0
- package/esm/formItem/formItem.vue.d.ts +18 -0
- package/esm/formItem/formItem.vue.mjs +102 -0
- package/esm/formItem/formItem.vue2.mjs +4 -0
- package/esm/formItem/index.d.ts +71 -0
- package/esm/formItem/index.mjs +12 -0
- package/esm/hooks/attr/attr.FormItem.d.ts +876 -0
- package/esm/hooks/attr/attr.FormItem.mjs +120 -0
- package/esm/hooks/index.d.ts +13 -0
- package/esm/hooks/register/register.FormHideItem.d.ts +9 -0
- package/esm/hooks/register/register.FormHideItem.mjs +38 -0
- package/esm/hooks/register/register.FormItem.d.ts +802 -0
- package/esm/hooks/register/register.FormItem.mjs +55 -0
- package/esm/hooks/register/register.FormList.d.ts +789 -0
- package/esm/hooks/register/register.FormList.mjs +43 -0
- package/esm/hooks/register/register.form.d.ts +3 -0
- package/esm/hooks/register/register.form.mjs +12 -0
- package/esm/hooks/useAttrs.d.ts +24 -0
- package/esm/hooks/useAttrs.mjs +45 -0
- package/esm/hooks/useEffect.d.ts +2 -0
- package/esm/hooks/useEffect.mjs +14 -0
- package/esm/hooks/useForm.d.ts +8 -0
- package/esm/hooks/useForm.mjs +26 -0
- package/esm/hooks/useFormItem.d.ts +7 -0
- package/esm/hooks/useFormItem.mjs +26 -0
- package/esm/hooks/useFormItemParentName.d.ts +18 -0
- package/esm/hooks/useFormItemParentName.mjs +37 -0
- package/esm/hooks/useFormList.d.ts +7 -0
- package/esm/hooks/useFormList.mjs +26 -0
- package/esm/hooks/useHtmlFor.d.ts +2 -0
- package/esm/hooks/useHtmlFor.mjs +11 -0
- package/esm/hooks/useMultipleForm.d.ts +7 -0
- package/esm/hooks/useMultipleForm.mjs +27 -0
- package/esm/index.d.ts +11 -0
- package/esm/index.mjs +59 -0
- package/esm/instance/ruleIntsnace.d.ts +49 -0
- package/esm/instance/ruleIntsnace.mjs +73 -0
- package/esm/interface/index.d.ts +36 -0
- package/esm/interface/layout.d.ts +28 -0
- package/esm/interface/layout.formItem.d.ts +39 -0
- package/esm/layout/index.d.ts +65 -0
- package/esm/layout/index.mjs +12 -0
- package/esm/layout/layout.form.rows.vue.d.ts +10 -0
- package/esm/layout/layout.form.rows.vue.mjs +31 -0
- package/esm/layout/layout.form.rows.vue2.mjs +4 -0
- package/esm/layout/layout.formItem.vue.d.ts +18 -0
- package/esm/layout/layout.formItem.vue.mjs +216 -0
- package/esm/layout/layout.formItem.vue2.mjs +4 -0
- package/esm/layout/layout.vue.d.ts +16 -0
- package/esm/layout/layout.vue.mjs +166 -0
- package/esm/layout/layout.vue2.mjs +4 -0
- package/esm/utils/index.d.ts +1 -0
- package/esm/utils/withInstall.d.ts +3 -0
- package/esm/utils/withInstall.mjs +22 -0
- package/lib/component.d.ts +3 -0
- package/lib/component.js +12 -0
- package/lib/form/index.d.ts +37 -0
- package/lib/form/index.js +6 -0
- package/lib/form/index.vue.d.ts +19 -0
- package/lib/form/index.vue.js +110 -0
- package/lib/form/index.vue2.js +4 -0
- package/lib/formItem/form.Item.base.vue.d.ts +16 -0
- package/lib/formItem/form.Item.base.vue.js +114 -0
- package/lib/formItem/form.Item.base.vue2.js +4 -0
- package/lib/formItem/form.hide.item.vue.d.ts +16 -0
- package/lib/formItem/form.hide.item.vue.js +78 -0
- package/lib/formItem/form.hide.item.vue2.js +4 -0
- package/lib/formItem/formItem.vue.d.ts +18 -0
- package/lib/formItem/formItem.vue.js +102 -0
- package/lib/formItem/formItem.vue2.js +4 -0
- package/lib/formItem/index.d.ts +71 -0
- package/lib/formItem/index.js +12 -0
- package/lib/hooks/attr/attr.FormItem.d.ts +876 -0
- package/lib/hooks/attr/attr.FormItem.js +120 -0
- package/lib/hooks/index.d.ts +13 -0
- package/lib/hooks/register/register.FormHideItem.d.ts +9 -0
- package/lib/hooks/register/register.FormHideItem.js +38 -0
- package/lib/hooks/register/register.FormItem.d.ts +802 -0
- package/lib/hooks/register/register.FormItem.js +55 -0
- package/lib/hooks/register/register.FormList.d.ts +789 -0
- package/lib/hooks/register/register.FormList.js +43 -0
- package/lib/hooks/register/register.form.d.ts +3 -0
- package/lib/hooks/register/register.form.js +12 -0
- package/lib/hooks/useAttrs.d.ts +24 -0
- package/lib/hooks/useAttrs.js +45 -0
- package/lib/hooks/useEffect.d.ts +2 -0
- package/lib/hooks/useEffect.js +14 -0
- package/lib/hooks/useForm.d.ts +8 -0
- package/lib/hooks/useForm.js +26 -0
- package/lib/hooks/useFormItem.d.ts +7 -0
- package/lib/hooks/useFormItem.js +26 -0
- package/lib/hooks/useFormItemParentName.d.ts +18 -0
- package/lib/hooks/useFormItemParentName.js +37 -0
- package/lib/hooks/useFormList.d.ts +7 -0
- package/lib/hooks/useFormList.js +26 -0
- package/lib/hooks/useHtmlFor.d.ts +2 -0
- package/lib/hooks/useHtmlFor.js +11 -0
- package/lib/hooks/useMultipleForm.d.ts +7 -0
- package/lib/hooks/useMultipleForm.js +27 -0
- package/lib/index.d.ts +11 -0
- package/lib/index.js +59 -0
- package/lib/instance/ruleIntsnace.d.ts +49 -0
- package/lib/instance/ruleIntsnace.js +73 -0
- package/lib/interface/index.d.ts +36 -0
- package/lib/interface/layout.d.ts +28 -0
- package/lib/interface/layout.formItem.d.ts +39 -0
- package/lib/layout/index.d.ts +65 -0
- package/lib/layout/index.js +12 -0
- package/lib/layout/layout.form.rows.vue.d.ts +10 -0
- package/lib/layout/layout.form.rows.vue.js +31 -0
- package/lib/layout/layout.form.rows.vue2.js +4 -0
- package/lib/layout/layout.formItem.vue.d.ts +18 -0
- package/lib/layout/layout.formItem.vue.js +216 -0
- package/lib/layout/layout.formItem.vue2.js +4 -0
- package/lib/layout/layout.vue.d.ts +16 -0
- package/lib/layout/layout.vue.js +166 -0
- package/lib/layout/layout.vue2.js +4 -0
- package/lib/utils/index.d.ts +1 -0
- package/lib/utils/withInstall.d.ts +3 -0
- package/lib/utils/withInstall.js +22 -0
- package/package.json +33 -0
- package/src/component.ts +3 -0
- package/src/form/index.ts +3 -0
- package/src/form/index.vue +66 -0
- package/src/formItem/form.Item.base.vue +54 -0
- package/src/formItem/form.hide.item.vue +28 -0
- package/src/formItem/formItem.vue +38 -0
- package/src/formItem/index.ts +7 -0
- package/src/hooks/attr/attr.FormItem.tsx +170 -0
- package/src/hooks/index.ts +13 -0
- package/src/hooks/register/register.FormHideItem.ts +45 -0
- package/src/hooks/register/register.FormItem.ts +80 -0
- package/src/hooks/register/register.FormList.ts +49 -0
- package/src/hooks/register/register.form.ts +12 -0
- package/src/hooks/useAttrs.ts +66 -0
- package/src/hooks/useEffect.ts +13 -0
- package/src/hooks/useForm.ts +28 -0
- package/src/hooks/useFormItem.ts +28 -0
- package/src/hooks/useFormItemParentName.ts +49 -0
- package/src/hooks/useFormList.ts +28 -0
- package/src/hooks/useHtmlFor.ts +9 -0
- package/src/hooks/useMultipleForm.ts +29 -0
- package/src/index.ts +16 -0
- package/src/instance/ruleIntsnace.ts +105 -0
- package/src/interface/index.ts +40 -0
- package/src/interface/layout.formItem.ts +42 -0
- package/src/interface/layout.ts +29 -0
- package/src/layout/index.ts +8 -0
- package/src/layout/layout.form.rows.vue +19 -0
- package/src/layout/layout.formItem.vue +119 -0
- package/src/layout/layout.vue +97 -0
- package/src/utils/index.ts +1 -0
- package/src/utils/withInstall.ts +28 -0
- package/src/vite-env.d.ts +1 -0
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
import { watch, toValue } from "vue";
|
|
2
|
+
import { useRegisterFormItem } from "./register.FormItem.mjs";
|
|
3
|
+
import { useFormList } from "../useFormList.mjs";
|
|
4
|
+
import { useEffect } from "../useEffect.mjs";
|
|
5
|
+
const useRegisterFormList = (options) => {
|
|
6
|
+
const { ruleInstance, formItemInstance, form, newName, parentItem } = useRegisterFormItem(options);
|
|
7
|
+
const formListInstance = useFormList();
|
|
8
|
+
watch(
|
|
9
|
+
[newName.value],
|
|
10
|
+
() => {
|
|
11
|
+
formListInstance.ctor(newName.value);
|
|
12
|
+
},
|
|
13
|
+
{ immediate: true }
|
|
14
|
+
);
|
|
15
|
+
watch(
|
|
16
|
+
[form, formItemInstance, ruleInstance.value],
|
|
17
|
+
() => {
|
|
18
|
+
formListInstance.instance = form;
|
|
19
|
+
formListInstance.formItemInstance = formItemInstance;
|
|
20
|
+
formListInstance.rule = ruleInstance.value;
|
|
21
|
+
},
|
|
22
|
+
{ immediate: true }
|
|
23
|
+
);
|
|
24
|
+
watch(
|
|
25
|
+
[options.sort, parentItem.value],
|
|
26
|
+
() => {
|
|
27
|
+
formListInstance.sort = toValue(parentItem.value.sort);
|
|
28
|
+
formListInstance.parentDataField = toValue(parentItem.value.name);
|
|
29
|
+
},
|
|
30
|
+
{ immediate: true }
|
|
31
|
+
);
|
|
32
|
+
useEffect(() => {
|
|
33
|
+
return form.registerFormList(newName.value, formListInstance);
|
|
34
|
+
});
|
|
35
|
+
return {
|
|
36
|
+
ruleInstance,
|
|
37
|
+
formItemInstance,
|
|
38
|
+
formListInstance
|
|
39
|
+
};
|
|
40
|
+
};
|
|
41
|
+
export {
|
|
42
|
+
useRegisterFormList
|
|
43
|
+
};
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import { useMultipleFormInject } from "../useMultipleForm.mjs";
|
|
2
|
+
import { useEffect } from "../useEffect.mjs";
|
|
3
|
+
const useRegisterForm = (form, name) => {
|
|
4
|
+
const multipleForm = useMultipleFormInject();
|
|
5
|
+
useEffect(() => {
|
|
6
|
+
if (name) return multipleForm.ctor(name, form);
|
|
7
|
+
});
|
|
8
|
+
return multipleForm;
|
|
9
|
+
};
|
|
10
|
+
export {
|
|
11
|
+
useRegisterForm
|
|
12
|
+
};
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
import { StyleValue, ComputedRef } from 'vue';
|
|
2
|
+
import { ComputedRefBase } from '../interface';
|
|
3
|
+
export type AttrsOptions = {
|
|
4
|
+
/**列数据*/
|
|
5
|
+
colCount?: ComputedRefBase<number | undefined>;
|
|
6
|
+
/**规则校验失败错误提示位置*/
|
|
7
|
+
errorLayout?: ComputedRefBase<'left-bottom' | 'right-bottom' | 'top-right' | 'top-left' | undefined>;
|
|
8
|
+
/**label显示模式*/
|
|
9
|
+
labelMode?: ComputedRefBase<'left' | 'top' | 'hide' | undefined>;
|
|
10
|
+
/**是否显示label后的冒号*/
|
|
11
|
+
showColon?: ComputedRefBase<boolean | undefined>;
|
|
12
|
+
/**表单项 className*/
|
|
13
|
+
formItemClass?: ComputedRefBase<string | undefined>;
|
|
14
|
+
/**表单项 style*/
|
|
15
|
+
formItemStyle?: ComputedRefBase<StyleValue | undefined>;
|
|
16
|
+
/**表单项 label className*/
|
|
17
|
+
formItemLabelClass?: ComputedRefBase<string | undefined>;
|
|
18
|
+
/**表单项 label style*/
|
|
19
|
+
formItemLabelStyle?: ComputedRefBase<StyleValue | undefined>;
|
|
20
|
+
};
|
|
21
|
+
/**公共属性 Context */
|
|
22
|
+
export declare function useAttrsProvide(options: AttrsOptions): void;
|
|
23
|
+
/**子项中获取公共属性*/
|
|
24
|
+
export declare function useAttrsInject(): ComputedRef<AttrsOptions>;
|
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
import { inject, computed, toRefs, ref, provide, reactive } from "vue";
|
|
2
|
+
const attrsProvideSymbol = Symbol("carefrees-attrs");
|
|
3
|
+
function useAttrsProvide(options) {
|
|
4
|
+
const {
|
|
5
|
+
colCount = ref(4),
|
|
6
|
+
errorLayout = ref("left-bottom"),
|
|
7
|
+
labelMode = ref("top"),
|
|
8
|
+
showColon = ref(true),
|
|
9
|
+
formItemClass,
|
|
10
|
+
formItemStyle,
|
|
11
|
+
formItemLabelClass,
|
|
12
|
+
formItemLabelStyle
|
|
13
|
+
} = options;
|
|
14
|
+
const data = computed(() => {
|
|
15
|
+
return {
|
|
16
|
+
colCount,
|
|
17
|
+
errorLayout,
|
|
18
|
+
labelMode,
|
|
19
|
+
showColon,
|
|
20
|
+
formItemClass,
|
|
21
|
+
formItemStyle,
|
|
22
|
+
formItemLabelClass,
|
|
23
|
+
formItemLabelStyle
|
|
24
|
+
};
|
|
25
|
+
});
|
|
26
|
+
provide(attrsProvideSymbol, reactive(data));
|
|
27
|
+
}
|
|
28
|
+
function useAttrsInject() {
|
|
29
|
+
const attrs = inject(
|
|
30
|
+
attrsProvideSymbol,
|
|
31
|
+
computed(
|
|
32
|
+
() => toRefs({
|
|
33
|
+
colCount: 4,
|
|
34
|
+
errorLayout: "left-bottom",
|
|
35
|
+
labelMode: "top",
|
|
36
|
+
showColon: true
|
|
37
|
+
})
|
|
38
|
+
)
|
|
39
|
+
);
|
|
40
|
+
return attrs;
|
|
41
|
+
}
|
|
42
|
+
export {
|
|
43
|
+
useAttrsInject,
|
|
44
|
+
useAttrsProvide
|
|
45
|
+
};
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import { ref, onMounted, onUnmounted } from "vue";
|
|
2
|
+
const useEffect = (fun) => {
|
|
3
|
+
const unRegisterRef = ref();
|
|
4
|
+
onMounted(() => {
|
|
5
|
+
unRegisterRef.value = fun();
|
|
6
|
+
});
|
|
7
|
+
onUnmounted(() => {
|
|
8
|
+
typeof unRegisterRef.value === "function" && unRegisterRef.value();
|
|
9
|
+
unRegisterRef.value = void 0;
|
|
10
|
+
});
|
|
11
|
+
};
|
|
12
|
+
export {
|
|
13
|
+
useEffect
|
|
14
|
+
};
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import { FormInstanceBase } from '@carefrees/form-utils';
|
|
2
|
+
import { Ref } from 'vue';
|
|
3
|
+
/**表单实例 Context */
|
|
4
|
+
export declare function useFormProvide<T = any>(form: FormInstanceBase<T>): void;
|
|
5
|
+
/**子项中获取表单实例*/
|
|
6
|
+
export declare function useFormInject<T = any>(): FormInstanceBase<T>;
|
|
7
|
+
/**初始化表单实例*/
|
|
8
|
+
export declare function useForm<T = any>(form?: FormInstanceBase<T>): Ref<FormInstanceBase<T>, FormInstanceBase<T>>;
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
import { FormInstanceBase } from "@carefrees/form-utils";
|
|
2
|
+
import { ref, provide, inject } from "vue";
|
|
3
|
+
const formProvideSymbol = Symbol("carefrees-form");
|
|
4
|
+
function useFormProvide(form) {
|
|
5
|
+
provide(formProvideSymbol, form);
|
|
6
|
+
}
|
|
7
|
+
function useFormInject() {
|
|
8
|
+
const form = inject(formProvideSymbol, new FormInstanceBase());
|
|
9
|
+
return form;
|
|
10
|
+
}
|
|
11
|
+
function useForm(form) {
|
|
12
|
+
const refForm = ref();
|
|
13
|
+
if (!refForm.value) {
|
|
14
|
+
if (form) {
|
|
15
|
+
refForm.value = form;
|
|
16
|
+
} else {
|
|
17
|
+
refForm.value = new FormInstanceBase();
|
|
18
|
+
}
|
|
19
|
+
}
|
|
20
|
+
return refForm;
|
|
21
|
+
}
|
|
22
|
+
export {
|
|
23
|
+
useForm,
|
|
24
|
+
useFormInject,
|
|
25
|
+
useFormProvide
|
|
26
|
+
};
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
import { FormItemInstanceBase } from '@carefrees/form-utils';
|
|
2
|
+
/**表单项实例 Context */
|
|
3
|
+
export declare function useFormItemProvide(formItem: FormItemInstanceBase): void;
|
|
4
|
+
/**子项中获取表单项实例*/
|
|
5
|
+
export declare function useFormItemInject(): FormItemInstanceBase;
|
|
6
|
+
/**s初始化 表单项实例*/
|
|
7
|
+
export declare function useFormItem(formItem?: FormItemInstanceBase): FormItemInstanceBase;
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
import { FormItemInstanceBase } from "@carefrees/form-utils";
|
|
2
|
+
import { ref, provide, inject } from "vue";
|
|
3
|
+
const formItemProvideSymbol = Symbol("carefrees-form-item");
|
|
4
|
+
function useFormItemProvide(formItem) {
|
|
5
|
+
provide(formItemProvideSymbol, formItem);
|
|
6
|
+
}
|
|
7
|
+
function useFormItemInject() {
|
|
8
|
+
const formItem = inject(formItemProvideSymbol, new FormItemInstanceBase());
|
|
9
|
+
return formItem;
|
|
10
|
+
}
|
|
11
|
+
function useFormItem(formItem) {
|
|
12
|
+
const refForm = ref();
|
|
13
|
+
if (!refForm.value) {
|
|
14
|
+
if (formItem) {
|
|
15
|
+
refForm.value = formItem;
|
|
16
|
+
} else {
|
|
17
|
+
refForm.value = new FormItemInstanceBase();
|
|
18
|
+
}
|
|
19
|
+
}
|
|
20
|
+
return refForm.value;
|
|
21
|
+
}
|
|
22
|
+
export {
|
|
23
|
+
useFormItem,
|
|
24
|
+
useFormItemInject,
|
|
25
|
+
useFormItemProvide
|
|
26
|
+
};
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
import { ComputedRef } from 'vue';
|
|
2
|
+
import { PartialComputedRefs } from '../interface';
|
|
3
|
+
export interface FormItemParentNamOptions {
|
|
4
|
+
/**字段*/
|
|
5
|
+
name: string;
|
|
6
|
+
/**排序*/
|
|
7
|
+
sort?: string;
|
|
8
|
+
/**是否拼接父级字段*/
|
|
9
|
+
isJoinParentField?: boolean;
|
|
10
|
+
}
|
|
11
|
+
export type FormItemParentNameProviderProps = PartialComputedRefs<Omit<FormItemParentNamOptions, 'isJoinParentField'>>;
|
|
12
|
+
export declare const useFormItemParentNameProvide: (props: FormItemParentNameProviderProps) => void;
|
|
13
|
+
/**表单项获取父级字段*/
|
|
14
|
+
export declare const useFormItemParentNameInject: (options: FormItemParentNamOptions) => {
|
|
15
|
+
newName: ComputedRef<string>;
|
|
16
|
+
newSort: ComputedRef<string>;
|
|
17
|
+
parentItem: ComputedRef<PartialComputedRefs<Omit<FormItemParentNamOptions, "isJoinParentField">>>;
|
|
18
|
+
};
|
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
import { provide, computed, inject, ref, toValue } from "vue";
|
|
2
|
+
const parentNameProvideSymbol = Symbol("carefrees-parent-name");
|
|
3
|
+
const useFormItemParentNameProvide = (props) => {
|
|
4
|
+
const { name, sort } = props;
|
|
5
|
+
provide(
|
|
6
|
+
parentNameProvideSymbol,
|
|
7
|
+
computed(() => ({ name, sort }))
|
|
8
|
+
);
|
|
9
|
+
};
|
|
10
|
+
const useFormItemParentNameInject = (options) => {
|
|
11
|
+
const { isJoinParentField = true, sort, name } = options;
|
|
12
|
+
const parentItem = inject(
|
|
13
|
+
parentNameProvideSymbol,
|
|
14
|
+
computed(() => ({ name: ref(""), sort: ref("") }))
|
|
15
|
+
);
|
|
16
|
+
const newName = computed(() => {
|
|
17
|
+
const _name = toValue(parentItem.value.name);
|
|
18
|
+
if (_name && isJoinParentField) {
|
|
19
|
+
if (/^\./.test(`${name}`)) {
|
|
20
|
+
return [_name, name].filter(Boolean).join("");
|
|
21
|
+
} else if (name) {
|
|
22
|
+
return [_name, ".", name].filter(Boolean).join("");
|
|
23
|
+
}
|
|
24
|
+
return [_name, name].filter(Boolean).join("");
|
|
25
|
+
}
|
|
26
|
+
return [name].filter(Boolean).join("");
|
|
27
|
+
});
|
|
28
|
+
const newSort = computed(() => {
|
|
29
|
+
const _sort = toValue(parentItem.value.sort);
|
|
30
|
+
return [isJoinParentField ? _sort : "", sort].filter(Boolean).join("-");
|
|
31
|
+
});
|
|
32
|
+
return { newName, newSort, parentItem };
|
|
33
|
+
};
|
|
34
|
+
export {
|
|
35
|
+
useFormItemParentNameInject,
|
|
36
|
+
useFormItemParentNameProvide
|
|
37
|
+
};
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
import { FormListInstanceBase } from '@carefrees/form-utils';
|
|
2
|
+
/**表单List实例 Context */
|
|
3
|
+
export declare function useFormListProvide(formList: FormListInstanceBase): void;
|
|
4
|
+
/**子项中获取表单List实例*/
|
|
5
|
+
export declare function useFormListInject(): FormListInstanceBase;
|
|
6
|
+
/**初始化 表单List实例*/
|
|
7
|
+
export declare function useFormList(formList?: FormListInstanceBase): FormListInstanceBase;
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
import { FormListInstanceBase } from "@carefrees/form-utils";
|
|
2
|
+
import { provide, inject, ref } from "vue";
|
|
3
|
+
const formListProvideSymbol = Symbol("carefrees-form-list");
|
|
4
|
+
function useFormListProvide(formList) {
|
|
5
|
+
provide(formListProvideSymbol, formList);
|
|
6
|
+
}
|
|
7
|
+
function useFormListInject() {
|
|
8
|
+
const formList = inject(formListProvideSymbol, new FormListInstanceBase());
|
|
9
|
+
return formList;
|
|
10
|
+
}
|
|
11
|
+
function useFormList(formList) {
|
|
12
|
+
const refForm = ref();
|
|
13
|
+
if (!refForm.value) {
|
|
14
|
+
if (formList) {
|
|
15
|
+
refForm.value = formList;
|
|
16
|
+
} else {
|
|
17
|
+
refForm.value = new FormListInstanceBase();
|
|
18
|
+
}
|
|
19
|
+
}
|
|
20
|
+
return refForm.value;
|
|
21
|
+
}
|
|
22
|
+
export {
|
|
23
|
+
useFormList,
|
|
24
|
+
useFormListInject,
|
|
25
|
+
useFormListProvide
|
|
26
|
+
};
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import { ref, computed } from "vue";
|
|
2
|
+
let localId = 0;
|
|
3
|
+
const useHtmlFor = (suffix) => {
|
|
4
|
+
const count = ref(localId++);
|
|
5
|
+
return computed(() => {
|
|
6
|
+
return `carefree-vue-form-item_${count.value.toString(32)}_${suffix.value}`;
|
|
7
|
+
});
|
|
8
|
+
};
|
|
9
|
+
export {
|
|
10
|
+
useHtmlFor
|
|
11
|
+
};
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
import { MultipleInstanceBase } from '@carefrees/form-utils';
|
|
2
|
+
/**多表单收集 Context */
|
|
3
|
+
export declare function useMultipleFormProvide(multipleForm?: MultipleInstanceBase): void;
|
|
4
|
+
/**子项中获取 多表单收集 实例*/
|
|
5
|
+
export declare function useMultipleFormInject(): MultipleInstanceBase;
|
|
6
|
+
/**初始化 多表单收集 实例*/
|
|
7
|
+
export declare function useMultipleForm(multipleForm?: MultipleInstanceBase): MultipleInstanceBase;
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
import { MultipleInstanceBase } from "@carefrees/form-utils";
|
|
2
|
+
import { inject, provide, ref } from "vue";
|
|
3
|
+
const multipleFormProvideSymbol = Symbol("carefrees-multiple-form");
|
|
4
|
+
function useMultipleFormProvide(multipleForm) {
|
|
5
|
+
const newMultipleForm = useMultipleForm(multipleForm);
|
|
6
|
+
provide(multipleFormProvideSymbol, newMultipleForm);
|
|
7
|
+
}
|
|
8
|
+
function useMultipleFormInject() {
|
|
9
|
+
const multipleForm = inject(multipleFormProvideSymbol, new MultipleInstanceBase());
|
|
10
|
+
return multipleForm;
|
|
11
|
+
}
|
|
12
|
+
function useMultipleForm(multipleForm) {
|
|
13
|
+
const refForm = ref();
|
|
14
|
+
if (!refForm.value) {
|
|
15
|
+
if (multipleForm) {
|
|
16
|
+
refForm.value = multipleForm;
|
|
17
|
+
} else {
|
|
18
|
+
refForm.value = new MultipleInstanceBase();
|
|
19
|
+
}
|
|
20
|
+
}
|
|
21
|
+
return refForm.value;
|
|
22
|
+
}
|
|
23
|
+
export {
|
|
24
|
+
useMultipleForm,
|
|
25
|
+
useMultipleFormInject,
|
|
26
|
+
useMultipleFormProvide
|
|
27
|
+
};
|
package/esm/index.d.ts
ADDED
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import { App } from 'vue';
|
|
2
|
+
export * from './hooks';
|
|
3
|
+
export * from './component';
|
|
4
|
+
export * from './utils';
|
|
5
|
+
export * from './interface';
|
|
6
|
+
export * from './interface/layout';
|
|
7
|
+
export * from './interface/layout.formItem';
|
|
8
|
+
declare const _default: {
|
|
9
|
+
install: (app: App) => void;
|
|
10
|
+
};
|
|
11
|
+
export default _default;
|
package/esm/index.mjs
ADDED
|
@@ -0,0 +1,59 @@
|
|
|
1
|
+
import * as component from "./component.mjs";
|
|
2
|
+
import { useAttrsInject, useAttrsProvide } from "./hooks/useAttrs.mjs";
|
|
3
|
+
import { useForm, useFormInject, useFormProvide } from "./hooks/useForm.mjs";
|
|
4
|
+
import { useFormItem, useFormItemInject, useFormItemProvide } from "./hooks/useFormItem.mjs";
|
|
5
|
+
import { useFormList, useFormListInject, useFormListProvide } from "./hooks/useFormList.mjs";
|
|
6
|
+
import { useHtmlFor } from "./hooks/useHtmlFor.mjs";
|
|
7
|
+
import { useMultipleForm, useMultipleFormInject, useMultipleFormProvide } from "./hooks/useMultipleForm.mjs";
|
|
8
|
+
import { useFormItemParentNameInject, useFormItemParentNameProvide } from "./hooks/useFormItemParentName.mjs";
|
|
9
|
+
import { useEffect } from "./hooks/useEffect.mjs";
|
|
10
|
+
import { useRegisterFormHideItem } from "./hooks/register/register.FormHideItem.mjs";
|
|
11
|
+
import { useRegisterFormItem } from "./hooks/register/register.FormItem.mjs";
|
|
12
|
+
import { useRegisterFormList } from "./hooks/register/register.FormList.mjs";
|
|
13
|
+
import { useRegisterForm } from "./hooks/register/register.form.mjs";
|
|
14
|
+
import { useFormItemAttr } from "./hooks/attr/attr.FormItem.mjs";
|
|
15
|
+
import { withInstall } from "./utils/withInstall.mjs";
|
|
16
|
+
import { Form } from "./form/index.mjs";
|
|
17
|
+
import { FormHideItem, FormItem, FormItemBase } from "./formItem/index.mjs";
|
|
18
|
+
import { FormLayoutRows, Layout, LayoutFormItem } from "./layout/index.mjs";
|
|
19
|
+
const index = {
|
|
20
|
+
install: (app) => {
|
|
21
|
+
for (const c in component) {
|
|
22
|
+
app.use(component[c]);
|
|
23
|
+
}
|
|
24
|
+
}
|
|
25
|
+
};
|
|
26
|
+
export {
|
|
27
|
+
Form,
|
|
28
|
+
FormHideItem,
|
|
29
|
+
FormItem,
|
|
30
|
+
FormItemBase,
|
|
31
|
+
FormLayoutRows,
|
|
32
|
+
Layout,
|
|
33
|
+
LayoutFormItem,
|
|
34
|
+
index as default,
|
|
35
|
+
useAttrsInject,
|
|
36
|
+
useAttrsProvide,
|
|
37
|
+
useEffect,
|
|
38
|
+
useForm,
|
|
39
|
+
useFormInject,
|
|
40
|
+
useFormItem,
|
|
41
|
+
useFormItemAttr,
|
|
42
|
+
useFormItemInject,
|
|
43
|
+
useFormItemParentNameInject,
|
|
44
|
+
useFormItemParentNameProvide,
|
|
45
|
+
useFormItemProvide,
|
|
46
|
+
useFormList,
|
|
47
|
+
useFormListInject,
|
|
48
|
+
useFormListProvide,
|
|
49
|
+
useFormProvide,
|
|
50
|
+
useHtmlFor,
|
|
51
|
+
useMultipleForm,
|
|
52
|
+
useMultipleFormInject,
|
|
53
|
+
useMultipleFormProvide,
|
|
54
|
+
useRegisterForm,
|
|
55
|
+
useRegisterFormHideItem,
|
|
56
|
+
useRegisterFormItem,
|
|
57
|
+
useRegisterFormList,
|
|
58
|
+
withInstall
|
|
59
|
+
};
|
|
@@ -0,0 +1,49 @@
|
|
|
1
|
+
import { RuleItem } from 'async-validator';
|
|
2
|
+
import { MessageType, FormInstanceBase } from '@carefrees/form-utils';
|
|
3
|
+
import { Ref } from 'vue';
|
|
4
|
+
export declare class RuleInstanceBase2 {
|
|
5
|
+
/**
|
|
6
|
+
* 顺序
|
|
7
|
+
* @example
|
|
8
|
+
* "0"
|
|
9
|
+
* "0-0"
|
|
10
|
+
* "0-0-0"
|
|
11
|
+
*/
|
|
12
|
+
sort?: string;
|
|
13
|
+
/**表单实例*/
|
|
14
|
+
instance?: FormInstanceBase;
|
|
15
|
+
/**
|
|
16
|
+
* 字段 ,分割方式与lodash的get和set方法值更新或设置路径一致
|
|
17
|
+
* @example
|
|
18
|
+
* 默认:"name"
|
|
19
|
+
* 嵌套字段:"name.a.doc"
|
|
20
|
+
* 嵌套字段:"name[1].a.doc"
|
|
21
|
+
* 嵌套字段:"name.a[2].doc"
|
|
22
|
+
*/
|
|
23
|
+
name: string;
|
|
24
|
+
/**规则*/
|
|
25
|
+
rules: Ref<RuleItem[]>;
|
|
26
|
+
/**错误提示内容*/
|
|
27
|
+
messages: Ref<MessageType[]>;
|
|
28
|
+
/**更新当前组件方法*/
|
|
29
|
+
updated?: Function;
|
|
30
|
+
/**判断是否必填*/
|
|
31
|
+
isRequired: () => boolean;
|
|
32
|
+
/**初始化*/
|
|
33
|
+
ctor: (name: string, rules: RuleItem[]) => this;
|
|
34
|
+
/**判断是否需要验证*/
|
|
35
|
+
isValidate: () => boolean;
|
|
36
|
+
/**更新提示信息*/
|
|
37
|
+
updatedMessages: (messages?: MessageType[]) => void;
|
|
38
|
+
/**更新规则*/
|
|
39
|
+
updatedRules: (rules: RuleItem[]) => void;
|
|
40
|
+
/**验证规则
|
|
41
|
+
* @param {boolean} isOnly 仅判断是否校验通过
|
|
42
|
+
*/
|
|
43
|
+
validate: (isOnly?: boolean) => Promise<unknown>;
|
|
44
|
+
/**获取校验结果*/
|
|
45
|
+
getValidateResult: () => {
|
|
46
|
+
tip: string | (string | undefined)[];
|
|
47
|
+
isInvalid: boolean;
|
|
48
|
+
};
|
|
49
|
+
}
|
|
@@ -0,0 +1,73 @@
|
|
|
1
|
+
import AsyncValidator from "async-validator";
|
|
2
|
+
import { ref, toValue } from "vue";
|
|
3
|
+
class RuleInstanceBase2 {
|
|
4
|
+
constructor() {
|
|
5
|
+
this.name = "";
|
|
6
|
+
this.rules = ref([]);
|
|
7
|
+
this.messages = ref([]);
|
|
8
|
+
this.isRequired = () => {
|
|
9
|
+
var _a, _b;
|
|
10
|
+
if ((_b = (_a = this.instance) == null ? void 0 : _a.getFieldHideRulesValue) == null ? void 0 : _b.call(_a, this.name)) {
|
|
11
|
+
return false;
|
|
12
|
+
}
|
|
13
|
+
const findItem = (toValue(this.rules) || []).find((item) => item == null ? void 0 : item.required);
|
|
14
|
+
return !!findItem;
|
|
15
|
+
};
|
|
16
|
+
this.ctor = (name, rules) => {
|
|
17
|
+
this.name = name;
|
|
18
|
+
this.rules.value = rules || [];
|
|
19
|
+
return this;
|
|
20
|
+
};
|
|
21
|
+
this.isValidate = () => {
|
|
22
|
+
var _a, _b;
|
|
23
|
+
if ((_b = (_a = this.instance) == null ? void 0 : _a.getFieldHideRulesValue) == null ? void 0 : _b.call(_a, this.name)) {
|
|
24
|
+
return false;
|
|
25
|
+
}
|
|
26
|
+
const _rules = toValue(this.rules);
|
|
27
|
+
return !!(Array.isArray(_rules) && _rules.length);
|
|
28
|
+
};
|
|
29
|
+
this.updatedMessages = (messages) => {
|
|
30
|
+
var _a;
|
|
31
|
+
this.messages.value = messages || [];
|
|
32
|
+
(_a = this.updated) == null ? void 0 : _a.call(this, {});
|
|
33
|
+
};
|
|
34
|
+
this.updatedRules = (rules) => {
|
|
35
|
+
var _a;
|
|
36
|
+
this.rules.value = rules;
|
|
37
|
+
(_a = this.updatedMessages) == null ? void 0 : _a.call(this, []);
|
|
38
|
+
};
|
|
39
|
+
this.validate = (isOnly = false) => {
|
|
40
|
+
return new Promise((resolve, reject) => {
|
|
41
|
+
var _a, _b, _c, _d;
|
|
42
|
+
const value = (_b = (_a = this.instance) == null ? void 0 : _a.getFieldValue) == null ? void 0 : _b.call(_a, this.name);
|
|
43
|
+
if ((_d = (_c = this.instance) == null ? void 0 : _c.getFieldHideRulesValue) == null ? void 0 : _d.call(_c, this.name)) {
|
|
44
|
+
this.updatedMessages([]);
|
|
45
|
+
resolve({ [this.name]: value });
|
|
46
|
+
}
|
|
47
|
+
new AsyncValidator({ [this.name]: toValue(this.rules) || [] }).validate({ [this.name]: value }).then((values) => {
|
|
48
|
+
if (!isOnly) this.updatedMessages([]);
|
|
49
|
+
resolve(values);
|
|
50
|
+
}).catch(({ errors }) => {
|
|
51
|
+
if (Array.isArray(errors)) {
|
|
52
|
+
if (!isOnly) this.updatedMessages(errors);
|
|
53
|
+
reject(errors);
|
|
54
|
+
} else {
|
|
55
|
+
reject();
|
|
56
|
+
}
|
|
57
|
+
});
|
|
58
|
+
});
|
|
59
|
+
};
|
|
60
|
+
this.getValidateResult = () => {
|
|
61
|
+
const _messages = toValue(this.messages);
|
|
62
|
+
const tip = Array.isArray(_messages) ? _messages.map((it) => it.message) : "";
|
|
63
|
+
const isInvalid = Array.isArray(tip) ? !!tip.length : !!tip;
|
|
64
|
+
return {
|
|
65
|
+
tip,
|
|
66
|
+
isInvalid
|
|
67
|
+
};
|
|
68
|
+
};
|
|
69
|
+
}
|
|
70
|
+
}
|
|
71
|
+
export {
|
|
72
|
+
RuleInstanceBase2
|
|
73
|
+
};
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
import { ComputedRef, Ref, VNodeChild, StyleValue, UnwrapNestedRefs } from 'vue';
|
|
2
|
+
import { FormItemAttrOptions } from '../hooks/attr/attr.FormItem';
|
|
3
|
+
import { LayoutFormItemProps } from './layout.formItem';
|
|
4
|
+
import { FormLayoutProps } from './layout';
|
|
5
|
+
import { FormInstanceBase, ValidateErrorEntity } from '@carefrees/form-utils';
|
|
6
|
+
export type ComputedRefBase<T> = ComputedRef<T> | Ref<T>;
|
|
7
|
+
export type PartialComputedRefs<T> = {
|
|
8
|
+
[K in keyof T]: ComputedRefBase<T[K]>;
|
|
9
|
+
};
|
|
10
|
+
export interface FormItemProps extends FormItemAttrOptions, LayoutFormItemProps {
|
|
11
|
+
/**不进行样式渲染*/
|
|
12
|
+
noStyle?: boolean;
|
|
13
|
+
/**输入框组件*/
|
|
14
|
+
input?: VNodeChild;
|
|
15
|
+
}
|
|
16
|
+
export interface FormProps<T = any> extends FormLayoutProps {
|
|
17
|
+
form?: FormInstanceBase;
|
|
18
|
+
style?: StyleValue;
|
|
19
|
+
class?: string;
|
|
20
|
+
layoutClass?: string;
|
|
21
|
+
layoutStyle?: StyleValue;
|
|
22
|
+
/**表单数据*/
|
|
23
|
+
formData?: any;
|
|
24
|
+
/**值更新触发*/
|
|
25
|
+
onValuesChange?: (changedValues: Partial<T>, values: UnwrapNestedRefs<T>) => void;
|
|
26
|
+
/**提交保存 验证成功*/
|
|
27
|
+
onFinish?: (values: T) => void;
|
|
28
|
+
/**提交保存 验证失败*/
|
|
29
|
+
onFinishFailed?: (errorInfo: ValidateErrorEntity<T>) => void;
|
|
30
|
+
/**隐藏表单项初始值*/
|
|
31
|
+
hideData?: Record<string, boolean>;
|
|
32
|
+
/**表单名称*/
|
|
33
|
+
name?: string;
|
|
34
|
+
/**隐藏规则校验*/
|
|
35
|
+
hideRuleData?: Record<string, boolean>;
|
|
36
|
+
}
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
import { AttrsOptions } from '../hooks/useAttrs';
|
|
2
|
+
import { VNodeChild, StyleValue } from 'vue';
|
|
3
|
+
export interface FormLayoutProps extends Omit<AttrsOptions, 'colCount'> {
|
|
4
|
+
/**标题*/
|
|
5
|
+
title?: VNodeChild;
|
|
6
|
+
/**额外内容*/
|
|
7
|
+
extra?: VNodeChild;
|
|
8
|
+
/**是否占据整行*/
|
|
9
|
+
isAllColSpan?: boolean;
|
|
10
|
+
class?: string;
|
|
11
|
+
/**头部ClassName*/
|
|
12
|
+
headerClass?: string;
|
|
13
|
+
/**内容Class*/
|
|
14
|
+
bodyClass?: string;
|
|
15
|
+
style?: StyleValue;
|
|
16
|
+
/**头部样式*/
|
|
17
|
+
headerStyle?: StyleValue;
|
|
18
|
+
/**内容样式*/
|
|
19
|
+
bodyStyle?: StyleValue;
|
|
20
|
+
/**是否添加边框*/
|
|
21
|
+
bordered?: boolean;
|
|
22
|
+
/**列数据*/
|
|
23
|
+
colCount?: number;
|
|
24
|
+
/**
|
|
25
|
+
* @description gap 属性是用来设置网格行与列之间的间隙,该属性是row-gap and column-gap的简写形式。
|
|
26
|
+
*/
|
|
27
|
+
gap?: string | number;
|
|
28
|
+
}
|
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
import { VNodeChild, StyleValue } from 'vue';
|
|
2
|
+
import { ComputedRefBase } from '.';
|
|
3
|
+
export interface LayoutFormItemProps {
|
|
4
|
+
/**规则校验失败错误提示位置*/
|
|
5
|
+
errorLayout?: 'left-bottom' | 'right-bottom' | 'top-right' | 'top-left';
|
|
6
|
+
/**必填样式*/
|
|
7
|
+
required?: boolean;
|
|
8
|
+
/**label显示模式*/
|
|
9
|
+
labelMode?: 'left' | 'top' | 'between' | 'hide';
|
|
10
|
+
/**只进行规则样式*/
|
|
11
|
+
onlyRuleStyle?: boolean;
|
|
12
|
+
label?: VNodeChild;
|
|
13
|
+
/**底部提示内容*/
|
|
14
|
+
helpText?: VNodeChild;
|
|
15
|
+
/**额外内容*/
|
|
16
|
+
extra?: VNodeChild;
|
|
17
|
+
/**是否显示label后的冒号*/
|
|
18
|
+
showColon?: boolean;
|
|
19
|
+
/**
|
|
20
|
+
* 表单项占据列数
|
|
21
|
+
* @default 1
|
|
22
|
+
*/
|
|
23
|
+
colSpan?: number;
|
|
24
|
+
/**
|
|
25
|
+
* 表单项占据行数
|
|
26
|
+
* @default 1
|
|
27
|
+
*/
|
|
28
|
+
rowSpan?: number;
|
|
29
|
+
htmlFor?: ComputedRefBase<string>;
|
|
30
|
+
/**规则验证结果*/
|
|
31
|
+
validateResult?: ComputedRefBase<{
|
|
32
|
+
tip: string | (string | undefined)[];
|
|
33
|
+
isInvalid: boolean;
|
|
34
|
+
}>;
|
|
35
|
+
style?: StyleValue;
|
|
36
|
+
class?: string;
|
|
37
|
+
labelStyle?: StyleValue;
|
|
38
|
+
labelClass?: string;
|
|
39
|
+
}
|