From 33eca8a97d59f5cc453e1a60ee81b1519527d0f1 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E9=99=88=E5=87=AF=E9=BE=99?= <502431556@qq.com> Date: Fri, 28 Jan 2022 11:36:18 +0800 Subject: [PATCH] feat: Add Search component and add search demo --- src/components/Form/src/Form.vue | 12 ++- src/components/Search/index.ts | 3 + src/components/Search/src/Search.vue | 106 +++++++++++++++++++++++++ src/hooks/web/useForm.ts | 1 - src/locales/en.ts | 23 +++++- src/locales/zh-CN.ts | 22 +++++- src/router/index.ts | 8 ++ src/views/Components/Search.vue | 114 +++++++++++++++++++++++++++ 8 files changed, 281 insertions(+), 8 deletions(-) create mode 100644 src/components/Search/index.ts create mode 100644 src/components/Search/src/Search.vue create mode 100644 src/views/Components/Search.vue diff --git a/src/components/Form/src/Form.vue b/src/components/Form/src/Form.vue index 8867d6d..96bf9f4 100644 --- a/src/components/Form/src/Form.vue +++ b/src/components/Form/src/Form.vue @@ -52,10 +52,16 @@ export default defineComponent({ const elFormRef = ref>() // useForm传入的props - const outsideProps = ref({ ...props }) + const outsideProps = ref({}) const getProps = computed(() => { - return { ...props, ...unref(outsideProps) } + const propsObj = { ...props } + for (const key in unref(outsideProps)) { + if (Reflect.has(propsObj, key)) { + propsObj[key] = unref(outsideProps)[key] + } + } + return propsObj }) // 表单数据 @@ -71,7 +77,7 @@ export default defineComponent({ } const setProps = (props: FormProps = {}) => { - outsideProps.value = Object.assign(unref(formModel), props) + outsideProps.value = props } const delSchema = (field: string) => { diff --git a/src/components/Search/index.ts b/src/components/Search/index.ts new file mode 100644 index 0000000..fcc6f16 --- /dev/null +++ b/src/components/Search/index.ts @@ -0,0 +1,3 @@ +import Search from './src/Search.vue' + +export { Search } diff --git a/src/components/Search/src/Search.vue b/src/components/Search/src/Search.vue new file mode 100644 index 0000000..1a23edb --- /dev/null +++ b/src/components/Search/src/Search.vue @@ -0,0 +1,106 @@ + + + diff --git a/src/hooks/web/useForm.ts b/src/hooks/web/useForm.ts index 0745bba..21d2186 100644 --- a/src/hooks/web/useForm.ts +++ b/src/hooks/web/useForm.ts @@ -39,7 +39,6 @@ export const useForm = (props?: FormProps) => { } = { setProps: async (props: FormProps = {}) => { const form = await getForm() - console.log(form) form?.setProps(props) }, diff --git a/src/locales/en.ts b/src/locales/en.ts index cdae43c..9ef9480 100644 --- a/src/locales/en.ts +++ b/src/locales/en.ts @@ -29,7 +29,9 @@ export default { tagsView: 'Tags view', tagsViewDes: 'Used to record routing history', tool: 'Tool', - toolDes: 'Used to set up custom systems' + toolDes: 'Used to set up custom systems', + query: 'Query', + reset: 'Reset' }, setting: { projectSetting: 'Project setting', @@ -95,7 +97,8 @@ export default { highlight: 'Highlight', infotip: 'Infotip', form: 'Form', - defaultForm: 'All examples' + defaultForm: 'All examples', + search: 'Search' }, analysis: { newUser: 'New user', @@ -280,5 +283,21 @@ export default { }, levelDemo: { menu: 'Multi level menu cache' + }, + searchDemo: { + search: 'Search', + searchDes: + 'Based on the secondary encapsulation of form components, the functions of query and reset are realized', + operate: 'operate', + change: 'Change', + grid: 'grid', + button: 'Button', + restore: 'Restore', + inline: 'inline', + bottom: 'Bottom', + position: 'position', + left: 'left', + center: 'center', + right: 'right' } } diff --git a/src/locales/zh-CN.ts b/src/locales/zh-CN.ts index d6ce482..7a20101 100644 --- a/src/locales/zh-CN.ts +++ b/src/locales/zh-CN.ts @@ -29,7 +29,9 @@ export default { tagsView: '标签页', tagsViewDes: '用于记录路由历史记录', tool: '工具', - toolDes: '用于设置定制系统' + toolDes: '用于设置定制系统', + query: '查询', + reset: '重置' }, setting: { projectSetting: '项目配置', @@ -95,7 +97,8 @@ export default { highlight: '高亮', infotip: '信息提示', form: '表单', - defaultForm: '全部示例' + defaultForm: '全部示例', + search: '查询' }, analysis: { newUser: '新增用户', @@ -278,5 +281,20 @@ export default { }, levelDemo: { menu: '多级菜单缓存' + }, + searchDemo: { + search: '查询', + searchDes: '基于 Form 组件二次封装,实现查询、重置功能', + operate: '操作', + change: '更改', + grid: '栅格', + button: '按钮', + restore: '还原', + inline: '内联', + bottom: '底部', + position: '位置', + left: '左', + center: '中', + right: '右' } } diff --git a/src/router/index.ts b/src/router/index.ts index 491ce77..0f16f9e 100644 --- a/src/router/index.ts +++ b/src/router/index.ts @@ -131,6 +131,14 @@ export const asyncRouterMap: AppRouteRecordRaw[] = [ } ] }, + { + path: 'search', + component: () => import('@/views/Components/Search.vue'), + name: 'Search', + meta: { + title: t('router.search') + } + }, { path: 'icon', component: () => import('@/views/Components/Icon.vue'), diff --git a/src/views/Components/Search.vue b/src/views/Components/Search.vue new file mode 100644 index 0000000..d949ceb --- /dev/null +++ b/src/views/Components/Search.vue @@ -0,0 +1,114 @@ + + +