-
Notifications
You must be signed in to change notification settings - Fork 5
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch '6.3' of https://github.com/steedos/steedos-widgets into…
… 6.3
- Loading branch information
Showing
4 changed files
with
61 additions
and
52 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
93 changes: 43 additions & 50 deletions
93
packages/@steedos-widgets/devextreme/src/components/DataGrid.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,59 +1,52 @@ | ||
import React, { useEffect, useRef } from 'react'; | ||
|
||
import { | ||
DataGrid | ||
} from 'devextreme-react/data-grid'; | ||
|
||
import { createObject } from '@steedos-widgets/amis-lib'; | ||
|
||
// 不要用 devextreme-react, rollup 编译报错 | ||
export const AmisDataGrid = ( { | ||
data: amisData, | ||
config, | ||
dataSource, | ||
keyExpr = "_id", | ||
className, | ||
...props | ||
} ) => { | ||
import React, { useEffect, useState } from 'react'; | ||
|
||
import DevExpress from './DevExpress'; | ||
|
||
export const AmisDataGrid = (props: any) => { | ||
const { | ||
config: configJSON = null, | ||
data: amisData, | ||
className, | ||
dataFilter | ||
} = props; | ||
|
||
const [config, setConfig] = useState(configJSON); | ||
|
||
let onDataFilter = null; | ||
|
||
let configJSON = {} | ||
if (typeof config === 'string') { | ||
try { | ||
configJSON = JSON.parse(config); | ||
} catch(e) {console.log(e)} | ||
} | ||
if (typeof config === 'object') { | ||
configJSON = config | ||
if (typeof dataFilter === 'string') { | ||
|
||
onDataFilter = new Function('config', 'DevExpress', 'data', 'return (async () => { ' + dataFilter + ' })()') | ||
} | ||
|
||
useEffect(() => { | ||
let isCancelled = false; | ||
(async () => { | ||
try { | ||
if (onDataFilter) { | ||
const newConfig = await onDataFilter(config, DevExpress, amisData); | ||
if (!isCancelled) { | ||
setConfig(newConfig || config); | ||
} | ||
} | ||
} catch (e) { | ||
console.warn(e); | ||
} | ||
})(); | ||
|
||
let onDataFilter = props.onDataFilter; | ||
const dataFilter = props.dataFilter; | ||
return () => { | ||
isCancelled = true; | ||
}; | ||
}, []); | ||
|
||
if (!onDataFilter && typeof dataFilter === 'string') { | ||
onDataFilter = new Function( | ||
'config', | ||
'DataGrid', | ||
'data', | ||
dataFilter | ||
) as any; | ||
if (!config) { | ||
return <>Loading...</>; | ||
} | ||
try { | ||
onDataFilter && | ||
(configJSON = | ||
onDataFilter(configJSON, DataGrid, amisData) || configJSON); | ||
} catch (e) { | ||
console.warn(e); | ||
} | ||
useEffect(() => { | ||
}, []) | ||
|
||
return ( | ||
<DataGrid | ||
<DevExpress.DataGrid | ||
className={className} | ||
dataSource={dataSource} | ||
keyExpr={keyExpr} | ||
{...configJSON}> | ||
</DataGrid> | ||
) | ||
} | ||
{...config} | ||
/> | ||
); | ||
}; |
16 changes: 16 additions & 0 deletions
16
packages/@steedos-widgets/devextreme/src/components/DevExpress.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
|
||
// const DevExpressLib = require('devextreme/bundles/modules/core'); | ||
// const data = DevExpressLib.data = require('devextreme/bundles/modules/data'); | ||
// data.odata = require('devextreme/bundles/modules/data.odata'); | ||
|
||
import DevExpress from 'devextreme/bundles/modules/core'; | ||
import data from 'devextreme/bundles/modules/data'; | ||
import 'devextreme/bundles/modules/data.odata'; | ||
import { | ||
DataGrid | ||
} from 'devextreme-react/data-grid'; | ||
|
||
DevExpress.data = data; | ||
DevExpress.DataGrid = DataGrid; | ||
|
||
export default DevExpress; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters