@carefrees/form-utils-vue 0.0.11 → 0.0.13
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 +104 -2
- package/assets/index.css +23 -12
- package/esm/component.js +3 -0
- package/esm/form/form.js +161 -0
- package/esm/form/form.vue.d.ts +10 -7
- package/esm/form/index.d.ts +12 -12
- package/esm/form/index.js +4 -0
- package/esm/formItem/form.Item.base.js +157 -0
- package/esm/formItem/form.Item.base.vue.d.ts +7 -8
- package/esm/formItem/form.hide.item.js +122 -0
- package/esm/formItem/form.hide.item.vue.d.ts +7 -8
- package/esm/formItem/formItem.js +151 -0
- package/esm/formItem/formItem.vue.d.ts +6 -9
- package/esm/formItem/index.d.ts +26 -37
- package/esm/formItem/index.js +8 -0
- package/esm/index.d.ts +2 -2
- package/esm/index.js +13 -0
- package/esm/interface/index.d.ts +6 -11
- package/esm/interface/index.js +0 -0
- package/esm/interface/layout.d.ts +1 -1
- package/esm/interface/layout.formItem.d.ts +1 -1
- package/esm/interface/layout.formItem.js +0 -0
- package/esm/interface/layout.js +0 -0
- package/esm/layout/index.d.ts +24 -33
- package/esm/layout/index.js +8 -0
- package/esm/layout/layout.form.rows.js +21 -0
- package/esm/layout/layout.form.rows.vue.d.ts +8 -5
- package/esm/layout/layout.formItem.js +195 -0
- package/esm/layout/layout.formItem.vue.d.ts +6 -9
- package/esm/layout/layout.js +160 -0
- package/esm/layout/layout.vue.d.ts +6 -8
- package/esm/utils/index.js +1 -0
- package/esm/utils/withInstall.d.ts +2 -2
- package/esm/utils/withInstall.js +15 -0
- package/package.json +7 -8
- package/src/form/form.vue +21 -7
- package/src/formItem/form.Item.base.vue +5 -5
- package/src/formItem/form.hide.item.vue +3 -1
- package/src/formItem/formItem.vue +2 -1
- package/src/index.ts +1 -1
- package/src/interface/index.ts +6 -13
- package/src/interface/layout.formItem.ts +1 -2
- package/src/interface/layout.ts +2 -1
- package/src/layout/layout.formItem.vue +2 -1
- package/src/layout/layout.vue +2 -1
- package/esm/component.mjs +0 -12
- package/esm/form/form.vue.mjs +0 -110
- package/esm/form/form.vue2.mjs +0 -4
- package/esm/form/index.mjs +0 -6
- package/esm/formItem/form.Item.base.vue.mjs +0 -114
- package/esm/formItem/form.Item.base.vue2.mjs +0 -4
- package/esm/formItem/form.hide.item.vue.mjs +0 -78
- package/esm/formItem/form.hide.item.vue2.mjs +0 -4
- package/esm/formItem/formItem.vue.mjs +0 -102
- package/esm/formItem/formItem.vue2.mjs +0 -4
- package/esm/formItem/index.mjs +0 -12
- package/esm/hooks/attr/attr.FormItem.d.ts +0 -97
- package/esm/hooks/attr/attr.FormItem.mjs +0 -120
- package/esm/hooks/index.d.ts +0 -13
- package/esm/hooks/register/register.FormHideItem.d.ts +0 -9
- package/esm/hooks/register/register.FormHideItem.mjs +0 -38
- package/esm/hooks/register/register.FormItem.d.ts +0 -23
- package/esm/hooks/register/register.FormItem.mjs +0 -55
- package/esm/hooks/register/register.FormList.d.ts +0 -9
- package/esm/hooks/register/register.FormList.mjs +0 -43
- package/esm/hooks/register/register.form.d.ts +0 -3
- package/esm/hooks/register/register.form.mjs +0 -12
- package/esm/hooks/useAttrs.d.ts +0 -24
- package/esm/hooks/useAttrs.mjs +0 -43
- package/esm/hooks/useEffect.d.ts +0 -2
- package/esm/hooks/useEffect.mjs +0 -14
- package/esm/hooks/useForm.d.ts +0 -8
- package/esm/hooks/useForm.mjs +0 -26
- package/esm/hooks/useFormItem.d.ts +0 -7
- package/esm/hooks/useFormItem.mjs +0 -26
- package/esm/hooks/useFormItemParentName.d.ts +0 -18
- package/esm/hooks/useFormItemParentName.mjs +0 -37
- package/esm/hooks/useFormList.d.ts +0 -7
- package/esm/hooks/useFormList.mjs +0 -26
- package/esm/hooks/useHtmlFor.d.ts +0 -2
- package/esm/hooks/useHtmlFor.mjs +0 -11
- package/esm/hooks/useMultipleForm.d.ts +0 -7
- package/esm/hooks/useMultipleForm.mjs +0 -27
- package/esm/index.mjs +0 -59
- package/esm/instance/ruleIntsnace.d.ts +0 -49
- package/esm/instance/ruleIntsnace.mjs +0 -73
- package/esm/layout/index.mjs +0 -12
- package/esm/layout/layout.form.rows.vue.mjs +0 -31
- package/esm/layout/layout.form.rows.vue2.mjs +0 -4
- package/esm/layout/layout.formItem.vue.mjs +0 -216
- package/esm/layout/layout.formItem.vue2.mjs +0 -4
- package/esm/layout/layout.vue.mjs +0 -166
- package/esm/layout/layout.vue2.mjs +0 -4
- package/esm/utils/withInstall.mjs +0 -22
- package/lib/component.d.ts +0 -3
- package/lib/component.js +0 -12
- package/lib/form/form.vue.d.ts +0 -19
- package/lib/form/form.vue.js +0 -110
- package/lib/form/form.vue2.js +0 -4
- package/lib/form/index.d.ts +0 -37
- package/lib/form/index.js +0 -6
- package/lib/formItem/form.Item.base.vue.d.ts +0 -16
- package/lib/formItem/form.Item.base.vue.js +0 -114
- package/lib/formItem/form.Item.base.vue2.js +0 -4
- package/lib/formItem/form.hide.item.vue.d.ts +0 -16
- package/lib/formItem/form.hide.item.vue.js +0 -78
- package/lib/formItem/form.hide.item.vue2.js +0 -4
- package/lib/formItem/formItem.vue.d.ts +0 -18
- package/lib/formItem/formItem.vue.js +0 -102
- package/lib/formItem/formItem.vue2.js +0 -4
- package/lib/formItem/index.d.ts +0 -71
- package/lib/formItem/index.js +0 -12
- package/lib/hooks/attr/attr.FormItem.d.ts +0 -97
- package/lib/hooks/attr/attr.FormItem.js +0 -120
- package/lib/hooks/index.d.ts +0 -13
- package/lib/hooks/register/register.FormHideItem.d.ts +0 -9
- package/lib/hooks/register/register.FormHideItem.js +0 -38
- package/lib/hooks/register/register.FormItem.d.ts +0 -23
- package/lib/hooks/register/register.FormItem.js +0 -55
- package/lib/hooks/register/register.FormList.d.ts +0 -9
- package/lib/hooks/register/register.FormList.js +0 -43
- package/lib/hooks/register/register.form.d.ts +0 -3
- package/lib/hooks/register/register.form.js +0 -12
- package/lib/hooks/useAttrs.d.ts +0 -24
- package/lib/hooks/useAttrs.js +0 -43
- package/lib/hooks/useEffect.d.ts +0 -2
- package/lib/hooks/useEffect.js +0 -14
- package/lib/hooks/useForm.d.ts +0 -8
- package/lib/hooks/useForm.js +0 -26
- package/lib/hooks/useFormItem.d.ts +0 -7
- package/lib/hooks/useFormItem.js +0 -26
- package/lib/hooks/useFormItemParentName.d.ts +0 -18
- package/lib/hooks/useFormItemParentName.js +0 -37
- package/lib/hooks/useFormList.d.ts +0 -7
- package/lib/hooks/useFormList.js +0 -26
- package/lib/hooks/useHtmlFor.d.ts +0 -2
- package/lib/hooks/useHtmlFor.js +0 -11
- package/lib/hooks/useMultipleForm.d.ts +0 -7
- package/lib/hooks/useMultipleForm.js +0 -27
- package/lib/index.d.ts +0 -11
- package/lib/index.js +0 -59
- package/lib/instance/ruleIntsnace.d.ts +0 -49
- package/lib/instance/ruleIntsnace.js +0 -73
- package/lib/interface/index.d.ts +0 -36
- package/lib/interface/layout.d.ts +0 -28
- package/lib/interface/layout.formItem.d.ts +0 -39
- package/lib/layout/index.d.ts +0 -65
- package/lib/layout/index.js +0 -12
- package/lib/layout/layout.form.rows.vue.d.ts +0 -10
- package/lib/layout/layout.form.rows.vue.js +0 -31
- package/lib/layout/layout.form.rows.vue2.js +0 -4
- package/lib/layout/layout.formItem.vue.d.ts +0 -18
- package/lib/layout/layout.formItem.vue.js +0 -216
- package/lib/layout/layout.formItem.vue2.js +0 -4
- package/lib/layout/layout.vue.d.ts +0 -16
- package/lib/layout/layout.vue.js +0 -166
- package/lib/layout/layout.vue2.js +0 -4
- package/lib/utils/index.d.ts +0 -1
- package/lib/utils/withInstall.d.ts +0 -3
- package/lib/utils/withInstall.js +0 -22
- package/src/hooks/attr/attr.FormItem.tsx +0 -174
- package/src/hooks/index.ts +0 -13
- package/src/hooks/register/register.FormHideItem.ts +0 -45
- package/src/hooks/register/register.FormItem.ts +0 -80
- package/src/hooks/register/register.FormList.ts +0 -49
- package/src/hooks/register/register.form.ts +0 -12
- package/src/hooks/useAttrs.ts +0 -64
- package/src/hooks/useEffect.ts +0 -13
- package/src/hooks/useForm.ts +0 -28
- package/src/hooks/useFormItem.ts +0 -28
- package/src/hooks/useFormItemParentName.ts +0 -49
- package/src/hooks/useFormList.ts +0 -28
- package/src/hooks/useHtmlFor.ts +0 -9
- package/src/hooks/useMultipleForm.ts +0 -29
- package/src/instance/ruleIntsnace.ts +0 -105
- package/src/vite-env.d.ts +0 -1
|
@@ -1,80 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* @description 注册组件
|
|
3
|
-
*/
|
|
4
|
-
|
|
5
|
-
import { Ref, ref, toValue, watch } from 'vue';
|
|
6
|
-
import type { RuleItem } from 'async-validator';
|
|
7
|
-
import { useFormInject } from '../useForm';
|
|
8
|
-
import { useFormItem } from '../useFormItem';
|
|
9
|
-
import { useFormItemParentNameInject } from '../useFormItemParentName';
|
|
10
|
-
import { useEffect } from '../useEffect';
|
|
11
|
-
import { RuleInstanceBase2 } from '../../instance/ruleIntsnace';
|
|
12
|
-
|
|
13
|
-
export interface RegisterFormItemOptions {
|
|
14
|
-
/**字段*/
|
|
15
|
-
name: string;
|
|
16
|
-
/**规则*/
|
|
17
|
-
rules?: RuleItem[];
|
|
18
|
-
/**排序值*/
|
|
19
|
-
sort?: string;
|
|
20
|
-
/**是否拼接父级字段*/
|
|
21
|
-
isJoinParentField?: boolean;
|
|
22
|
-
}
|
|
23
|
-
|
|
24
|
-
/**注册表单项到表单实例中*/
|
|
25
|
-
export const useRegisterFormItem = (options: RegisterFormItemOptions) => {
|
|
26
|
-
const { name, rules, sort, isJoinParentField = true } = options;
|
|
27
|
-
const form = useFormInject();
|
|
28
|
-
const deepRefData = ref<any>({});
|
|
29
|
-
const { newName, newSort, parentItem } = useFormItemParentNameInject({ name, sort, isJoinParentField });
|
|
30
|
-
// 注册规则
|
|
31
|
-
// 注册单个实例
|
|
32
|
-
const ruleInstance: Ref<RuleInstanceBase2> = ref<any>(new RuleInstanceBase2());
|
|
33
|
-
const formItemInstance = useFormItem();
|
|
34
|
-
|
|
35
|
-
watch(
|
|
36
|
-
() => [form],
|
|
37
|
-
() => {
|
|
38
|
-
ruleInstance.value.instance = form;
|
|
39
|
-
formItemInstance.instance = form;
|
|
40
|
-
},
|
|
41
|
-
{ immediate: true },
|
|
42
|
-
);
|
|
43
|
-
|
|
44
|
-
watch(
|
|
45
|
-
() => [toValue(newName)],
|
|
46
|
-
() => {
|
|
47
|
-
ruleInstance.value.ctor(toValue(newName), rules || []);
|
|
48
|
-
formItemInstance.ctor(toValue(newName), toValue(ruleInstance) as any);
|
|
49
|
-
},
|
|
50
|
-
{ immediate: true },
|
|
51
|
-
);
|
|
52
|
-
|
|
53
|
-
watch(
|
|
54
|
-
() => [toValue(newSort)],
|
|
55
|
-
() => {
|
|
56
|
-
ruleInstance.value.sort = toValue(newSort);
|
|
57
|
-
formItemInstance.sort = toValue(newSort);
|
|
58
|
-
},
|
|
59
|
-
{ immediate: true },
|
|
60
|
-
);
|
|
61
|
-
|
|
62
|
-
watch(
|
|
63
|
-
() => [toValue(parentItem)],
|
|
64
|
-
() => {
|
|
65
|
-
formItemInstance.parentDataField = toValue(toValue(parentItem).name);
|
|
66
|
-
},
|
|
67
|
-
{ immediate: true },
|
|
68
|
-
);
|
|
69
|
-
|
|
70
|
-
const updated = () => {
|
|
71
|
-
deepRefData.value = { __temp: new Date().valueOf() };
|
|
72
|
-
};
|
|
73
|
-
|
|
74
|
-
formItemInstance.updated = updated;
|
|
75
|
-
ruleInstance.value.updated = updated;
|
|
76
|
-
|
|
77
|
-
useEffect(() => form.registerFormItem(formItemInstance));
|
|
78
|
-
|
|
79
|
-
return { ruleInstance, formItemInstance, form, newName, newSort, parentItem, deepRefData };
|
|
80
|
-
};
|
|
@@ -1,49 +0,0 @@
|
|
|
1
|
-
import { watch, toValue } from 'vue';
|
|
2
|
-
import { RegisterFormItemOptions, useRegisterFormItem } from './register.FormItem';
|
|
3
|
-
import { useFormList } from '../useFormList';
|
|
4
|
-
import { useEffect } from '../useEffect';
|
|
5
|
-
|
|
6
|
-
export interface RegisterFormListOptions extends RegisterFormItemOptions {}
|
|
7
|
-
|
|
8
|
-
/**注册表单List到表单实例中*/
|
|
9
|
-
export const useRegisterFormList = (options: RegisterFormListOptions) => {
|
|
10
|
-
const { ruleInstance, formItemInstance, form, newName, parentItem } = useRegisterFormItem(options);
|
|
11
|
-
const formListInstance = useFormList();
|
|
12
|
-
|
|
13
|
-
watch(
|
|
14
|
-
() => [toValue(newName)],
|
|
15
|
-
() => {
|
|
16
|
-
formListInstance.ctor(toValue(newName));
|
|
17
|
-
},
|
|
18
|
-
{ immediate: true },
|
|
19
|
-
);
|
|
20
|
-
|
|
21
|
-
watch(
|
|
22
|
-
() => [form, formItemInstance, toValue(ruleInstance)],
|
|
23
|
-
() => {
|
|
24
|
-
formListInstance.instance = form;
|
|
25
|
-
formListInstance.formItemInstance = formItemInstance;
|
|
26
|
-
formListInstance.rule = toValue(ruleInstance) as any;
|
|
27
|
-
},
|
|
28
|
-
{ immediate: true },
|
|
29
|
-
);
|
|
30
|
-
|
|
31
|
-
watch(
|
|
32
|
-
() => [options.sort, toValue(parentItem)],
|
|
33
|
-
() => {
|
|
34
|
-
formListInstance.sort = toValue(parentItem.value.sort);
|
|
35
|
-
formListInstance.parentDataField = toValue(parentItem.value.name);
|
|
36
|
-
},
|
|
37
|
-
{ immediate: true },
|
|
38
|
-
);
|
|
39
|
-
|
|
40
|
-
useEffect(() => {
|
|
41
|
-
return form.registerFormList(newName.value, formListInstance);
|
|
42
|
-
});
|
|
43
|
-
|
|
44
|
-
return {
|
|
45
|
-
ruleInstance,
|
|
46
|
-
formItemInstance,
|
|
47
|
-
formListInstance,
|
|
48
|
-
};
|
|
49
|
-
};
|
|
@@ -1,12 +0,0 @@
|
|
|
1
|
-
import { useMultipleFormInject } from '../useMultipleForm';
|
|
2
|
-
import { FormInstanceBase } from '@carefrees/form-utils';
|
|
3
|
-
import { useEffect } from '../useEffect';
|
|
4
|
-
|
|
5
|
-
/**注册表单实例到多表单收集实例中*/
|
|
6
|
-
export const useRegisterForm = (form: FormInstanceBase, name?: string) => {
|
|
7
|
-
const multipleForm = useMultipleFormInject();
|
|
8
|
-
useEffect(() => {
|
|
9
|
-
if (name) return multipleForm.ctor(name, form);
|
|
10
|
-
});
|
|
11
|
-
return multipleForm;
|
|
12
|
-
};
|
package/src/hooks/useAttrs.ts
DELETED
|
@@ -1,64 +0,0 @@
|
|
|
1
|
-
/**公共属性*/
|
|
2
|
-
import { provide, inject, computed, StyleValue, ComputedRef, ref, toRefs, reactive } from 'vue';
|
|
3
|
-
import { ComputedRefBase } from '../interface';
|
|
4
|
-
|
|
5
|
-
export type AttrsOptions = {
|
|
6
|
-
/**列数据*/
|
|
7
|
-
colCount?: ComputedRefBase<number | undefined>;
|
|
8
|
-
/**规则校验失败错误提示位置*/
|
|
9
|
-
errorLayout?: ComputedRefBase<'left-bottom' | 'right-bottom' | 'top-right' | 'top-left' | undefined>;
|
|
10
|
-
/**label显示模式*/
|
|
11
|
-
labelMode?: ComputedRefBase<'left' | 'top' | 'hide' | undefined>;
|
|
12
|
-
/**是否显示label后的冒号*/
|
|
13
|
-
showColon?: ComputedRefBase<boolean | undefined>;
|
|
14
|
-
/**表单项 className*/
|
|
15
|
-
formItemClass?: ComputedRefBase<string | undefined>;
|
|
16
|
-
/**表单项 style*/
|
|
17
|
-
formItemStyle?: ComputedRefBase<StyleValue | undefined>;
|
|
18
|
-
/**表单项 label className*/
|
|
19
|
-
formItemLabelClass?: ComputedRefBase<string | undefined>;
|
|
20
|
-
/**表单项 label style*/
|
|
21
|
-
formItemLabelStyle?: ComputedRefBase<StyleValue | undefined>;
|
|
22
|
-
};
|
|
23
|
-
|
|
24
|
-
const attrsProvideSymbol = Symbol('carefrees-attrs');
|
|
25
|
-
|
|
26
|
-
/**公共属性 Context */
|
|
27
|
-
export function useAttrsProvide(options: AttrsOptions) {
|
|
28
|
-
const {
|
|
29
|
-
colCount = ref(4),
|
|
30
|
-
errorLayout = ref('left-bottom'),
|
|
31
|
-
labelMode = ref('top'),
|
|
32
|
-
showColon = ref(true),
|
|
33
|
-
formItemClass,
|
|
34
|
-
formItemStyle,
|
|
35
|
-
formItemLabelClass,
|
|
36
|
-
formItemLabelStyle,
|
|
37
|
-
} = options;
|
|
38
|
-
const data = computed(() => {
|
|
39
|
-
return {
|
|
40
|
-
colCount,
|
|
41
|
-
errorLayout,
|
|
42
|
-
labelMode,
|
|
43
|
-
showColon,
|
|
44
|
-
formItemClass,
|
|
45
|
-
formItemStyle,
|
|
46
|
-
formItemLabelClass,
|
|
47
|
-
formItemLabelStyle,
|
|
48
|
-
};
|
|
49
|
-
});
|
|
50
|
-
provide(attrsProvideSymbol, reactive(data));
|
|
51
|
-
}
|
|
52
|
-
/**子项中获取公共属性*/
|
|
53
|
-
export function useAttrsInject() {
|
|
54
|
-
const attrs = inject<ComputedRef<AttrsOptions>>(
|
|
55
|
-
attrsProvideSymbol,
|
|
56
|
-
computed(() => ({
|
|
57
|
-
colCount: ref(4),
|
|
58
|
-
errorLayout: ref('left-bottom'),
|
|
59
|
-
labelMode: ref('top'),
|
|
60
|
-
showColon: ref(true),
|
|
61
|
-
})),
|
|
62
|
-
);
|
|
63
|
-
return attrs;
|
|
64
|
-
}
|
package/src/hooks/useEffect.ts
DELETED
|
@@ -1,13 +0,0 @@
|
|
|
1
|
-
import { onMounted, onUnmounted, ref } from 'vue';
|
|
2
|
-
|
|
3
|
-
/**挂载卸载*/
|
|
4
|
-
export const useEffect = (fun: () => Function | undefined) => {
|
|
5
|
-
const unRegisterRef = ref();
|
|
6
|
-
onMounted(() => {
|
|
7
|
-
unRegisterRef.value = fun();
|
|
8
|
-
});
|
|
9
|
-
onUnmounted(() => {
|
|
10
|
-
typeof unRegisterRef.value === 'function' && unRegisterRef.value();
|
|
11
|
-
unRegisterRef.value = undefined;
|
|
12
|
-
});
|
|
13
|
-
};
|
package/src/hooks/useForm.ts
DELETED
|
@@ -1,28 +0,0 @@
|
|
|
1
|
-
import { FormInstanceBase } from '@carefrees/form-utils';
|
|
2
|
-
import { provide, inject, ref, Ref } from 'vue';
|
|
3
|
-
|
|
4
|
-
const formProvideSymbol = Symbol('carefrees-form');
|
|
5
|
-
|
|
6
|
-
/**表单实例 Context */
|
|
7
|
-
export function useFormProvide<T = any>(form: FormInstanceBase<T>) {
|
|
8
|
-
provide(formProvideSymbol, form);
|
|
9
|
-
}
|
|
10
|
-
|
|
11
|
-
/**子项中获取表单实例*/
|
|
12
|
-
export function useFormInject<T = any>() {
|
|
13
|
-
const form = inject<FormInstanceBase<T>>(formProvideSymbol, new FormInstanceBase<T>());
|
|
14
|
-
return form;
|
|
15
|
-
}
|
|
16
|
-
|
|
17
|
-
/**初始化表单实例*/
|
|
18
|
-
export function useForm<T = any>(form?: FormInstanceBase<T>) {
|
|
19
|
-
const refForm = ref<FormInstanceBase<T>>();
|
|
20
|
-
if (!refForm.value) {
|
|
21
|
-
if (form) {
|
|
22
|
-
refForm.value = form;
|
|
23
|
-
} else {
|
|
24
|
-
refForm.value = new FormInstanceBase<T>();
|
|
25
|
-
}
|
|
26
|
-
}
|
|
27
|
-
return refForm as Ref<FormInstanceBase<T>>;
|
|
28
|
-
}
|
package/src/hooks/useFormItem.ts
DELETED
|
@@ -1,28 +0,0 @@
|
|
|
1
|
-
import { FormItemInstanceBase } from '@carefrees/form-utils';
|
|
2
|
-
import { provide, inject, ref } from 'vue';
|
|
3
|
-
|
|
4
|
-
const formItemProvideSymbol = Symbol('carefrees-form-item');
|
|
5
|
-
|
|
6
|
-
/**表单项实例 Context */
|
|
7
|
-
export function useFormItemProvide(formItem: FormItemInstanceBase) {
|
|
8
|
-
provide(formItemProvideSymbol, formItem);
|
|
9
|
-
}
|
|
10
|
-
|
|
11
|
-
/**子项中获取表单项实例*/
|
|
12
|
-
export function useFormItemInject() {
|
|
13
|
-
const formItem = inject<FormItemInstanceBase>(formItemProvideSymbol, new FormItemInstanceBase());
|
|
14
|
-
return formItem;
|
|
15
|
-
}
|
|
16
|
-
|
|
17
|
-
/**s初始化 表单项实例*/
|
|
18
|
-
export function useFormItem(formItem?: FormItemInstanceBase) {
|
|
19
|
-
const refForm = ref<FormItemInstanceBase>();
|
|
20
|
-
if (!refForm.value) {
|
|
21
|
-
if (formItem) {
|
|
22
|
-
refForm.value = formItem;
|
|
23
|
-
} else {
|
|
24
|
-
refForm.value = new FormItemInstanceBase();
|
|
25
|
-
}
|
|
26
|
-
}
|
|
27
|
-
return refForm.value;
|
|
28
|
-
}
|
|
@@ -1,49 +0,0 @@
|
|
|
1
|
-
import { provide, inject, computed, ComputedRef, ref, toValue } from 'vue';
|
|
2
|
-
import { PartialComputedRefs } from '../interface';
|
|
3
|
-
|
|
4
|
-
export interface FormItemParentNamOptions {
|
|
5
|
-
/**字段*/
|
|
6
|
-
name: string;
|
|
7
|
-
/**排序*/
|
|
8
|
-
sort?: string;
|
|
9
|
-
/**是否拼接父级字段*/
|
|
10
|
-
isJoinParentField?: boolean;
|
|
11
|
-
}
|
|
12
|
-
|
|
13
|
-
export type FormItemParentNameProviderProps = PartialComputedRefs<Omit<FormItemParentNamOptions, 'isJoinParentField'>>;
|
|
14
|
-
|
|
15
|
-
const parentNameProvideSymbol = Symbol('carefrees-parent-name');
|
|
16
|
-
|
|
17
|
-
export const useFormItemParentNameProvide = (props: FormItemParentNameProviderProps) => {
|
|
18
|
-
const { name, sort } = props;
|
|
19
|
-
provide(
|
|
20
|
-
parentNameProvideSymbol,
|
|
21
|
-
computed(() => ({ name, sort })),
|
|
22
|
-
);
|
|
23
|
-
};
|
|
24
|
-
|
|
25
|
-
/**表单项获取父级字段*/
|
|
26
|
-
export const useFormItemParentNameInject = (options: FormItemParentNamOptions) => {
|
|
27
|
-
const { isJoinParentField = true, sort, name } = options;
|
|
28
|
-
const parentItem = inject<ComputedRef<FormItemParentNameProviderProps>>(
|
|
29
|
-
parentNameProvideSymbol,
|
|
30
|
-
computed(() => ({ name: ref(''), sort: ref('') })),
|
|
31
|
-
);
|
|
32
|
-
const newName = computed(() => {
|
|
33
|
-
const _name = toValue(parentItem.value.name);
|
|
34
|
-
if (_name && isJoinParentField) {
|
|
35
|
-
if (/^\./.test(`${name}`)) {
|
|
36
|
-
return [_name, name].filter(Boolean).join('');
|
|
37
|
-
} else if (name) {
|
|
38
|
-
return [_name, '.', name].filter(Boolean).join('');
|
|
39
|
-
}
|
|
40
|
-
return [_name, name].filter(Boolean).join('');
|
|
41
|
-
}
|
|
42
|
-
return [name].filter(Boolean).join('');
|
|
43
|
-
});
|
|
44
|
-
const newSort = computed(() => {
|
|
45
|
-
const _sort = toValue(parentItem.value.sort);
|
|
46
|
-
return [isJoinParentField ? _sort : '', sort].filter(Boolean).join('-');
|
|
47
|
-
});
|
|
48
|
-
return { newName, newSort, parentItem };
|
|
49
|
-
};
|
package/src/hooks/useFormList.ts
DELETED
|
@@ -1,28 +0,0 @@
|
|
|
1
|
-
import { FormListInstanceBase } from '@carefrees/form-utils';
|
|
2
|
-
import { provide, inject, ref } from 'vue';
|
|
3
|
-
|
|
4
|
-
const formListProvideSymbol = Symbol('carefrees-form-list');
|
|
5
|
-
|
|
6
|
-
/**表单List实例 Context */
|
|
7
|
-
export function useFormListProvide(formList: FormListInstanceBase) {
|
|
8
|
-
provide(formListProvideSymbol, formList);
|
|
9
|
-
}
|
|
10
|
-
|
|
11
|
-
/**子项中获取表单List实例*/
|
|
12
|
-
export function useFormListInject() {
|
|
13
|
-
const formList = inject<FormListInstanceBase>(formListProvideSymbol, new FormListInstanceBase());
|
|
14
|
-
return formList;
|
|
15
|
-
}
|
|
16
|
-
|
|
17
|
-
/**初始化 表单List实例*/
|
|
18
|
-
export function useFormList(formList?: FormListInstanceBase) {
|
|
19
|
-
const refForm = ref<FormListInstanceBase>();
|
|
20
|
-
if (!refForm.value) {
|
|
21
|
-
if (formList) {
|
|
22
|
-
refForm.value = formList;
|
|
23
|
-
} else {
|
|
24
|
-
refForm.value = new FormListInstanceBase();
|
|
25
|
-
}
|
|
26
|
-
}
|
|
27
|
-
return refForm.value;
|
|
28
|
-
}
|
package/src/hooks/useHtmlFor.ts
DELETED
|
@@ -1,9 +0,0 @@
|
|
|
1
|
-
import { ref, computed, Ref } from 'vue';
|
|
2
|
-
|
|
3
|
-
let localId = 0;
|
|
4
|
-
export const useHtmlFor = (suffix: Ref<string>) => {
|
|
5
|
-
const count = ref(localId++);
|
|
6
|
-
return computed(() => {
|
|
7
|
-
return `carefree-vue-form-item_${count.value.toString(32)}_${suffix.value}`;
|
|
8
|
-
});
|
|
9
|
-
};
|
|
@@ -1,29 +0,0 @@
|
|
|
1
|
-
import { MultipleInstanceBase } from "@carefrees/form-utils"
|
|
2
|
-
import { provide, inject, ref } from "vue"
|
|
3
|
-
|
|
4
|
-
const multipleFormProvideSymbol = Symbol("carefrees-multiple-form")
|
|
5
|
-
|
|
6
|
-
/**多表单收集 Context */
|
|
7
|
-
export function useMultipleFormProvide(multipleForm?: MultipleInstanceBase) {
|
|
8
|
-
const newMultipleForm = useMultipleForm(multipleForm)
|
|
9
|
-
provide(multipleFormProvideSymbol, newMultipleForm)
|
|
10
|
-
}
|
|
11
|
-
|
|
12
|
-
/**子项中获取 多表单收集 实例*/
|
|
13
|
-
export function useMultipleFormInject() {
|
|
14
|
-
const multipleForm = inject<MultipleInstanceBase>(multipleFormProvideSymbol, new MultipleInstanceBase())
|
|
15
|
-
return multipleForm
|
|
16
|
-
}
|
|
17
|
-
|
|
18
|
-
/**初始化 多表单收集 实例*/
|
|
19
|
-
export function useMultipleForm(multipleForm?: MultipleInstanceBase) {
|
|
20
|
-
const refForm = ref<MultipleInstanceBase>()
|
|
21
|
-
if (!refForm.value) {
|
|
22
|
-
if (multipleForm) {
|
|
23
|
-
refForm.value = multipleForm
|
|
24
|
-
} else {
|
|
25
|
-
refForm.value = new MultipleInstanceBase()
|
|
26
|
-
}
|
|
27
|
-
}
|
|
28
|
-
return refForm.value
|
|
29
|
-
}
|
|
@@ -1,105 +0,0 @@
|
|
|
1
|
-
import AsyncValidator, { RuleItem } from 'async-validator';
|
|
2
|
-
import type { MessageType, FormInstanceBase } from '@carefrees/form-utils';
|
|
3
|
-
import { ref, Ref, toValue } from 'vue';
|
|
4
|
-
|
|
5
|
-
export class RuleInstanceBase2 {
|
|
6
|
-
/**
|
|
7
|
-
* 顺序
|
|
8
|
-
* @example
|
|
9
|
-
* "0"
|
|
10
|
-
* "0-0"
|
|
11
|
-
* "0-0-0"
|
|
12
|
-
*/
|
|
13
|
-
sort?: string;
|
|
14
|
-
/**表单实例*/
|
|
15
|
-
instance?: FormInstanceBase;
|
|
16
|
-
/**
|
|
17
|
-
* 字段 ,分割方式与lodash的get和set方法值更新或设置路径一致
|
|
18
|
-
* @example
|
|
19
|
-
* 默认:"name"
|
|
20
|
-
* 嵌套字段:"name.a.doc"
|
|
21
|
-
* 嵌套字段:"name[1].a.doc"
|
|
22
|
-
* 嵌套字段:"name.a[2].doc"
|
|
23
|
-
*/
|
|
24
|
-
name: string = '';
|
|
25
|
-
/**规则*/
|
|
26
|
-
rules: Ref<RuleItem[]> = ref([]);
|
|
27
|
-
/**错误提示内容*/
|
|
28
|
-
messages: Ref<MessageType[]> = ref([]);
|
|
29
|
-
/**更新当前组件方法*/
|
|
30
|
-
updated?: Function;
|
|
31
|
-
|
|
32
|
-
/**判断是否必填*/
|
|
33
|
-
isRequired = () => {
|
|
34
|
-
if (this.instance?.getFieldHideRulesValue?.(this.name)) {
|
|
35
|
-
return false;
|
|
36
|
-
}
|
|
37
|
-
const findItem = (toValue(this.rules) || []).find((item) => item?.required);
|
|
38
|
-
return !!findItem;
|
|
39
|
-
};
|
|
40
|
-
/**初始化*/
|
|
41
|
-
ctor = (name: string, rules: RuleItem[]) => {
|
|
42
|
-
this.name = name;
|
|
43
|
-
this.rules.value = rules || [];
|
|
44
|
-
return this;
|
|
45
|
-
};
|
|
46
|
-
/**判断是否需要验证*/
|
|
47
|
-
isValidate = () => {
|
|
48
|
-
if (this.instance?.getFieldHideRulesValue?.(this.name)) {
|
|
49
|
-
return false;
|
|
50
|
-
}
|
|
51
|
-
const _rules = toValue(this.rules);
|
|
52
|
-
return !!(Array.isArray(_rules) && _rules.length);
|
|
53
|
-
};
|
|
54
|
-
/**更新提示信息*/
|
|
55
|
-
updatedMessages = (messages?: MessageType[]) => {
|
|
56
|
-
this.messages.value = messages || [];
|
|
57
|
-
this.updated?.({});
|
|
58
|
-
};
|
|
59
|
-
|
|
60
|
-
/**更新规则*/
|
|
61
|
-
updatedRules = (rules: RuleItem[]) => {
|
|
62
|
-
/**更新当前规则*/
|
|
63
|
-
this.rules.value = rules;
|
|
64
|
-
/**当前组件重新渲染*/
|
|
65
|
-
this.updatedMessages?.([]);
|
|
66
|
-
};
|
|
67
|
-
|
|
68
|
-
/**验证规则
|
|
69
|
-
* @param {boolean} isOnly 仅判断是否校验通过
|
|
70
|
-
*/
|
|
71
|
-
validate = (isOnly: boolean = false) => {
|
|
72
|
-
return new Promise((resolve, reject) => {
|
|
73
|
-
const value = this.instance?.getFieldValue?.(this.name);
|
|
74
|
-
if (this.instance?.getFieldHideRulesValue?.(this.name)) {
|
|
75
|
-
this.updatedMessages([]);
|
|
76
|
-
resolve({ [this.name]: value });
|
|
77
|
-
}
|
|
78
|
-
new AsyncValidator({ [this.name]: toValue(this.rules) || [] })
|
|
79
|
-
.validate({ [this.name]: value })
|
|
80
|
-
.then((values) => {
|
|
81
|
-
if (!isOnly) this.updatedMessages([]);
|
|
82
|
-
resolve(values);
|
|
83
|
-
})
|
|
84
|
-
.catch(({ errors }) => {
|
|
85
|
-
if (Array.isArray(errors)) {
|
|
86
|
-
if (!isOnly) this.updatedMessages(errors);
|
|
87
|
-
reject(errors);
|
|
88
|
-
} else {
|
|
89
|
-
reject();
|
|
90
|
-
}
|
|
91
|
-
});
|
|
92
|
-
});
|
|
93
|
-
};
|
|
94
|
-
|
|
95
|
-
/**获取校验结果*/
|
|
96
|
-
getValidateResult = () => {
|
|
97
|
-
const _messages = toValue(this.messages);
|
|
98
|
-
const tip = Array.isArray(_messages) ? _messages.map((it) => it.message) : '';
|
|
99
|
-
const isInvalid = Array.isArray(tip) ? !!tip.length : !!tip;
|
|
100
|
-
return {
|
|
101
|
-
tip,
|
|
102
|
-
isInvalid,
|
|
103
|
-
};
|
|
104
|
-
};
|
|
105
|
-
}
|
package/src/vite-env.d.ts
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
/// <reference types="vite/client" />
|