fix: useI18n type
This commit is contained in:
parent
3509ebec16
commit
c22de5c35b
|
|
@ -1,6 +1,21 @@
|
||||||
import { i18n } from '/@/locales/setupI18n';
|
import { i18n } from '/@/locales/setupI18n';
|
||||||
|
|
||||||
export function useI18n(namespace?: string) {
|
type I18nGlobalTranslation = {
|
||||||
|
(key: string): string;
|
||||||
|
(key: string, locale: string): string;
|
||||||
|
(key: string, locale: string, list: unknown[]): string;
|
||||||
|
(key: string, locale: string, named: Record<string, unknown>): string;
|
||||||
|
(key: string, list: unknown[]): string;
|
||||||
|
(key: string, named: Record<string, unknown>): string;
|
||||||
|
};
|
||||||
|
|
||||||
|
type I18nTranslationRestParameters = [string, any];
|
||||||
|
|
||||||
|
export function useI18n(
|
||||||
|
namespace?: string
|
||||||
|
): {
|
||||||
|
t: I18nGlobalTranslation;
|
||||||
|
} {
|
||||||
function getKey(key: string) {
|
function getKey(key: string) {
|
||||||
if (!namespace) {
|
if (!namespace) {
|
||||||
return key;
|
return key;
|
||||||
|
|
@ -22,9 +37,9 @@ export function useI18n(namespace?: string) {
|
||||||
|
|
||||||
const { t, ...methods } = i18n.global;
|
const { t, ...methods } = i18n.global;
|
||||||
|
|
||||||
const tFn: typeof t = (key: string, ...arg: any) => {
|
const tFn: I18nGlobalTranslation = (key: string, ...arg: any[]) => {
|
||||||
if (!key) return '';
|
if (!key) return '';
|
||||||
return t(getKey(key), ...(arg as Parameters<typeof t>));
|
return t(getKey(key), ...(arg as I18nTranslationRestParameters));
|
||||||
};
|
};
|
||||||
return {
|
return {
|
||||||
...methods,
|
...methods,
|
||||||
|
|
|
||||||
|
|
@ -1,5 +1,6 @@
|
||||||
<template>
|
<template>
|
||||||
<PageWrapper title="图片预览示例">
|
<PageWrapper title="图片预览示例">
|
||||||
|
<ImagePreview :imageList="imgList" />
|
||||||
<Alert message="有预览图" type="info" />
|
<Alert message="有预览图" type="info" />
|
||||||
<div class="flex justify-center mt-4">
|
<div class="flex justify-center mt-4">
|
||||||
<img :src="img" v-for="img in imgList" :key="img" class="mr-2" @click="handleClick(img)" />
|
<img :src="img" v-for="img in imgList" :key="img" class="mr-2" @click="handleClick(img)" />
|
||||||
|
|
@ -11,7 +12,7 @@
|
||||||
<script lang="ts">
|
<script lang="ts">
|
||||||
import { defineComponent } from 'vue';
|
import { defineComponent } from 'vue';
|
||||||
import { Alert } from 'ant-design-vue';
|
import { Alert } from 'ant-design-vue';
|
||||||
import { createImgPreview } from '/@/components/Preview/index';
|
import { createImgPreview, ImagePreview } from '/@/components/Preview/index';
|
||||||
import { PageWrapper } from '/@/components/Page';
|
import { PageWrapper } from '/@/components/Page';
|
||||||
|
|
||||||
const imgList: string[] = [
|
const imgList: string[] = [
|
||||||
|
|
@ -20,7 +21,7 @@
|
||||||
'https://picsum.photos/id/68/346/216',
|
'https://picsum.photos/id/68/346/216',
|
||||||
];
|
];
|
||||||
export default defineComponent({
|
export default defineComponent({
|
||||||
components: { Alert, PageWrapper },
|
components: { Alert, PageWrapper, ImagePreview },
|
||||||
setup() {
|
setup() {
|
||||||
function handleClick(img: string) {
|
function handleClick(img: string) {
|
||||||
createImgPreview({ imageList: [img] });
|
createImgPreview({ imageList: [img] });
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue