From 6a6b57d382f59f8ec820b75b6461712cd7df48dd Mon Sep 17 00:00:00 2001 From: Xc Date: Thu, 1 Aug 2024 10:10:03 +0800 Subject: [PATCH] =?UTF-8?q?create=E6=97=B6=E7=9A=84=E7=BB=86=E8=8A=82?= =?UTF-8?q?=E4=BF=AE=E6=AD=A3=EF=BC=8C=E6=A8=A1=E6=9D=BF=E4=B8=ADweb/names?= =?UTF-8?q?pace/console=E7=9A=84=E4=BF=AE=E6=94=B9?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- lib/create.js | 2 +- lib/template.js | 16 +- src/template.ts | 26 +-- .../app/components/footer/index.module.less | 16 ++ .../web/src/app/components/footer/index.tsx | 19 +++ .../app/components/footer/locales/zh-CN.json | 3 + .../namespaces/console/index.pc.module.less | 40 +++++ .../web/src/app/namespaces/console/index.tsx | 152 ++++++++++++------ .../app/namespaces/console/locales/zh-CN.json | 4 + 9 files changed, 208 insertions(+), 70 deletions(-) create mode 100644 template/web/src/app/components/footer/index.module.less create mode 100644 template/web/src/app/components/footer/index.tsx create mode 100644 template/web/src/app/components/footer/locales/zh-CN.json create mode 100644 template/web/src/app/namespaces/console/index.pc.module.less create mode 100644 template/web/src/app/namespaces/console/locales/zh-CN.json diff --git a/lib/create.js b/lib/create.js index 535e514..e5736e5 100644 --- a/lib/create.js +++ b/lib/create.js @@ -232,7 +232,7 @@ async function create(dirName, cmd) { } // 获取package.json内容 const packageJson = (0, template_1.packageJsonContent)({ - name: DEFAULT_PROJECT_NAME, // 后面再统一rename + name: DEFAULT_PROJECT_NAME, version, description, cliName: config_1.CLI_NAME, diff --git a/lib/template.js b/lib/template.js index 2db50bf..fd7267d 100644 --- a/lib/template.js +++ b/lib/template.js @@ -11,8 +11,10 @@ const path_1 = require("path"); */ function getPackageLatestVersion(name) { const result = (0, child_process_1.execSync)(`npm info ${name}`).toString('utf-8'); - const data = result.match(/latest: \d\.\d\.\d\s*published/g); - return data[0].slice(8, 13); + const data = result.match(/latest: \d+\.\d+\.\d+\s*published/g); + const versionStr = data[0]; + const version = versionStr.slice(8, versionStr.indexOf('published')).replace(/[^0-9.]/g, ''); + return version; } function packageJsonContent({ name, version, description, cliName, cliBinName, isDev, isModule, dependencies }) { let oakDependencyStr = ''; @@ -37,15 +39,15 @@ function packageJsonContent({ name, version, description, cliName, cliBinName, i else { // todo,这里从npmjs.org上获取最新版本 oakDependencyStr = ` - "oak-domain": "^${getPackageLatestVersion('oak-domain')}", - "oak-external-sdk": "^${getPackageLatestVersion('oak-external-sdk')}", - "oak-frontend-base": "^${getPackageLatestVersion('oak-frontend-base')}",`; + "oak-domain": "~${getPackageLatestVersion('oak-domain')}", + "oak-external-sdk": "~${getPackageLatestVersion('oak-external-sdk')}", + "oak-frontend-base": "~${getPackageLatestVersion('oak-frontend-base')}",`; if (dependencies?.length) { dependencies?.forEach((dep) => { - oakDependencyStr += `\n"${dep}": "^${getPackageLatestVersion(dep)}"`; + oakDependencyStr += `\n"${dep}": "~${getPackageLatestVersion(dep)}",`; }); } - oakDevDependencyStr = `"${cliName}": "^${getPackageLatestVersion(cliName)}",`; + oakDevDependencyStr = `"${cliName}": "~${getPackageLatestVersion(cliName)}",`; } const serverInitScript = isDev ? "cross-env NODE_ENV=development cross-env OAK_PLATFORM=server node scripts/initServer.js" : "cross-env OAK_PLATFORM=server node scripts/initServer.js"; const serverStartScript = isDev ? "cross-env NODE_ENV=development cross-env OAK_PLATFORM=server node scripts/startServer.js" : "cross-env OAK_PLATFORM=server node scripts/startServer.js"; diff --git a/src/template.ts b/src/template.ts index abdcf1b..44a6317 100644 --- a/src/template.ts +++ b/src/template.ts @@ -10,8 +10,11 @@ import { PackageJsonInput } from './interface'; */ function getPackageLatestVersion(name: string) { const result = execSync(`npm info ${name}`).toString('utf-8'); - const data = result.match(/latest: \d\.\d\.\d\s*published/g); - return data![0].slice(8, 13); + const data = result.match(/latest: \d+\.\d+\.\d+\s*published/g); + const versionStr = data![0]; + const version = versionStr.slice(8, versionStr.indexOf('published')).replace(/[^0-9.]/g, ''); + + return version; } @@ -50,17 +53,17 @@ export function packageJsonContent({ else { // todo,这里从npmjs.org上获取最新版本 oakDependencyStr = ` - "oak-domain": "^${getPackageLatestVersion('oak-domain')}", - "oak-external-sdk": "^${getPackageLatestVersion('oak-external-sdk')}", - "oak-frontend-base": "^${getPackageLatestVersion('oak-frontend-base')}",`; + "oak-domain": "~${getPackageLatestVersion('oak-domain')}", + "oak-external-sdk": "~${getPackageLatestVersion('oak-external-sdk')}", + "oak-frontend-base": "~${getPackageLatestVersion('oak-frontend-base')}",`; if (dependencies?.length) { dependencies?.forEach( (dep) => { - oakDependencyStr += `\n"${dep}": "^${getPackageLatestVersion(dep)}"`; + oakDependencyStr += `\n"${dep}": "~${getPackageLatestVersion(dep)}",`; } ); } - oakDevDependencyStr = `"${cliName}": "^${getPackageLatestVersion(cliName)}",` + oakDevDependencyStr = `"${cliName}": "~${getPackageLatestVersion(cliName)}",` } const serverInitScript = isDev ? "cross-env NODE_ENV=development cross-env OAK_PLATFORM=server node scripts/initServer.js" : "cross-env OAK_PLATFORM=server node scripts/initServer.js"; @@ -70,11 +73,10 @@ export function packageJsonContent({ "version": "${version}", "description": "${description}", "scripts": { - "make:domain": "${ - isModule - ? `cross-env COMPLING_AS_LIB=yes ${cliBinName}` - : cliBinName - } make:domain", + "make:domain": "${isModule + ? `cross-env COMPLING_AS_LIB=yes ${cliBinName}` + : cliBinName + } make:domain", "make:locale": "${cliBinName} make:locale ${isModule ? '-m' : ''}", "make:dep": "${cliBinName} make:dependency", "clean:cache": "rimraf node_modules/.cache", diff --git a/template/web/src/app/components/footer/index.module.less b/template/web/src/app/components/footer/index.module.less new file mode 100644 index 0000000..ed16317 --- /dev/null +++ b/template/web/src/app/components/footer/index.module.less @@ -0,0 +1,16 @@ +.footer { + background: unset !important; +} + +.panel { + display: flex; + flex-direction: column; + align-items: center; + + /** 文本1 */ + font-size: 12px; + font-weight: 400; + letter-spacing: 0px; + line-height: 16.8px; + color: rgba(165, 192, 203, 1); +} \ No newline at end of file diff --git a/template/web/src/app/components/footer/index.tsx b/template/web/src/app/components/footer/index.tsx new file mode 100644 index 0000000..5dea63f --- /dev/null +++ b/template/web/src/app/components/footer/index.tsx @@ -0,0 +1,19 @@ +import React from 'react'; +import { Layout } from 'antd'; +import Style from './index.module.less'; + +const { Footer } = Layout; + +export default function Render() { + + return ( + + ); +} diff --git a/template/web/src/app/components/footer/locales/zh-CN.json b/template/web/src/app/components/footer/locales/zh-CN.json new file mode 100644 index 0000000..a27f2e8 --- /dev/null +++ b/template/web/src/app/components/footer/locales/zh-CN.json @@ -0,0 +1,3 @@ +{ + "copyright": "Oak Team & INSTITUTE OF COMPUTING INNOVATION, ZHEJIANG UNIVERSITY" +} \ No newline at end of file diff --git a/template/web/src/app/namespaces/console/index.pc.module.less b/template/web/src/app/namespaces/console/index.pc.module.less new file mode 100644 index 0000000..a25a6c4 --- /dev/null +++ b/template/web/src/app/namespaces/console/index.pc.module.less @@ -0,0 +1,40 @@ +.mixPanel { + height: 100% !important; + background: var(--oak-bg-color-page) !important; + min-height: unset !important; +} + +.mixMain { + background: unset !important; + flex-direction: row !important; + flex: 1 !important; +} + +.mixLayout { + background: unset !important; + overflow: auto !important; + min-height: unset !important; +} + +.mixContent { + background: unset !important; + min-height: unset !important; +} + +.login { + width: 100%; + height: 100%; + display: flex; + flex-direction: column; + align-items: center; + justify-content: center; +} + +.loadingBox { + height: 100%; + display: flex; + flex-direction: row; + align-items: center; + justify-content: center; + flex: 1; +} \ No newline at end of file diff --git a/template/web/src/app/namespaces/console/index.tsx b/template/web/src/app/namespaces/console/index.tsx index ca083d8..3026f80 100644 --- a/template/web/src/app/namespaces/console/index.tsx +++ b/template/web/src/app/namespaces/console/index.tsx @@ -1,70 +1,122 @@ - import React, { useEffect, useState } from 'react'; -import { Routes, Route, Outlet, useLocation } from 'react-router-dom'; +import { Outlet, useLocation } from 'react-router-dom'; +import { Layout, Spin, Result, Button } from 'antd'; +import Styles from './index.pc.module.less'; import Header from '../../components/header'; -import Styles from './web.pc.module.less'; +import Footer from '../../components/footer'; +import Login from 'oak-general-business/es/components/user/login'; import useFeatures from '@project/hooks/useFeatures'; -// import Menu from '@project/components/console/menu'; -import { useWidth } from 'oak-frontend-base/es/platforms/web'; +// import Menu from '@project/components/menu'; + +import { + OakTokenExpiredException, + OakUserInfoLoadingException, +} from 'oak-general-business'; + +import { OakUnloggedInException } from 'oak-domain/lib/types/Exception'; + +const { Content } = Layout; + +type Status = 'waiting' | 'success' | 'fail'; function Console(props: { namespace: string }) { const { namespace } = props; const features = useFeatures(); - const [currentMenuPath, setCmp] = useState(''); + features.navigator.setNamespace(namespace); - const width = useWidth(); - const location = useLocation(); - const { pathname } = location; - const path = pathname.slice(namespace.length); - const showBack = currentMenuPath && currentMenuPath !== path; - const isRoot = features.token.isRoot(); - // const mode = features.console.getMode(true); - const [mode, setMode] = useState(features.console.getMode(true)); + const [userId, setUserId] = useState(''); + const [status, setStatus] = useState('waiting'); + + const init = async () => { + try { + const id = features.token.getUserId(true); + if (id) { + setUserId(id); + } else { + setUserId(''); + } + setStatus('success'); + } catch (err) { + if (err instanceof OakUserInfoLoadingException) { + setStatus('waiting'); + return; + } + setStatus('fail'); + } + }; useEffect(() => { - features.navigator.setNamespace(namespace); - features.console.initialize(); - const location = window.location; - const { pathname } = location; - const path2 = pathname.slice(namespace.length); - setCmp(path2); - const unModeSubscribe = features.console.subscribe( - () => { - const newMode = features.console.getMode(); - setMode(newMode); - } - ) + init(); + const unsub1 = features.token.subscribe(() => { + init(); + }); + const unsub2 = features.locales.subscribe(() => { + init(); + }); return () => { - unModeSubscribe(); - features.console.destroy(); + unsub1(); + unsub2(); }; }, []); - // const showOpenStoreBtn = !isRoot && !mode && pathname === '/console'; - const [showOpenStore, setShowOpenStore] = useState(true); - useEffect(() => { - if (mode || isRoot) { - setShowOpenStore(false); - } else { - setShowOpenStore(true); - } - }, [mode, isRoot]) - return ( -
-
-
+ const location = useLocation(); + const { pathname } = location; + const isRoot = features.token.isRoot(); + + if (status === 'waiting') { + return ( +
+
-
- {/* setCmp(path)} - /> */} -
- + ); + } + + if (status === 'fail') { + return ( + +
+ { + window.location.reload(); + }} + > + {features.locales.t('reload')} + , + ]} + />
+
+ ); + } + + if (userId) { + return ( + +
+ + {/* */} + + + + +
+ ); } -export default Console; \ No newline at end of file +export default Console; diff --git a/template/web/src/app/namespaces/console/locales/zh-CN.json b/template/web/src/app/namespaces/console/locales/zh-CN.json new file mode 100644 index 0000000..8c991e4 --- /dev/null +++ b/template/web/src/app/namespaces/console/locales/zh-CN.json @@ -0,0 +1,4 @@ +{ + "errorInLoading": "抱歉,页面加载出现错误!请稍后再试。", + "reload": "重新加载" +} \ No newline at end of file