Skip to content

Commit

Permalink
feat: Table重构
Browse files Browse the repository at this point in the history
  • Loading branch information
kailong321200875 committed Jul 10, 2023
1 parent 002d03a commit 94800b0
Show file tree
Hide file tree
Showing 13 changed files with 575 additions and 307 deletions.
9 changes: 9 additions & 0 deletions mock/role/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -142,6 +142,14 @@ const adminList = [
title: 'UseTable'
}
},
{
path: 'tree-table',
component: 'views/Components/Table/TreeTable',
name: 'TreeTable',
meta: {
title: 'TreeTable'
}
},
{
path: 'ref-table',
component: 'views/Components/Table/RefTable',
Expand Down Expand Up @@ -481,6 +489,7 @@ const testList: string[] = [
'/components/table',
'/components/table/default-table',
'/components/table/use-table',
'/components/table/tree-table',
'/components/table/ref-table',
'/components/editor-demo',
'/components/editor-demo/editor',
Expand Down
124 changes: 122 additions & 2 deletions mock/table/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,15 +12,28 @@ const count = 100
const baseContent =
'<p>I am testing data, I am testing data.</p><p><img src="https://wpimg.wallstcn.com/4c69009c-0fd4-4153-b112-6cb53d1cf943"></p>'

let List: {
interface ListProps {
id: string
author: string
title: string
content: string
importance: number
display_time: string
pageviews: number
}[] = []
}

interface TreeListProps {
id: string
author: string
title: string
content: string
importance: number
display_time: string
pageviews: number
children: TreeListProps[]
}

let List: ListProps[] = []

for (let i = 0; i < count; i++) {
List.push(
Expand All @@ -38,7 +51,114 @@ for (let i = 0; i < count; i++) {
)
}

const treeList: TreeListProps[] = []

for (let i = 0; i < count; i++) {
treeList.push(
Mock.mock({
id: toAnyString(),
// timestamp: +Mock.Random.date('T'),
author: '@first',
title: '@title(5, 10)',
content: baseContent,
importance: '@integer(1, 3)',
display_time: '@datetime',
pageviews: '@integer(300, 5000)',
children: [
{
id: toAnyString(),
// timestamp: +Mock.Random.date('T'),
author: '@first',
title: '@title(5, 10)',
content: baseContent,
importance: '@integer(1, 3)',
display_time: '@datetime',
pageviews: '@integer(300, 5000)',
children: [
{
id: toAnyString(),
// timestamp: +Mock.Random.date('T'),
author: '@first',
title: '@title(5, 10)',
content: baseContent,
importance: '@integer(1, 3)',
display_time: '@datetime',
pageviews: '@integer(300, 5000)'
},
{
id: toAnyString(),
// timestamp: +Mock.Random.date('T'),
author: '@first',
title: '@title(5, 10)',
content: baseContent,
importance: '@integer(1, 3)',
display_time: '@datetime',
pageviews: '@integer(300, 5000)'
}
]
},
{
id: toAnyString(),
// timestamp: +Mock.Random.date('T'),
author: '@first',
title: '@title(5, 10)',
content: baseContent,
importance: '@integer(1, 3)',
display_time: '@datetime',
pageviews: '@integer(300, 5000)'
},
{
id: toAnyString(),
// timestamp: +Mock.Random.date('T'),
author: '@first',
title: '@title(5, 10)',
content: baseContent,
importance: '@integer(1, 3)',
display_time: '@datetime',
pageviews: '@integer(300, 5000)'
},
{
id: toAnyString(),
// timestamp: +Mock.Random.date('T'),
author: '@first',
title: '@title(5, 10)',
content: baseContent,
importance: '@integer(1, 3)',
display_time: '@datetime',
pageviews: '@integer(300, 5000)'
}
]
// image_uri
})
)
}

export default [
// 树形列表接口
{
url: '/example/treeList',
method: 'get',
timeout,
response: ({ query }) => {
const { title, pageIndex, pageSize } = query
const mockList = treeList.filter((item) => {
if (title && item.title.indexOf(title) < 0) return false
return true
})
const pageList = mockList.filter(
(_, index) => index < pageSize * pageIndex && index >= pageSize * (pageIndex - 1)
)
return {
data: {
code: code,
data: {
total: mockList.length,
list: pageList
}
}
}
}
},
// 列表接口
{
url: '/example/list',
Expand Down
4 changes: 4 additions & 0 deletions src/api/table/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,10 @@ export const getTableListApi = (params: any) => {
return request.get({ url: '/example/list', params })
}

export const getTreeTableListApi = (params: any) => {
return request.get({ url: '/example/treeList', params })
}

export const saveTableApi = (data: Partial<TableData>): Promise<IResponse> => {
return request.post({ url: '/example/save', data })
}
Expand Down
4 changes: 3 additions & 1 deletion src/components/Table/index.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import Table from './src/Table.vue'
import { ElTable } from 'element-plus'
import { TableSetProps } from './src/types'
import { TableColumn, TableSetProps } from './src/types'

export type {
TableColumn,
Expand All @@ -13,6 +13,8 @@ export type {
export interface TableExpose {
setProps: (props: Recordable) => void
setColumn: (columnProps: TableSetProps[]) => void
addColumn: (column: TableColumn, index?: number) => void
delColumn: (field: string) => void
selections: Recordable[]
elTableRef: ComponentRef<typeof ElTable>
}
Expand Down
Loading

0 comments on commit 94800b0

Please sign in to comment.