wip(VForm): VForm coding
parent
7528fe6da6
commit
d7d0ada558
@ -1,8 +1,39 @@
|
|||||||
|
// import { useI18n } from '@/hooks/web/useI18n'
|
||||||
|
// const { t } = useI18n()
|
||||||
/**
|
/**
|
||||||
*
|
*
|
||||||
* @param schema 对应组件数据
|
* @param schema 对应组件数据
|
||||||
* @description 用于自动设置placeholder
|
* @description 用于自动设置placeholder
|
||||||
*/
|
*/
|
||||||
export function setTextPlaceholder(schema: VFormSchema) {
|
export function setTextPlaceholder(schema: VFormSchema): {
|
||||||
|
placeholder?: string
|
||||||
|
startPlaceholder?: string
|
||||||
|
endPlaceholder?: string
|
||||||
|
} {
|
||||||
console.log(schema)
|
console.log(schema)
|
||||||
|
// const textMap = ['Input', 'Autocomplete', 'InputNumber']
|
||||||
|
// const selectMap = ['Select', 'TimePicker', 'DatePicker', 'TimeSelect', 'TimeSelect']
|
||||||
|
// if (textMap.includes(schema?.component as string)) {
|
||||||
|
// return {
|
||||||
|
// placeholder: t('common.inputText')
|
||||||
|
// }
|
||||||
|
// }
|
||||||
|
// if (selectMap.includes(schema?.component as string)) {
|
||||||
|
// // 一些范围选择器
|
||||||
|
// const twoTextMap = ['datetimerange', 'daterange', 'monthrange', 'datetimerange', 'daterange']
|
||||||
|
// if (
|
||||||
|
// twoTextMap.includes(schema?.componentProps?.type || schema?.componentProps?.isRange) as string
|
||||||
|
// ) {
|
||||||
|
// return {
|
||||||
|
// startPlaceholder: t('common.startTimeText'),
|
||||||
|
// endPlaceholder: t('common.endTimeText'),
|
||||||
|
// rangeSeparator: '-'
|
||||||
|
// }
|
||||||
|
// } else {
|
||||||
|
// return {
|
||||||
|
// placeholder: t('common.selectText')
|
||||||
|
// }
|
||||||
|
// }
|
||||||
|
// }
|
||||||
|
return {}
|
||||||
}
|
}
|
||||||
|
|||||||
@ -0,0 +1,50 @@
|
|||||||
|
// // import { i18n } from '@/plugins/i18n'
|
||||||
|
|
||||||
|
// 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]
|
||||||
|
|
||||||
|
// function getKey(namespace: string | undefined, key: string) {
|
||||||
|
// if (!namespace) {
|
||||||
|
// return key
|
||||||
|
// }
|
||||||
|
// if (key.startsWith(namespace)) {
|
||||||
|
// return key
|
||||||
|
// }
|
||||||
|
// return `${namespace}.${key}`
|
||||||
|
// }
|
||||||
|
|
||||||
|
// export function useI18n(namespace?: string): {
|
||||||
|
// t: I18nGlobalTranslation
|
||||||
|
// } {
|
||||||
|
// const normalFn = {
|
||||||
|
// t: (key: string) => {
|
||||||
|
// return getKey(namespace, key)
|
||||||
|
// }
|
||||||
|
// }
|
||||||
|
|
||||||
|
// if (!i18n) {
|
||||||
|
// return normalFn
|
||||||
|
// }
|
||||||
|
|
||||||
|
// const { t, ...methods } = i18n.global
|
||||||
|
|
||||||
|
// const tFn: I18nGlobalTranslation = (key: string, ...arg: any[]) => {
|
||||||
|
// if (!key) return ''
|
||||||
|
// if (!key.includes('.') && !namespace) return key
|
||||||
|
// return t(getKey(namespace, key), ...(arg as I18nTranslationRestParameters))
|
||||||
|
// }
|
||||||
|
// return {
|
||||||
|
// ...methods,
|
||||||
|
// t: tFn
|
||||||
|
// }
|
||||||
|
// }
|
||||||
|
|
||||||
|
// export const t = (key: string) => key
|
||||||
@ -1,18 +1,16 @@
|
|||||||
|
// 引入windi css
|
||||||
|
import '@/plugins/windicss'
|
||||||
import { createApp } from 'vue'
|
import { createApp } from 'vue'
|
||||||
|
|
||||||
import App from './App.vue'
|
import App from './App.vue'
|
||||||
|
|
||||||
const app = createApp(App)
|
const app = createApp(App)
|
||||||
|
|
||||||
// 引入windi css
|
|
||||||
import '@/plugins/windicss'
|
|
||||||
|
|
||||||
// 引入多语言
|
// 引入多语言
|
||||||
import { setupI18n } from '@/plugins/i18n'
|
import { setupI18n } from '@/plugins/i18n'
|
||||||
setupI18n(app)
|
|
||||||
|
|
||||||
// 引入状态管理
|
// 引入状态管理
|
||||||
import { setupStore } from '@/store'
|
import { setupStore } from '@/store'
|
||||||
setupStore(app)
|
;(async () => {
|
||||||
|
await setupI18n(app)
|
||||||
|
|
||||||
|
setupStore(app)
|
||||||
|
|
||||||
app.mount('#app')
|
app.mount('#app')
|
||||||
|
})()
|
||||||
|
|||||||
@ -0,0 +1,16 @@
|
|||||||
|
import { Slots } from 'vue'
|
||||||
|
import { isFunction } from '@/utils/is'
|
||||||
|
|
||||||
|
export function getSlot(slots: Slots, slot = 'default', data?: Recordable) {
|
||||||
|
// Reflect.has 判断一个对象是否存在某个属性
|
||||||
|
if (!slots || !Reflect.has(slots, slot)) {
|
||||||
|
return null
|
||||||
|
}
|
||||||
|
if (!isFunction(slots[slot])) {
|
||||||
|
console.error(`${slot} is not a function!`)
|
||||||
|
return null
|
||||||
|
}
|
||||||
|
const slotFn = slots[slot]
|
||||||
|
if (!slotFn) return null
|
||||||
|
return slotFn(data)
|
||||||
|
}
|
||||||
Loading…
Reference in New Issue