Skip to content

Commit

Permalink
Merge branch '6.3' of https://github.com/steedos/steedos-widgets into…
Browse files Browse the repository at this point in the history
… 6.3
  • Loading branch information
baozhoutao committed Dec 4, 2024
2 parents d2d624e + 29a0fb4 commit 70a441d
Show file tree
Hide file tree
Showing 4 changed files with 61 additions and 52 deletions.
2 changes: 1 addition & 1 deletion packages/@steedos-widgets/ckeditor/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
"scripts": {
"prebuild": "rimraf dist",
"http": "npx http-server ../ --port 8080 --cors -c -1",
"build": "yarn build-types && yarn build-rollup",
"build.disabled": "yarn build-types && yarn build-rollup",
"build-types": "tsc --emitDeclarationOnly --declaration --declarationDir dist/types",
"build-rollup": "rollup -c rollup.config.ts"
},
Expand Down
93 changes: 43 additions & 50 deletions packages/@steedos-widgets/devextreme/src/components/DataGrid.tsx
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 packages/@steedos-widgets/devextreme/src/components/DevExpress.ts
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;
2 changes: 1 addition & 1 deletion packages/@steedos-widgets/devextreme/src/metas/DataGrid.ts
Original file line number Diff line number Diff line change
Expand Up @@ -139,7 +139,7 @@ export default {
name: "dataFilter",
label: "数据加工",
description: "如果后端没有直接返回 DataGrid 配置,可以自己写一段函数来包装。\
签名:(config, DataGrid, data) => config \
签名:(config, DevExpress, data) => config \
"
},
],
Expand Down

0 comments on commit 70a441d

Please sign in to comment.