mirror of
https://github.com/alibaba/lowcode-engine.git
synced 2026-01-23 09:58:12 +00:00
fix: 🐛 解决 Rax 出码到小程序的时候 require(xxx) 语句不能被编译的问题
This commit is contained in:
parent
42e41bbd12
commit
332a473cd2
@ -11,6 +11,7 @@ import {
|
|||||||
DataSourceConfig,
|
DataSourceConfig,
|
||||||
isJSExpression,
|
isJSExpression,
|
||||||
isJSFunction,
|
isJSFunction,
|
||||||
|
JSExpression,
|
||||||
} from '../../../types';
|
} from '../../../types';
|
||||||
|
|
||||||
import { generateUnknownType } from '../../../utils/compositeType';
|
import { generateUnknownType } from '../../../utils/compositeType';
|
||||||
@ -37,24 +38,31 @@ const pluginFactory: BuilderComponentPluginFactory<PluginConfig> = (config?) =>
|
|||||||
const dataSourceItems: DataSourceConfig[] = (dataSourceConfig && dataSourceConfig.list) || [];
|
const dataSourceItems: DataSourceConfig[] = (dataSourceConfig && dataSourceConfig.list) || [];
|
||||||
const dataSourceEngineOptions = { runtimeConfig: true };
|
const dataSourceEngineOptions = { runtimeConfig: true };
|
||||||
if (dataSourceItems.length > 0) {
|
if (dataSourceItems.length > 0) {
|
||||||
Object.assign(dataSourceEngineOptions, {
|
const requestHandlersMap = {} as Record<string, JSExpression>;
|
||||||
requestHandlersMap: dataSourceItems.reduce(
|
|
||||||
(handlers, ds) =>
|
dataSourceItems.forEach((ds) => {
|
||||||
ds.type in handlers && ds.type !== 'custom'
|
if (!(ds.type in requestHandlersMap) && ds.type !== 'custom') {
|
||||||
? handlers
|
const handlerName = '__$$' + changeCase.camelCase(ds.type) + 'RequestHandler';
|
||||||
: {
|
|
||||||
...handlers,
|
requestHandlersMap[ds.type] = {
|
||||||
[ds.type]: {
|
|
||||||
type: 'JSExpression',
|
type: 'JSExpression',
|
||||||
value:
|
value: handlerName + (ds.type === 'urlParams' ? '({ search: this.props.location.search })' : ''),
|
||||||
`require('@ali/lowcode-datasource-engine/handlers/${changeCase.kebabCase(ds.type)}')` +
|
};
|
||||||
(ds.type === 'urlParams' ? '({ search: this.props.location.search })' : ''),
|
|
||||||
},
|
next.chunks.push({
|
||||||
},
|
type: ChunkType.STRING,
|
||||||
{} as Record<string, CompositeValue>,
|
fileType: FileType.JSX,
|
||||||
),
|
name: COMMON_CHUNK_NAME.ExternalDepsImport,
|
||||||
|
content: `
|
||||||
|
import ${handlerName} from '@ali/lowcode-datasource-engine/handlers/${changeCase.kebabCase(ds.type)}';
|
||||||
|
`,
|
||||||
|
linkAfter: [],
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
Object.assign(dataSourceEngineOptions, { requestHandlersMap });
|
||||||
|
}
|
||||||
|
|
||||||
next.chunks.push({
|
next.chunks.push({
|
||||||
type: ChunkType.STRING,
|
type: ChunkType.STRING,
|
||||||
|
|||||||
@ -9,6 +9,10 @@ import Text from 'rax-text';
|
|||||||
|
|
||||||
import Image from 'rax-image';
|
import Image from 'rax-image';
|
||||||
|
|
||||||
|
import __$$urlParamsRequestHandler from '@ali/lowcode-datasource-engine/handlers/url-params';
|
||||||
|
|
||||||
|
import __$$fetchRequestHandler from '@ali/lowcode-datasource-engine/handlers/fetch';
|
||||||
|
|
||||||
import { create as __$$createDataSourceEngine } from '@ali/lowcode-datasource-engine';
|
import { create as __$$createDataSourceEngine } from '@ali/lowcode-datasource-engine';
|
||||||
|
|
||||||
import { isMiniApp as __$$isMiniApp } from 'universal-env';
|
import { isMiniApp as __$$isMiniApp } from 'universal-env';
|
||||||
@ -44,9 +48,9 @@ class Home$$Page extends Component {
|
|||||||
_dataSourceConfig = this._defineDataSourceConfig();
|
_dataSourceConfig = this._defineDataSourceConfig();
|
||||||
_dataSourceEngine = __$$createDataSourceEngine(this._dataSourceConfig, this._context, {
|
_dataSourceEngine = __$$createDataSourceEngine(this._dataSourceConfig, this._context, {
|
||||||
runtimeConfig: true,
|
runtimeConfig: true,
|
||||||
requestHandlers: {
|
requestHandlersMap: {
|
||||||
urlParams: require('@ali/lowcode-datasource-engine/handlers/url-params')({ search: this.props.location.search }),
|
urlParams: __$$urlParamsRequestHandler({ search: this.props.location.search }),
|
||||||
fetch: require('@ali/lowcode-datasource-engine/handlers/fetch'),
|
fetch: __$$fetchRequestHandler,
|
||||||
},
|
},
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user