@jari-ace/element-plus-component 0.1.10 → 0.2.0

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 (156) hide show
  1. package/README.md +18 -18
  2. package/dist/components/form/JaForm.vue.d.ts +0 -3
  3. package/dist/components/form/JaForm.vue.d.ts.map +1 -1
  4. package/dist/components/form/JaForm.vue.js +68 -22
  5. package/dist/components/form/JaForm.vue.js.map +1 -1
  6. package/dist/components/formItem/JaFormItem.vue.d.ts +0 -4
  7. package/dist/components/formItem/JaFormItem.vue.d.ts.map +1 -1
  8. package/dist/components/formItem/JaFormItem.vue.js +8 -26
  9. package/dist/components/formItem/JaFormItem.vue.js.map +1 -1
  10. package/dist/components/userPicker/src/UserPicker.vue.d.ts +17 -0
  11. package/dist/components/userPicker/src/UserPicker.vue.d.ts.map +1 -1
  12. package/dist/components/userPicker/src/UserPicker.vue.js +15 -0
  13. package/dist/components/userPicker/src/UserPicker.vue.js.map +1 -1
  14. package/dist/components/userSelectDialog/src/userSelectDialog.vue.d.ts +17 -0
  15. package/dist/components/userSelectDialog/src/userSelectDialog.vue.d.ts.map +1 -1
  16. package/dist/components/userSelectDialog/src/userSelectDialog.vue.js +15 -0
  17. package/dist/components/userSelectDialog/src/userSelectDialog.vue.js.map +1 -1
  18. package/dist/hooks/useBackendValidations.js +0 -1
  19. package/dist/hooks/useBackendValidations.js.map +1 -1
  20. package/dist/hooks/useClassificationLevels.d.ts +21 -0
  21. package/dist/hooks/useClassificationLevels.d.ts.map +1 -0
  22. package/dist/hooks/useClassificationLevels.js +55 -0
  23. package/dist/hooks/useClassificationLevels.js.map +1 -0
  24. package/dist/hooks/useUserRefQuery.d.ts +6 -0
  25. package/dist/hooks/useUserRefQuery.d.ts.map +1 -1
  26. package/dist/hooks/useUserRefQuery.js +4 -0
  27. package/dist/hooks/useUserRefQuery.js.map +1 -1
  28. package/dist/index.d.ts +0 -1
  29. package/dist/index.d.ts.map +1 -1
  30. package/dist/index.js +0 -1
  31. package/dist/index.js.map +1 -1
  32. package/lib/index.css +1 -1
  33. package/lib/index.js +1527 -1531
  34. package/lib/index.umd.cjs +2 -2
  35. package/package.json +61 -61
  36. package/packages/components/autoComplete/JaAutoComplete.vue +47 -47
  37. package/packages/components/autoComplete/index.ts +5 -5
  38. package/packages/components/avatar/JaAvatar.vue +126 -126
  39. package/packages/components/avatar/avatarToken.ts +11 -11
  40. package/packages/components/avatar/defaultImg.ts +14 -14
  41. package/packages/components/avatar/index.ts +7 -7
  42. package/packages/components/button/JaButton.vue +51 -51
  43. package/packages/components/button/index.ts +4 -4
  44. package/packages/components/channelPicker/index.ts +7 -7
  45. package/packages/components/channelPicker/src/ChannelPicker.vue +43 -43
  46. package/packages/components/channelPicker/src/JaChannelPicker.vue +42 -42
  47. package/packages/components/checkbox/JaCheckbox.vue +73 -73
  48. package/packages/components/checkbox/index.ts +4 -4
  49. package/packages/components/checkboxGroup/JaCheckboxGroup.vue +45 -45
  50. package/packages/components/checkboxGroup/index.ts +4 -4
  51. package/packages/components/customGroupTree/index.ts +10 -10
  52. package/packages/components/customGroupTree/src/customGroupTree.vue +91 -91
  53. package/packages/components/datePicker/JaDatePicker.vue +52 -52
  54. package/packages/components/datePicker/index.ts +4 -4
  55. package/packages/components/departmentPicker/index.ts +4 -4
  56. package/packages/components/departmentPicker/src/DepartmentPicker.vue +107 -107
  57. package/packages/components/departmentPicker/src/consts.ts +2 -2
  58. package/packages/components/departmentTree/index.ts +10 -10
  59. package/packages/components/departmentTree/src/departmentTree.vue +135 -135
  60. package/packages/components/dropdownButton/JaDropdownButton.vue +59 -59
  61. package/packages/components/dropdownButton/index.ts +4 -4
  62. package/packages/components/enumList/EnumListInput.vue +107 -107
  63. package/packages/components/enumList/JaEnumList.vue +39 -39
  64. package/packages/components/enumList/index.ts +7 -7
  65. package/packages/components/enumPicker/index.ts +5 -5
  66. package/packages/components/enumPicker/src/EnumPicker.vue +103 -103
  67. package/packages/components/form/JaForm.vue +186 -146
  68. package/packages/components/form/index.ts +5 -5
  69. package/packages/components/form/types.ts +4 -4
  70. package/packages/components/formItem/JaFormItem.vue +68 -87
  71. package/packages/components/formItem/index.ts +4 -4
  72. package/packages/components/index.ts +34 -34
  73. package/packages/components/input/JaInput.vue +143 -143
  74. package/packages/components/input/index.ts +4 -4
  75. package/packages/components/inputI18n/I18nBundleEditor.vue +76 -76
  76. package/packages/components/inputI18n/InputI18n.vue +146 -146
  77. package/packages/components/inputI18n/JaInputI18n.vue +50 -50
  78. package/packages/components/inputI18n/index.ts +8 -8
  79. package/packages/components/inputNumber/JaInputNumber.vue +98 -98
  80. package/packages/components/inputNumber/index.ts +4 -4
  81. package/packages/components/mapItemList/JaMapItemList.vue +35 -35
  82. package/packages/components/mapItemList/MapItemListInput.vue +191 -191
  83. package/packages/components/mapItemList/index.ts +7 -7
  84. package/packages/components/numberList/JaNumberList.vue +36 -36
  85. package/packages/components/numberList/NumberListInput.vue +111 -111
  86. package/packages/components/numberList/index.ts +7 -7
  87. package/packages/components/properyPicker/JaPropertyPicker.vue +38 -38
  88. package/packages/components/properyPicker/PropertyPicker.vue +314 -314
  89. package/packages/components/properyPicker/index.ts +7 -7
  90. package/packages/components/radioGroup/JaRadioGroup.vue +50 -50
  91. package/packages/components/radioGroup/index.ts +4 -4
  92. package/packages/components/rolePicker/RoleEditor.vue +129 -129
  93. package/packages/components/rolePicker/RolePicker.vue +44 -44
  94. package/packages/components/rolePicker/RolePickerRaw.vue +56 -56
  95. package/packages/components/rolePicker/baseRolePicker.vue +87 -87
  96. package/packages/components/rolePicker/index.ts +10 -10
  97. package/packages/components/scrollbar/Scrollbar.vue +89 -89
  98. package/packages/components/scrollbar/index.ts +5 -5
  99. package/packages/components/scrollbar/utils.ts +17 -17
  100. package/packages/components/select/JaSelect.vue +48 -48
  101. package/packages/components/select/index.ts +4 -4
  102. package/packages/components/stringList/JaStringList.vue +36 -36
  103. package/packages/components/stringList/StringListInput.vue +96 -96
  104. package/packages/components/stringList/index.ts +7 -7
  105. package/packages/components/switch/JaSwitch.vue +50 -50
  106. package/packages/components/switch/index.ts +4 -4
  107. package/packages/components/timePicker/JaTimePicker.vue +52 -52
  108. package/packages/components/timePicker/index.ts +5 -5
  109. package/packages/components/tip/index.ts +4 -4
  110. package/packages/components/tip/src/AceTip.vue +43 -43
  111. package/packages/components/upload/index.ts +6 -6
  112. package/packages/components/upload/src/Upload.vue +25 -25
  113. package/packages/components/upload/src/type.ts +3 -3
  114. package/packages/components/userGroupPicker/index.ts +4 -4
  115. package/packages/components/userGroupPicker/src/UserGroupPicker.vue +94 -94
  116. package/packages/components/userGroupTree/index.ts +10 -10
  117. package/packages/components/userGroupTree/src/userGroupTree.vue +149 -149
  118. package/packages/components/userPicker/index.ts +10 -10
  119. package/packages/components/userPicker/src/CustomGroupManager.vue +189 -189
  120. package/packages/components/userPicker/src/JaUserList.vue +283 -283
  121. package/packages/components/userPicker/src/JaUserPicker.vue +37 -37
  122. package/packages/components/userPicker/src/UserPicker.vue +376 -368
  123. package/packages/components/userSelectDialog/index.ts +6 -6
  124. package/packages/components/userSelectDialog/src/userSelectDialog.vue +462 -455
  125. package/packages/components/userTag/UserInfoTag.vue +397 -397
  126. package/packages/components/userTag/index.ts +6 -6
  127. package/packages/components/userTag/sharedAxios.ts +8 -8
  128. package/packages/directives/auth/index.ts +41 -41
  129. package/packages/directives/autofocus/index.ts +29 -29
  130. package/packages/directives/index.ts +10 -10
  131. package/packages/directives/shortcut/index.ts +192 -192
  132. package/packages/hooks/useAppInstances.ts +34 -34
  133. package/packages/hooks/useBackendValidations.ts +81 -81
  134. package/packages/hooks/useBridage.ts +157 -157
  135. package/packages/hooks/useClassificationLevels.ts +62 -0
  136. package/packages/hooks/useDateTimeShortCuts.ts +65 -65
  137. package/packages/hooks/useRealms.ts +28 -28
  138. package/packages/hooks/useTreeData.ts +45 -45
  139. package/packages/hooks/useUserRefQuery.ts +232 -224
  140. package/packages/index.ts +21 -22
  141. package/packages/list.json +7 -7
  142. package/packages/types/custom.d.ts +13 -13
  143. package/packages/types/window.d.ts +16 -16
  144. package/packages/utils/install.ts +43 -43
  145. package/packages/utils/objectUtils.ts +31 -31
  146. package/theme-style/fonts/iconfont.json +5196 -5196
  147. package/theme-style/index.scss +10 -10
  148. package/theme-style/styles/element-plus-var.scss +1419 -1419
  149. package/theme-style/styles/iconfont.css +2979 -2979
  150. package/theme-style/styles/theme-var.scss +72 -72
  151. package/theme-style/styles/transition.scss +122 -122
  152. package/dist/utils/formUtils.d.ts +0 -7
  153. package/dist/utils/formUtils.d.ts.map +0 -1
  154. package/dist/utils/formUtils.js +0 -54
  155. package/dist/utils/formUtils.js.map +0 -1
  156. package/packages/utils/formUtils.ts +0 -57
@@ -1,39 +1,39 @@
1
- <script setup lang="ts">
2
- import {inject, watch, ref} from "vue";
3
- import {getValue, setValue} from "../../utils/objectUtils";
4
- import type {ValidationInstance} from "../../hooks/useBackendValidations";
5
- import EnumListInput from "./EnumListInput.vue";
6
-
7
- const model = inject('aceFormModel') as Record<string, never>
8
- const prop = inject('aceFormItemProp') as string
9
- const validator = inject('aceFormValidator') as ValidationInstance
10
- const emit = defineEmits<{
11
- change: [value: string[]]
12
- }>()
13
-
14
- const props = defineProps<{ enumValues: Record<string, string> }>()
15
-
16
- function onChange(value: string[]) {
17
- validator.removeFieldError(prop)
18
- setValue(model.formData, prop, mv.value);
19
- emit('change', value)
20
- }
21
-
22
- const mv = ref(getValue(model.formData, prop) as string[] ?? [""]);
23
- watch(() => model.formData, () => {
24
- mv.value = getValue(model.formData, prop) as string[] ?? [""]
25
- }, {
26
- deep: true
27
- })
28
- </script>
29
-
30
- <template>
31
- <enum-list-input v-model="mv"
32
- :enum-values="enumValues"
33
- @change="onChange"
34
- v-bind="$attrs"/>
35
- </template>
36
-
37
- <style scoped lang="scss">
38
-
39
- </style>
1
+ <script setup lang="ts">
2
+ import {inject, watch, ref} from "vue";
3
+ import {getValue, setValue} from "../../utils/objectUtils";
4
+ import type {ValidationInstance} from "../../hooks/useBackendValidations";
5
+ import EnumListInput from "./EnumListInput.vue";
6
+
7
+ const model = inject('aceFormModel') as Record<string, never>
8
+ const prop = inject('aceFormItemProp') as string
9
+ const validator = inject('aceFormValidator') as ValidationInstance
10
+ const emit = defineEmits<{
11
+ change: [value: string[]]
12
+ }>()
13
+
14
+ const props = defineProps<{ enumValues: Record<string, string> }>()
15
+
16
+ function onChange(value: string[]) {
17
+ validator.removeFieldError(prop)
18
+ setValue(model.formData, prop, mv.value);
19
+ emit('change', value)
20
+ }
21
+
22
+ const mv = ref(getValue(model.formData, prop) as string[] ?? [""]);
23
+ watch(() => model.formData, () => {
24
+ mv.value = getValue(model.formData, prop) as string[] ?? [""]
25
+ }, {
26
+ deep: true
27
+ })
28
+ </script>
29
+
30
+ <template>
31
+ <enum-list-input v-model="mv"
32
+ :enum-values="enumValues"
33
+ @change="onChange"
34
+ v-bind="$attrs"/>
35
+ </template>
36
+
37
+ <style scoped lang="scss">
38
+
39
+ </style>
@@ -1,7 +1,7 @@
1
- import {type SFCWithInstall, withInstall} from "../../utils/install";
2
- import EnumList from "./JaEnumList.vue";
3
- import EnumListInput from "./EnumListInput.vue";
4
-
5
- export const JaEnumList: SFCWithInstall<typeof EnumList> = withInstall(EnumList);
6
-
7
- export const JaEnumListRaw: SFCWithInstall<typeof EnumListInput> = withInstall(EnumListInput);
1
+ import {type SFCWithInstall, withInstall} from "../../utils/install";
2
+ import EnumList from "./JaEnumList.vue";
3
+ import EnumListInput from "./EnumListInput.vue";
4
+
5
+ export const JaEnumList: SFCWithInstall<typeof EnumList> = withInstall(EnumList);
6
+
7
+ export const JaEnumListRaw: SFCWithInstall<typeof EnumListInput> = withInstall(EnumListInput);
@@ -1,5 +1,5 @@
1
-
2
- import {type SFCWithInstall, withInstall} from "../../utils/install";
3
- import EnumPicker from "./src/EnumPicker.vue";
4
-
5
- export const JaEnumPicker: SFCWithInstall<typeof EnumPicker> = withInstall(EnumPicker);
1
+
2
+ import {type SFCWithInstall, withInstall} from "../../utils/install";
3
+ import EnumPicker from "./src/EnumPicker.vue";
4
+
5
+ export const JaEnumPicker: SFCWithInstall<typeof EnumPicker> = withInstall(EnumPicker);
@@ -1,103 +1,103 @@
1
- <script setup lang="ts">
2
- import type { EnumValueDefinition } from '@jari-ace/app-bolts';
3
-
4
- import { computed, ref, watch } from 'vue';
5
-
6
- import { createAxiosWithoutCache } from '@jari-ace/app-bolts';
7
- import { useEnumApi } from '@jari-ace/app-bolts';
8
- import { ElOption, ElSelect } from 'element-plus';
9
- // 遍历出EnumValueDefinition类型的KEY 并排除掉
10
- type KeyFields = 'id' | 'text' | 'value';
11
-
12
- interface ModelValue {
13
- value?: string;
14
- text?: string;
15
- id?: string;
16
- }
17
- const props = withDefaults(
18
- defineProps<{
19
- clearable?: boolean; // 是否可清空
20
- filterable?: boolean; // 是否可筛选
21
- keyField?: KeyFields;
22
- multiple?: boolean; // 是否多选
23
- name: string; // 枚举名称,用于获取枚举数据
24
- serviceName: string;
25
- }>(),
26
- {
27
- multiple: false,
28
- clearable: true,
29
- filterable: true,
30
- keyField: 'value',
31
- },
32
- );
33
-
34
- const enums = ref<EnumValueDefinition[]>([]);
35
- const loading = ref<boolean>(false);
36
- const model = defineModel<ModelValue[]>({
37
- default: () => [],
38
- });
39
-
40
- const axios = createAxiosWithoutCache();
41
- const api = useEnumApi(axios);
42
- async function loadData() {
43
- if (!props.name || !props.serviceName) return;
44
- loading.value = true;
45
- api
46
- .queryByName(props.serviceName, props.name)
47
- .then((res) => {
48
- enums.value = res.values;
49
- })
50
- .finally(() => {
51
- loading.value = false;
52
- });
53
- }
54
-
55
- const modelValue = computed((): string | string[] | undefined => {
56
- if (props.multiple) {
57
- return model.value.map((m) => m[props.keyField] as string) || [];
58
- } else {
59
- if (model.value[0] !== undefined) {
60
- return model.value[0][props.keyField];
61
- }
62
- }
63
- return '';
64
- });
65
-
66
- const handleChange = (value: string | string[]) => {
67
- if (typeof value === 'string') {
68
- const obj = enums.value.find((e) => e[props.keyField] === value);
69
- model.value = obj ? [obj] : [];
70
- } else {
71
- model.value = enums.value.filter((e) => value.includes(e[props.keyField]));
72
- }
73
- };
74
-
75
- // function filter(queryName: string) {
76
- // bindingChannels.value = channels.value?.filter(c => c.name.indexOf(queryName) > -1) ?? [];
77
- // }
78
-
79
- loadData();
80
-
81
- watch(() => props.name, loadData);
82
- watch(() => props.serviceName, loadData);
83
- </script>
84
-
85
- <template>
86
- <ElSelect
87
- v-loading="loading"
88
- :model-value="modelValue"
89
- :filterable="props.filterable"
90
- :multiple="props.multiple"
91
- :clearable="props.clearable"
92
- @change="handleChange"
93
- >
94
- <ElOption
95
- v-for="item in enums"
96
- :key="item.id"
97
- :value="item[props.keyField]"
98
- :label="item.text"
99
- />
100
- </ElSelect>
101
- </template>
102
-
103
- <style scoped lang="scss"></style>
1
+ <script setup lang="ts">
2
+ import type { EnumValueDefinition } from '@jari-ace/app-bolts';
3
+
4
+ import { computed, ref, watch } from 'vue';
5
+
6
+ import { createAxiosWithoutCache } from '@jari-ace/app-bolts';
7
+ import { useEnumApi } from '@jari-ace/app-bolts';
8
+ import { ElOption, ElSelect } from 'element-plus';
9
+ // 遍历出EnumValueDefinition类型的KEY 并排除掉
10
+ type KeyFields = 'id' | 'text' | 'value';
11
+
12
+ interface ModelValue {
13
+ value?: string;
14
+ text?: string;
15
+ id?: string;
16
+ }
17
+ const props = withDefaults(
18
+ defineProps<{
19
+ clearable?: boolean; // 是否可清空
20
+ filterable?: boolean; // 是否可筛选
21
+ keyField?: KeyFields;
22
+ multiple?: boolean; // 是否多选
23
+ name: string; // 枚举名称,用于获取枚举数据
24
+ serviceName: string;
25
+ }>(),
26
+ {
27
+ multiple: false,
28
+ clearable: true,
29
+ filterable: true,
30
+ keyField: 'value',
31
+ },
32
+ );
33
+
34
+ const enums = ref<EnumValueDefinition[]>([]);
35
+ const loading = ref<boolean>(false);
36
+ const model = defineModel<ModelValue[]>({
37
+ default: () => [],
38
+ });
39
+
40
+ const axios = createAxiosWithoutCache();
41
+ const api = useEnumApi(axios);
42
+ async function loadData() {
43
+ if (!props.name || !props.serviceName) return;
44
+ loading.value = true;
45
+ api
46
+ .queryByName(props.serviceName, props.name)
47
+ .then((res) => {
48
+ enums.value = res.values;
49
+ })
50
+ .finally(() => {
51
+ loading.value = false;
52
+ });
53
+ }
54
+
55
+ const modelValue = computed((): string | string[] | undefined => {
56
+ if (props.multiple) {
57
+ return model.value.map((m) => m[props.keyField] as string) || [];
58
+ } else {
59
+ if (model.value[0] !== undefined) {
60
+ return model.value[0][props.keyField];
61
+ }
62
+ }
63
+ return '';
64
+ });
65
+
66
+ const handleChange = (value: string | string[]) => {
67
+ if (typeof value === 'string') {
68
+ const obj = enums.value.find((e) => e[props.keyField] === value);
69
+ model.value = obj ? [obj] : [];
70
+ } else {
71
+ model.value = enums.value.filter((e) => value.includes(e[props.keyField]));
72
+ }
73
+ };
74
+
75
+ // function filter(queryName: string) {
76
+ // bindingChannels.value = channels.value?.filter(c => c.name.indexOf(queryName) > -1) ?? [];
77
+ // }
78
+
79
+ loadData();
80
+
81
+ watch(() => props.name, loadData);
82
+ watch(() => props.serviceName, loadData);
83
+ </script>
84
+
85
+ <template>
86
+ <ElSelect
87
+ v-loading="loading"
88
+ :model-value="modelValue"
89
+ :filterable="props.filterable"
90
+ :multiple="props.multiple"
91
+ :clearable="props.clearable"
92
+ @change="handleChange"
93
+ >
94
+ <ElOption
95
+ v-for="item in enums"
96
+ :key="item.id"
97
+ :value="item[props.keyField]"
98
+ :label="item.text"
99
+ />
100
+ </ElSelect>
101
+ </template>
102
+
103
+ <style scoped lang="scss"></style>
@@ -1,146 +1,186 @@
1
- <script setup lang="ts">
2
- import {type PropType, provide, ref, computed, watch} from "vue";
3
- import {ElForm, type FormInstance, type FormRules} from "element-plus";
4
- import {type ValidationInstance} from "../../hooks/useBackendValidations";
5
- import type {JaFormModel} from "./types";
6
- import {mergeRules} from '../../utils/formUtils'
7
- interface Props {
8
- model: JaFormModel,
9
- inline?:boolean,
10
- labelPosition?: "left" | "top" | "right",
11
- labelWidth?: string | number,
12
- labelSuffix?: string,
13
- hideRequiredAsterisk?: boolean,
14
- showMessage?: boolean,
15
- inlineMessage?: boolean,
16
- statusIcon?: boolean,
17
- validateOnRuleChange?: boolean,
18
- rules?: FormRules,
19
- size?: "small" | "default" | "large",
20
- disabled?: boolean,
21
- scrollToError?: boolean,
22
- validator: ValidationInstance,
23
- requiredPosition?: 'left' | 'right'
24
- }
25
-
26
- const formRef = ref<FormInstance | undefined>(undefined);
27
-
28
-
29
- const props = withDefaults(defineProps<Props>(),{
30
- inline:false,
31
- labelPosition:'top',
32
- hideRequiredAsterisk:true,
33
- showMessage:true,
34
- inlineMessage:true,
35
- statusIcon:false,
36
- validateOnRuleChange:true,
37
- size:'small',
38
- scrollToError:true,
39
- requiredPosition:'right',
40
- })
41
-
42
-
43
-
44
-
45
-
46
- defineEmits(["validate", "click"]);
47
- provide("aceFormValidator", props.validator);
48
- provide("aceFormModel", props.model);
49
- provide("aceFormSize", props.size);
50
- provide("aceFormRequiredPosition", props.requiredPosition);
51
- const rules = ref<FormRules>({})
52
-
53
- const model = computed(() => {
54
- return props.model.formData?props.model.formData:props.model;
55
- });
56
-
57
-
58
-
59
- defineExpose({
60
- elForm: formRef,
61
- getElForm:():FormInstance|undefined=>formRef.value,
62
- validate:async (submit: () => Promise<any>, onFail?: () => void) => {
63
- if(!formRef)return;
64
- //先清空之前的校验
65
- formRef.value.clearValidate();
66
- //判断是否有传入rules如果有则先执行 formRef.value!.validate()
67
- if(props.rules && Object.keys(props.rules).length>0){
68
- await formRef.value.validate((valid,fields)=>{
69
- //判断校验是否成功
70
- if(valid){
71
- //前端校验已成功,执行异步submit
72
- submit()
73
- .then(() => {
74
- //成功
75
- //校验通过清楚所有的错误校验信息
76
- props.validator?.clearFiledErrors();
77
- })
78
- .catch(() => {
79
- //失败
80
- //合并rules
81
- rules.value = mergeRules(props.rules, props.validator.rules);
82
- formRef.value.validate();
83
- if (onFail) onFail();
84
- });
85
- }else{
86
- console.log('error submit!',fields)
87
- }
88
- })
89
- }else{
90
- submit()
91
- .then(() => {
92
- props.validator?.clearFiledErrors();
93
- })
94
- .catch(async () => {
95
- //失败
96
- //合并rules
97
- rules.value = mergeRules(props.rules, props.validator.rules);
98
- await formRef.value.validate();
99
- if (onFail) onFail();
100
- });
101
- }
102
-
103
-
104
-
105
- },
106
- getRules: () => rules.value,
107
- });
108
-
109
-
110
- watch(() => props.model.formData, () => {
111
- props.validator?.clearFiledErrors();
112
- })
113
-
114
- watch(() => props.rules, () => {
115
- //合并rules
116
- rules.value = mergeRules(props.rules, props.validator.rules);
117
- }, { immediate: true })
118
-
119
-
120
- </script>
121
-
122
- <template>
123
- <el-form
124
- ref="formRef"
125
- :model="model"
126
- :rules="rules"
127
- :inline="inline"
128
- :label-position="labelPosition"
129
- :label-width="labelWidth"
130
- :label-suffix="labelSuffix"
131
- :hide-required-asterisk="hideRequiredAsterisk"
132
- :show-message="showMessage"
133
- :inline-message="inlineMessage"
134
- :status-icon="statusIcon"
135
- :validate-on-rule-change="validateOnRuleChange"
136
- :size="size"
137
- :disabled="disabled"
138
- :scroll-to-error="scrollToError"
139
- @validate="(prop, isValid, message) => $emit('validate', prop, isValid,message)"
140
- @click="() => $emit('click')"
141
- >
142
- <slot></slot>
143
- </el-form>
144
- </template>
145
-
146
- <style scoped lang="scss"></style>
1
+ <script setup lang="ts">
2
+ import {type PropType, provide, ref, computed, watch} from "vue";
3
+ import {ElForm, type FormInstance, type FormRules} from "element-plus";
4
+ import {type ValidationInstance} from "../../hooks/useBackendValidations";
5
+ import type {JaFormModel} from "./types";
6
+
7
+ interface Props {
8
+ model: JaFormModel,
9
+ inline?:boolean,
10
+ labelPosition?: "left" | "top" | "right",
11
+ labelWidth?: string | number,
12
+ labelSuffix?: string,
13
+ hideRequiredAsterisk?: boolean,
14
+ showMessage?: boolean,
15
+ inlineMessage?: boolean,
16
+ statusIcon?: boolean,
17
+ validateOnRuleChange?: boolean,
18
+ rules?: FormRules,
19
+ size?: "small" | "default" | "large",
20
+ disabled?: boolean,
21
+ scrollToError?: boolean,
22
+ validator: ValidationInstance,
23
+ }
24
+
25
+ const formRef = ref<FormInstance | undefined>(undefined);
26
+
27
+
28
+ const props = withDefaults(defineProps<Props>(),{
29
+ inline:false,
30
+ labelPosition:'top',
31
+ hideRequiredAsterisk:true,
32
+ showMessage:true,
33
+ inlineMessage:true,
34
+ statusIcon:false,
35
+ validateOnRuleChange:true,
36
+ size:'small',
37
+ scrollToError:true,
38
+
39
+ })
40
+
41
+ // const props = defineProps({
42
+ // model: {
43
+ // type: Object as PropType<JaFormModel>,
44
+ // required: true,
45
+ // },
46
+ // inline: {
47
+ // type: Boolean,
48
+ // default: false,
49
+ // },
50
+ // labelPosition: {
51
+ // type: String as PropType<"left" | "top" | "right">,
52
+ // default: "top",
53
+ // },
54
+ // labelWidth: {
55
+ // type: [String, Number],
56
+ // },
57
+ // labelSuffix: {
58
+ // type: String,
59
+ // },
60
+ // hideRequiredAsterisk: {
61
+ // type: Boolean,
62
+ // default: false,
63
+ // },
64
+ // showMessage: {
65
+ // type: Boolean,
66
+ // default: true,
67
+ // },
68
+ // inlineMessage: {
69
+ // type: Boolean,
70
+ // default: true,
71
+ // },
72
+ // statusIcon: {
73
+ // type: Boolean,
74
+ // default: false,
75
+ // },
76
+ // validateOnRuleChange: {
77
+ // type: Boolean,
78
+ // default: true,
79
+ // },
80
+ // rules: {
81
+ // type: Object as PropType<FormRules>,
82
+ // default: {},
83
+ // },
84
+ // size: {
85
+ // type: String as PropType<"small" | "default" | "large">,
86
+ // default: "small",
87
+ // },
88
+ // disabled: {
89
+ // type: Boolean,
90
+ // default: false,
91
+ // },
92
+ // scrollToError: {
93
+ // type: Boolean,
94
+ // default: true,
95
+ // },
96
+ // validator: {
97
+ // type: Object as PropType<ValidationInstance>,
98
+ // required: true,
99
+ // },
100
+ // });
101
+
102
+ defineEmits(["validate", "click"]);
103
+ provide("aceFormValidator", props.validator);
104
+ provide("aceFormModel", props.model);
105
+ provide("aceFormSize", props.size);
106
+
107
+ const rules = computed<FormRules>(() => {
108
+ return {
109
+ ...props.rules,
110
+ ...props.validator.rules,
111
+ };
112
+ });
113
+
114
+ defineExpose({
115
+ elForm: formRef,
116
+ getElForm:():FormInstance|undefined=>formRef.value,
117
+ validate:async (submit: () => Promise<any>, onFail?: () => void) => {
118
+ if(!formRef)return;
119
+ //先清空之前的校验
120
+ formRef.value.clearValidate();
121
+ //判断是否有传入rules如果有则先执行 formRef.value!.validate()
122
+ if(props.rules){
123
+ await formRef.value.validate((valid,fields)=>{
124
+ //判断校验是否成功
125
+ if(valid){
126
+ //前端校验已成功,执行异步submit
127
+ submit()
128
+ .then(() => {
129
+ //校验通过清楚所有的错误校验信息
130
+ props.validator?.clearFiledErrors();
131
+ })
132
+ .catch(() => {
133
+ //失败
134
+ formRef.value.validate();
135
+ if (onFail) onFail();
136
+ });
137
+ }else{
138
+ console.log('error submit!',fields)
139
+ }
140
+ })
141
+ }else{
142
+ submit()
143
+ .then(() => {
144
+ props.validator?.clearFiledErrors();
145
+ })
146
+ .catch(async () => {
147
+ await formRef.value.validate();
148
+ if (onFail) onFail();
149
+ });
150
+ }
151
+
152
+
153
+
154
+ },
155
+ });
156
+
157
+ watch(() => props.model.formData, () => {
158
+ props.validator?.clearFiledErrors();
159
+ })
160
+ </script>
161
+
162
+ <template>
163
+ <el-form
164
+ ref="formRef"
165
+ :model="model.formData"
166
+ :rules="rules"
167
+ :inline="inline"
168
+ :label-position="labelPosition"
169
+ :label-width="labelWidth"
170
+ :label-suffix="labelSuffix"
171
+ :hide-required-asterisk="hideRequiredAsterisk"
172
+ :show-message="showMessage"
173
+ :inline-message="inlineMessage"
174
+ :status-icon="statusIcon"
175
+ :validate-on-rule-change="validateOnRuleChange"
176
+ :size="size"
177
+ :disabled="disabled"
178
+ :scroll-to-error="scrollToError"
179
+ @validate="(prop, isValid, message) => $emit('validate', prop, isValid,message)"
180
+ @click="() => $emit('click')"
181
+ >
182
+ <slot></slot>
183
+ </el-form>
184
+ </template>
185
+
186
+ <style scoped lang="scss"></style>
@@ -1,5 +1,5 @@
1
- import {withInstall, type SFCWithInstall} from "../../utils/install";
2
- import Form from "./JaForm.vue";
3
- export const JaForm: SFCWithInstall<typeof Form> = withInstall(Form);
4
- export * from "./types"
5
- export default Form;
1
+ import {withInstall, type SFCWithInstall} from "../../utils/install";
2
+ import Form from "./JaForm.vue";
3
+ export const JaForm: SFCWithInstall<typeof Form> = withInstall(Form);
4
+ export * from "./types"
5
+ export default Form;