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

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 (51) hide show
  1. package/dist/components/form/JaForm.vue.d.ts +3 -0
  2. package/dist/components/form/JaForm.vue.d.ts.map +1 -1
  3. package/dist/components/form/JaForm.vue.js +22 -68
  4. package/dist/components/form/JaForm.vue.js.map +1 -1
  5. package/dist/components/formItem/JaFormItem.vue.d.ts +4 -0
  6. package/dist/components/formItem/JaFormItem.vue.d.ts.map +1 -1
  7. package/dist/components/formItem/JaFormItem.vue.js +26 -8
  8. package/dist/components/formItem/JaFormItem.vue.js.map +1 -1
  9. package/dist/components/inputI18n/InputI18n.vue.d.ts.map +1 -1
  10. package/dist/components/inputI18n/InputI18n.vue.js +2 -2
  11. package/dist/components/inputI18n/InputI18n.vue.js.map +1 -1
  12. package/dist/components/userPicker/src/UserPicker.vue.d.ts +0 -3
  13. package/dist/components/userPicker/src/UserPicker.vue.d.ts.map +1 -1
  14. package/dist/components/userPicker/src/UserPicker.vue.js +9 -7
  15. package/dist/components/userPicker/src/UserPicker.vue.js.map +1 -1
  16. package/dist/components/userSelectDialog/src/userSelectDialog.vue.d.ts +2 -5
  17. package/dist/components/userSelectDialog/src/userSelectDialog.vue.d.ts.map +1 -1
  18. package/dist/components/userSelectDialog/src/userSelectDialog.vue.js +14 -11
  19. package/dist/components/userSelectDialog/src/userSelectDialog.vue.js.map +1 -1
  20. package/dist/hooks/useBackendValidations.js +1 -0
  21. package/dist/hooks/useBackendValidations.js.map +1 -1
  22. package/dist/hooks/useRealms.d.ts +22 -0
  23. package/dist/hooks/useRealms.d.ts.map +1 -0
  24. package/dist/hooks/useRealms.js +25 -0
  25. package/dist/hooks/useRealms.js.map +1 -0
  26. package/dist/hooks/useUserRefQuery.d.ts.map +1 -1
  27. package/dist/hooks/useUserRefQuery.js +4 -2
  28. package/dist/hooks/useUserRefQuery.js.map +1 -1
  29. package/dist/index.d.ts +1 -0
  30. package/dist/index.d.ts.map +1 -1
  31. package/dist/index.js +1 -0
  32. package/dist/index.js.map +1 -1
  33. package/dist/utils/formUtils.d.ts +7 -0
  34. package/dist/utils/formUtils.d.ts.map +1 -0
  35. package/dist/utils/formUtils.js +54 -0
  36. package/dist/utils/formUtils.js.map +1 -0
  37. package/lib/index.css +1 -1
  38. package/lib/index.js +1697 -1648
  39. package/lib/index.umd.cjs +2 -2
  40. package/package.json +2 -2
  41. package/packages/components/enumPicker/src/EnumPicker.vue +103 -103
  42. package/packages/components/form/JaForm.vue +29 -69
  43. package/packages/components/formItem/JaFormItem.vue +35 -16
  44. package/packages/components/inputI18n/InputI18n.vue +6 -2
  45. package/packages/components/userPicker/src/UserPicker.vue +8 -6
  46. package/packages/components/userSelectDialog/src/userSelectDialog.vue +16 -8
  47. package/packages/hooks/useBackendValidations.ts +81 -81
  48. package/packages/hooks/useRealms.ts +28 -0
  49. package/packages/hooks/useUserRefQuery.ts +4 -2
  50. package/packages/index.ts +1 -0
  51. package/packages/utils/formUtils.ts +57 -0
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@jari-ace/element-plus-component",
3
3
  "private": false,
4
- "version": "0.1.8",
4
+ "version": "0.1.10",
5
5
  "main": "lib/index.umd.cjs",
6
6
  "module": "lib/index.js",
7
7
  "types": "dist/index.d.ts",
@@ -24,7 +24,7 @@
24
24
  "animate.css": "^4.1.1"
25
25
  },
26
26
  "devDependencies": {
27
- "@jari-ace/app-bolts": "0.3.6",
27
+ "@jari-ace/app-bolts": "catalog:",
28
28
  "@types/lodash-es": "^4.17.12",
29
29
  "@vitejs/plugin-vue": "^5.2.1",
30
30
  "@vitejs/plugin-vue-jsx": "^4.1.1",
@@ -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>
@@ -3,7 +3,7 @@ import {type PropType, provide, ref, computed, watch} from "vue";
3
3
  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
+ import {mergeRules} from '../../utils/formUtils'
7
7
  interface Props {
8
8
  model: JaFormModel,
9
9
  inline?:boolean,
@@ -20,6 +20,7 @@ interface Props {
20
20
  disabled?: boolean,
21
21
  scrollToError?: boolean,
22
22
  validator: ValidationInstance,
23
+ requiredPosition?: 'left' | 'right'
23
24
  }
24
25
 
25
26
  const formRef = ref<FormInstance | undefined>(undefined);
@@ -35,82 +36,26 @@ const props = withDefaults(defineProps<Props>(),{
35
36
  validateOnRuleChange:true,
36
37
  size:'small',
37
38
  scrollToError:true,
38
-
39
+ requiredPosition:'right',
39
40
  })
40
41
 
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
- // });
42
+
43
+
44
+
101
45
 
102
46
  defineEmits(["validate", "click"]);
103
47
  provide("aceFormValidator", props.validator);
104
48
  provide("aceFormModel", props.model);
105
49
  provide("aceFormSize", props.size);
50
+ provide("aceFormRequiredPosition", props.requiredPosition);
51
+ const rules = ref<FormRules>({})
106
52
 
107
- const rules = computed<FormRules>(() => {
108
- return {
109
- ...props.rules,
110
- ...props.validator.rules,
111
- };
53
+ const model = computed(() => {
54
+ return props.model.formData?props.model.formData:props.model;
112
55
  });
113
56
 
57
+
58
+
114
59
  defineExpose({
115
60
  elForm: formRef,
116
61
  getElForm:():FormInstance|undefined=>formRef.value,
@@ -119,18 +64,21 @@ defineExpose({
119
64
  //先清空之前的校验
120
65
  formRef.value.clearValidate();
121
66
  //判断是否有传入rules如果有则先执行 formRef.value!.validate()
122
- if(props.rules){
67
+ if(props.rules && Object.keys(props.rules).length>0){
123
68
  await formRef.value.validate((valid,fields)=>{
124
69
  //判断校验是否成功
125
70
  if(valid){
126
71
  //前端校验已成功,执行异步submit
127
72
  submit()
128
73
  .then(() => {
74
+ //成功
129
75
  //校验通过清楚所有的错误校验信息
130
76
  props.validator?.clearFiledErrors();
131
77
  })
132
78
  .catch(() => {
133
79
  //失败
80
+ //合并rules
81
+ rules.value = mergeRules(props.rules, props.validator.rules);
134
82
  formRef.value.validate();
135
83
  if (onFail) onFail();
136
84
  });
@@ -144,6 +92,9 @@ defineExpose({
144
92
  props.validator?.clearFiledErrors();
145
93
  })
146
94
  .catch(async () => {
95
+ //失败
96
+ //合并rules
97
+ rules.value = mergeRules(props.rules, props.validator.rules);
147
98
  await formRef.value.validate();
148
99
  if (onFail) onFail();
149
100
  });
@@ -152,17 +103,26 @@ defineExpose({
152
103
 
153
104
 
154
105
  },
106
+ getRules: () => rules.value,
155
107
  });
156
108
 
109
+
157
110
  watch(() => props.model.formData, () => {
158
111
  props.validator?.clearFiledErrors();
159
112
  })
113
+
114
+ watch(() => props.rules, () => {
115
+ //合并rules
116
+ rules.value = mergeRules(props.rules, props.validator.rules);
117
+ }, { immediate: true })
118
+
119
+
160
120
  </script>
161
121
 
162
122
  <template>
163
123
  <el-form
164
124
  ref="formRef"
165
- :model="model.formData"
125
+ :model="model"
166
126
  :rules="rules"
167
127
  :inline="inline"
168
128
  :label-position="labelPosition"
@@ -1,8 +1,13 @@
1
1
  <script setup lang="ts">
2
- import {provide, ref, withDefaults, defineProps, defineExpose} from 'vue'
2
+ import { provide, ref, withDefaults, defineProps, defineExpose, inject, computed } from "vue";
3
3
  import {ElFormItem, ElIcon, ElText, type FormItemRule, ElTooltip} from 'element-plus'
4
4
  import {QuestionFilled} from "@element-plus/icons-vue";
5
5
 
6
+ type RequiredPosition = 'left' | 'right'
7
+
8
+
9
+
10
+ const aceFormRequiredPosition = inject('aceFormRequiredPosition')
6
11
  const props = withDefaults(defineProps<{
7
12
  prop?: string | string[]
8
13
  rules?: FormItemRule | FormItemRule[]
@@ -14,15 +19,23 @@ const props = withDefaults(defineProps<{
14
19
  showMessage?: boolean
15
20
  inlineMessage?: boolean
16
21
  size?: 'small' | 'default' | 'large'
22
+ requiredPosition?: RequiredPosition
23
+ labelGap?:string
17
24
  }>(), {
18
25
  required: false,
19
26
  showMessage: true,
20
27
  inlineMessage: true,
21
- size: 'small'
28
+ size: 'small',
29
+ labelGap:'4px'
22
30
  })
23
31
 
24
32
  provide('aceFormItemProp', props.prop)
25
33
 
34
+ const requiredPosition = computed(()=>{
35
+ return props.requiredPosition || aceFormRequiredPosition
36
+ })
37
+
38
+
26
39
  const formItem = ref<typeof ElFormItem | null>(null)
27
40
  defineExpose({
28
41
  resetField: () => {
@@ -46,20 +59,26 @@ defineExpose({
46
59
  :inline-message="inlineMessage"
47
60
  :size="size">
48
61
  <template #label>
49
- <el-text class="el-form-item__label">
50
- {{ props.label }}
51
- <span style="color:red" v-if="props.required">*</span>
52
- <el-tooltip
53
- v-if="labelRemark"
54
- placement="top">
55
- <el-icon>
56
- <question-filled/>
57
- </el-icon>
58
- <template #content>
59
- <div v-html="labelRemark"/>
60
- </template>
61
- </el-tooltip>
62
- </el-text>
62
+ <div style="display: flex;" :style="{
63
+ gap: labelGap
64
+ }">
65
+ <span style="color:red" v-if="props.required && requiredPosition==='left'">*</span>
66
+ <el-text class="el-form-item__label">
67
+ {{ props.label }}
68
+ <el-tooltip
69
+ v-if="labelRemark"
70
+ placement="top">
71
+ <el-icon>
72
+ <question-filled/>
73
+ </el-icon>
74
+ <template #content>
75
+ <div v-html="labelRemark"/>
76
+ </template>
77
+ </el-tooltip>
78
+ </el-text>
79
+ <span style="color:red" v-if="props.required && requiredPosition==='right'">*</span>
80
+ </div>
81
+
63
82
  </template>
64
83
  <slot></slot>
65
84
  <slot name="error"></slot>
@@ -1,7 +1,11 @@
1
1
  <script setup lang="ts">
2
2
  import {ElInput, ElOption, ElSelect} from "element-plus";
3
3
  import {nextTick, onUnmounted, ref, watch} from "vue"
4
- import {createAxios, useAppMessageApi, useLoginUser} from "@jari-ace/app-bolts";
4
+ import {
5
+ createAxiosWithoutCache,
6
+ useAppMessageApi,
7
+ useLoginUser
8
+ } from "@jari-ace/app-bolts";
5
9
  import MessageEditor from "./I18nBundleEditor.vue"
6
10
  import {trim} from "lodash-es";
7
11
  import {useAppInstances} from "../../hooks/useAppInstances";
@@ -20,7 +24,7 @@ const props = withDefaults(defineProps<{
20
24
  const model = defineModel<string>({
21
25
  default: ""
22
26
  })
23
- const axios = createAxios()
27
+ const axios = createAxiosWithoutCache()
24
28
  const api = useAppMessageApi(axios)
25
29
  const locale = useLoginUser().locale
26
30
  const messageKeys = ref<string[]>()
@@ -31,12 +31,12 @@ import {JaUserSelectDialog} from "../../userSelectDialog";
31
31
  import {JaScrollbar} from "../../scrollbar";
32
32
  import CustomGroupManager from "./CustomGroupManager.vue";
33
33
  import JaUserList from "./JaUserList.vue";
34
-
34
+ import {useRealms} from '../../../hooks/useRealms'
35
35
  const props = defineProps({
36
36
  /**
37
37
  * 可选择用户的用户域ID
38
38
  */
39
- realmId: {type: String, required: false, default: 1},
39
+ realmId: {type: String, required: false},
40
40
  /**
41
41
  * 弹出下拉选框的快捷键
42
42
  */
@@ -65,13 +65,15 @@ const props = defineProps({
65
65
  */
66
66
  maxHeight: {type: [Number, String], required: false},
67
67
  })
68
+
68
69
  const localRealmId = ref<string>();
69
70
 
70
- function loadRealmId() {
71
+ async function loadRealmId() {
71
72
  if (props.realmId) {
72
73
  localRealmId.value = props.realmId;
73
74
  } else {
74
- localRealmId.value = useLoginUser().realmId;
75
+ const defaultRealm = await useRealms().getDefaultRealm();
76
+ localRealmId.value = defaultRealm.id;
75
77
  }
76
78
  }
77
79
 
@@ -126,8 +128,8 @@ function switchUserSelect(u: UserReference) {
126
128
 
127
129
 
128
130
  function onPopoverShow() {
129
- if (!queryParams.value.realmId || queryParams.value.realmId !== localRealmId.value) {
130
- queryParams.value.realmId = localRealmId.value
131
+ if (props.realmId) {
132
+ queryParams.value.realmId = props.realmId
131
133
  }
132
134
  if (queryParams.value.name && queryParams.value.name.length > minLengthToTriggerUserQuery) {
133
135
  queryParams.value.name = undefined;
@@ -37,12 +37,13 @@ import {JaButton} from "../../button";
37
37
  import throttle from "lodash-es/throttle";
38
38
  import {JaUserGroupTree} from "../../userGroupTree";
39
39
  import {JaCustomGroupTree} from "../../customGroupTree";
40
+ import { useRealms } from "../../../hooks/useRealms";
40
41
  //#region Props和Const声明和初始化
41
42
  const props = defineProps({
42
43
  /**
43
44
  * 可选择用户的用户域ID
44
45
  */
45
- realmId: {type: String, required: true, default: 1},
46
+ realmId: {type: String, required: false},
46
47
  /**
47
48
  * 是否多选模式
48
49
  */
@@ -59,12 +60,20 @@ const selectedUsers = defineModel<UserReference[] | UserReference | null>({
59
60
  required: true
60
61
  });
61
62
  const localRealmId = ref<string>();
62
- const login = useLoginUser();
63
- if (props.realmId) {
64
- localRealmId.value = props.realmId;
65
- } else {
66
- localRealmId.value = login.realmId;
63
+
64
+
65
+ async function loadRealmId() {
66
+ if (props.realmId) {
67
+ localRealmId.value = props.realmId;
68
+ } else {
69
+ const defaultRealm = await useRealms().getDefaultRealm();
70
+ localRealmId.value = defaultRealm.id;
71
+ }
67
72
  }
73
+
74
+ loadRealmId()
75
+
76
+
68
77
  if (props.multiple) {
69
78
  if (!selectedUsers.value) {
70
79
  selectedUsers.value = [];
@@ -256,8 +265,7 @@ function switchSelectOnlyView() {
256
265
  }
257
266
 
258
267
  function onOpen() {
259
- if (!userQuery.queryParams.value.realmId || userQuery.queryParams.value.realmId
260
- !== localRealmId.value) {
268
+ if (!userQuery.queryParams.value.realmId && localRealmId.value) {
261
269
  userQuery.queryParams.value.realmId = localRealmId.value;
262
270
  }
263
271