Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: 修复更新冲突问题 #577

Merged
merged 27 commits into from
Jul 30, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
27 commits
Select commit Hold shift + click to select a range
aaf2545
fix: 修复徽章显示错误的问题
jhoneybee Nov 18, 2020
b217c67
feat: 添加列的的 `headerRenderer` 属性来自定义渲染
jhoneybee Nov 19, 2020
6fb7d97
fix: 修复表格在弹出框中无法正确的显示编辑框
Dec 15, 2020
d909a41
fix: 修复eslint
Dec 15, 2020
74553ca
fix: 修复eslint
Dec 15, 2020
ca0f4c0
fix: 修复无法在照片墙上进行调用删除文件
Jan 5, 2021
f065396
fix: 调整上传组件
Jan 19, 2021
1e6adc2
feat: 添加表格的改变事件
jhoneybee Mar 31, 2021
f9a6324
Merge branch 'develop' of https://github.com/jhoneybee/rwpjs into table
Mar 31, 2021
d379744
fix: 合并代码
Mar 31, 2021
bf1cb4f
fix: 修复图片大小的问题
Apr 7, 2021
8d89470
feat: 修复显示列信息的问题
Apr 22, 2021
2af4846
feat: 修复表格刷新数据的时候会显示隐藏列信息
Apr 23, 2021
1151af7
feat: 修复tree节点拖动的问题
May 20, 2021
0b67218
feat: 滚动的时候会导致显示的顺序不对
Jun 9, 2021
94f6b6c
feat: 修改版本号
Jun 9, 2021
c21ae59
feat: 修复更新冲突问题
Jun 15, 2021
c218263
feat: 表格添加隐藏底部, tree 修复拖拽问题
Jun 15, 2021
d29a955
feat: 修复发布的版本错误
Jun 24, 2021
6c0a50d
fix: 修复upload上传图片的问题
Jun 25, 2021
943b4b1
fix: 修复table 表格的问题
Jul 1, 2021
49e88d9
fix: 修复点击check的选中框的时候会导致多次触发的问题
Jul 6, 2021
ac5b97d
fix: 添加版本号,发布到1.28.5
Jul 8, 2021
b2074c1
fix: 修复展开的时候,编辑会走缓存
Jul 28, 2021
743fba2
fix: 添加demo
Jul 28, 2021
e508b90
fix: 删除多余的TableHandle
Jul 28, 2021
7aa35c4
fix: 修复更新的数据的时候没有准确获取数据信息
Jul 28, 2021
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Empty file removed packages/cli/package-lock.json
Empty file.
6 changes: 3 additions & 3 deletions packages/react-ui/package.json
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
{
"name": "@rwp/react-ui",
"version": "1.27.1-canary",
"version": "1.28.7-canary",
"license": "AGPL-3.0",
"scripts": {
"start": "dumi dev",
"docs:build": "dumi build",
"docs:deploy": "gh-pages -d docs-dist",
"build": "father-build && yarn build:browser ",
"build": "father-build",
"build:browser": "webpack --config webpack.config.js",
"deploy": "yarn docs:build && yarn run docs:deploy",
"lint:script": "yarn build && eslint ./src/**/*.{js,jsx,ts,tsx}",
Expand All @@ -27,7 +27,7 @@
"dependencies": {
"@ant-design/icons": "~4.3.0",
"@ant-design/pro-layout": "~6.13.0",
"antd": "~4.9.2",
"antd": "4.9.2",
"classnames": "~2.2.6",
"lodash": "~4.17.15",
"mobx": "~5.15.6",
Expand Down
3 changes: 3 additions & 0 deletions packages/react-ui/src/table/column/MultipleSelectColumn.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,9 @@ import { Checkbox } from '../../index'
export const MultipleSelectColumn = (props : FormatterProps<any, unknown>) => (
<Checkbox
checked={props.isRowSelected}
onClick={(e) => {
e.stopPropagation();
}}
onChange={(e: { target: { checked: any }; nativeEvent: MouseEvent }) => {
const { checked } = e.target
props.onRowSelectionChange(checked, (e.nativeEvent as MouseEvent).shiftKey)
Expand Down
2 changes: 2 additions & 0 deletions packages/react-ui/src/table/column/PreFormatColumn.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,8 @@ export const preFormatColumn = (
),
...restProps
} = element

console.log(editable)
const TempEditor = editable ? editor || Input : undefined


Expand Down
62 changes: 51 additions & 11 deletions packages/react-ui/src/table/demo/base-table.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,17 +2,57 @@
* title: 基础表格
* desc: 这是一个基础的表格,通过`props.columns`来设置列信息, `props.loadData` 来加载表格数据
*/
import React from 'react'
import React, { useRef } from 'react'
// eslint-disable-next-line import/no-unresolved
import { Table } from '@rwp/react-ui'
import { Button, Table } from '@rwp/react-ui'
import { columns, loadData } from './common/user'
import { useState } from 'react';

export default () => (
<Table
columns={columns}
loadData={loadData}
onChangeColumn={(data) => {
console.log(data)
}}
/>
)
export default () => {
const ref = useRef<HTMLDivElement>();
const [group,setGroup] = useState<string[]>()
return (
<div
style={{
height: 500,
overflow: 'scroll'
}}
>
<Button
onClick={() => {
setGroup(['dateBirth'])
}}
>
点击分组
</Button>
<Table
ref={ref}
columns={columns}
groupColumn={group}
groupRenderer={({ row }) => {
console.log(JSON.parse(JSON.stringify(row)))
return JSON.stringify(row)
}}
loadData={loadData}
getPopupContainer={(element: HTMLDivElement) => {
return element.parentElement!
}}
onRowsUpdate={(data, onCommit) => {
// console.log([...data])
onCommit().then((ele) => {
console.log(ele)
})
}}
onChangeColumn={(data) => {
console.log(data)
}}

/>
<div
style={{
marginTop: 500
}}
/>
</div>
)
}
19 changes: 12 additions & 7 deletions packages/react-ui/src/table/demo/common/user.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,6 @@ export const editColumns = [{
title: '出生日期'
}]


export const columns = [{
name: '$index',
title: '序号',
Expand All @@ -75,20 +74,26 @@ export const columns = [{
)
},{
name: 'pageNo',
title: '当前页码'
title: '当前页码',
editable: true
},{
name: 'idCard',
title: '身份证'
title: '身份证',
editable: true
},{
name: 'username',
title: '用户名称'
title: '用户名称',
editable: true
},{
name: 'password',
title: '用户密码'
title: '用户密码',
editable: true
},{
name: 'phone',
title: '电话号码'
title: '电话号码',
editable: true
},{
name: 'dateBirth',
title: '出生日期'
title: '出生日期',
editable: true
}]
14 changes: 9 additions & 5 deletions packages/react-ui/src/table/demo/select-table.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import React, { useState } from 'react'
// eslint-disable-next-line import/no-unresolved
import { Table, Switch } from '@rwp/react-ui'
import { columns, loadData } from './common/user'
let i =0;

export default () => {
const [selectBox, setSelectBox] = useState<'multiple' | 'none' | 'single'>('multiple')
Expand All @@ -16,11 +17,11 @@ export default () => {
checkedChildren="单选"
unCheckedChildren="多选"
onChange={(value: any) => {
if (value) {
setSelectBox('single')
} else {
setSelectBox('multiple')
}
// if (value) {
// setSelectBox('single')
// } else {
// setSelectBox('multiple')
// }
}}
/>
<br /> <br />
Expand All @@ -29,6 +30,9 @@ export default () => {
selectBox={selectBox}
columns={columns}
loadData={loadData}
onRowClick={(rowIdx) => {
console.log('row', rowIdx)
}}
/>
</>
)
Expand Down
50 changes: 35 additions & 15 deletions packages/react-ui/src/table/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -89,11 +89,22 @@ export const Table = observer<TableProps>((props: TableProps) => {
}
})

const currentRef = useRef<HTMLDivElement>(null);
useEffect(() => {
// 装载数据
if (enableInitLoadData) reloadFun()

const ele = props.getPopupContainer?.(currentRef.current!)

ele?.addEventListener('scroll', () => {
if (store.contextMenu.position && store.contextMenu.position.idx >= 0 && store.contextMenu.position.rowIdx >= 0) {
gridRef.current?.selectCell(store.contextMenu.position, false)
}
})
}, [])



useEffect(() => {
store.setGroupColumn(props.groupColumn || [])
}, [props.groupColumn])
Expand Down Expand Up @@ -121,7 +132,11 @@ export const Table = observer<TableProps>((props: TableProps) => {

useEffect(() => {
store.columns = props.columns
store.visibleColumns = props.columns.map(ele => ele.name)

if (store.visibleColumns === null || store.visibleColumns?.length === 0) {
store.visibleColumns = props.columns.map(ele => ele.name)
}

}, [props.columns])

if (table && gridRef.current) {
Expand Down Expand Up @@ -250,7 +265,7 @@ export const Table = observer<TableProps>((props: TableProps) => {
}}
onRowsUpdate={e => {
const onCommit = () => {
store.commit(e)
return store.commit(e)
}
props.onRowsUpdate!(e, onCommit)
}}
Expand Down Expand Up @@ -301,20 +316,25 @@ export const Table = observer<TableProps>((props: TableProps) => {
return node
}
return (
<StoreContext.Provider value={store}>
<Spin
spinning={store.loading}
wrapperClassName={`${tableClassPrefix}-spin`}
>
<div
className={`${tableClassPrefix}-content`}
<div
ref={currentRef}
className={`${tableClassPrefix}-container`}
>
<StoreContext.Provider value={store}>
<Spin
spinning={store.loading}
wrapperClassName={`${tableClassPrefix}-spin`}
>
{rdg}
{getPluginNode(<Tools />)}
</div>
{getPluginNode(footer)}
</Spin>
</StoreContext.Provider>
<div
className={`${tableClassPrefix}-content`}
>
{rdg}
{getPluginNode(<Tools />)}
</div>
{props.mode === 'HIDE-FOOTER' ? null : getPluginNode(footer)}
</Spin>
</StoreContext.Provider>
</div>
)
})

Expand Down
3 changes: 2 additions & 1 deletion packages/react-ui/src/table/row/GroupRow.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -29,8 +29,9 @@ export const GroupRow = ({
const store = useStore()
if ($type === 'GROUP') {
let groupTitle = <h4 >{$title}</h4>

if (GroupRenderer) {
groupTitle = <GroupRenderer row={rowProps.row}/>
groupTitle = <GroupRenderer row={rowProps.row} />
}
const Icon = store.expandedKeys.includes($id) ? DownOutlined : RightOutlined
return (
Expand Down
18 changes: 14 additions & 4 deletions packages/react-ui/src/table/store.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -145,6 +145,7 @@ export function createStore() {

})
}

loopsGroupData(groupDatas)
return newData
},
Expand Down Expand Up @@ -217,11 +218,15 @@ export function createStore() {
},
// 提交修改的信息
commit(e: RowsUpdateEvent) {
return new Promise<void>(resolve => {
return new Promise<Row[]>(resolve => {
const updates: Row[] = []
const rows: Row[] = this.dataSource

const { datas } = this
if (e.action === 'CELL_UPDATE' || e.action === 'COPY_PASTE') {
rows[e.toRow] = { ...rows[e.toRow], ...(e.updated as any) }
const index = datas.findIndex(ele => ele.$index === rows[e.toRow].$index )
datas[index] = { ...rows[e.toRow], ...(e.updated as any) }
updates.push({ ...rows[e.toRow], ...(e.updated as any) })
}

if (e.action === 'CELL_DRAG') {
Expand All @@ -231,12 +236,17 @@ export function createStore() {
}
rows.forEach((value, index) => {
if (cells.includes(index)) {
rows[index] = { ...rows[index], ...(e.updated as any) }
const dataIndex = datas.findIndex(ele => ele.$index === rows[index].$index )
datas[dataIndex] = { ...rows[index], ...(e.updated as any) }
updates.push({ ...rows[index], ...(e.updated as any) })
}
})
}
if (this.isGroup) {
this.cacheGroupDatas = undefined
}
this.setDataSource(rows)
resolve()
resolve(updates)
})
},
get isGroup(){
Expand Down
4 changes: 4 additions & 0 deletions packages/react-ui/src/table/style/index.less
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,10 @@
}
}

.@{table-prefix-cls}-container {
height: 100%;
}

.@{table-prefix-cls}-cell{
text-overflow: inherit;
overflow: inherit;
Expand Down
4 changes: 3 additions & 1 deletion packages/react-ui/src/table/type.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -164,7 +164,7 @@ export interface TableProps {
/**
* 模式
*/
mode?: 'SIMPLE' | 'NORMAL',
mode?: 'SIMPLE' | 'NORMAL' | 'HIDE-FOOTER',

/**
* 行高
Expand Down Expand Up @@ -263,4 +263,6 @@ export interface TableProps {
* 改变列的时候触发的事件
*/
onChangeColumn?: (columns: ColumnProps[]) => void

getPopupContainer?: (element: HTMLElement ) => HTMLElement
}
2 changes: 1 addition & 1 deletion packages/react-ui/src/tree/index.md
Original file line number Diff line number Diff line change
Expand Up @@ -173,7 +173,7 @@ export default () => {
setTimeout(() => {
console.log(info.event.preventDefault)
re()
}, 1000)
}, 10)
})
}}
onSelect={(keys) => {
Expand Down
Loading