123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362 |
- <script setup lang="ts">
- import { ContentWrap } from '@/components/ContentWrap'
- import { useI18n } from '@/hooks/web/useI18n'
- import { Search } from '@/components/Search'
- import { reactive, ref, unref } from 'vue'
- import { ElButton } from 'element-plus'
- import { getDictOneApi } from '@/api/common'
- import { FormSchema } from '@/components/Form'
- import { useSearch } from '@/hooks/web/useSearch'
- const { t } = useI18n()
- const { searchRegister, searchMethods } = useSearch()
- const { setSchema, setProps, setValues } = searchMethods
- const treeSelectData = [
- {
- value: '1',
- label: 'Level one 1',
- children: [
- {
- value: '1-1',
- label: 'Level two 1-1',
- children: [
- {
- value: '1-1-1',
- label: 'Level three 1-1-1'
- }
- ]
- }
- ]
- },
- {
- value: '2',
- label: 'Level one 2',
- children: [
- {
- value: '2-1',
- label: 'Level two 2-1',
- children: [
- {
- value: '2-1-1',
- label: 'Level three 2-1-1'
- }
- ]
- },
- {
- value: '2-2',
- label: 'Level two 2-2',
- children: [
- {
- value: '2-2-1',
- label: 'Level three 2-2-1'
- }
- ]
- }
- ]
- },
- {
- value: '3',
- label: 'Level one 3',
- children: [
- {
- value: '3-1',
- label: 'Level two 3-1',
- children: [
- {
- value: '3-1-1',
- label: 'Level three 3-1-1'
- }
- ]
- },
- {
- value: '3-2',
- label: 'Level two 3-2',
- children: [
- {
- value: '3-2-1',
- label: 'Level three 3-2-1'
- }
- ]
- }
- ]
- }
- ]
- // 模拟远程加载
- const getTreeSelectData = () => {
- return new Promise((resolve) => {
- setTimeout(() => {
- resolve(treeSelectData)
- }, 3000)
- })
- }
- const schema = reactive<FormSchema[]>([
- {
- field: 'field1',
- label: t('formDemo.input'),
- component: 'Input'
- },
- {
- field: 'field2',
- label: t('formDemo.select'),
- component: 'Select',
- componentProps: {
- options: [
- {
- label: 'option1',
- value: '1'
- },
- {
- label: 'option2',
- value: '2'
- }
- ],
- on: {
- change: (value: string) => {
- console.log(value)
- }
- }
- }
- },
- {
- field: 'field3',
- label: t('formDemo.radio'),
- component: 'RadioGroup',
- componentProps: {
- options: [
- {
- label: 'option-1',
- value: '1'
- },
- {
- label: 'option-2',
- value: '2'
- }
- ]
- }
- },
- {
- field: 'field5',
- component: 'DatePicker',
- label: t('formDemo.datePicker'),
- componentProps: {
- type: 'date'
- }
- },
- {
- field: 'field6',
- component: 'TimeSelect',
- label: t('formDemo.timeSelect')
- },
- {
- field: 'field8',
- label: t('formDemo.input'),
- component: 'Input'
- },
- {
- field: 'field9',
- label: t('formDemo.input'),
- component: 'Input'
- },
- {
- field: 'field10',
- label: t('formDemo.input'),
- component: 'Input'
- },
- {
- field: 'field11',
- label: t('formDemo.input'),
- component: 'Input'
- },
- {
- field: 'field12',
- label: t('formDemo.input'),
- component: 'Input'
- },
- {
- field: 'field13',
- label: t('formDemo.input'),
- component: 'Input'
- },
- {
- field: 'field14',
- label: t('formDemo.input'),
- component: 'Input'
- },
- {
- field: 'field15',
- label: t('formDemo.input'),
- component: 'Input'
- },
- {
- field: 'field16',
- label: t('formDemo.input'),
- component: 'Input'
- },
- {
- field: 'field17',
- label: t('formDemo.input'),
- component: 'Input'
- },
- {
- field: 'field18',
- label: t('formDemo.input'),
- component: 'Input'
- },
- {
- field: 'field19',
- label: `${t('formDemo.treeSelect')}`,
- component: 'TreeSelect',
- // 远程加载option
- optionApi: async () => {
- const res = await getTreeSelectData()
- return res
- }
- }
- ])
- const isGrid = ref(false)
- const changeGrid = (grid: boolean) => {
- setProps({
- isCol: grid
- })
- // isGrid.value = grid
- }
- const layout = ref('inline')
- const changeLayout = () => {
- layout.value = unref(layout) === 'inline' ? 'bottom' : 'inline'
- }
- const buttonPosition = ref('left')
- const changePosition = (position: string) => {
- layout.value = 'bottom'
- buttonPosition.value = position
- }
- const getDictOne = async () => {
- const res = await getDictOneApi()
- if (res) {
- setSchema([
- {
- field: 'field2',
- path: 'componentProps.options',
- value: res.data
- }
- ])
- }
- }
- const handleSearch = (data: any) => {
- console.log(data)
- }
- const delRadio = () => {
- setSchema([
- {
- field: 'field3',
- path: 'remove',
- value: true
- }
- ])
- }
- const restoreRadio = () => {
- setSchema([
- {
- field: 'field3',
- path: 'remove',
- value: false
- }
- ])
- }
- const setValue = () => {
- setValues({
- field1: 'Joy'
- })
- }
- const searchLoading = ref(false)
- const changeSearchLoading = () => {
- searchLoading.value = true
- setTimeout(() => {
- searchLoading.value = false
- }, 2000)
- }
- const resetLoading = ref(false)
- const changeResetLoading = () => {
- resetLoading.value = true
- setTimeout(() => {
- resetLoading.value = false
- }, 2000)
- }
- </script>
- <template>
- <ContentWrap
- :title="`${t('searchDemo.search')} ${t('searchDemo.operate')}`"
- style="margin-bottom: 20px"
- >
- <ElButton @click="changeGrid(true)">{{ t('searchDemo.grid') }}</ElButton>
- <ElButton @click="changeGrid(false)">
- {{ t('searchDemo.restore') }} {{ t('searchDemo.grid') }}
- </ElButton>
- <ElButton @click="changeLayout">
- {{ t('searchDemo.button') }} {{ t('searchDemo.position') }}
- </ElButton>
- <ElButton @click="changePosition('left')">
- {{ t('searchDemo.bottom') }} {{ t('searchDemo.position') }}-{{ t('searchDemo.left') }}
- </ElButton>
- <ElButton @click="changePosition('center')">
- {{ t('searchDemo.bottom') }} {{ t('searchDemo.position') }}-{{ t('searchDemo.center') }}
- </ElButton>
- <ElButton @click="changePosition('right')">
- {{ t('searchDemo.bottom') }} {{ t('searchDemo.position') }}-{{ t('searchDemo.right') }}
- </ElButton>
- <ElButton @click="getDictOne">
- {{ t('formDemo.select') }} {{ t('searchDemo.dynamicOptions') }}
- </ElButton>
- <ElButton @click="delRadio">{{ t('searchDemo.deleteRadio') }}</ElButton>
- <ElButton @click="restoreRadio">{{ t('searchDemo.restoreRadio') }}</ElButton>
- <ElButton @click="setValue">{{ t('formDemo.setValue') }}</ElButton>
- <ElButton @click="changeSearchLoading">
- {{ t('searchDemo.search') }} {{ t('searchDemo.loading') }}
- </ElButton>
- <ElButton @click="changeResetLoading">
- {{ t('searchDemo.reset') }} {{ t('searchDemo.loading') }}
- </ElButton>
- </ContentWrap>
- <ContentWrap :title="t('searchDemo.search')" :message="t('searchDemo.searchDes')">
- <Search
- :schema="schema"
- :is-col="isGrid"
- :layout="layout"
- :button-position="buttonPosition"
- :search-loading="searchLoading"
- :reset-loading="resetLoading"
- show-expand
- expand-field="field6"
- @search="handleSearch"
- @reset="handleSearch"
- @register="searchRegister"
- />
- </ContentWrap>
- </template>
- <style lang="less" scoped>
- .el-button {
- margin-top: 10px;
- }
- </style>
|