diff --git a/src/App.vue b/src/App.vue index 1894909..0a95423 100644 --- a/src/App.vue +++ b/src/App.vue @@ -5,10 +5,12 @@ import zhCn from 'element-plus/lib/locale/lang/zh-cn' // import en from 'element-plus/lib/locale/lang/en' import { VFrom, VFormExpose } from '@/components/Form' const formRef = ref & VFormExpose>() +import { useI18n } from '@/hooks/web/useI18n' +const { t } = useI18n() onMounted(() => { const form = unref(formRef.value) - console.log(form?.$el) + console.log(form) }) const schema = reactive([ { @@ -33,5 +35,6 @@ const schema = reactive([ +
{{ t('common.inputText') }}
diff --git a/src/components/Form/src/VForm.vue b/src/components/Form/src/VForm.vue index 2d7c05e..c263b38 100644 --- a/src/components/Form/src/VForm.vue +++ b/src/components/Form/src/VForm.vue @@ -66,16 +66,20 @@ export default defineComponent({ typeof defineComponent > return ( - + + {item.options ? renderOptions() : null} + ) }} ) }) - // return
{schema[0]?.field}
+ } + + // 渲染options + function renderOptions() { + // const optionsMap = ['Radio', 'Checkbox', 'Select'] + return
2222
} // 过滤传入Form组件的属性 diff --git a/src/components/Form/src/components/Checkbox.vue b/src/components/Form/src/components/Checkbox.vue new file mode 100644 index 0000000..e69de29 diff --git a/src/components/Form/src/components/Radio.vue b/src/components/Form/src/components/Radio.vue new file mode 100644 index 0000000..e69de29 diff --git a/src/components/Form/src/components/Select.vue b/src/components/Form/src/components/Select.vue new file mode 100644 index 0000000..e69de29 diff --git a/src/components/Form/src/helper.ts b/src/components/Form/src/helper.ts index 3a5e967..f2b25eb 100644 --- a/src/components/Form/src/helper.ts +++ b/src/components/Form/src/helper.ts @@ -1,6 +1,5 @@ import { useI18n } from '@/hooks/web/useI18n' const { t } = useI18n() -console.log(t) interface PlaceholderMoel { placeholder?: string @@ -15,11 +14,9 @@ interface PlaceholderMoel { * @description 用于自动设置placeholder */ export function setTextPlaceholder(schema: VFormSchema): PlaceholderMoel { - console.log(schema) const textMap = ['Input', 'Autocomplete', 'InputNumber'] const selectMap = ['Select', 'TimePicker', 'DatePicker', 'TimeSelect', 'TimeSelect'] if (textMap.includes(schema?.component as string)) { - console.log(t('common.inputText')) return { placeholder: t('common.inputText') } diff --git a/src/hooks/web/useI18n.ts b/src/hooks/web/useI18n.ts index 1063550..9ee6e2c 100644 --- a/src/hooks/web/useI18n.ts +++ b/src/hooks/web/useI18n.ts @@ -29,7 +29,6 @@ export function useI18n(namespace?: string): { return getKey(namespace, key) } } - console.log(i18n) if (!i18n) { return normalFn @@ -48,4 +47,4 @@ export function useI18n(namespace?: string): { } } -// export const t = (key: string) => key +export const t = (key: string) => key diff --git a/src/main.ts b/src/main.ts index 1639e71..bbfc0d6 100644 --- a/src/main.ts +++ b/src/main.ts @@ -1,15 +1,12 @@ // 引入windi css import '@/plugins/windicss' + import { createApp } from 'vue' import App from './App.vue' const app = createApp(App) -// 引入多语言 -import { setupI18n } from '@/plugins/i18n' + // 引入状态管理 import { setupStore } from '@/store' - -setupI18n(app) - setupStore(app) app.mount('#app') diff --git a/src/plugins/i18n/index.ts b/src/plugins/i18n/index.ts index a06c031..f84c5c1 100644 --- a/src/plugins/i18n/index.ts +++ b/src/plugins/i18n/index.ts @@ -1,20 +1,16 @@ import { createI18n } from 'vue-i18n' -import type { App } from 'vue' -import type { I18nOptions } from 'vue-i18n' -export let i18n: ReturnType +export const i18n = setupI18n() -const messages = Object.fromEntries( - Object.entries(import.meta.globEager('../../locales/*.ts')).map(([key, value]) => { - return [key.slice(14, -3), value.default] - }) -) - -export function setupI18n(app: App): void { - i18n = createI18n({ +function setupI18n() { + const messages = Object.fromEntries( + Object.entries(import.meta.globEager('../../locales/*.ts')).map(([key, value]) => { + return [key.slice(14, -3), value.default] + }) + ) + return createI18n({ legacy: false, locale: 'zh-CN', messages - } as I18nOptions) - app.use(i18n) + }) } diff --git a/vite.config.ts b/vite.config.ts index 3b42c52..61d27ce 100644 --- a/vite.config.ts +++ b/vite.config.ts @@ -86,6 +86,10 @@ export default ({ command, mode }: ConfigEnv): UserConfig => { }, resolve: { alias: [ + { + find: 'vue-i18n', + replacement: 'vue-i18n/dist/vue-i18n.cjs.js' + }, { find: /\@\//, replacement: `${pathResolve('src')}/`