123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452 |
- <script setup lang="tsx">
- import { Form } from '@/components/Form'
- import { reactive, ref, onMounted, computed, unref } 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'
- const appStore = useAppStore()
- const { t } = useI18n()
- const isMobile = computed(() => appStore.getMobile)
- const toggle = ref(false)
- 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}
- disabled={unref(toggle)}
- 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'),
- componentProps: {
- editorConfig: {
- placeholder: '请输入内容...'
- }
- },
- 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',
- value: 'test',
- label: `default`,
- },
- ])
- const { register, formRef, methods } = useForm({
- schema,
- labelWidth: 'auto',
- labelPosition: isMobile.value ? 'top' : 'right'
- })
- const changeToggle = () => {
- toggle.value = !unref(toggle)
- }
- </script>
- <template>
- <button @click="changeToggle">测试</button>
- <ContentWrap :title="t('formDemo.defaultForm')" :message="t('formDemo.formDes')">
- <Form @register="register" label-width="auto" :label-position="isMobile ? 'top' : 'right'">
- </Form>
- </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>
|