From ef35bde801a0720aa25e8264833c30a01aec017d 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, 11 Feb 2022 17:17:29 +0800
Subject: [PATCH] wip: example demo developing
---
mock/table/index.ts | 35 +++-
src/api/table/index.ts | 4 +
src/components/Form/src/componentMap.ts | 4 +-
src/components/Form/src/helper.ts | 2 +-
src/components/Search/src/Search.vue | 4 +-
src/components/Table/src/Table.vue | 5 +-
src/hooks/web/useTable.ts | 21 ++-
src/locales/en.ts | 17 +-
src/locales/zh-CN.ts | 17 +-
src/router/index.ts | 21 +++
src/views/Example/Dialog/ExampleDialog.vue | 170 ++++++++++++++++++
src/views/Example/Dialog/components/Write.vue | 136 ++++++++++++++
types/componentType/form.d.ts | 1 +
13 files changed, 425 insertions(+), 12 deletions(-)
create mode 100644 src/views/Example/Dialog/ExampleDialog.vue
create mode 100644 src/views/Example/Dialog/components/Write.vue
diff --git a/mock/table/index.ts b/mock/table/index.ts
index 5192e80..f06f7f5 100644
--- a/mock/table/index.ts
+++ b/mock/table/index.ts
@@ -12,7 +12,7 @@ const count = 100
const baseContent =
'
I am testing data, I am testing data.

'
-const List: {
+let List: {
id: string
author: string
title: string
@@ -39,7 +39,7 @@ for (let i = 0; i < count; i++) {
}
export default [
- // 登录接口
+ // 列表接口
{
url: '/example/list',
method: 'get',
@@ -61,5 +61,36 @@ export default [
}
}
}
+ },
+ // 保存接口
+ {
+ url: '/example/save',
+ method: 'post',
+ timeout,
+ response: ({ body }) => {
+ if (!body.id) {
+ List = [
+ Object.assign(body, {
+ id: toAnyString()
+ })
+ ].concat(List)
+ return {
+ code: result_code,
+ data: 'success'
+ }
+ } else {
+ List.map((item) => {
+ if (item.id === body.id) {
+ for (const key in item) {
+ item[key] = body[key]
+ }
+ }
+ })
+ return {
+ code: result_code,
+ data: 'success'
+ }
+ }
+ }
}
] as MockMethod[]
diff --git a/src/api/table/index.ts b/src/api/table/index.ts
index 6858589..ce0f685 100644
--- a/src/api/table/index.ts
+++ b/src/api/table/index.ts
@@ -9,3 +9,7 @@ export const getTableListApi = ({ params }: AxiosConfig) => {
list: TableData[]
}>({ url: '/example/list', method: 'get', params })
}
+
+export const saveTableApi = ({ data }: AxiosConfig) => {
+ return request({ url: '/example/save', method: 'post', data })
+}
diff --git a/src/components/Form/src/componentMap.ts b/src/components/Form/src/componentMap.ts
index e79bb98..822f64d 100644
--- a/src/components/Form/src/componentMap.ts
+++ b/src/components/Form/src/componentMap.ts
@@ -19,6 +19,7 @@ import {
ElDivider
} from 'element-plus'
import { InputPassword } from '@/components/InputPassword'
+import { Editor } from '@/components/Editor'
const componentMap: Recordable = {
Radio: ElRadioGroup,
@@ -40,7 +41,8 @@ const componentMap: Recordable = {
TimeSelect: ElTimeSelect,
SelectV2: ElSelectV2,
RadioButton: ElRadioGroup,
- InputPassword: InputPassword
+ InputPassword: InputPassword,
+ Editor: Editor
}
export { componentMap }
diff --git a/src/components/Form/src/helper.ts b/src/components/Form/src/helper.ts
index 60b3a3b..fbd7959 100644
--- a/src/components/Form/src/helper.ts
+++ b/src/components/Form/src/helper.ts
@@ -57,7 +57,7 @@ export const setGridProp = (col: ColProps = {}): ColProps => {
sm: 12,
md: 12,
lg: 12,
- xl: 8
+ xl: 12
}),
...col
}
diff --git a/src/components/Search/src/Search.vue b/src/components/Search/src/Search.vue
index 6a6b74b..b768002 100644
--- a/src/components/Search/src/Search.vue
+++ b/src/components/Search/src/Search.vue
@@ -112,7 +112,7 @@ const setVisible = () => {
{{ t('common.reset') }}
-
+
{{ t(visible ? 'common.shrink' : 'common.expand') }}
@@ -130,7 +130,7 @@ const setVisible = () => {
{{ t('common.reset') }}
-
+
{{ t(visible ? 'common.shrink' : 'common.expand') }}
diff --git a/src/components/Table/src/Table.vue b/src/components/Table/src/Table.vue
index 2fedbc6..5dd850e 100644
--- a/src/components/Table/src/Table.vue
+++ b/src/components/Table/src/Table.vue
@@ -259,13 +259,12 @@ export default defineComponent({
}
return () => (
- <>
+
{{
default: () => rnderTableColumn(),
@@ -281,7 +280,7 @@ export default defineComponent({
{...unref(pagination)}
>
) : undefined}
- >
+
)
}
})
diff --git a/src/hooks/web/useTable.ts b/src/hooks/web/useTable.ts
index a2c8cde..4be92df 100644
--- a/src/hooks/web/useTable.ts
+++ b/src/hooks/web/useTable.ts
@@ -22,6 +22,8 @@ interface TableObject {
tableList: K[]
parmasObj: L
loading: boolean
+ dialogVisible: boolean
+ currentRow: Nullable
}
export const useTable = (
@@ -39,7 +41,11 @@ export const useTable = (
// AxiosConfig 配置
parmasObj: {} as L,
// 加载中
- loading: true
+ loading: true,
+ // 弹窗
+ dialogVisible: false,
+ // 当前行的数据
+ currentRow: null
})
const parmasObj = computed(() => {
@@ -93,6 +99,7 @@ export const useTable = (
setProps: (props: Recordable) => void
getList: () => Promise
setColumn: (columnProps: TableSetPropsType[]) => void
+ setSearchParmas: (data: Recordable) => void
} = {
getList: async () => {
tableObject.loading = true
@@ -114,6 +121,18 @@ export const useTable = (
setColumn: async (columnProps: TableSetPropsType[]) => {
const table = await getTable()
table?.setColumn(columnProps)
+ },
+ // 与Search组件结合
+ setSearchParmas: (data: Recordable) => {
+ tableObject.currentPage = 1
+ tableObject.parmasObj = Object.assign(tableObject.parmasObj, {
+ params: {
+ pageSize: tableObject.pageSize,
+ pageIndex: tableObject.currentPage,
+ ...data
+ }
+ })
+ methods.getList()
}
}
diff --git a/src/locales/en.ts b/src/locales/en.ts
index 130f755..2a57b79 100644
--- a/src/locales/en.ts
+++ b/src/locales/en.ts
@@ -107,7 +107,9 @@ export default {
richText: 'Rich text',
dialog: 'Dialog',
imageViewer: 'Image viewer',
- descriptions: 'Descriptions'
+ descriptions: 'Descriptions',
+ example: 'Example',
+ exampleDialog: 'Example dialog'
},
analysis: {
newUser: 'New user',
@@ -360,5 +362,18 @@ export default {
email: 'Email',
addr: 'Address',
form: 'Combined with Form component'
+ },
+ exampleDemo: {
+ title: 'Title',
+ add: 'Add',
+ del: 'Delete',
+ edit: 'Edit',
+ author: 'Author',
+ displayTime: 'Display time',
+ importance: 'Importance',
+ pageviews: 'Pageviews',
+ important: 'Important',
+ content: 'Content',
+ save: 'Save'
}
}
diff --git a/src/locales/zh-CN.ts b/src/locales/zh-CN.ts
index 39e24c4..2f6ecb0 100644
--- a/src/locales/zh-CN.ts
+++ b/src/locales/zh-CN.ts
@@ -107,7 +107,9 @@ export default {
richText: '富文本',
dialog: '弹窗',
imageViewer: '图片预览',
- descriptions: '描述'
+ descriptions: '描述',
+ example: '综合示例',
+ exampleDialog: '综合示例 - 弹窗'
},
analysis: {
newUser: '新增用户',
@@ -357,5 +359,18 @@ export default {
email: '邮箱',
addr: '地址',
form: '与 Form 组件组合'
+ },
+ exampleDemo: {
+ title: '标题',
+ add: '新增',
+ del: '删除',
+ edit: '编辑',
+ author: '作者',
+ displayTime: '创建时间',
+ importance: '重要性',
+ pageviews: '阅读数',
+ important: '重要',
+ content: '内容',
+ save: '保存'
}
}
diff --git a/src/router/index.ts b/src/router/index.ts
index a68881b..cbbb9a3 100644
--- a/src/router/index.ts
+++ b/src/router/index.ts
@@ -333,6 +333,27 @@ export const asyncRouterMap: AppRouteRecordRaw[] = [
}
}
]
+ },
+ {
+ path: '/example',
+ component: Layout,
+ redirect: '/example/example-dialog',
+ name: 'Example',
+ meta: {
+ title: t('router.example'),
+ icon: 'ep:management',
+ alwaysShow: true
+ },
+ children: [
+ {
+ path: 'example-dialog',
+ component: () => import('@/views/Example/Dialog/ExampleDialog.vue'),
+ name: 'ExampleDialog',
+ meta: {
+ title: t('router.exampleDialog')
+ }
+ }
+ ]
}
]
diff --git a/src/views/Example/Dialog/ExampleDialog.vue b/src/views/Example/Dialog/ExampleDialog.vue
new file mode 100644
index 0000000..dd92078
--- /dev/null
+++ b/src/views/Example/Dialog/ExampleDialog.vue
@@ -0,0 +1,170 @@
+
+
+
+
+
+
+
+ {{ t('exampleDemo.add') }}
+ {{ t('exampleDemo.del') }}
+
+
+
+
+
+ {{ t('exampleDemo.edit') }}
+
+
+
+
+
+
+
diff --git a/src/views/Example/Dialog/components/Write.vue b/src/views/Example/Dialog/components/Write.vue
new file mode 100644
index 0000000..3221583
--- /dev/null
+++ b/src/views/Example/Dialog/components/Write.vue
@@ -0,0 +1,136 @@
+
+
+
+
+
diff --git a/types/componentType/form.d.ts b/types/componentType/form.d.ts
index 269068d..178b670 100644
--- a/types/componentType/form.d.ts
+++ b/types/componentType/form.d.ts
@@ -22,6 +22,7 @@ declare global {
| 'TimeSelect'
| 'SelectV2'
| 'InputPassword'
+ | 'Editor'
declare type ColProps = {
span?: number