@carefrees/form-utils-vue 0.0.12 → 0.0.14
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +54 -9
- package/esm/form/form.js +13 -12
- package/esm/formItem/form.Item.base.js +1 -6
- package/esm/formItem/form.Item.base.vue.d.ts +1 -0
- package/esm/formItem/form.hide.item.js +1 -5
- package/esm/formItem/form.hide.item.vue.d.ts +1 -0
- package/esm/formItem/formItem.js +0 -4
- package/esm/formItem/index.d.ts +2 -0
- package/esm/index.d.ts +1 -1
- package/esm/index.js +1 -1
- package/esm/interface/index.d.ts +4 -13
- package/esm/interface/layout.d.ts +1 -1
- package/esm/interface/layout.formItem.d.ts +1 -1
- package/esm/layout/layout.formItem.js +1 -1
- package/esm/layout/layout.js +1 -1
- package/package.json +3 -2
- package/src/form/form.vue +15 -12
- 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 +4 -15
- 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/hooks/attr/attr.FormItem.d.ts +0 -97
- package/esm/hooks/attr/attr.FormItem.js +0 -97
- package/esm/hooks/index.d.ts +0 -13
- package/esm/hooks/index.js +0 -13
- package/esm/hooks/register/register.FormHideItem.d.ts +0 -9
- package/esm/hooks/register/register.FormHideItem.js +0 -42
- package/esm/hooks/register/register.FormItem.d.ts +0 -26
- package/esm/hooks/register/register.FormItem.js +0 -67
- package/esm/hooks/register/register.FormList.d.ts +0 -9
- package/esm/hooks/register/register.FormList.js +0 -42
- package/esm/hooks/register/register.form.d.ts +0 -3
- package/esm/hooks/register/register.form.js +0 -10
- package/esm/hooks/useAttrs.d.ts +0 -25
- package/esm/hooks/useAttrs.js +0 -26
- package/esm/hooks/useEffect.d.ts +0 -2
- package/esm/hooks/useEffect.js +0 -12
- package/esm/hooks/useForm.d.ts +0 -8
- package/esm/hooks/useForm.js +0 -17
- package/esm/hooks/useFormItem.d.ts +0 -7
- package/esm/hooks/useFormItem.js +0 -17
- package/esm/hooks/useFormItemParentName.d.ts +0 -18
- package/esm/hooks/useFormItemParentName.js +0 -47
- package/esm/hooks/useFormList.d.ts +0 -7
- package/esm/hooks/useFormList.js +0 -17
- package/esm/hooks/useHtmlFor.d.ts +0 -2
- package/esm/hooks/useHtmlFor.js +0 -7
- package/esm/hooks/useMultipleForm.d.ts +0 -7
- package/esm/hooks/useMultipleForm.js +0 -18
- package/esm/instance/ruleIntsnace.d.ts +0 -49
- package/esm/instance/ruleIntsnace.js +0 -65
- 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
|
@@ -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
|
-
}
|