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
|
|
package/components/form/form.vue
CHANGED
|
@@ -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
|
+
}
|