2021-12-08 10:47:33 +08:00
|
|
|
<script setup lang="ts">
|
2021-12-16 17:15:03 +08:00
|
|
|
import { reactive, ref, onMounted } from 'vue'
|
2021-12-16 14:32:20 +08:00
|
|
|
import { ElConfigProvider, ElIcon } from 'element-plus'
|
2021-12-11 11:46:10 +08:00
|
|
|
import zhCn from 'element-plus/lib/locale/lang/zh-cn'
|
|
|
|
// import en from 'element-plus/lib/locale/lang/en'
|
2021-12-16 14:32:20 +08:00
|
|
|
import { VFrom } from '@/components/Form'
|
|
|
|
import Calendar from '~icons/ep/calendar'
|
2021-12-16 17:15:03 +08:00
|
|
|
import { useI18n } from '@/hooks/web/useI18n'
|
|
|
|
const { t } = useI18n()
|
|
|
|
|
|
|
|
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)
|
|
|
|
}
|
|
|
|
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()
|
|
|
|
})
|
2021-12-11 20:50:05 +08:00
|
|
|
|
2021-12-17 15:10:39 +08:00
|
|
|
const initials = ['a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j']
|
|
|
|
const options = ref<FormOptions[]>(
|
|
|
|
Array.from({ length: 1000 }).map((_, idx) => ({
|
|
|
|
value: `Option ${idx + 1}`,
|
|
|
|
label: `${initials[idx % 10]}${idx}`
|
|
|
|
}))
|
|
|
|
)
|
|
|
|
const options2 = ref<FormOptions[]>(
|
|
|
|
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}`
|
|
|
|
}))
|
|
|
|
}
|
|
|
|
})
|
|
|
|
)
|
|
|
|
|
2021-12-14 17:42:43 +08:00
|
|
|
const schema = reactive<VFormSchema[]>([
|
|
|
|
{
|
|
|
|
field: 'field1',
|
2021-12-16 17:15:03 +08:00
|
|
|
label: t('formDemo.input'),
|
|
|
|
component: 'Divider'
|
2021-12-15 21:26:14 +08:00
|
|
|
},
|
|
|
|
{
|
|
|
|
field: 'field2',
|
2021-12-16 17:15:03 +08:00
|
|
|
label: t('formDemo.default'),
|
2021-12-14 17:42:43 +08:00
|
|
|
component: 'Input'
|
2021-12-16 14:32:20 +08:00
|
|
|
},
|
|
|
|
{
|
|
|
|
field: 'field3',
|
2021-12-16 17:15:03 +08:00
|
|
|
label: `${t('formDemo.icon')}1`,
|
2021-12-16 14:32:20 +08:00
|
|
|
component: 'Input',
|
|
|
|
componentProps: {
|
|
|
|
suffixIcon: Calendar,
|
|
|
|
prefixIcon: Calendar
|
|
|
|
}
|
|
|
|
},
|
|
|
|
{
|
|
|
|
field: 'field4',
|
2021-12-16 17:15:03 +08:00
|
|
|
label: `${t('formDemo.icon')}2`,
|
2021-12-16 14:32:20 +08:00
|
|
|
component: 'Input',
|
|
|
|
componentProps: {
|
|
|
|
slots: {
|
|
|
|
suffix: true,
|
|
|
|
prefix: true
|
|
|
|
}
|
|
|
|
}
|
|
|
|
},
|
|
|
|
{
|
|
|
|
field: 'field5',
|
2021-12-16 17:15:03 +08:00
|
|
|
label: t('formDemo.mixed'),
|
2021-12-16 14:32:20 +08:00
|
|
|
component: 'Input',
|
|
|
|
componentProps: {
|
|
|
|
slots: {
|
|
|
|
prepend: true,
|
|
|
|
append: true
|
|
|
|
}
|
|
|
|
}
|
|
|
|
},
|
|
|
|
{
|
|
|
|
field: 'field6',
|
2021-12-16 17:15:03 +08:00
|
|
|
label: t('formDemo.textarea'),
|
2021-12-16 14:32:20 +08:00
|
|
|
component: 'Input',
|
|
|
|
componentProps: {
|
|
|
|
type: 'textarea',
|
|
|
|
rows: 1
|
|
|
|
}
|
|
|
|
},
|
|
|
|
{
|
|
|
|
field: 'field7',
|
2021-12-16 17:15:03 +08:00
|
|
|
label: t('formDemo.autocomplete'),
|
|
|
|
component: 'Divider'
|
|
|
|
},
|
|
|
|
{
|
|
|
|
field: 'field8',
|
|
|
|
label: t('formDemo.default'),
|
|
|
|
component: 'Autocomplete',
|
|
|
|
componentProps: {
|
|
|
|
fetchSuggestions: querySearch,
|
|
|
|
onSelect: handleSelect
|
|
|
|
}
|
|
|
|
},
|
|
|
|
{
|
|
|
|
field: 'field9',
|
|
|
|
label: t('formDemo.slot'),
|
|
|
|
component: 'Autocomplete',
|
|
|
|
componentProps: {
|
|
|
|
fetchSuggestions: querySearch,
|
|
|
|
onSelect: handleSelect,
|
|
|
|
slots: {
|
|
|
|
default: true
|
|
|
|
}
|
|
|
|
}
|
|
|
|
},
|
|
|
|
{
|
|
|
|
field: 'field10',
|
2021-12-16 14:32:20 +08:00
|
|
|
component: 'Divider',
|
|
|
|
componentProps: {
|
2021-12-16 17:15:03 +08:00
|
|
|
text: t('formDemo.inputNumber')
|
2021-12-16 14:32:20 +08:00
|
|
|
}
|
2021-12-16 17:15:03 +08:00
|
|
|
},
|
|
|
|
{
|
|
|
|
field: 'field11',
|
|
|
|
label: t('formDemo.default'),
|
|
|
|
component: 'InputNumber'
|
|
|
|
},
|
|
|
|
{
|
|
|
|
field: 'field11',
|
|
|
|
label: t('formDemo.position'),
|
|
|
|
component: 'InputNumber',
|
|
|
|
componentProps: {
|
|
|
|
controlsPosition: 'right'
|
|
|
|
}
|
|
|
|
},
|
|
|
|
{
|
|
|
|
field: 'field12',
|
|
|
|
label: t('formDemo.select'),
|
|
|
|
component: 'Divider'
|
|
|
|
},
|
|
|
|
{
|
|
|
|
field: 'field13',
|
|
|
|
label: t('formDemo.default'),
|
|
|
|
component: 'Select',
|
|
|
|
options: [
|
|
|
|
{
|
|
|
|
label: '选项1',
|
|
|
|
value: '1'
|
|
|
|
},
|
|
|
|
{
|
|
|
|
label: '选项2',
|
|
|
|
value: '2'
|
|
|
|
}
|
|
|
|
]
|
|
|
|
},
|
|
|
|
{
|
|
|
|
field: 'field14',
|
|
|
|
label: t('formDemo.slot'),
|
|
|
|
component: 'Select',
|
|
|
|
options: [
|
|
|
|
{
|
|
|
|
label: '选项1',
|
|
|
|
value: '1'
|
|
|
|
},
|
|
|
|
{
|
|
|
|
label: '选项2',
|
|
|
|
value: '2'
|
|
|
|
}
|
|
|
|
],
|
|
|
|
optionsSlot: true
|
|
|
|
},
|
|
|
|
{
|
|
|
|
field: 'field15',
|
|
|
|
label: t('formDemo.group'),
|
|
|
|
component: 'Select',
|
|
|
|
options: [
|
|
|
|
{
|
|
|
|
label: '选项1',
|
|
|
|
options: [
|
|
|
|
{
|
|
|
|
label: '选项1-1',
|
|
|
|
value: '1-1'
|
|
|
|
},
|
|
|
|
{
|
|
|
|
label: '选项1-2',
|
|
|
|
value: '1-2'
|
|
|
|
}
|
|
|
|
]
|
|
|
|
},
|
|
|
|
{
|
|
|
|
label: '选项2',
|
|
|
|
options: [
|
|
|
|
{
|
|
|
|
label: '选项2-1',
|
|
|
|
value: '2-1'
|
|
|
|
},
|
|
|
|
{
|
|
|
|
label: '选项2-2',
|
|
|
|
value: '2-2'
|
|
|
|
}
|
|
|
|
]
|
|
|
|
}
|
|
|
|
]
|
|
|
|
},
|
|
|
|
{
|
|
|
|
field: 'field16',
|
|
|
|
label: `${t('formDemo.group')}${t('formDemo.slot')}`,
|
|
|
|
component: 'Select',
|
|
|
|
options: [
|
|
|
|
{
|
|
|
|
label: '选项1',
|
|
|
|
options: [
|
|
|
|
{
|
|
|
|
label: '选项1-1',
|
|
|
|
value: '1-1'
|
|
|
|
},
|
|
|
|
{
|
|
|
|
label: '选项1-2',
|
|
|
|
value: '1-2'
|
|
|
|
}
|
|
|
|
]
|
|
|
|
},
|
|
|
|
{
|
|
|
|
label: '选项2',
|
|
|
|
options: [
|
|
|
|
{
|
|
|
|
label: '选项2-1',
|
|
|
|
value: '2-1'
|
|
|
|
},
|
|
|
|
{
|
|
|
|
label: '选项2-2',
|
|
|
|
value: '2-2'
|
|
|
|
}
|
|
|
|
]
|
|
|
|
}
|
|
|
|
],
|
|
|
|
optionsSlot: true
|
2021-12-17 15:10:39 +08:00
|
|
|
},
|
|
|
|
{
|
|
|
|
field: 'field17',
|
|
|
|
label: `${t('formDemo.selectV2')}`,
|
|
|
|
component: 'Divider'
|
|
|
|
},
|
|
|
|
{
|
|
|
|
field: 'field18',
|
|
|
|
label: t('formDemo.default'),
|
|
|
|
component: 'SelectV2',
|
|
|
|
options: options.value
|
|
|
|
},
|
|
|
|
{
|
|
|
|
field: 'field18',
|
|
|
|
label: t('formDemo.slot'),
|
|
|
|
component: 'SelectV2',
|
|
|
|
options: options.value,
|
|
|
|
componentProps: {
|
|
|
|
slots: {
|
|
|
|
default: true
|
|
|
|
}
|
|
|
|
}
|
|
|
|
},
|
|
|
|
{
|
|
|
|
field: 'field19',
|
|
|
|
label: t('formDemo.group'),
|
|
|
|
component: 'SelectV2',
|
|
|
|
options: options2.value
|
|
|
|
},
|
|
|
|
{
|
|
|
|
field: 'field20',
|
|
|
|
label: `${t('formDemo.group')}${t('formDemo.slot')}`,
|
|
|
|
component: 'SelectV2',
|
|
|
|
options: options2.value,
|
|
|
|
componentProps: {
|
|
|
|
slots: {
|
|
|
|
default: true
|
|
|
|
}
|
|
|
|
}
|
2021-12-14 17:42:43 +08:00
|
|
|
}
|
|
|
|
])
|
2021-12-08 10:47:33 +08:00
|
|
|
</script>
|
|
|
|
|
2021-12-11 11:46:10 +08:00
|
|
|
<template>
|
|
|
|
<ElConfigProvider :locale="zhCn">
|
2021-12-16 14:32:20 +08:00
|
|
|
<VFrom :schema="schema">
|
|
|
|
<template #field4-prefix>
|
|
|
|
<ElIcon class="el-input__icon"><Calendar /></ElIcon>
|
|
|
|
</template>
|
|
|
|
<template #field4-suffix>
|
|
|
|
<ElIcon class="el-input__icon"><Calendar /></ElIcon>
|
|
|
|
</template>
|
|
|
|
|
|
|
|
<template #field5-prepend> Http:// </template>
|
|
|
|
<template #field5-append> .com </template>
|
2021-12-16 17:15:03 +08:00
|
|
|
|
|
|
|
<template #field9-default="{ item }">
|
|
|
|
<div class="value">{{ item.value }}</div>
|
|
|
|
<span class="link">{{ item.link }}</span>
|
|
|
|
</template>
|
|
|
|
|
2021-12-17 15:10:39 +08:00
|
|
|
<template #field14-option="{ item }">
|
|
|
|
<span style="float: left">{{ item.label }}</span>
|
|
|
|
<span style="float: right; font-size: 13px; color: var(--el-text-color-secondary)">
|
|
|
|
{{ item.value }}
|
|
|
|
</span>
|
|
|
|
</template>
|
|
|
|
|
|
|
|
<template #field16-option="{ item }">
|
|
|
|
<span style="float: left">{{ item.label }}</span>
|
|
|
|
<span style="float: right; font-size: 13px; color: var(--el-text-color-secondary)">
|
|
|
|
{{ item.value }}
|
|
|
|
</span>
|
|
|
|
</template>
|
|
|
|
|
|
|
|
<template #field18-default="{ item }">
|
2021-12-16 17:15:03 +08:00
|
|
|
<span style="float: left">{{ item.label }}</span>
|
2021-12-17 15:10:39 +08:00
|
|
|
<span style="float: right; font-size: 13px; color: var(--el-text-color-secondary)">
|
|
|
|
{{ item.value }}
|
|
|
|
</span>
|
2021-12-16 17:15:03 +08:00
|
|
|
</template>
|
|
|
|
|
2021-12-17 15:10:39 +08:00
|
|
|
<template #field20-default="{ item }">
|
2021-12-16 17:15:03 +08:00
|
|
|
<span style="float: left">{{ item.label }}</span>
|
2021-12-17 15:10:39 +08:00
|
|
|
<span style="float: right; font-size: 13px; color: var(--el-text-color-secondary)">
|
|
|
|
{{ item.value }}
|
|
|
|
</span>
|
2021-12-16 17:15:03 +08:00
|
|
|
</template>
|
2021-12-16 14:32:20 +08:00
|
|
|
</VFrom>
|
2021-12-11 11:46:10 +08:00
|
|
|
</ElConfigProvider>
|
|
|
|
</template>
|