mirror of
https://github.com/alibaba/lowcode-engine.git
synced 2026-01-13 09:41:57 +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';
|
||||
|
||||
@ -9,6 +9,7 @@ import {
|
||||
FileType,
|
||||
ICodeStruct,
|
||||
} from '../../../types';
|
||||
import { generateUnknownType } from '../../../utils/compositeType';
|
||||
import { isContainerSchema } from '../../../utils/schema';
|
||||
import { RAX_CHUNK_NAME } from './const';
|
||||
|
||||
@ -67,7 +68,15 @@ const pluginFactory: BuilderComponentPluginFactory<PluginConfig> = (config?) =>
|
||||
// TODO: 下面的定义应该需要调用 @ali/lowcode-datasource-engine 的方法来搞:
|
||||
content: `
|
||||
_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],
|
||||
});
|
||||
@ -78,3 +87,17 @@ const pluginFactory: BuilderComponentPluginFactory<PluginConfig> = (config?) =>
|
||||
};
|
||||
|
||||
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() {
|
||||
return [
|
||||
{ id: 'urlParams', type: 'urlParams' },
|
||||
{ id: 'user', type: 'fetch', options: { method: 'GET', uri: 'https://shs.alibaba-inc.com/mock/1458/demo/user' } },
|
||||
{
|
||||
id: 'orders',
|
||||
type: 'fetch',
|
||||
options: { method: 'GET', uri: 'https://shs.alibaba-inc.com/mock/1458/demo/orders' },
|
||||
},
|
||||
];
|
||||
return function () {
|
||||
return [
|
||||
{ id: 'urlParams', type: 'urlParams', isInit: () => undefined, options: () => undefined },
|
||||
{
|
||||
id: 'user',
|
||||
type: 'fetch',
|
||||
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() {
|
||||
|
||||
@ -89,7 +89,10 @@
|
||||
type: 'fetch',
|
||||
options: {
|
||||
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