@carefrees/form-utils-vue 0.0.12 → 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.
Files changed (71) hide show
  1. package/README.md +54 -6
  2. package/esm/form/form.js +12 -7
  3. package/esm/formItem/form.Item.base.js +1 -6
  4. package/esm/formItem/form.Item.base.vue.d.ts +1 -0
  5. package/esm/formItem/form.hide.item.js +1 -5
  6. package/esm/formItem/form.hide.item.vue.d.ts +1 -0
  7. package/esm/formItem/formItem.js +0 -4
  8. package/esm/formItem/index.d.ts +2 -0
  9. package/esm/index.d.ts +1 -1
  10. package/esm/index.js +1 -1
  11. package/esm/interface/index.d.ts +4 -11
  12. package/esm/interface/layout.d.ts +1 -1
  13. package/esm/interface/layout.formItem.d.ts +1 -1
  14. package/esm/layout/layout.formItem.js +1 -1
  15. package/esm/layout/layout.js +1 -1
  16. package/package.json +3 -2
  17. package/src/form/form.vue +13 -6
  18. package/src/formItem/form.Item.base.vue +5 -5
  19. package/src/formItem/form.hide.item.vue +3 -1
  20. package/src/formItem/formItem.vue +2 -1
  21. package/src/index.ts +1 -1
  22. package/src/interface/index.ts +4 -13
  23. package/src/interface/layout.formItem.ts +1 -2
  24. package/src/interface/layout.ts +2 -1
  25. package/src/layout/layout.formItem.vue +2 -1
  26. package/src/layout/layout.vue +2 -1
  27. package/esm/hooks/attr/attr.FormItem.d.ts +0 -97
  28. package/esm/hooks/attr/attr.FormItem.js +0 -97
  29. package/esm/hooks/index.d.ts +0 -13
  30. package/esm/hooks/index.js +0 -13
  31. package/esm/hooks/register/register.FormHideItem.d.ts +0 -9
  32. package/esm/hooks/register/register.FormHideItem.js +0 -42
  33. package/esm/hooks/register/register.FormItem.d.ts +0 -26
  34. package/esm/hooks/register/register.FormItem.js +0 -67
  35. package/esm/hooks/register/register.FormList.d.ts +0 -9
  36. package/esm/hooks/register/register.FormList.js +0 -42
  37. package/esm/hooks/register/register.form.d.ts +0 -3
  38. package/esm/hooks/register/register.form.js +0 -10
  39. package/esm/hooks/useAttrs.d.ts +0 -25
  40. package/esm/hooks/useAttrs.js +0 -26
  41. package/esm/hooks/useEffect.d.ts +0 -2
  42. package/esm/hooks/useEffect.js +0 -12
  43. package/esm/hooks/useForm.d.ts +0 -8
  44. package/esm/hooks/useForm.js +0 -17
  45. package/esm/hooks/useFormItem.d.ts +0 -7
  46. package/esm/hooks/useFormItem.js +0 -17
  47. package/esm/hooks/useFormItemParentName.d.ts +0 -18
  48. package/esm/hooks/useFormItemParentName.js +0 -47
  49. package/esm/hooks/useFormList.d.ts +0 -7
  50. package/esm/hooks/useFormList.js +0 -17
  51. package/esm/hooks/useHtmlFor.d.ts +0 -2
  52. package/esm/hooks/useHtmlFor.js +0 -7
  53. package/esm/hooks/useMultipleForm.d.ts +0 -7
  54. package/esm/hooks/useMultipleForm.js +0 -18
  55. package/esm/instance/ruleIntsnace.d.ts +0 -49
  56. package/esm/instance/ruleIntsnace.js +0 -65
  57. package/src/hooks/attr/attr.FormItem.tsx +0 -174
  58. package/src/hooks/index.ts +0 -13
  59. package/src/hooks/register/register.FormHideItem.ts +0 -45
  60. package/src/hooks/register/register.FormItem.ts +0 -80
  61. package/src/hooks/register/register.FormList.ts +0 -49
  62. package/src/hooks/register/register.form.ts +0 -12
  63. package/src/hooks/useAttrs.ts +0 -64
  64. package/src/hooks/useEffect.ts +0 -13
  65. package/src/hooks/useForm.ts +0 -28
  66. package/src/hooks/useFormItem.ts +0 -28
  67. package/src/hooks/useFormItemParentName.ts +0 -49
  68. package/src/hooks/useFormList.ts +0 -28
  69. package/src/hooks/useHtmlFor.ts +0 -9
  70. package/src/hooks/useMultipleForm.ts +0 -29
  71. package/src/instance/ruleIntsnace.ts +0 -105
@@ -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
- }