Commit c22de5c35b4781322c9ee17ad375ec0af2fe60a7

Authored by vben
1 parent 3509ebec

fix: useI18n type

src/hooks/web/useI18n.ts
1 1 import { i18n } from '/@/locales/setupI18n';
2 2  
3   -export function useI18n(namespace?: string) {
  3 +type I18nGlobalTranslation = {
  4 + (key: string): string;
  5 + (key: string, locale: string): string;
  6 + (key: string, locale: string, list: unknown[]): string;
  7 + (key: string, locale: string, named: Record<string, unknown>): string;
  8 + (key: string, list: unknown[]): string;
  9 + (key: string, named: Record<string, unknown>): string;
  10 +};
  11 +
  12 +type I18nTranslationRestParameters = [string, any];
  13 +
  14 +export function useI18n(
  15 + namespace?: string
  16 +): {
  17 + t: I18nGlobalTranslation;
  18 +} {
4 19 function getKey(key: string) {
5 20 if (!namespace) {
6 21 return key;
... ... @@ -22,9 +37,9 @@ export function useI18n(namespace?: string) {
22 37  
23 38 const { t, ...methods } = i18n.global;
24 39  
25   - const tFn: typeof t = (key: string, ...arg: any) => {
  40 + const tFn: I18nGlobalTranslation = (key: string, ...arg: any[]) => {
26 41 if (!key) return '';
27   - return t(getKey(key), ...(arg as Parameters<typeof t>));
  42 + return t(getKey(key), ...(arg as I18nTranslationRestParameters));
28 43 };
29 44 return {
30 45 ...methods,
... ...
src/views/demo/feat/img-preview/index.vue
1 1 <template>
2 2 <PageWrapper title="图片预览示例">
  3 + <ImagePreview :imageList="imgList" />
3 4 <Alert message="有预览图" type="info" />
4 5 <div class="flex justify-center mt-4">
5 6 <img :src="img" v-for="img in imgList" :key="img" class="mr-2" @click="handleClick(img)" />
... ... @@ -11,7 +12,7 @@
11 12 <script lang="ts">
12 13 import { defineComponent } from 'vue';
13 14 import { Alert } from 'ant-design-vue';
14   - import { createImgPreview } from '/@/components/Preview/index';
  15 + import { createImgPreview, ImagePreview } from '/@/components/Preview/index';
15 16 import { PageWrapper } from '/@/components/Page';
16 17  
17 18 const imgList: string[] = [
... ... @@ -20,7 +21,7 @@
20 21 'https://picsum.photos/id/68/346/216',
21 22 ];
22 23 export default defineComponent({
23   - components: { Alert, PageWrapper },
  24 + components: { Alert, PageWrapper, ImagePreview },
24 25 setup() {
25 26 function handleClick(img: string) {
26 27 createImgPreview({ imageList: [img] });
... ...