@jari-ace/element-plus-component 0.1.1 → 0.1.6

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 (39) hide show
  1. package/dist/components/enumPicker/index.d.ts +4 -0
  2. package/dist/components/enumPicker/index.d.ts.map +1 -0
  3. package/dist/components/enumPicker/index.js +4 -0
  4. package/dist/components/enumPicker/index.js.map +1 -0
  5. package/dist/components/enumPicker/src/EnumPicker.vue.d.ts +29 -0
  6. package/dist/components/enumPicker/src/EnumPicker.vue.d.ts.map +1 -0
  7. package/dist/components/enumPicker/src/EnumPicker.vue.js +140 -0
  8. package/dist/components/enumPicker/src/EnumPicker.vue.js.map +1 -0
  9. package/dist/components/form/JaForm.vue.d.ts +23 -126
  10. package/dist/components/form/JaForm.vue.d.ts.map +1 -1
  11. package/dist/components/form/JaForm.vue.js +127 -192
  12. package/dist/components/form/JaForm.vue.js.map +1 -1
  13. package/dist/components/formItem/JaFormItem.vue.d.ts +12 -12
  14. package/dist/components/index.d.ts +1 -0
  15. package/dist/components/index.d.ts.map +1 -1
  16. package/dist/components/index.js +1 -0
  17. package/dist/components/index.js.map +1 -1
  18. package/dist/components/rolePicker/baseRolePicker.vue.d.ts.map +1 -1
  19. package/dist/components/rolePicker/baseRolePicker.vue.js +1 -0
  20. package/dist/components/rolePicker/baseRolePicker.vue.js.map +1 -1
  21. package/dist/components/tip/index.d.ts +35 -1
  22. package/dist/components/tip/index.d.ts.map +1 -1
  23. package/dist/components/upload/index.d.ts +1 -1
  24. package/dist/components/upload/index.d.ts.map +1 -1
  25. package/dist/components/userTag/UserInfoTag.vue.d.ts +1 -1
  26. package/dist/hooks/useBackendValidations.d.ts +7 -1
  27. package/dist/hooks/useBackendValidations.d.ts.map +1 -1
  28. package/dist/hooks/useBackendValidations.js +21 -2
  29. package/dist/hooks/useBackendValidations.js.map +1 -1
  30. package/dist/hooks/useUserRefQuery.d.ts +2 -2
  31. package/lib/index.js +1422 -1272
  32. package/lib/index.umd.cjs +2 -2
  33. package/package.json +1 -1
  34. package/packages/components/enumPicker/index.ts +5 -0
  35. package/packages/components/enumPicker/src/EnumPicker.vue +103 -0
  36. package/packages/components/form/JaForm.vue +131 -71
  37. package/packages/components/index.ts +1 -0
  38. package/packages/components/rolePicker/baseRolePicker.vue +1 -0
  39. package/packages/hooks/useBackendValidations.ts +81 -55
@@ -0,0 +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/src/api/domainModel/enum';
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>
@@ -4,68 +4,100 @@ import {ElForm, type FormInstance, type FormRules} from "element-plus";
4
4
  import {type ValidationInstance} from "../../hooks/useBackendValidations";
5
5
  import type {JaFormModel} from "./types";
6
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
+
7
25
  const formRef = ref<FormInstance | undefined>(undefined);
8
26
 
9
- const props = defineProps({
10
- model: {
11
- type: Object as PropType<JaFormModel>,
12
- required: true,
13
- },
14
- inline: {
15
- type: Boolean,
16
- default: false,
17
- },
18
- labelPosition: {
19
- type: String as PropType<"left" | "top" | "right">,
20
- default: "top",
21
- },
22
- labelWidth: {
23
- type: [String, Number],
24
- },
25
- labelSuffix: {
26
- type: String,
27
- },
28
- hideRequiredAsterisk: {
29
- type: Boolean,
30
- default: false,
31
- },
32
- showMessage: {
33
- type: Boolean,
34
- default: true,
35
- },
36
- inlineMessage: {
37
- type: Boolean,
38
- default: true,
39
- },
40
- statusIcon: {
41
- type: Boolean,
42
- default: false,
43
- },
44
- validateOnRuleChange: {
45
- type: Boolean,
46
- default: true,
47
- },
48
- rules: {
49
- type: Object as PropType<FormRules>,
50
- default: {},
51
- },
52
- size: {
53
- type: String as PropType<"small" | "default" | "large">,
54
- default: "small",
55
- },
56
- disabled: {
57
- type: Boolean,
58
- default: false,
59
- },
60
- scrollToError: {
61
- type: Boolean,
62
- default: true,
63
- },
64
- validator: {
65
- type: Object as PropType<ValidationInstance>,
66
- required: true,
67
- },
68
- });
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
+ // });
69
101
 
70
102
  defineEmits(["validate", "click"]);
71
103
  provide("aceFormValidator", props.validator);
@@ -81,16 +113,44 @@ const rules = computed<FormRules>(() => {
81
113
 
82
114
  defineExpose({
83
115
  elForm: formRef,
84
- validate: (submit: () => Promise<any>, onFail?: () => void) => {
85
- formRef.value!.clearValidate();
86
- return submit()
87
- .then(() => {
88
- props.validator?.clearFiledErrors();
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
+ }
89
140
  })
90
- .catch(() => {
91
- formRef.value!.validate();
92
- if (onFail) onFail();
93
- });
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
+
94
154
  },
95
155
  });
96
156
 
@@ -102,7 +162,7 @@ watch(() => props.model.formData, () => {
102
162
  <template>
103
163
  <el-form
104
164
  ref="formRef"
105
- :model="model"
165
+ :model="model.formData"
106
166
  :rules="rules"
107
167
  :inline="inline"
108
168
  :label-position="labelPosition"
@@ -116,7 +176,7 @@ watch(() => props.model.formData, () => {
116
176
  :size="size"
117
177
  :disabled="disabled"
118
178
  :scroll-to-error="scrollToError"
119
- @validate="(prop, isValid, message) => $emit('validate', prop, isValid)"
179
+ @validate="(prop, isValid, message) => $emit('validate', prop, isValid,message)"
120
180
  @click="() => $emit('click')"
121
181
  >
122
182
  <slot></slot>
@@ -31,3 +31,4 @@ export * from "./channelPicker"
31
31
  export * from "./properyPicker"
32
32
  export * from "./inputI18n"
33
33
  export * from "./checkboxGroup"
34
+ export * from "./enumPicker"
@@ -22,6 +22,7 @@ const loadData = async () => {
22
22
  if (!props.appName) return;
23
23
  currentApp.value = await appApi.getByName(props.appName);
24
24
  roles.value = await api.getAllRole(currentApp.value.id);
25
+ console.log(roles.value)
25
26
  if (selectedRoleName.value) {
26
27
  currentRole.value = findRole(selectedRoleName.value, roles.value);
27
28
  } else {
@@ -1,55 +1,81 @@
1
- import type {FormRules} from "element-plus";
2
- import type {IAceAxios, ValidationError} from "@jari-ace/app-bolts";
3
- import {createAxiosWithoutCache} from "@jari-ace/app-bolts";
4
- import {reactive} from "vue";
5
-
6
- export type ValidationInstance = {
7
- axios: IAceAxios;
8
- rules: FormRules;
9
- removeFieldError: (prop: string) => void;
10
- clearFiledErrors: () => void;
11
- };
12
-
13
- export function useBackendValidations<T>(props: string[], axios?: IAceAxios): ValidationInstance {
14
- const rules = reactive<FormRules>({});
15
- let errors: ValidationError[] = [];
16
- if (!axios) axios = createAxiosWithoutCache();
17
- axios!.setDefaultRequestConfig({
18
- validationErrorProcessor: (errs) => {
19
- errors = errs;
20
- },
21
- });
22
-
23
- for (const p of props) {
24
- rules[p] = {
25
- trigger: "blur",
26
- validator: (rule: any, value: any, callback: any) => {
27
- if (!errors) return;
28
- let hasErr = false;
29
- for (const err of errors) {
30
- let fn = err.fieldName;
31
- if (fn?.endsWith("[]")) {
32
- fn = fn.substring(0, fn.length - 2);
33
- }
34
- if (fn === p) {
35
- hasErr = true
36
- callback(new Error(err.message));
37
- }
38
- }
39
- if (!hasErr) callback();
40
- },
41
- };
42
- }
43
- const removeFieldError = (prop: string) => {
44
- errors = errors.filter((err) => err.fieldName !== prop);
45
- };
46
- const clearFiledErrors = () => {
47
- errors = []
48
- };
49
- return {
50
- removeFieldError,
51
- clearFiledErrors,
52
- axios,
53
- rules,
54
- };
55
- }
1
+ import type { FormRules ,FormItemRule} from "element-plus";
2
+ import type { IAceAxios, ValidationError } from "@jari-ace/app-bolts";
3
+ import { createAxiosWithoutCache } from "@jari-ace/app-bolts";
4
+ import { reactive } from "vue";
5
+
6
+ export type ValidationInstance = {
7
+ axios: IAceAxios;
8
+ rules: FormRules;
9
+ removeFieldError: (prop: string) => void;
10
+ clearFiledErrors: () => void;
11
+ };
12
+
13
+ /**
14
+ * 后端校验
15
+ * @param props
16
+ * @param axios
17
+ * @param customRules
18
+ */
19
+ export function useBackendValidations(
20
+ props: string[],
21
+ axios?: IAceAxios,
22
+ customRules?: FormRules,
23
+ ): ValidationInstance {
24
+ const rules = reactive<FormRules>({});
25
+ let errors: ValidationError[] = [];
26
+ if (!axios) axios = createAxiosWithoutCache();
27
+ axios!.setDefaultRequestConfig({
28
+ validationErrorProcessor: (errs) => {
29
+ errors = errs;
30
+ },
31
+ });
32
+
33
+ for (const p of props) {
34
+ // rules[p] = [
35
+ const rule = {
36
+ trigger: "blur",
37
+ validator: (rule: any, value: any, callback: any) => {
38
+ if (!errors) return;
39
+ let hasErr = false;
40
+ for (const err of errors) {
41
+ let fn = err.fieldName;
42
+ if (fn?.endsWith("[]")) {
43
+ fn = fn.substring(0, fn.length - 2);
44
+ }
45
+ if (fn === p) {
46
+ hasErr = true;
47
+ callback(new Error(err.message));
48
+ }
49
+ }
50
+ if (!hasErr) callback();
51
+ },
52
+ };
53
+
54
+ if (customRules&&customRules[p]) {
55
+ //合并数组customRules[p]
56
+ if (Array.isArray(customRules[p])) {
57
+ rules[p] = [rule,...customRules[p] as FormItemRule[]];
58
+ } else {
59
+ rules[p] = [rule, customRules[p] as FormItemRule];
60
+ }
61
+ }else{
62
+ rules[p] = rule
63
+ }
64
+
65
+
66
+ }
67
+ const removeFieldError = (prop: string) => {
68
+ errors = errors.filter((err) => err.fieldName !== prop);
69
+ };
70
+ const clearFiledErrors = () => {
71
+ errors = [];
72
+ };
73
+
74
+
75
+ return {
76
+ removeFieldError,
77
+ clearFiledErrors,
78
+ axios,
79
+ rules,
80
+ };
81
+ }