From c2f3f7e6462da393fc6891a13572c7c4bf73de89 Mon Sep 17 00:00:00 2001
From: wkj <278599135@qq.com>
Date: Thu, 18 Aug 2022 11:15:39 +0800
Subject: [PATCH] =?UTF-8?q?=E8=B0=83=E6=95=B4=E6=A8=A1=E7=89=88=E7=9B=AE?=
=?UTF-8?q?=E5=BD=95=EF=BC=8C=E5=AF=B9=E7=BC=96=E8=AF=91=E8=BE=B9=E7=95=8C?=
=?UTF-8?q?=E8=BF=9B=E8=A1=8C=E5=A4=84=E7=90=86?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
---
config/babel-plugin/oakI18n.js | 1 -
config/babel-plugin/oakPath.js | 15 ++-
config/babel-plugin/oakRender.js | 1 -
config/babel-plugin/oakStyle.js | 3 +-
config/babel-plugin/router.js | 111 +++++++++++++-----
template/web/src/App.less | 6 +-
template/web/src/App.tsx | 10 +-
.../src/{template => components}/Loading.tsx | 0
.../console/index.tsx | 0
.../frontend/index.tsx | 0
.../notFound/index.tsx | 0
template/web/src/index.less | 6 +
12 files changed, 103 insertions(+), 50 deletions(-)
rename template/web/src/{template => components}/Loading.tsx (100%)
rename template/web/src/{template => components}/console/index.tsx (100%)
rename template/web/src/{template => components}/frontend/index.tsx (100%)
rename template/web/src/{template => components}/notFound/index.tsx (100%)
diff --git a/config/babel-plugin/oakI18n.js b/config/babel-plugin/oakI18n.js
index e63eb9e..1699456 100644
--- a/config/babel-plugin/oakI18n.js
+++ b/config/babel-plugin/oakI18n.js
@@ -1,7 +1,6 @@
const fs = require('fs');
const { relative, resolve } = require('path');
const t = require('@babel/types');
-const pull = require('lodash/pull');
const { assert } = require('console');
const oakRegex =
diff --git a/config/babel-plugin/oakPath.js b/config/babel-plugin/oakPath.js
index da513b1..d75185b 100644
--- a/config/babel-plugin/oakPath.js
+++ b/config/babel-plugin/oakPath.js
@@ -1,7 +1,6 @@
const fs = require('fs');
const { relative, resolve } = require('path');
const t = require('@babel/types');
-const pull = require('lodash/pull');
const { assert } = require('console');
function isOakNamespaceIdentifier(node, name) {
@@ -38,9 +37,17 @@ module.exports = (babel) => {
: lessFileExists
? './index.less'
: './index.pc.less';
- body.unshift(
- t.importDeclaration([], t.stringLiteral(lessFileImport))
- );
+ if (
+ (lessFileExists && !pcLessFileExists) ||
+ (!lessFileExists && pcLessFileExists)
+ ) {
+ body.unshift(
+ t.importDeclaration(
+ [],
+ t.stringLiteral(lessFileImport)
+ )
+ );
+ }
}
},
JSXAttribute(path, state) {
diff --git a/config/babel-plugin/oakRender.js b/config/babel-plugin/oakRender.js
index e182425..a653ae1 100644
--- a/config/babel-plugin/oakRender.js
+++ b/config/babel-plugin/oakRender.js
@@ -1,7 +1,6 @@
const fs = require('fs');
const { relative, resolve } = require('path');
const t = require('@babel/types');
-const pull = require('lodash/pull');
const { assert } = require('console');
module.exports = (babel) => {
diff --git a/config/babel-plugin/oakStyle.js b/config/babel-plugin/oakStyle.js
index 23bbe75..f8c1d2f 100644
--- a/config/babel-plugin/oakStyle.js
+++ b/config/babel-plugin/oakStyle.js
@@ -1,8 +1,7 @@
const fs = require('fs');
const { relative } = require('path');
-const t = require('@babel/types');
-const pull = require('lodash/pull');
const { assert } = require('console');
+const t = require('@babel/types');
const generate = require('@babel/generator').default;
const parser = require("@babel/parser");
diff --git a/config/babel-plugin/router.js b/config/babel-plugin/router.js
index ba9a93a..914d006 100644
--- a/config/babel-plugin/router.js
+++ b/config/babel-plugin/router.js
@@ -1,6 +1,6 @@
+const fs = require('fs');
const { relative, join } = require('path');
const t = require('@babel/types');
-const pull = require('lodash/pull');
const assert = require('assert');
const AppPaths = require('../web/paths');
@@ -16,45 +16,92 @@ module.exports = () => {
// 在Function App前面插入router的相关代码
const functionAppNode = body[body.length - 2];
const routerDelarationNode = body[body.length - 3];
- assert(t.isFunctionDeclaration(functionAppNode) && t.isIdentifier(functionAppNode.id) && functionAppNode.id.name === 'App');
- assert(t.isVariableDeclaration(routerDelarationNode) && routerDelarationNode.kind === 'let'
- && t.isVariableDeclarator(routerDelarationNode.declarations[0]) && t.isIdentifier(routerDelarationNode.declarations[0].id)
- && routerDelarationNode.declarations[0].id.name === 'routers');
+ assert(
+ t.isFunctionDeclaration(functionAppNode) &&
+ t.isIdentifier(functionAppNode.id) &&
+ functionAppNode.id.name === 'App'
+ );
+ assert(
+ t.isVariableDeclaration(routerDelarationNode) &&
+ routerDelarationNode.kind === 'let' &&
+ t.isVariableDeclarator(
+ routerDelarationNode.declarations[0]
+ ) &&
+ t.isIdentifier(
+ routerDelarationNode.declarations[0].id
+ ) &&
+ routerDelarationNode.declarations[0].id.name ===
+ 'routers'
+ );
- const { pages } = require(join(cwd, appDir, 'src', 'app.json'));
- const objs = pages.map(
- (ele) => {
- const relPath = ele.replace('@project', AppPaths.appRootSrc).replace('@oak-general-business', AppPaths.oakGeneralBusinessAppPath);
- const { navigationBarTitleText } = require(`${relPath}.json`);
- const pagePath = ele.slice(ele.indexOf('pages/') + 6, ele.length - 6);
- return t.objectExpression([
- t.objectProperty(t.identifier('title'), t.stringLiteral(navigationBarTitleText || '')),
- t.objectProperty(t.identifier('path'), t.stringLiteral(pagePath)),
- t.objectProperty(t.identifier('element'), t.callExpression(
- t.memberExpression(t.identifier('React'), t.identifier('lazy')),
+ const { pages } = require(join(
+ cwd,
+ appDir,
+ 'src',
+ 'app.json'
+ ));
+ const objs = pages.map((ele) => {
+ const relPath = ele
+ .replace('@project', AppPaths.appRootSrc)
+ .replace(
+ '@oak-general-business',
+ AppPaths.oakGeneralBusinessAppPath
+ );
+ const jsonFileExists = fs.existsSync(`${relPath}.json`);
+ const pagePath = ele.slice(
+ ele.indexOf('pages/') + 6,
+ ele.length - 6
+ );
+ const params = [
+ t.objectProperty(
+ t.identifier('path'),
+ t.stringLiteral(pagePath)
+ ),
+ t.objectProperty(
+ t.identifier('element'),
+ t.callExpression(
+ t.memberExpression(
+ t.identifier('React'),
+ t.identifier('lazy')
+ ),
[
t.arrowFunctionExpression(
[],
- t.callExpression(
- t.import(),
- [
- t.stringLiteral(ele)
- ]
- )
- )
+ t.callExpression(t.import(), [
+ t.stringLiteral(ele),
+ ])
+ ),
]
- ))
- ]);
+ )
+ ),
+ ];
+ if (jsonFileExists) {
+ const {
+ navigationBarTitleText,
+ } = require(`${relPath}.json`);
+ params.unshift(
+ t.objectProperty(
+ t.identifier('title'),
+ t.stringLiteral(
+ navigationBarTitleText || ''
+ )
+ )
+ );
}
- );
+ return t.objectExpression(params);
+ });
- body.splice(body.length - 2, 0, t.expressionStatement(
- t.assignmentExpression(
- '=',
- t.identifier('routers'),
- t.arrayExpression(objs)
+ body.splice(
+ body.length - 2,
+ 0,
+ t.expressionStatement(
+ t.assignmentExpression(
+ '=',
+ t.identifier('routers'),
+ t.arrayExpression(objs)
+ )
)
- ));
+ );
}
},
},
diff --git a/template/web/src/App.less b/template/web/src/App.less
index 66123d5..601e26a 100644
--- a/template/web/src/App.less
+++ b/template/web/src/App.less
@@ -1,6 +1,2 @@
@import 'tdesign-react/es/style/index.css'; // 少量公共样式
-@import 'tdesign-mobile-react/es/style/index.css'; // 少量公共样式
-
-:root {
- --td-screen-xs: 576px;
-}
\ No newline at end of file
+@import 'tdesign-mobile-react/es/style/index.css'; // 少量公共样式
\ No newline at end of file
diff --git a/template/web/src/App.tsx b/template/web/src/App.tsx
index 794890e..38eaec4 100644
--- a/template/web/src/App.tsx
+++ b/template/web/src/App.tsx
@@ -2,10 +2,10 @@ import React from 'react';
import { Routes, Route } from 'react-router-dom';
import './App.less';
-import Loading from './template/Loading';
-const Console = React.lazy(() => import('./template/console'));
-const Frontend = React.lazy(() => import('./template/frontend'));
-const NotFound = React.lazy(() => import('./template/notFound'));
+import Loading from './components/Loading';
+const Console = React.lazy(() => import('./components/console'));
+const Frontend = React.lazy(() => import('./components/frontend'));
+const NotFound = React.lazy(() => import('./components/notFound'));
const Message = React.lazy(() => import('@oak-general-business/components/message'));
const DebugPanel = React.lazy(() => import('@oak-general-business/components/func/debugPanel'));
@@ -24,7 +24,7 @@ function getRoutes(routers2: Router[], namespace?: string) {
path={path}
element={
}>
-
+
}
>
diff --git a/template/web/src/template/Loading.tsx b/template/web/src/components/Loading.tsx
similarity index 100%
rename from template/web/src/template/Loading.tsx
rename to template/web/src/components/Loading.tsx
diff --git a/template/web/src/template/console/index.tsx b/template/web/src/components/console/index.tsx
similarity index 100%
rename from template/web/src/template/console/index.tsx
rename to template/web/src/components/console/index.tsx
diff --git a/template/web/src/template/frontend/index.tsx b/template/web/src/components/frontend/index.tsx
similarity index 100%
rename from template/web/src/template/frontend/index.tsx
rename to template/web/src/components/frontend/index.tsx
diff --git a/template/web/src/template/notFound/index.tsx b/template/web/src/components/notFound/index.tsx
similarity index 100%
rename from template/web/src/template/notFound/index.tsx
rename to template/web/src/components/notFound/index.tsx
diff --git a/template/web/src/index.less b/template/web/src/index.less
index ec2585e..66ede7b 100644
--- a/template/web/src/index.less
+++ b/template/web/src/index.less
@@ -11,3 +11,9 @@ code {
font-family: source-code-pro, Menlo, Monaco, Consolas, 'Courier New',
monospace;
}
+
+html,
+body,
+#root {
+ height: 100%;
+}