@skyfox2000/webui 1.5.15 → 1.5.17

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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@skyfox2000/webui",
3
- "version": "1.5.15",
3
+ "version": "1.5.17",
4
4
  "description": "后台前端通用组件定义, 支持国际化",
5
5
  "type": "module",
6
6
  "keywords": [],
@@ -1,18 +1,11 @@
1
1
  <script setup lang="ts">
2
2
  import { formValidate, useInputFactory } from '@/index';
3
3
  import { Input } from 'ant-design-vue';
4
- import { ref, watch } from 'vue';
4
+ import { ref, watch, computed, useAttrs } from 'vue';
5
5
  import { useI18n } from 'vue-i18n';
6
6
  const { t } = useI18n();
7
7
 
8
8
  const { editorCtrl, labelText, errInfo } = useInputFactory();
9
- const onBlur = () => {
10
- if (errInfo?.value.errClass && editorCtrl) {
11
- /// 重新开始验证
12
- formValidate(editorCtrl);
13
- }
14
- };
15
-
16
9
  const props = withDefaults(defineProps<{
17
10
  value?: any;
18
11
  /**
@@ -29,7 +22,22 @@ const props = withDefaults(defineProps<{
29
22
 
30
23
  // 如果初始value为undefined,自动设置undefValue为true
31
24
  const undefValue = props.value === undefined ? true : props.undefValue;
32
- const emit = defineEmits(['update:value']);
25
+ const emit = defineEmits(['update:value', 'blur', 'change']);
26
+
27
+ // 过滤已配置的事件处理器
28
+ const filteredAttrs = computed(() => {
29
+ const { onBlur, onChange, ...rest } = useAttrs();
30
+ return rest;
31
+ });
32
+
33
+ const onBlur = (e: any) => {
34
+ if (errInfo?.value.errClass && editorCtrl) {
35
+ /// 重新开始验证
36
+ formValidate(editorCtrl);
37
+ }
38
+ emit('blur', e)
39
+ };
40
+
33
41
  // 内部值,拦截外部传入的 value
34
42
  const innerValue = ref(props.value);
35
43
 
@@ -53,10 +61,12 @@ watch(
53
61
  },
54
62
  );
55
63
 
56
- const onClear = () => {
64
+ const onClear = (e: any) => {
57
65
  if (innerValue.value === '') {
58
66
  innerValue.value = undefValue ? undefined : null;
59
67
  }
68
+
69
+ emit('change', e)
60
70
  };
61
71
  </script>
62
72
  <template>
@@ -65,16 +75,8 @@ const onClear = () => {
65
75
  errInfo?.errClass,
66
76
  errInfo?.errClass === 'error' && !$slots.addonBefore && !$slots.addonAfter
67
77
  ? '!border-red-300 shadow-[0_0_3px_0px_#ff4d4f]'
68
- : '',
69
- ]"
70
- v-model:value="innerValue"
71
- autocomplete="new-password"
72
- :allow-clear="true"
73
- :placeholder="t('webui.common.placeholder', [labelText])"
74
- @blur="onBlur"
75
- @change="onClear"
76
- v-bind="$attrs"
77
- >
78
+ : '',]" v-model:value="innerValue" autocomplete="new-password" :allow-clear="true"
79
+ :placeholder="t('webui.common.placeholder', [labelText])" @blur="onBlur" @change="onClear" v-bind="filteredAttrs">
78
80
  <template #addonBefore v-if="$slots.addonBefore">
79
81
  <slot name="addonBefore"></slot>
80
82
  </template>
package/src/index.ts CHANGED
@@ -162,6 +162,7 @@ export {
162
162
  validateData,
163
163
  resetRules,
164
164
  getRuleTexts,
165
+ getValidator,
165
166
  useInputFactory,
166
167
  useFormItemFactory,
167
168
  } from '@/utils/form-validate';
@@ -169,6 +169,16 @@ export const getRuleTexts = (rules?: Record<string, ValidateRule>) => {
169
169
  return result;
170
170
  };
171
171
 
172
+ export const getValidator = (rules: Record<string, ValidateRule>) : Validator => {
173
+ /**
174
+ * 设置自定义文字显示与验证条件
175
+ */
176
+ const ruleValidator = new Validator({});
177
+ ruleValidator.messages(validMessages.messages());
178
+ ruleValidator.define(rules);
179
+ return ruleValidator;
180
+ }
181
+
172
182
  /**
173
183
  * 表单数据验证
174
184
  * @param editorCtrl 表单控制对象