sard-uniapp 1.19.4 → 1.19.5

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/CHANGELOG.md CHANGED
@@ -1,3 +1,12 @@
1
+ ## [1.19.5](https://github.com/sutras/sard-uniapp/compare/v1.19.4...v1.19.5) (2025-06-22)
2
+
3
+
4
+ ### Features
5
+
6
+ * 新增useLocaleProvide, useLocale钩子函数 ([a374df8](https://github.com/sutras/sard-uniapp/commit/a374df85f75c1b76e24e1f99ef58c1377ed7b4a5))
7
+
8
+
9
+
1
10
  ## [1.19.4](https://github.com/sutras/sard-uniapp/compare/v1.19.3...v1.19.4) (2025-06-19)
2
11
 
3
12
 
@@ -150,9 +150,7 @@ export default _defineComponent({
150
150
  validate().catch(noop);
151
151
  }
152
152
  },
153
- {
154
- deep: true
155
- }
153
+ { deep: true, flush: "post" }
156
154
  );
157
155
  provide(
158
156
  formContextSymbol,
@@ -129,6 +129,18 @@ export default _defineComponent({
129
129
  validateState.value = props.error ? "error" : "";
130
130
  }
131
131
  );
132
+ watch(
133
+ () => props.rules,
134
+ () => {
135
+ if (validateMessage.value) {
136
+ validate().catch(noop);
137
+ }
138
+ },
139
+ {
140
+ deep: true,
141
+ flush: "post"
142
+ }
143
+ );
132
144
  const shouldShowError = computed(() => {
133
145
  return props.showError && formContext.showError && validateMessage.value;
134
146
  });
@@ -1,3 +1,4 @@
1
+ import { type App, type InjectionKey, type Ref } from 'vue';
1
2
  export declare const currentLocale: import("vue").ShallowRef<Record<string, any>, Record<string, any>>;
2
3
  export interface LocaleTranslate {
3
4
  (chainOrData?: string | Record<string, number | string>, data?: Record<string, number | string>): string;
@@ -8,3 +9,6 @@ export declare function useTranslate(prefix?: string): {
8
9
  select: (chain?: string) => any;
9
10
  };
10
11
  export declare function setLocale(locale: Record<string, any>): void;
12
+ export declare const localeContextSymbol: InjectionKey<Ref<string>>;
13
+ export declare function useLocaleProvide<T extends Record<string, any>>(app: App, languages: T, defaultLocale: keyof T): void;
14
+ export declare function useLocale(): Ref<string, string> | undefined;
@@ -1,4 +1,4 @@
1
- import { shallowRef, computed } from 'vue';
1
+ import { shallowRef, computed, inject, ref, watch, } from 'vue';
2
2
  import zhCN from './lang/zh-CN';
3
3
  import { chainGet } from '../../utils';
4
4
  export const currentLocale = shallowRef(zhCN);
@@ -42,3 +42,16 @@ export function useTranslate(prefix = '') {
42
42
  export function setLocale(locale) {
43
43
  currentLocale.value = locale;
44
44
  }
45
+ export const localeContextSymbol = Symbol('locale-context');
46
+ export function useLocaleProvide(app, languages, defaultLocale) {
47
+ const locale = ref(defaultLocale);
48
+ watch(locale, () => {
49
+ setLocale(languages[locale.value]);
50
+ }, {
51
+ immediate: true,
52
+ });
53
+ app.provide(localeContextSymbol, locale);
54
+ }
55
+ export function useLocale() {
56
+ return inject(localeContextSymbol);
57
+ }
package/package.json CHANGED
@@ -2,7 +2,7 @@
2
2
  "id": "sard-uniapp",
3
3
  "name": "sard-uniapp",
4
4
  "displayName": "sard-uniapp",
5
- "version": "1.19.4",
5
+ "version": "1.19.5",
6
6
  "description": "sard-uniapp 是一套基于 Uniapp + Vue3 框架开发的兼容多端的 UI 组件库",
7
7
  "main": "index.js",
8
8
  "scripts": {