Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
S
submodule
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
web_component
submodule
Commits
3e9fd63d
Commit
3e9fd63d
authored
Aug 06, 2020
by
zhangwenshuai
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
update
parent
5872244b
Changes
6
Hide whitespace changes
Inline
Side-by-side
Showing
6 changed files
with
94 additions
and
58 deletions
+94
-58
Cell.tsx
components/apolloTable/component/Cell.tsx
+1
-4
DragResized.tsx
components/apolloTable/component/DragResized.tsx
+9
-3
Table.tsx
components/apolloTable/component/Table.tsx
+41
-13
index.tsx
components/apolloTable/component/index.tsx
+2
-2
interface.tsx
components/apolloTable/component/interface.tsx
+33
-32
cache.ts
components/apolloTable/utils/cache.ts
+8
-4
No files found.
components/apolloTable/component/Cell.tsx
View file @
3e9fd63d
...
@@ -9,7 +9,7 @@ import { CellProps, CellDataProps } from './interface';
...
@@ -9,7 +9,7 @@ import { CellProps, CellDataProps } from './interface';
import
FormHelper
from
'../utils/formHelper'
;
import
FormHelper
from
'../utils/formHelper'
;
import
expandIcon
from
'../assets/extend.png'
;
import
expandIcon
from
'../assets/extend.png'
;
import
{
transferAttr
}
from
'./base/_utils/transferAttr'
;
import
{
transferAttr
}
from
'./base/_utils/transferAttr'
;
import
{
emptyModel
}
from
'
@/submodule/components/apolloTable/component
/base/_utils/setFormatter'
;
import
{
emptyModel
}
from
'
.
/base/_utils/setFormatter'
;
enum
EDIT_STATUS
{
enum
EDIT_STATUS
{
'FREE'
,
// 空闲
'FREE'
,
// 空闲
...
@@ -50,9 +50,6 @@ const Cell = (props: CellProps) => {
...
@@ -50,9 +50,6 @@ const Cell = (props: CellProps) => {
const
cellUnit
=
useRef
(
null
);
const
cellUnit
=
useRef
(
null
);
const
[
status
,
setStatus
]
=
useState
(
'detail'
);
const
[
status
,
setStatus
]
=
useState
(
'detail'
);
// useEffect(() => {
// setStatus('detail');
// }, [cellData]);
const
resetEditStatus
=
()
=>
{
const
resetEditStatus
=
()
=>
{
setStatus
(
'detail'
);
setStatus
(
'detail'
);
if
(
typeof
onEmitMsg
===
'function'
)
{
if
(
typeof
onEmitMsg
===
'function'
)
{
...
...
components/apolloTable/component/DragResized.tsx
View file @
3e9fd63d
import
React
from
'react'
;
import
React
from
'react'
;
import
{
ResizableBox
}
from
'react-resizable'
;
import
{
ResizableBox
}
from
'react-resizable'
;
import
{
getCache
,
saveCache
}
from
'../utils/cache'
;
import
styles
from
'./DragResized.less'
;
import
styles
from
'./DragResized.less'
;
const
DragResized
=
(
props
:
any
)
=>
{
const
DragResized
=
(
props
:
any
)
=>
{
const
{
style
,
columnName
,
onDragFixed
,
tableId
,
onResizeCb
}
=
props
;
const
{
style
,
columnName
,
tableId
,
onResizeCb
,
cachedFeAttr
}
=
props
;
// 表格
// 表格
const
container
:
any
=
document
.
querySelector
(
`#apolloTable_
${
tableId
}
`
);
const
container
:
any
=
document
.
querySelector
(
`#apolloTable_
${
tableId
}
`
);
...
@@ -27,8 +28,13 @@ const DragResized = (props: any) => {
...
@@ -27,8 +28,13 @@ const DragResized = (props: any) => {
// 列伸缩结束
// 列伸缩结束
const
onResizeWidthStop
=
(
e
:
any
,
{
size
}:
{
size
:
{
width
:
number
}
})
=>
{
const
onResizeWidthStop
=
(
e
:
any
,
{
size
}:
{
size
:
{
width
:
number
}
})
=>
{
dividerWrap
.
style
.
display
=
'none'
;
dividerWrap
.
style
.
display
=
'none'
;
if
(
typeof
onDragFixed
===
'function'
)
{
const
cachedCols
=
getCache
({
tableId
});
onDragFixed
([{
columnName
,
width
:
size
.
width
}]);
if
(
cachedFeAttr
&&
cachedCols
)
{
cachedCols
[
columnName
]
=
{
...
cachedCols
[
columnName
],
width
:
size
.
width
,
};
saveCache
({
tableId
,
data
:
cachedCols
});
}
}
if
(
typeof
onResizeCb
===
'function'
)
{
if
(
typeof
onResizeCb
===
'function'
)
{
onResizeCb
(
columnName
,
size
.
width
);
onResizeCb
(
columnName
,
size
.
width
);
...
...
components/apolloTable/component/Table.tsx
View file @
3e9fd63d
...
@@ -14,6 +14,7 @@ import RightDragFixed from './RightDragFixed';
...
@@ -14,6 +14,7 @@ import RightDragFixed from './RightDragFixed';
import
DragSorted
from
'./DragSorted'
;
import
DragSorted
from
'./DragSorted'
;
import
DragResized
from
'./DragResized'
;
import
DragResized
from
'./DragResized'
;
import
{
getMergeClassName
,
getMergeStyle
}
from
'../utils/utils'
;
import
{
getMergeClassName
,
getMergeStyle
}
from
'../utils/utils'
;
import
{
saveCache
,
getCache
}
from
'../utils/cache'
;
import
{
Consumer
}
from
'./context'
;
import
{
Consumer
}
from
'./context'
;
const
borderStyle
=
'1px solid #ececec'
;
const
borderStyle
=
'1px solid #ececec'
;
...
@@ -33,7 +34,7 @@ export default class AirTable extends Component<TableProps, TableState> {
...
@@ -33,7 +34,7 @@ export default class AirTable extends Component<TableProps, TableState> {
grid6
:
any
;
grid6
:
any
;
memoizeFormatColumns
:
Function
;
memoizeFormatColumns
:
Function
;
memoizeData
:
Function
;
memoizeData
:
Function
;
...
@@ -77,7 +78,7 @@ export default class AirTable extends Component<TableProps, TableState> {
...
@@ -77,7 +78,7 @@ export default class AirTable extends Component<TableProps, TableState> {
rowHeight
:
rowHeight
||
80
,
rowHeight
:
rowHeight
||
80
,
headerHeight
:
headerHeight
||
60
,
headerHeight
:
headerHeight
||
60
,
};
};
this
.
memoizeFormatColumns
=
memoizeOne
(
this
.
memoize
FormatColumns
);
this
.
memoizeFormatColumns
=
memoizeOne
(
this
.
get
FormatColumns
);
this
.
memoizeLeftColumns
=
memoizeOne
(
this
.
getLeftColumns
);
this
.
memoizeLeftColumns
=
memoizeOne
(
this
.
getLeftColumns
);
this
.
memoizeRightColumns
=
memoizeOne
(
this
.
getRightColumns
);
this
.
memoizeRightColumns
=
memoizeOne
(
this
.
getRightColumns
);
this
.
memoizeColumns
=
memoizeOne
(
this
.
getShowColumns
);
this
.
memoizeColumns
=
memoizeOne
(
this
.
getShowColumns
);
...
@@ -87,11 +88,39 @@ export default class AirTable extends Component<TableProps, TableState> {
...
@@ -87,11 +88,39 @@ export default class AirTable extends Component<TableProps, TableState> {
this
.
memoizeData
=
memoizeOne
(
this
.
filterData
);
this
.
memoizeData
=
memoizeOne
(
this
.
filterData
);
}
}
// 格式化列数据(添加缓存的前端属性)
memoizeFormatColumns
=
(
columns
:
ColumnProps
[])
=>
{
const
{
cachedFeAttr
}
=
this
.
props
;
}
// 格式化列数据(添加缓存的前端属性)
getFormatColumns
=
(
columns
:
ColumnProps
[])
=>
{
columns
.
sort
((
a
,
b
)
=>
{
return
a
.
orderNo
-
b
.
orderNo
;
});
const
{
cachedFeAttr
,
tableId
}
=
this
.
props
;
if
(
cachedFeAttr
)
{
const
cachedCols
=
getCache
({
tableId
});
if
(
cachedCols
)
{
columns
=
columns
.
map
((
item
:
any
)
=>
{
return
{
...
item
,
...
cachedCols
[
item
.
columnName
],
};
});
}
else
{
const
data
:
any
=
{};
columns
.
map
((
item
:
any
)
=>
{
data
[
item
.
columnName
]
=
{
columnName
:
item
.
columnName
,
width
:
item
.
width
,
align
:
item
.
align
,
fixed
:
item
.
fixed
,
hideScope
:
item
.
hideScope
,
orderNo
:
item
.
orderNo
,
};
});
saveCache
({
tableId
,
data
});
}
}
return
columns
;
};
// 获取左侧固定列数量
// 获取左侧固定列数量
getLeftColumns
=
(
columns
:
ColumnProps
[])
=>
{
getLeftColumns
=
(
columns
:
ColumnProps
[])
=>
{
...
@@ -110,7 +139,7 @@ export default class AirTable extends Component<TableProps, TableState> {
...
@@ -110,7 +139,7 @@ export default class AirTable extends Component<TableProps, TableState> {
// 获取表格显示列
// 获取表格显示列
getShowColumns
=
(
columns
:
ColumnProps
[])
=>
{
getShowColumns
=
(
columns
:
ColumnProps
[])
=>
{
return
columns
.
filter
((
item
)
=>
{
return
columns
.
filter
((
item
)
=>
{
return
!
item
.
hideScope
||
item
.
hideScope
.
indexOf
(
'LIST'
)
===
-
1
;
return
!
!
item
.
showStatus
&&
(
!
item
.
hideScope
||
item
.
hideScope
.
indexOf
(
'LIST'
)
===
-
1
)
;
});
});
};
};
...
@@ -340,7 +369,7 @@ export default class AirTable extends Component<TableProps, TableState> {
...
@@ -340,7 +369,7 @@ export default class AirTable extends Component<TableProps, TableState> {
{
columnIndex
,
key
,
style
}:
any
,
{
columnIndex
,
key
,
style
}:
any
,
)
=>
{
)
=>
{
if
(
showColumns
.
length
===
0
)
return
null
;
if
(
showColumns
.
length
===
0
)
return
null
;
const
{
sortConfig
,
showIndex
,
rowSelection
,
dataSource
,
onDragSorted
,
tableId
,
onDragFixed
}
=
this
.
props
;
const
{
sortConfig
,
showIndex
,
rowSelection
,
dataSource
,
onDragSorted
,
tableId
,
cachedFeAttr
}
=
this
.
props
;
const
{
const
{
columnType
=
1
,
columnType
=
1
,
columnName
,
columnName
,
...
@@ -356,8 +385,8 @@ export default class AirTable extends Component<TableProps, TableState> {
...
@@ -356,8 +385,8 @@ export default class AirTable extends Component<TableProps, TableState> {
<
DragResized
<
DragResized
columnName=
{
columnName
}
columnName=
{
columnName
}
style=
{
style
}
style=
{
style
}
onDragFixed=
{
onDragFixed
}
tableId=
{
tableId
}
tableId=
{
tableId
}
cachedFeAttr=
{
cachedFeAttr
}
onResizeCb=
{
this
.
onResizeCb
}
onResizeCb=
{
this
.
onResizeCb
}
>
>
<
DragSorted
<
DragSorted
...
@@ -499,10 +528,9 @@ export default class AirTable extends Component<TableProps, TableState> {
...
@@ -499,10 +528,9 @@ export default class AirTable extends Component<TableProps, TableState> {
const
{
overscanColumnCount
,
overscanRowCount
,
rowHeight
,
headerHeight
,
columnWidth
}
=
this
.
config
;
const
{
overscanColumnCount
,
overscanRowCount
,
rowHeight
,
headerHeight
,
columnWidth
}
=
this
.
config
;
const
scrollbarWidth
=
scrollbarSize
()
||
0
;
const
scrollbarWidth
=
scrollbarSize
()
||
0
;
const
formatColumns
=
this
.
memoizeFormatColumns
(
columns
);
const
formatColumns
=
this
.
memoizeFormatColumns
(
columns
);
const
showColumns
=
this
.
memoizeColumns
(
columns
);
const
showColumns
=
this
.
memoizeColumns
(
formatColumns
);
const
leftColumns
=
this
.
memoizeLeftColumns
(
showColumns
);
const
leftColumns
=
this
.
memoizeLeftColumns
(
columns
);
const
rightColumns
=
this
.
memoizeRightColumns
(
showColumns
);
const
rightColumns
=
this
.
memoizeRightColumns
(
columns
);
// 有隐藏列时,修正数据与列头不匹配问题
// 有隐藏列时,修正数据与列头不匹配问题
const
showData
=
this
.
memoizeData
(
showColumns
,
dataSource
);
const
showData
=
this
.
memoizeData
(
showColumns
,
dataSource
);
const
leftData
=
this
.
memoizeData
(
leftColumns
,
dataSource
);
const
leftData
=
this
.
memoizeData
(
leftColumns
,
dataSource
);
...
...
components/apolloTable/component/index.tsx
View file @
3e9fd63d
...
@@ -88,7 +88,7 @@ class AirTable extends React.Component<CommonProps, CommonState> {
...
@@ -88,7 +88,7 @@ class AirTable extends React.Component<CommonProps, CommonState> {
onDragSorted
,
onDragSorted
,
onEmitMsg
,
onEmitMsg
,
tableId
,
tableId
,
onDragFixed
,
cachedFeAttr
,
}
=
this
.
props
;
}
=
this
.
props
;
const
sortConfig
=
operateConfig
const
sortConfig
=
operateConfig
&&
operateConfig
.
menusGroup
&&
operateConfig
.
menusGroup
...
@@ -150,7 +150,7 @@ class AirTable extends React.Component<CommonProps, CommonState> {
...
@@ -150,7 +150,7 @@ class AirTable extends React.Component<CommonProps, CommonState> {
onDragSorted=
{
onDragSorted
}
onDragSorted=
{
onDragSorted
}
onEmitMsg=
{
onEmitMsg
}
onEmitMsg=
{
onEmitMsg
}
tableId=
{
tableId
}
tableId=
{
tableId
}
onDragFixed=
{
onDragFixed
}
cachedFeAttr=
{
cachedFeAttr
}
/>
/>
</
div
>
</
div
>
</
div
>
</
div
>
...
...
components/apolloTable/component/interface.tsx
View file @
3e9fd63d
...
@@ -50,36 +50,37 @@ export interface LoadConfigProps {
...
@@ -50,36 +50,37 @@ export interface LoadConfigProps {
}
}
export
interface
TableProps
extends
LoadConfigProps
{
export
interface
TableProps
extends
LoadConfigProps
{
columns
:
ColumnProps
[];
// 列配置
tableId
:
string
|
number
;
// 表格唯一id
dataSource
:
RowProps
[];
// 数据源
columns
:
ColumnProps
[];
// 列配置
rowClassName
?:
string
|
Function
;
// 行class
dataSource
:
RowProps
[];
// 数据源
rowStyle
?:
Object
|
Function
;
// 行style
rowClassName
?:
string
|
Function
;
// 行class
rowStyle
?:
Object
|
Function
;
// 行style
rowRenderer
?:
Function
;
rowRenderer
?:
Function
;
bordered
?:
boolean
;
// 是否显示边框
bordered
?:
boolean
;
// 是否显示边框
height
?:
number
;
// 表格高度
height
?:
number
;
// 表格高度
width
?:
number
;
// 表格宽度
width
?:
number
;
// 表格宽度
emitChangeCell
?:
Function
;
// 单元格修改回调
emitChangeCell
?:
Function
;
// 单元格修改回调
sortConfig
?:
any
;
sortConfig
?:
any
;
paginationConfig
?:
any
;
// 分页配置
paginationConfig
?:
any
;
// 分页配置
showIndex
?:
boolean
;
// 是否显示序号
showIndex
?:
boolean
;
// 是否显示序号
showExpand
?:
any
;
// 是否显示展开详情图标
showExpand
?:
any
;
// 是否显示展开详情图标
emptyPlaceholder
?:
string
;
// 数据为空时默认显示
emptyPlaceholder
?:
string
;
// 数据为空时默认显示
cellEditable
?:
boolean
;
// 单元格是否可编辑
cellEditable
?:
boolean
;
// 单元格是否可编辑
rowHeight
?:
number
;
// 初始化行高
rowHeight
?:
number
;
// 初始化行高
headerHeight
?:
number
;
// 初始化表头高度
headerHeight
?:
number
;
// 初始化表头高度
columnWidth
?:
number
;
// 初始化单元格宽度
columnWidth
?:
number
;
// 初始化单元格宽度
loading
?:
boolean
;
// 是否加载中
loading
?:
boolean
;
// 是否加载中
rowSelection
?:
any
;
// 复选配置
rowSelection
?:
any
;
// 复选配置
noDataPlaceholder
?:
any
;
// 无数据时显示文案
noDataPlaceholder
?:
any
;
// 无数据时显示文案
contentMenu
?:
any
;
// 右键菜单
contentMenu
?:
any
;
// 右键菜单
loadComp
?:
any
;
// 加载动画组件
loadComp
?:
any
;
// 加载动画组件
canFixed
?:
boolean
;
// 是否可以拖拽自定义固定列
canFixed
?:
boolean
;
// 是否可以拖拽自定义固定列
canSorted
?:
boolean
;
// 是否可以拖拽自定义列排序
canSorted
?:
boolean
;
// 是否可以拖拽自定义列排序
canResized
?:
boolean
;
// 是否可以拖拽自定义列伸缩
canResized
?:
boolean
;
// 是否可以拖拽自定义列伸缩
onDragSorted
?:
Function
;
// 拖拽更改列排序回调
onDragSorted
?:
Function
;
// 拖拽更改列排序回调
onDragFixed
?:
Function
;
// 拖拽更改列排序回调
onDragFixed
?:
Function
;
// 拖拽更改列排序回调
onEmitMsg
?:
Function
;
onEmitMsg
?:
Function
;
// 是否支持消息协同
tableId
?:
string
|
number
;
// tableId
cachedFeAttr
?:
boolean
;
// 是否启用前端缓存
}
}
export
interface
TableState
{
export
interface
TableState
{
columns
:
ColumnProps
[];
columns
:
ColumnProps
[];
...
@@ -95,8 +96,8 @@ export interface CommonProps extends TableProps {
...
@@ -95,8 +96,8 @@ export interface CommonProps extends TableProps {
className
?:
string
;
className
?:
string
;
tableClassName
?:
string
;
tableClassName
?:
string
;
showCondition
?:
boolean
;
showCondition
?:
boolean
;
id
?:
string
;
id
?:
string
;
onEmitMsg
?:
Function
;
onEmitMsg
?:
Function
;
}
}
export
interface
CommonState
extends
TableState
{}
export
interface
CommonState
extends
TableState
{}
...
@@ -135,8 +136,8 @@ export interface CellProps {
...
@@ -135,8 +136,8 @@ export interface CellProps {
changeSelectedCell
?:
Function
;
changeSelectedCell
?:
Function
;
position
:
string
;
position
:
string
;
onEmitMsg
?:
Function
;
onEmitMsg
?:
Function
;
tableId
?:
string
|
number
;
tableId
?:
string
|
number
;
maxPopHeight
?:
string
|
number
;
maxPopHeight
?:
string
|
number
;
}
}
export
interface
EditCellProps
{
export
interface
EditCellProps
{
...
...
components/apolloTable/utils/cache.ts
View file @
3e9fd63d
const
cachePrefix
=
'TABLE_COLS'
;
const
cachePrefix
=
'TABLE_COLS'
;
const
getKey
=
(
tableId
)
=>
{
const
getKey
=
(
tableId
:
number
|
string
)
=>
{
return
`
${
cachePrefix
}
_
${
tableId
}
`
;
return
`
${
cachePrefix
}
_
${
tableId
}
`
;
};
};
export
const
saveCache
=
({
tableId
,
data
})
=>
{
export
const
saveCache
=
({
tableId
,
data
}
:
{
tableId
:
number
|
string
;
data
:
any
}
)
=>
{
localStorage
.
setItem
(
getKey
(
tableId
),
JSON
.
stringify
(
data
));
localStorage
.
setItem
(
getKey
(
tableId
),
JSON
.
stringify
(
data
));
};
};
export
const
getCache
=
({
tableId
})
=>
{
export
const
getCache
=
({
tableId
}:
{
tableId
:
number
|
string
})
=>
{
const
data
=
localStorage
.
getItem
(
getKey
(
tableId
));
if
(
!
data
)
{
return
null
;
}
try
{
try
{
return
JSON
.
parse
(
localStorage
.
getItem
(
getKey
(
tableId
))
);
return
JSON
.
parse
(
data
);
}
catch
(
e
)
{
}
catch
(
e
)
{
console
.
warn
(
'获取localStorage失败'
);
console
.
warn
(
'获取localStorage失败'
);
}
}
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment