diff --git a/packages/umi-build-dev/src/plugins/commands/block/ui/server/index.ts b/packages/umi-build-dev/src/plugins/commands/block/ui/server/index.ts index 7ab8dfb67116..36d2030d528d 100644 --- a/packages/umi-build-dev/src/plugins/commands/block/ui/server/index.ts +++ b/packages/umi-build-dev/src/plugins/commands/block/ui/server/index.ts @@ -148,6 +148,7 @@ export default (api: IApi) => { success: true, }); break; + // 取消任务 case 'org.umi.block.cancel': success({ @@ -179,16 +180,84 @@ export default (api: IApi) => { break; case 'org.umi.block.checkIfCanAdd': + function haveFeature(feature) { + return payload.item.features && payload.item.features.includes(feature); + } + if (!api.config.routes) { - failure({ + return failure({ message: lang === 'zh-CN' ? '区块添加不支持约定式路由,请转成配置式路由。' : 'The block adding does not support the conventional route, please convert to a configuration route.', }); - } else { - success({}); } + + const payloadType = payload.type === 'block' ? '区块' : '模板'; + const isBigfish = !!process.env.BIGFISH_COMPAT; + const reactPlugin = api.config.plugins.find(p => { + return p === 'umi-plugin-react' || p[0] === 'umi-plugin-react'; + }); + const reactPluginOpts = reactPlugin + ? typeof reactPlugin === 'string' + ? {} + : reactPlugin[1] + : {}; + + // antd 特性依赖 + // bigfish 默认开了 antd + if (haveFeature('antd') && !isBigfish) { + if (!reactPlugin || !reactPluginOpts.antd) { + return failure({ + message: + lang === 'zh-CN' + ? `${payloadType}依赖 antd,请安装 umi-plugin-react 插件并开启 antd 。` + : 'Block depends on antd, please install umi-plugin-react and enable antd.', + }); + } + } + + // dva 特性依赖 + if (haveFeature('dva')) { + if (isBigfish) { + if (!api.config.dva) { + return failure({ + message: `${payloadType}依赖 dva,请开启 dva 配置。`, + }); + } + } else { + if (!reactPlugin || !reactPluginOpts.locale) { + return failure({ + message: + lang === 'zh-CN' + ? `${payloadType}依赖 dva,请安装 umi-plugin-react 插件并开启 dva 。` + : 'Block depends on dva, please install umi-plugin-react and enable dva.', + }); + } + } + } + + // locale 特性依赖 + if (haveFeature('i18n')) { + if (isBigfish) { + if (!api.config.locale) { + return failure({ + message: `${payloadType}依赖 locale,请开启 locale 配置。`, + }); + } + } else { + if (!reactPlugin || !reactPluginOpts.locale) { + return failure({ + message: + lang === 'zh-CN' + ? `${payloadType}依赖国际化(i18n),请安装 umi-plugin-react 插件并开启 locale 。` + : 'Block depends on i18n, please install umi-plugin-react and enable locale.', + }); + } + } + } + + success({}); break; // 检查路由是否存在 diff --git a/packages/umi-build-dev/src/plugins/commands/block/ui/ui/BlockList/BlockItem.tsx b/packages/umi-build-dev/src/plugins/commands/block/ui/ui/BlockList/BlockItem.tsx index 9b171353a360..5e736af776a9 100644 --- a/packages/umi-build-dev/src/plugins/commands/block/ui/ui/BlockList/BlockItem.tsx +++ b/packages/umi-build-dev/src/plugins/commands/block/ui/ui/BlockList/BlockItem.tsx @@ -70,6 +70,10 @@ const onBeforeOpenModal = async (api, { item, type, onShowModal }) => { try { await api.callRemote({ type: 'org.umi.block.checkIfCanAdd', + payload: { + item, + type, + }, }); } catch (e) { message.error(e.message);