wip(VForm): VForm coding

This commit is contained in:
陈凯龙 2021-12-15 17:16:53 +08:00
parent 3e002a68f2
commit 558abb86dc
10 changed files with 29 additions and 29 deletions

View File

@ -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<ComponentRef<typeof VFrom> & 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<VFormSchema[]>([
{
@ -33,5 +35,6 @@ const schema = reactive<VFormSchema[]>([
<!-- <VFrom :is-col="false" :schema="schema" /> -->
<!-- <Component :is="VFrom" /> -->
<!-- <RouterView class="app" /> -->
<div>{{ t('common.inputText') }}</div>
</ElConfigProvider>
</template>

View File

@ -66,16 +66,20 @@ export default defineComponent({
typeof defineComponent
>
return (
<Com
v-model={test.value}
{...(autoSetPlaceholder && setTextPlaceholder(item))}
></Com>
<Com v-model={test.value} {...(autoSetPlaceholder && setTextPlaceholder(item))}>
{item.options ? renderOptions() : null}
</Com>
)
}}
</ElFormItem>
)
})
// return <div>{schema[0]?.field}</div>
}
// options
function renderOptions() {
// const optionsMap = ['Radio', 'Checkbox', 'Select']
return <div>2222</div>
}
// Form

View File

@ -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')
}

View File

@ -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

View File

@ -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')

View File

@ -1,20 +1,16 @@
import { createI18n } from 'vue-i18n'
import type { App } from 'vue'
import type { I18nOptions } from 'vue-i18n'
export let i18n: ReturnType<typeof createI18n>
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)
})
}

View File

@ -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')}/`