types(VForm): Adding VForm types
parent
bc9195b21e
commit
7528fe6da6
@ -1,3 +1,3 @@
|
||||
{
|
||||
"recommendations": ["johnsoncodehk.volar", "lokalise.i18n-ally", "esbenp.prettier-vscode"]
|
||||
"recommendations": ["johnsoncodehk.volar", "lokalise.i18n-ally"]
|
||||
}
|
||||
|
||||
@ -1,8 +1,8 @@
|
||||
import BfFrom from './src/BfForm.vue'
|
||||
import VFrom from './src/VForm.vue'
|
||||
|
||||
export interface BfFormExpose {
|
||||
export interface VFormExpose {
|
||||
count: number
|
||||
sayHello: () => void
|
||||
}
|
||||
|
||||
export { BfFrom }
|
||||
export { VFrom }
|
||||
|
||||
@ -1,16 +0,0 @@
|
||||
<script lang="tsx" setup>
|
||||
// import { ref } from 'vue'
|
||||
// import { ElCol, ElRow } from 'element-plus'
|
||||
// import { propTypes } from '@/utils/propTypes'
|
||||
import { array } from 'vue-types'
|
||||
|
||||
defineProps({
|
||||
schema: array<BfFormSchema>()
|
||||
})
|
||||
</script>
|
||||
|
||||
<template>
|
||||
<div>hahah</div>
|
||||
</template>
|
||||
|
||||
<style lang="less" scoped></style>
|
||||
@ -0,0 +1,43 @@
|
||||
<script lang="tsx">
|
||||
import { PropType, defineComponent, onMounted, ref, unref } from 'vue'
|
||||
import { ElForm } from 'element-plus'
|
||||
// import { COMPONENT_MAP } from './componentMap'
|
||||
import { propTypes } from '@/utils/propTypes'
|
||||
|
||||
export default defineComponent({
|
||||
name: 'VForm',
|
||||
props: {
|
||||
// 生成Form的布局结构数组
|
||||
schema: {
|
||||
type: Array as PropType<VFormSchema[]>,
|
||||
require: true,
|
||||
default: () => []
|
||||
},
|
||||
// 是否需要栅格布局
|
||||
isCol: propTypes.bool.def(true),
|
||||
// 表单数据对象
|
||||
model: {
|
||||
type: Object as PropType<Recordable>,
|
||||
default: () => ({})
|
||||
},
|
||||
// 是否自动设置placeholder
|
||||
autoSetPlaceholder: propTypes.bool.def(true),
|
||||
// 是否自定义内容
|
||||
isCustom: propTypes.bool.def(false)
|
||||
},
|
||||
setup() {
|
||||
const formRef = ref<ComponentRef<typeof ElForm>>()
|
||||
onMounted(() => {
|
||||
console.log(unref(formRef)?.clearValidate)
|
||||
})
|
||||
|
||||
// function renderWrap() {}
|
||||
|
||||
// function renderFormItem() {}
|
||||
|
||||
return () => <ElForm ref={formRef}></ElForm>
|
||||
}
|
||||
})
|
||||
</script>
|
||||
|
||||
<style lang="less" scoped></style>
|
||||
@ -0,0 +1,42 @@
|
||||
import type { Component } from 'vue'
|
||||
import {
|
||||
ElCascader,
|
||||
ElCheckboxGroup,
|
||||
ElColorPicker,
|
||||
ElDatePicker,
|
||||
ElInput,
|
||||
ElInputNumber,
|
||||
ElRadioGroup,
|
||||
ElRate,
|
||||
ElSelect,
|
||||
ElSelectV2,
|
||||
ElSlider,
|
||||
ElSwitch,
|
||||
ElTimePicker,
|
||||
ElTimeSelect,
|
||||
ElTransfer,
|
||||
ElAutocomplete,
|
||||
ElDivider
|
||||
} from 'element-plus'
|
||||
|
||||
const COMPONENT_MAP: Recordable<Component, ComponentName> = {
|
||||
Radio: ElRadioGroup,
|
||||
Checkbox: ElCheckboxGroup,
|
||||
Input: ElInput,
|
||||
Autocomplete: ElAutocomplete,
|
||||
InputNumber: ElInputNumber,
|
||||
Select: ElSelect,
|
||||
Cascader: ElCascader,
|
||||
Switch: ElSwitch,
|
||||
Slider: ElSlider,
|
||||
TimePicker: ElTimePicker,
|
||||
DatePicker: ElDatePicker,
|
||||
Rate: ElRate,
|
||||
ColorPicker: ElColorPicker,
|
||||
Transfer: ElTransfer,
|
||||
Divider: ElDivider,
|
||||
TimeSelect: ElTimeSelect,
|
||||
SelectV2: ElSelectV2
|
||||
}
|
||||
|
||||
export { COMPONENT_MAP }
|
||||
@ -0,0 +1,8 @@
|
||||
/**
|
||||
*
|
||||
* @param schema 对应组件数据
|
||||
* @description 用于自动设置placeholder
|
||||
*/
|
||||
export function setTextPlaceholder(schema: VFormSchema) {
|
||||
console.log(schema)
|
||||
}
|
||||
@ -1,8 +1,8 @@
|
||||
export default {
|
||||
test: {
|
||||
about: 'About'
|
||||
},
|
||||
test2: {
|
||||
go: 'Go'
|
||||
common: {
|
||||
inputText: 'Please input',
|
||||
selectText: 'Please select',
|
||||
startTimeText: 'Start time',
|
||||
endTimeText: 'End time'
|
||||
}
|
||||
}
|
||||
|
||||
@ -1,8 +1,8 @@
|
||||
export default {
|
||||
test: {
|
||||
about: '关于'
|
||||
},
|
||||
test2: {
|
||||
go: '去'
|
||||
common: {
|
||||
inputText: '请输入',
|
||||
selectText: '请选择',
|
||||
startTimeText: '开始时间',
|
||||
endTimeText: '结束时间'
|
||||
}
|
||||
}
|
||||
|
||||
@ -1,2 +1,2 @@
|
||||
// 命名空间
|
||||
@namespace: vbf;
|
||||
@namespace: v;
|
||||
|
||||
@ -0,0 +1,101 @@
|
||||
// copy to vben-admin
|
||||
|
||||
const toString = Object.prototype.toString
|
||||
|
||||
export function is(val: unknown, type: string) {
|
||||
return toString.call(val) === `[object ${type}]`
|
||||
}
|
||||
|
||||
export function isDef<T = unknown>(val?: T): val is T {
|
||||
return typeof val !== 'undefined'
|
||||
}
|
||||
|
||||
export function isUnDef<T = unknown>(val?: T): val is T {
|
||||
return !isDef(val)
|
||||
}
|
||||
|
||||
export function isObject(val: any): val is Record<any, any> {
|
||||
return val !== null && is(val, 'Object')
|
||||
}
|
||||
|
||||
export function isEmpty<T = unknown>(val: T): val is T {
|
||||
if (isArray(val) || isString(val)) {
|
||||
return val.length === 0
|
||||
}
|
||||
|
||||
if (val instanceof Map || val instanceof Set) {
|
||||
return val.size === 0
|
||||
}
|
||||
|
||||
if (isObject(val)) {
|
||||
return Object.keys(val).length === 0
|
||||
}
|
||||
|
||||
return false
|
||||
}
|
||||
|
||||
export function isDate(val: unknown): val is Date {
|
||||
return is(val, 'Date')
|
||||
}
|
||||
|
||||
export function isNull(val: unknown): val is null {
|
||||
return val === null
|
||||
}
|
||||
|
||||
export function isNullAndUnDef(val: unknown): val is null | undefined {
|
||||
return isUnDef(val) && isNull(val)
|
||||
}
|
||||
|
||||
export function isNullOrUnDef(val: unknown): val is null | undefined {
|
||||
return isUnDef(val) || isNull(val)
|
||||
}
|
||||
|
||||
export function isNumber(val: unknown): val is number {
|
||||
return is(val, 'Number')
|
||||
}
|
||||
|
||||
export function isPromise<T = any>(val: unknown): val is Promise<T> {
|
||||
return is(val, 'Promise') && isObject(val) && isFunction(val.then) && isFunction(val.catch)
|
||||
}
|
||||
|
||||
export function isString(val: unknown): val is string {
|
||||
return is(val, 'String')
|
||||
}
|
||||
|
||||
export function isFunction(val: unknown): val is Function {
|
||||
return typeof val === 'function'
|
||||
}
|
||||
|
||||
export function isBoolean(val: unknown): val is boolean {
|
||||
return is(val, 'Boolean')
|
||||
}
|
||||
|
||||
export function isRegExp(val: unknown): val is RegExp {
|
||||
return is(val, 'RegExp')
|
||||
}
|
||||
|
||||
export function isArray(val: any): val is Array<any> {
|
||||
return val && Array.isArray(val)
|
||||
}
|
||||
|
||||
export function isWindow(val: any): val is Window {
|
||||
return typeof window !== 'undefined' && is(val, 'Window')
|
||||
}
|
||||
|
||||
export function isElement(val: unknown): val is Element {
|
||||
return isObject(val) && !!val.tagName
|
||||
}
|
||||
|
||||
export function isMap(val: unknown): val is Map<any, any> {
|
||||
return is(val, 'Map')
|
||||
}
|
||||
|
||||
export const isServer = typeof window === 'undefined'
|
||||
|
||||
export const isClient = !isServer
|
||||
|
||||
export function isUrl(path: string): boolean {
|
||||
const reg =
|
||||
/(((^https?:(?:\/\/)?)(?:[-:&=\+\$,\w]+@)?[A-Za-z0-9.-]+(?::\d+)?|(?:www.|[-:&=\+\$,\w]+@)[A-Za-z0-9.-]+)((?:\/[\+~%\/.\w-_]*)?\??(?:[-\+=&%@.\w_]*)#?(?:[\w]*))?)$/
|
||||
return reg.test(path)
|
||||
}
|
||||
Loading…
Reference in New Issue