1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462 |
- <script setup lang="tsx">
- import { Form } from '@/components/Form'
- import { reactive, ref, onMounted, computed } from 'vue'
- import { useI18n } from '@/hooks/web/useI18n'
- import { useIcon } from '@/hooks/web/useIcon'
- import { ContentWrap } from '@/components/ContentWrap'
- import { useAppStore } from '@/store/modules/app'
- import { SelectOption, RadioOption, CheckboxOption, FormSchema } from '@/components/Form'
- import { useForm } from '@/hooks/web/useForm'
- import {
- ElOption,
- ElOptionGroup,
- ElButton,
- ElRadio,
- ElRadioButton,
- ElCheckbox,
- ElCheckboxButton
- } from 'element-plus'
- import { getDictOneApi } from '@/api/common'
- const appStore = useAppStore()
- const { t } = useI18n()
- const isMobile = computed(() => appStore.getMobile)
- const restaurants = ref<Recordable[]>([])
- const querySearch = (queryString: string, cb: Fn) => {
- const results = queryString
- ? restaurants.value.filter(createFilter(queryString))
- : restaurants.value
- // call callback function to return suggestions
- cb(results)
- }
- let timeout: NodeJS.Timeout
- const querySearchAsync = (queryString: string, cb: (arg: any) => void) => {
- const results = queryString
- ? restaurants.value.filter(createFilter(queryString))
- : restaurants.value
- clearTimeout(timeout)
- timeout = setTimeout(() => {
- cb(results)
- }, 3000 * Math.random())
- }
- const createFilter = (queryString: string) => {
- return (restaurant: Recordable) => {
- return restaurant.value.toLowerCase().indexOf(queryString.toLowerCase()) === 0
- }
- }
- const loadAll = () => {
- return [
- { value: 'vue', link: 'https://github.com/vuejs/vue' },
- { value: 'element', link: 'https://github.com/ElemeFE/element' },
- { value: 'cooking', link: 'https://github.com/ElemeFE/cooking' },
- { value: 'mint-ui', link: 'https://github.com/ElemeFE/mint-ui' },
- { value: 'vuex', link: 'https://github.com/vuejs/vuex' },
- { value: 'vue-router', link: 'https://github.com/vuejs/vue-router' },
- { value: 'babel', link: 'https://github.com/babel/babel' }
- ]
- }
- const handleSelect = (item: Recordable) => {
- console.log(item)
- }
- onMounted(() => {
- restaurants.value = loadAll()
- })
- const initials = ['a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j']
- const options = ref(
- Array.from({ length: 1000 }).map((_, idx) => ({
- value: `Option ${idx + 1}`,
- label: `${initials[idx % 10]}${idx}`
- }))
- )
- const options2 = ref(
- Array.from({ length: 10 }).map((_, idx) => {
- const label = idx + 1
- return {
- value: `Group ${label}`,
- label: `Group ${label}`,
- options: Array.from({ length: 10 }).map((_, idx) => ({
- value: `Option ${idx + 1 + 10 * label}`,
- label: `${initials[idx % 10]}${idx + 1 + 10 * label}`
- }))
- }
- })
- )
- const options3 = [
- {
- value: 'guide',
- label: 'Guide',
- children: [
- {
- value: 'disciplines',
- label: 'Disciplines',
- children: [
- {
- value: 'consistency',
- label: 'Consistency'
- },
- {
- value: 'feedback',
- label: 'Feedback'
- },
- {
- value: 'efficiency',
- label: 'Efficiency'
- },
- {
- value: 'controllability',
- label: 'Controllability'
- }
- ]
- },
- {
- value: 'navigation',
- label: 'Navigation',
- children: [
- {
- value: 'side nav',
- label: 'Side Navigation'
- },
- {
- value: 'top nav',
- label: 'Top Navigation'
- }
- ]
- }
- ]
- },
- {
- value: 'component',
- label: 'Component',
- children: [
- {
- value: 'basic',
- label: 'Basic',
- children: [
- {
- value: 'layout',
- label: 'Layout'
- },
- {
- value: 'color',
- label: 'Color'
- },
- {
- value: 'typography',
- label: 'Typography'
- },
- {
- value: 'icon',
- label: 'Icon'
- },
- {
- value: 'button',
- label: 'Button'
- }
- ]
- },
- {
- value: 'form',
- label: 'Form',
- children: [
- {
- value: 'radio',
- label: 'Radio'
- },
- {
- value: 'checkbox',
- label: 'Checkbox'
- },
- {
- value: 'input',
- label: 'Input'
- },
- {
- value: 'input-number',
- label: 'InputNumber'
- },
- {
- value: 'select',
- label: 'Select'
- },
- {
- value: 'cascader',
- label: 'Cascader'
- },
- {
- value: 'switch',
- label: 'Switch'
- },
- {
- value: 'slider',
- label: 'Slider'
- },
- {
- value: 'time-picker',
- label: 'TimePicker'
- },
- {
- value: 'date-picker',
- label: 'DatePicker'
- },
- {
- value: 'datetime-picker',
- label: 'DateTimePicker'
- },
- {
- value: 'upload',
- label: 'Upload'
- },
- {
- value: 'rate',
- label: 'Rate'
- },
- {
- value: 'form',
- label: 'Form'
- }
- ]
- },
- {
- value: 'data',
- label: 'Data',
- children: [
- {
- value: 'table',
- label: 'Table'
- },
- {
- value: 'tag',
- label: 'Tag'
- },
- {
- value: 'progress',
- label: 'Progress'
- },
- {
- value: 'tree',
- label: 'Tree'
- },
- {
- value: 'pagination',
- label: 'Pagination'
- },
- {
- value: 'badge',
- label: 'Badge'
- }
- ]
- },
- {
- value: 'notice',
- label: 'Notice',
- children: [
- {
- value: 'alert',
- label: 'Alert'
- },
- {
- value: 'loading',
- label: 'Loading'
- },
- {
- value: 'message',
- label: 'Message'
- },
- {
- value: 'message-box',
- label: 'MessageBox'
- },
- {
- value: 'notification',
- label: 'Notification'
- }
- ]
- },
- {
- value: 'navigation',
- label: 'Navigation',
- children: [
- {
- value: 'menu',
- label: 'Menu'
- },
- {
- value: 'tabs',
- label: 'Tabs'
- },
- {
- value: 'breadcrumb',
- label: 'Breadcrumb'
- },
- {
- value: 'dropdown',
- label: 'Dropdown'
- },
- {
- value: 'steps',
- label: 'Steps'
- }
- ]
- },
- {
- value: 'others',
- label: 'Others',
- children: [
- {
- value: 'dialog',
- label: 'Dialog'
- },
- {
- value: 'tooltip',
- label: 'Tooltip'
- },
- {
- value: 'popover',
- label: 'Popover'
- },
- {
- value: 'card',
- label: 'Card'
- },
- {
- value: 'carousel',
- label: 'Carousel'
- },
- {
- value: 'collapse',
- label: 'Collapse'
- }
- ]
- }
- ]
- }
- ]
- const generateData = () => {
- const data: {
- value: number
- desc: string
- disabled: boolean
- }[] = []
- for (let i = 1; i <= 15; i++) {
- data.push({
- value: i,
- desc: `Option ${i}`,
- disabled: i % 4 === 0
- })
- }
- return data
- }
- const holidays = [
- '2021-10-01',
- '2021-10-02',
- '2021-10-03',
- '2021-10-04',
- '2021-10-05',
- '2021-10-06',
- '2021-10-07'
- ]
- const isHoliday = ({ dayjs }) => {
- return holidays.includes(dayjs.format('YYYY-MM-DD'))
- }
- const schema = reactive<FormSchema[]>([
- {
- field: 'field1',
- label: t('formDemo.input'),
- component: 'Divider'
- },
- {
- field: 'field2',
- label: t('formDemo.default'),
- component: 'Input',
- componentProps: {
- formatter: (value) => `$ ${value}`.replace(/\B(?=(\d{3})+(?!\d))/g, ','),
- parser: (value) => value.replace(/\$\s?|(,*)/g, '')
- }
- },
- {
- field: 'field3',
- label: `${t('formDemo.icon')}1`,
- component: 'Input',
- componentProps: {
- suffixIcon: useIcon({ icon: 'ep:calendar' }),
- prefixIcon: useIcon({ icon: 'ep:share' })
- }
- },
- {
- field: 'field4',
- label: `${t('formDemo.icon')}2`,
- component: 'Input',
- componentProps: {
- slots: {
- suffix: () => {
- return useIcon({ icon: 'ep:share' })
- },
- prefix: () => useIcon({ icon: 'ep:calendar' })
- }
- }
- },
- {
- field: 'field5',
- label: t('formDemo.mixed'),
- component: 'Input',
- componentProps: {
- slots: {
- prepend: () => useIcon({ icon: 'ep:calendar' }),
- append: () => useIcon({ icon: 'ep:share' })
- }
- }
- },
- {
- field: 'input-field7',
- label: t('formDemo.password'),
- component: 'Input',
- componentProps: {
- showPassword: true
- }
- },
- {
- field: 'field6',
- label: t('formDemo.textarea'),
- component: 'Input',
- componentProps: {
- type: 'textarea',
- rows: 2
- }
- },
- {
- field: 'field7',
- label: t('formDemo.autocomplete'),
- component: 'Divider'
- },
- {
- field: 'field8',
- label: t('formDemo.default'),
- component: 'Autocomplete',
- componentProps: {
- fetchSuggestions: querySearch,
- on: {
- select: handleSelect
- }
- }
- },
- {
- field: 'field9',
- label: t('formDemo.slot'),
- component: 'Autocomplete',
- componentProps: {
- fetchSuggestions: querySearch,
- on: {
- select: handleSelect
- },
- slots: {
- default: ({ item }) => {
- return (
- <>
- <div class="value">{item?.value}</div>
- <span class="link">{item?.link}</span>
- </>
- )
- }
- }
- }
- },
- {
- field: 'autocomplete-field10',
- label: t('formDemo.remoteSearch'),
- component: 'Autocomplete',
- componentProps: {
- fetchSuggestions: querySearchAsync,
- on: {
- select: handleSelect
- }
- }
- },
- {
- field: 'field10',
- component: 'Divider',
- label: t('formDemo.inputNumber')
- },
- {
- field: 'field11',
- label: t('formDemo.default'),
- component: 'InputNumber',
- value: 0
- },
- {
- field: 'field12',
- label: t('formDemo.position'),
- component: 'InputNumber',
- componentProps: {
- controlsPosition: 'right'
- },
- value: 10
- },
- {
- field: 'field13',
- label: t('formDemo.select'),
- component: 'Divider'
- },
- {
- field: 'field14',
- label: t('formDemo.default'),
- component: 'Select',
- componentProps: {
- options: [
- {
- disabled: true,
- label: 'option1',
- value: '1'
- },
- {
- label: 'option2',
- value: '2'
- }
- ]
- }
- },
- {
- field: 'field15',
- label: t('formDemo.slot'),
- component: 'Select',
- componentProps: {
- options: [
- {
- label: 'option1',
- value: '1'
- },
- {
- label: 'option2',
- value: '2'
- }
- ],
- slots: {
- default: (options: SelectOption[]) => {
- if (options.length) {
- return options?.map((v) => {
- return <ElOption key={v.value} label={v.label} value={v.value} />
- })
- } else {
- return null
- }
- },
- prefix: () => useIcon({ icon: 'ep:calendar' }),
- empty: () => {
- return useIcon({ icon: 'ep:share' })
- }
- }
- }
- },
- {
- field: 'select-field18',
- label: t('formDemo.optionSlot'),
- component: 'Select',
- componentProps: {
- options: [
- {
- value: 'Beijing',
- label: 'Beijing'
- },
- {
- value: 'Shanghai',
- label: 'Shanghai'
- },
- {
- value: 'Nanjing',
- label: 'Nanjing'
- },
- {
- value: 'Chengdu',
- label: 'Chengdu'
- },
- {
- value: 'Shenzhen',
- label: 'Shenzhen'
- },
- {
- value: 'Guangzhou',
- label: 'Guangzhou'
- }
- ],
- slots: {
- optionDefault: (option: SelectOption) => {
- return (
- <>
- <span style="float: left">{option.label}</span>
- <span style="float: right; color: var(--el-text-color-secondary); font-size: 13px;">
- {option.value}
- </span>
- </>
- )
- }
- }
- }
- },
- {
- field: 'field16',
- label: t('formDemo.selectGroup'),
- component: 'Select',
- componentProps: {
- options: [
- {
- label: 'option1',
- options: [
- {
- disabled: true,
- label: 'option1-1',
- value: '1-1'
- },
- {
- label: 'option1-2',
- value: '1-2'
- }
- ]
- },
- {
- label: 'option2',
- options: [
- {
- label: 'option2-1',
- value: '2-1'
- },
- {
- label: 'option2-2',
- value: '2-2'
- }
- ]
- }
- ]
- }
- },
- {
- field: 'field17',
- label: `${t('formDemo.selectGroup')} ${t('formDemo.slot')}`,
- component: 'Select',
- componentProps: {
- options: [
- {
- label: 'option1',
- options: [
- {
- label: 'option1-1',
- value: '1-1'
- },
- {
- label: 'option1-2',
- value: '1-2'
- }
- ]
- },
- {
- label: 'option2',
- options: [
- {
- label: 'option2-1',
- value: '2-1'
- },
- {
- label: 'option2-2',
- value: '2-2'
- }
- ]
- }
- ],
- slots: {
- optionGroupDefault: (option: SelectOption) => {
- return (
- <ElOptionGroup key={option.label} label={`${option.label} ${option.label}`}>
- {option?.options?.map((v) => {
- return <ElOption key={v.value} label={v.label} value={v.value} />
- })}
- </ElOptionGroup>
- )
- }
- }
- }
- },
- {
- field: 'field18',
- label: `${t('formDemo.selectV2')}`,
- component: 'Divider'
- },
- {
- field: 'field19',
- label: t('formDemo.default'),
- component: 'SelectV2',
- componentProps: {
- value: undefined,
- options: options.value
- }
- },
- {
- field: 'field20',
- label: t('formDemo.slot'),
- component: 'SelectV2',
- componentProps: {
- options: options.value,
- slots: {
- default: (option: SelectOption) => {
- return (
- <>
- <span style="margin-right: 8px">{option?.label}</span>
- <span style="color: var(--el-text-color-secondary); font-size: 13px">
- {option?.value}
- </span>
- </>
- )
- }
- }
- }
- },
- {
- field: 'field21',
- label: t('formDemo.selectGroup'),
- component: 'SelectV2',
- componentProps: {
- options: options2.value
- }
- },
- {
- field: 'field22',
- label: `${t('formDemo.selectGroup')} ${t('formDemo.slot')}`,
- component: 'SelectV2',
- componentProps: {
- options: options2.value,
- slots: {
- default: (option: SelectOption) => {
- return (
- <>
- <span style="margin-right: 8px">{option?.label}</span>
- <span style="color: var(--el-text-color-secondary); font-size: 13px">
- {option?.value}
- </span>
- </>
- )
- }
- }
- }
- },
- {
- field: 'field23',
- label: t('formDemo.cascader'),
- component: 'Divider'
- },
- {
- field: 'field24',
- label: t('formDemo.default'),
- component: 'Cascader',
- componentProps: {
- options: options3,
- props: {
- multiple: true
- }
- }
- },
- {
- field: 'field25',
- label: t('formDemo.slot'),
- component: 'Cascader',
- componentProps: {
- options: options3,
- slots: {
- default: ({ data, node }) => {
- return (
- <>
- <span>{data.label}</span>
- {!node.isLeaf ? <span> ({data.children.length}) </span> : null}
- </>
- )
- }
- }
- }
- },
- {
- field: 'field26',
- label: t('formDemo.switch'),
- component: 'Divider'
- },
- {
- field: 'field27',
- label: t('formDemo.default'),
- component: 'Switch',
- value: false
- },
- {
- field: 'field28',
- label: t('formDemo.icon'),
- component: 'Switch',
- value: false,
- componentProps: {
- activeIcon: useIcon({ icon: 'ep:check' }),
- inactiveIcon: useIcon({ icon: 'ep:close' })
- }
- },
- {
- field: 'field29',
- label: t('formDemo.rate'),
- component: 'Divider'
- },
- {
- field: 'field30',
- label: t('formDemo.default'),
- component: 'Rate',
- value: 0
- },
- {
- field: 'field31',
- label: t('formDemo.icon'),
- component: 'Rate',
- value: null,
- componentProps: {
- voidIcon: useIcon({ icon: 'ep:chat-round' }),
- icons: [
- useIcon({ icon: 'ep:chat-round' }),
- useIcon({ icon: 'ep:chat-line-round' }),
- useIcon({ icon: 'ep:chat-dot-round' })
- ]
- }
- },
- {
- field: 'field32',
- label: t('formDemo.colorPicker'),
- component: 'Divider'
- },
- {
- field: 'field33',
- label: t('formDemo.default'),
- component: 'ColorPicker'
- },
- {
- field: 'field34',
- label: t('formDemo.transfer'),
- component: 'Divider'
- },
- {
- field: 'field35',
- label: t('formDemo.default'),
- component: 'Transfer',
- componentProps: {
- props: {
- key: 'value',
- label: 'desc'
- },
- data: generateData()
- },
- value: [],
- colProps: {
- span: 24
- }
- },
- {
- field: 'field36',
- label: t('formDemo.slot'),
- component: 'Transfer',
- componentProps: {
- props: {
- key: 'value',
- label: 'desc'
- },
- filterable: true,
- leftDefaultChecked: [2, 3],
- rightDefaultChecked: [1],
- titles: ['Source', 'Target'],
- buttonTexts: ['To Left', 'To Right'],
- format: {
- noChecked: '${total}',
- hasChecked: '${checked}/${total}'
- },
- data: generateData(),
- slots: {
- default: ({ option }) => {
- return (
- <span>
- {option.value} - {option.desc}
- </span>
- )
- },
- leftFooter: () => {
- return (
- <ElButton class="transfer-footer" size="small">
- Operation
- </ElButton>
- )
- },
- rightFooter: () => {
- return (
- <ElButton class="transfer-footer" size="small">
- Operation
- </ElButton>
- )
- }
- }
- },
- value: [1],
- colProps: {
- span: 24
- }
- },
- {
- field: 'field37',
- label: `${t('formDemo.render')}`,
- component: 'Transfer',
- componentProps: {
- props: {
- key: 'value',
- label: 'desc',
- disabled: 'disabled'
- },
- leftDefaultChecked: [2, 3],
- rightDefaultChecked: [1],
- data: generateData(),
- renderContent: (h, option) => {
- return h('span', null, `${option.value} - ${option.desc}`)
- }
- },
- value: [1],
- colProps: {
- span: 24
- }
- },
- {
- field: 'field38',
- label: t('formDemo.radio'),
- component: 'Divider'
- },
- {
- field: 'field39-2',
- label: t('formDemo.radioGroup'),
- component: 'RadioGroup',
- componentProps: {
- options: [
- {
- // disabled: true,
- label: 'option-1',
- value: '1'
- },
- {
- label: 'option-2',
- value: '2'
- }
- ]
- }
- },
- {
- field: 'field39-3',
- label: `${t('formDemo.radioGroup')} ${t('formDemo.slot')}`,
- component: 'RadioGroup',
- componentProps: {
- options: [
- {
- // disabled: true,
- label: 'option-1',
- value: '1'
- },
- {
- label: 'option-2',
- value: '2'
- }
- ],
- slots: {
- default: (options: RadioOption[]) => {
- return options?.map((v) => {
- return (
- <ElRadio label={v.value}>
- {v.label}({v.value})
- </ElRadio>
- )
- })
- }
- }
- }
- },
- {
- field: 'field40',
- label: t('formDemo.button'),
- component: 'RadioButton',
- componentProps: {
- options: [
- {
- label: 'option-1',
- value: '1'
- },
- {
- label: 'option-2',
- value: '2'
- }
- ]
- }
- },
- {
- field: 'field40-1',
- label: `${t('formDemo.button')} ${t('formDemo.slot')}`,
- component: 'RadioButton',
- componentProps: {
- options: [
- {
- label: 'option-1',
- value: '1'
- },
- {
- label: 'option-2',
- value: '2'
- }
- ],
- slots: {
- default: (options: RadioOption[]) => {
- return options?.map((v) => {
- return (
- <ElRadioButton label={v.value}>
- {v.label}({v.value})
- </ElRadioButton>
- )
- })
- }
- }
- }
- },
- {
- field: 'field41',
- label: t('formDemo.checkbox'),
- component: 'Divider'
- },
- {
- field: 'field42-2',
- label: t('formDemo.checkboxGroup'),
- component: 'CheckboxGroup',
- value: [],
- componentProps: {
- options: [
- {
- label: 'option-1',
- value: '1'
- },
- {
- label: 'option-2',
- value: '2'
- },
- {
- label: 'option-3',
- value: '3'
- }
- ]
- }
- },
- {
- field: 'field42-3',
- label: `${t('formDemo.checkboxGroup')} ${t('formDemo.slot')}`,
- component: 'CheckboxGroup',
- value: [],
- componentProps: {
- options: [
- {
- label: 'option-1',
- value: '1'
- },
- {
- label: 'option-2',
- value: '2'
- },
- {
- label: 'option-3',
- value: '3'
- }
- ],
- slots: {
- default: (options: CheckboxOption[]) => {
- return options?.map((v) => {
- return (
- <ElCheckbox label={v.value}>
- {v.label}({v.value})
- </ElCheckbox>
- )
- })
- }
- }
- }
- },
- {
- field: 'field43',
- label: t('formDemo.button'),
- component: 'CheckboxButton',
- value: [],
- componentProps: {
- options: [
- {
- disabled: true,
- label: 'option-1',
- value: '1'
- },
- {
- label: 'option-2',
- value: '2'
- },
- {
- label: 'option-3',
- value: '23'
- }
- ]
- }
- },
- {
- field: 'field43-1',
- label: `${t('formDemo.button')} ${t('formDemo.slot')}`,
- component: 'CheckboxButton',
- value: [],
- componentProps: {
- options: [
- {
- disabled: true,
- label: 'option-1',
- value: '1'
- },
- {
- label: 'option-2',
- value: '2'
- },
- {
- label: 'option-3',
- value: '23'
- }
- ],
- slots: {
- default: (options: CheckboxOption[]) => {
- return options?.map((v) => {
- return (
- <ElCheckboxButton label={v.value}>
- {v.label}({v.value})
- </ElCheckboxButton>
- )
- })
- }
- }
- }
- },
- {
- field: 'field44',
- component: 'Divider',
- label: t('formDemo.slider')
- },
- {
- field: 'field45',
- component: 'Slider',
- label: t('formDemo.default'),
- value: 0
- },
- {
- field: 'field46',
- component: 'Divider',
- label: t('formDemo.datePicker')
- },
- {
- field: 'field47',
- component: 'DatePicker',
- label: t('formDemo.default'),
- componentProps: {
- type: 'date'
- }
- },
- {
- field: 'field48',
- component: 'DatePicker',
- label: t('formDemo.shortcuts'),
- componentProps: {
- type: 'date',
- disabledDate: (time: Date) => {
- return time.getTime() > Date.now()
- },
- shortcuts: [
- {
- text: t('formDemo.today'),
- value: new Date()
- },
- {
- text: t('formDemo.yesterday'),
- value: () => {
- const date = new Date()
- date.setTime(date.getTime() - 3600 * 1000 * 24)
- return date
- }
- },
- {
- text: t('formDemo.aWeekAgo'),
- value: () => {
- const date = new Date()
- date.setTime(date.getTime() - 3600 * 1000 * 24 * 7)
- return date
- }
- }
- ]
- }
- },
- {
- field: 'field47-1',
- component: 'DatePicker',
- label: t('formDemo.slot'),
- value: '2021-10-29',
- componentProps: {
- type: 'date',
- slots: {
- default: (cell: any) => {
- return (
- <div class={{ cell: true, current: cell.isCurrent }}>
- <span class="text">{cell.text}</span>
- {isHoliday(cell) ? <span class="holiday" /> : null}
- </div>
- )
- }
- }
- }
- },
- {
- field: 'field49',
- component: 'DatePicker',
- label: t('formDemo.week'),
- componentProps: {
- type: 'week',
- format: `[${t('formDemo.week')}]`
- }
- },
- {
- field: 'field50',
- component: 'DatePicker',
- label: t('formDemo.year'),
- componentProps: {
- type: 'year'
- }
- },
- {
- field: 'field51',
- component: 'DatePicker',
- label: t('formDemo.month'),
- componentProps: {
- type: 'month'
- }
- },
- {
- field: 'field52',
- component: 'DatePicker',
- label: t('formDemo.dates'),
- componentProps: {
- type: 'dates'
- }
- },
- {
- field: 'field53',
- component: 'DatePicker',
- label: t('formDemo.daterange'),
- componentProps: {
- type: 'daterange'
- }
- },
- {
- field: 'field54',
- component: 'DatePicker',
- label: t('formDemo.monthrange'),
- componentProps: {
- type: 'monthrange'
- }
- },
- {
- field: 'field56',
- component: 'Divider',
- label: t('formDemo.dateTimePicker')
- },
- {
- field: 'field57',
- component: 'DatePicker',
- label: t('formDemo.default'),
- componentProps: {
- type: 'datetime'
- }
- },
- {
- field: 'field58',
- component: 'DatePicker',
- label: t('formDemo.shortcuts'),
- componentProps: {
- type: 'datetime',
- shortcuts: [
- {
- text: t('formDemo.today'),
- value: new Date()
- },
- {
- text: t('formDemo.yesterday'),
- value: () => {
- const date = new Date()
- date.setTime(date.getTime() - 3600 * 1000 * 24)
- return date
- }
- },
- {
- text: t('formDemo.aWeekAgo'),
- value: () => {
- const date = new Date()
- date.setTime(date.getTime() - 3600 * 1000 * 24 * 7)
- return date
- }
- }
- ]
- }
- },
- {
- field: 'field59',
- component: 'DatePicker',
- label: t('formDemo.dateTimerange'),
- componentProps: {
- type: 'datetimerange'
- }
- },
- {
- field: 'field60',
- component: 'Divider',
- label: t('formDemo.timePicker')
- },
- {
- field: 'field61',
- component: 'TimePicker',
- label: t('formDemo.default')
- },
- {
- field: 'field62',
- component: 'Divider',
- label: t('formDemo.timeSelect')
- },
- {
- field: 'field63',
- component: 'TimeSelect',
- label: t('formDemo.default')
- },
- {
- field: 'field64',
- component: 'Divider',
- label: t('formDemo.richText')
- },
- {
- field: 'field65',
- component: 'Editor',
- value: 'hello world',
- label: t('formDemo.default'),
- colProps: {
- span: 24
- }
- },
- {
- field: 'field66',
- component: 'Divider',
- label: t('formDemo.inputPassword')
- },
- {
- field: 'field67',
- component: 'InputPassword',
- label: t('formDemo.default'),
- componentProps: {
- strength: true
- }
- },
- {
- field: 'field68',
- component: 'Divider',
- label: `${t('formDemo.form')} ${t('formDemo.slot')}`
- },
- {
- field: 'field69',
- component: 'Input',
- label: `label`,
- formItemProps: {
- slots: {
- label: ({ label }) => {
- return (
- <div class="custom-label">
- <span class="label-text">custom {label}</span>
- </div>
- )
- }
- }
- }
- },
- {
- field: 'field70',
- component: 'Divider',
- label: `${t('formDemo.remoteLoading')}`
- },
- {
- field: 'field71',
- label: `${t('formDemo.select')}`,
- component: 'Select',
- componentProps: {
- options: []
- },
- // 远程加载option
- optionApi: async () => {
- const res = await getDictOneApi()
- return res.data
- }
- }
- ])
- const { register, formRef, methods } = useForm()
- </script>
- <template>
- <ContentWrap :title="t('formDemo.defaultForm')" :message="t('formDemo.formDes')">
- <Form
- @register="register"
- :schema="schema"
- label-width="auto"
- :label-position="isMobile ? 'top' : 'right'"
- />
- </ContentWrap>
- </template>
- <style lang="less">
- .cell {
- height: 30px;
- padding: 3px 0;
- box-sizing: border-box;
- .text {
- width: 24px;
- height: 24px;
- display: block;
- margin: 0 auto;
- line-height: 24px;
- position: absolute;
- left: 50%;
- transform: translateX(-50%);
- border-radius: 50%;
- }
- &.current {
- .text {
- color: #fff;
- background: #626aef;
- }
- }
- .holiday {
- position: absolute;
- width: 6px;
- height: 6px;
- background: var(--el-color-danger);
- border-radius: 50%;
- bottom: 0px;
- left: 50%;
- transform: translateX(-50%);
- }
- }
- .transfer-footer {
- margin-left: 15px;
- padding: 6px 5px;
- }
- </style>
|