mirror of
https://github.com/alibaba/lowcode-engine.git
synced 2026-03-05 01:37:17 +00:00
feat: 🎸 补充一个默认的数据源的构建后的样子
This commit is contained in:
parent
e33a95e479
commit
78f34ab1ca
@ -1,4 +1,4 @@
|
|||||||
import { DataSourceConfig } from '@ali/lowcode-types';
|
import { CompositeValue, DataSourceConfig, isJSExpression, isJSFunction } from '@ali/lowcode-types';
|
||||||
|
|
||||||
import { CLASS_DEFINE_CHUNK_NAME, COMMON_CHUNK_NAME } from '../../../const/generator';
|
import { CLASS_DEFINE_CHUNK_NAME, COMMON_CHUNK_NAME } from '../../../const/generator';
|
||||||
|
|
||||||
@ -9,6 +9,7 @@ import {
|
|||||||
FileType,
|
FileType,
|
||||||
ICodeStruct,
|
ICodeStruct,
|
||||||
} from '../../../types';
|
} from '../../../types';
|
||||||
|
import { generateUnknownType } from '../../../utils/compositeType';
|
||||||
import { isContainerSchema } from '../../../utils/schema';
|
import { isContainerSchema } from '../../../utils/schema';
|
||||||
import { RAX_CHUNK_NAME } from './const';
|
import { RAX_CHUNK_NAME } from './const';
|
||||||
|
|
||||||
@ -67,7 +68,15 @@ const pluginFactory: BuilderComponentPluginFactory<PluginConfig> = (config?) =>
|
|||||||
// TODO: 下面的定义应该需要调用 @ali/lowcode-datasource-engine 的方法来搞:
|
// TODO: 下面的定义应该需要调用 @ali/lowcode-datasource-engine 的方法来搞:
|
||||||
content: `
|
content: `
|
||||||
_defineDataSourceList() {
|
_defineDataSourceList() {
|
||||||
return ${JSON.stringify(dataSourceItems)};
|
return (function(){
|
||||||
|
return (${generateUnknownType([
|
||||||
|
...dataSourceItems.map((item) => ({
|
||||||
|
...item,
|
||||||
|
isInit: wrapAsFunction(item.isInit),
|
||||||
|
options: wrapAsFunction(item.options),
|
||||||
|
})),
|
||||||
|
])});
|
||||||
|
}).call(this._context);
|
||||||
}`,
|
}`,
|
||||||
linkAfter: [RAX_CHUNK_NAME.ClassRenderEnd],
|
linkAfter: [RAX_CHUNK_NAME.ClassRenderEnd],
|
||||||
});
|
});
|
||||||
@ -78,3 +87,17 @@ const pluginFactory: BuilderComponentPluginFactory<PluginConfig> = (config?) =>
|
|||||||
};
|
};
|
||||||
|
|
||||||
export default pluginFactory;
|
export default pluginFactory;
|
||||||
|
|
||||||
|
function wrapAsFunction(value: CompositeValue): CompositeValue {
|
||||||
|
if (isJSExpression(value) || isJSFunction(value)) {
|
||||||
|
return {
|
||||||
|
type: 'JSExpression',
|
||||||
|
value: `() => (${value.value})`,
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
return {
|
||||||
|
type: 'JSExpression',
|
||||||
|
value: `() => (${generateUnknownType(value)})`,
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|||||||
@ -162,15 +162,23 @@ class Home$$Page extends Component {
|
|||||||
}
|
}
|
||||||
|
|
||||||
_defineDataSourceList() {
|
_defineDataSourceList() {
|
||||||
return [
|
return function () {
|
||||||
{ id: 'urlParams', type: 'urlParams' },
|
return [
|
||||||
{ id: 'user', type: 'fetch', options: { method: 'GET', uri: 'https://shs.alibaba-inc.com/mock/1458/demo/user' } },
|
{ id: 'urlParams', type: 'urlParams', isInit: () => undefined, options: () => undefined },
|
||||||
{
|
{
|
||||||
id: 'orders',
|
id: 'user',
|
||||||
type: 'fetch',
|
type: 'fetch',
|
||||||
options: { method: 'GET', uri: 'https://shs.alibaba-inc.com/mock/1458/demo/orders' },
|
options: () => ({ method: 'GET', uri: 'https://shs.alibaba-inc.com/mock/1458/demo/user' }),
|
||||||
},
|
isInit: () => undefined,
|
||||||
];
|
},
|
||||||
|
{
|
||||||
|
id: 'orders',
|
||||||
|
type: 'fetch',
|
||||||
|
options: () => ({ method: 'GET', uri: this.state.user.ordersApiUri }),
|
||||||
|
isInit: () => undefined,
|
||||||
|
},
|
||||||
|
];
|
||||||
|
}.call(this._context);
|
||||||
}
|
}
|
||||||
|
|
||||||
_defineUtils() {
|
_defineUtils() {
|
||||||
|
|||||||
@ -89,7 +89,10 @@
|
|||||||
type: 'fetch',
|
type: 'fetch',
|
||||||
options: {
|
options: {
|
||||||
method: 'GET',
|
method: 'GET',
|
||||||
uri: 'https://shs.alibaba-inc.com/mock/1458/demo/orders',
|
uri: {
|
||||||
|
type: 'JSExpression',
|
||||||
|
value: 'this.state.user.ordersApiUri',
|
||||||
|
},
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
],
|
],
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user