From 8e13f79be6fb09dac05f49836af07f9ee7dc2fbe Mon Sep 17 00:00:00 2001 From: Xc Date: Wed, 10 Apr 2024 16:15:30 +0800 Subject: [PATCH] =?UTF-8?q?template=E5=90=915.0=E9=9D=A0=E6=8B=A2?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- lib/server/start.d.ts | 3 +- lib/server/start.js | 13 ++-- lib/template.js | 2 + src/server/start.ts | 12 +-- src/template.ts | 2 + template/src/aspects/index.ts | 4 + template/src/config/color.ts | 8 -- template/src/config/connector.ts | 9 +++ template/src/config/oakExternalLib.json | 1 - template/src/configuration/access.dev.ts | 10 +++ template/src/configuration/access.prod.ts | 11 +++ template/src/configuration/access.ts | 3 + .../src/configuration/attrUpdateMatrix.ts | 15 ++++ .../src/{config => configuration}/cache.ts | 2 +- template/src/configuration/dependency.ts | 5 ++ template/src/configuration/index.ts | 21 +++++- .../src/{config => configuration}/relation.ts | 9 +-- template/src/configuration/render.ts | 7 ++ template/src/configuration/server.ts | 13 ++++ template/src/context/BackendRuntimeContext.ts | 29 ++------ .../src/context/FrontendRuntimeContext.ts | 23 ++---- template/src/data/i18n.ts | 3 +- template/src/entities/Store.ts | 20 ++++- template/src/features/Console.ts | 8 +- template/src/features/Menu.ts | 15 +--- template/src/features/Sample.ts | 18 +---- template/src/features/index.ts | 28 +------ template/src/initialize.dev.ts | 74 ------------------- template/src/initialize.prod.ts | 74 ------------------- template/src/page.mp.ts | 2 +- template/src/page.native.ts | 1 + template/src/page.ts | 2 +- template/src/page.web.ts | 2 +- template/src/types/Exception.ts | 4 +- template/src/types/RuntimeCxt.ts | 15 ---- template/web/src/index.tsx | 23 +++--- template/web/src/initialize.ts | 15 +--- templateFiles/RuntimeCxt.ts | 14 ++++ templateFiles/initialize.dev.ts | 4 +- templateFiles/initialize.prod.ts | 7 +- 40 files changed, 195 insertions(+), 336 deletions(-) delete mode 100644 template/src/config/color.ts create mode 100644 template/src/config/connector.ts delete mode 100644 template/src/config/oakExternalLib.json create mode 100644 template/src/configuration/access.dev.ts create mode 100644 template/src/configuration/access.prod.ts create mode 100644 template/src/configuration/access.ts create mode 100644 template/src/configuration/attrUpdateMatrix.ts rename template/src/{config => configuration}/cache.ts (75%) create mode 100644 template/src/configuration/dependency.ts rename template/src/{config => configuration}/relation.ts (58%) create mode 100644 template/src/configuration/render.ts create mode 100644 template/src/configuration/server.ts delete mode 100644 template/src/initialize.dev.ts delete mode 100644 template/src/initialize.prod.ts create mode 100644 template/src/page.native.ts delete mode 100644 template/src/types/RuntimeCxt.ts create mode 100644 templateFiles/RuntimeCxt.ts diff --git a/lib/server/start.d.ts b/lib/server/start.d.ts index 8c0934e..967f985 100644 --- a/lib/server/start.d.ts +++ b/lib/server/start.d.ts @@ -4,4 +4,5 @@ import { Connector, EntityDict } from 'oak-domain/lib/types'; import { EntityDict as BaseEntityDict } from 'oak-domain/lib/base-app-domain'; import { AsyncContext } from 'oak-domain/lib/store/AsyncRowStore'; import { SyncContext } from 'oak-domain/lib/store/SyncRowStore'; -export declare function startup>(path: string, connector: Connector, omitWatchers?: boolean, omitTimers?: boolean, routine?: (context: AsyncContext) => Promise): Promise; +import { AccessConfiguration } from 'oak-domain/lib/types/Configuration'; +export declare function startup>(path: string, connector: Connector, accessConfiguration: AccessConfiguration, omitWatchers?: boolean, omitTimers?: boolean, routine?: (context: AsyncContext) => Promise): Promise; diff --git a/lib/server/start.js b/lib/server/start.js index 2e53e5a..c1429d3 100644 --- a/lib/server/start.js +++ b/lib/server/start.js @@ -5,7 +5,6 @@ const tslib_1 = require("tslib"); /// require("./polyfill"); const http_1 = require("http"); -const path_1 = tslib_1.__importDefault(require("path")); const koa_1 = tslib_1.__importDefault(require("koa")); const koa_router_1 = tslib_1.__importDefault(require("koa-router")); const koa_body_1 = tslib_1.__importDefault(require("koa-body")); @@ -16,7 +15,7 @@ const sticky_1 = require("@socket.io/sticky"); const socket_io_1 = require("socket.io"); const DATA_SUBSCRIBER_NAMESPACE = '/ds'; const SERVER_SUBSCRIBER_NAMESPACE = process.env.OAK_SSUB_NAMESPACE || '/ssub'; -async function startup(path, connector, omitWatchers, omitTimers, routine) { +async function startup(path, connector, accessConfiguration, omitWatchers, omitTimers, routine) { const koa = new koa_1.default(); // socket const httpServer = (0, http_1.createServer)(koa.callback()); @@ -68,7 +67,6 @@ async function startup(path, connector, omitWatchers, omitTimers, routine) { multipart: true, })); const router = new koa_router_1.default(); - const serverConfig = require(path_1.default.join(path, '/configuration/server.json')); // 如果是开发环境,允许options if (['development', 'staging'].includes(process.env.NODE_ENV)) { koa.use(async (ctx, next) => { @@ -109,7 +107,8 @@ async function startup(path, connector, omitWatchers, omitTimers, routine) { namespace: DATA_SUBSCRIBER_NAMESPACE, path: connector.getSubscribeRouter(), // 如果是开发环境就直连@socket.io/pm2的监听端口 - port: process.env.NODE_ENV === 'development' ? (process.env.PM2_PORT || 8080) : serverConfig.port, + // 这里看不懂,似乎不对,要测试。by Xc 20240410 + port: process.env.NODE_ENV === 'development' ? (process.env.PM2_PORT || 8080) : accessConfiguration.http.port, }; // 开发环境socket直接连接 return; @@ -119,7 +118,7 @@ async function startup(path, connector, omitWatchers, omitTimers, routine) { response.body = { namespace: DATA_SUBSCRIBER_NAMESPACE, path: connector.getSubscribeRouter(), - port: serverConfig.port, + port: accessConfiguration.http.port, }; return; } @@ -145,12 +144,12 @@ async function startup(path, connector, omitWatchers, omitTimers, routine) { ctx.response.body = endpoints; }); koa.use(router.routes()); - console.log(`server will listen on port ${serverConfig.port}`); + console.log(`server will listen on port ${accessConfiguration.http.port || (accessConfiguration.http.ssl ? 443 : 80)}`); koa.on('error', (err) => { console.error(err); throw err; }); - httpServer.listen(serverConfig.port); + httpServer.listen(accessConfiguration.http.port); if (!omitWatchers) { appLoader.startWatchers(); } diff --git a/lib/template.js b/lib/template.js index be5bf07..e90a1dd 100644 --- a/lib/template.js +++ b/lib/template.js @@ -49,6 +49,7 @@ function packageJsonContent({ name, version, description, cliName, cliBinName, i "scripts": { "make:domain": "${cliBinName} make:domain", "make:locale": "${cliBinName} make:locale", + "make:dep": "${cliBinName} make:dependency", "clean:cache": "rimraf node_modules/.cache", "copy-config-json": "copyfiles -u 1 src/config/*.json lib/", "start:mp": "${cliBinName} start --target mp --mode development", @@ -67,6 +68,7 @@ function packageJsonContent({ name, version, description, cliName, cliBinName, i "build-analyze:web": "${cliBinName} build --target web --mode production --analyze", "build-sourcemap-analyze:web": "${cliBinName} build --target web --mode production --sourcemap --analyze", "build": "tsc -p tsconfig.build.json && tsc-alias -p tsconfig.build.json && npm run copy-config-json", + "prebuild": "npm run make:locale && npm run make:dep", "run:ios": "oak-cli run -p ios", "run:android": "oak-cli run -p android", "server:init": "${serverInitScript}", diff --git a/src/server/start.ts b/src/server/start.ts index 34138e0..5f46918 100644 --- a/src/server/start.ts +++ b/src/server/start.ts @@ -13,6 +13,7 @@ import { SyncContext } from 'oak-domain/lib/store/SyncRowStore'; import { createAdapter } from "@socket.io/cluster-adapter"; import { setupWorker } from "@socket.io/sticky"; import { Server } from "socket.io"; +import { AccessConfiguration } from 'oak-domain/lib/types/Configuration'; const DATA_SUBSCRIBER_NAMESPACE = '/ds'; const SERVER_SUBSCRIBER_NAMESPACE = process.env.OAK_SSUB_NAMESPACE || '/ssub'; @@ -20,6 +21,7 @@ const SERVER_SUBSCRIBER_NAMESPACE = process.env.OAK_SSUB_NAMESPACE || '/ssub'; export async function startup>( path: string, connector: Connector, + accessConfiguration: AccessConfiguration, omitWatchers?: boolean, omitTimers?: boolean, routine?: (context: AsyncContext) => Promise, @@ -78,7 +80,6 @@ export async function startup { @@ -123,7 +124,8 @@ export async function startup { console.error(err); throw err; }); - httpServer.listen(serverConfig.port); + httpServer.listen(accessConfiguration.http.port); if (!omitWatchers) { appLoader.startWatchers(); diff --git a/src/template.ts b/src/template.ts index 1983f71..461bedf 100644 --- a/src/template.ts +++ b/src/template.ts @@ -58,6 +58,7 @@ export function packageJsonContent({ "scripts": { "make:domain": "${cliBinName} make:domain", "make:locale": "${cliBinName} make:locale", + "make:dep": "${cliBinName} make:dependency", "clean:cache": "rimraf node_modules/.cache", "copy-config-json": "copyfiles -u 1 src/config/*.json lib/", "start:mp": "${cliBinName} start --target mp --mode development", @@ -76,6 +77,7 @@ export function packageJsonContent({ "build-analyze:web": "${cliBinName} build --target web --mode production --analyze", "build-sourcemap-analyze:web": "${cliBinName} build --target web --mode production --sourcemap --analyze", "build": "tsc -p tsconfig.build.json && tsc-alias -p tsconfig.build.json && npm run copy-config-json", + "prebuild": "npm run make:locale && npm run make:dep", "run:ios": "oak-cli run -p ios", "run:android": "oak-cli run -p android", "server:init": "${serverInitScript}", diff --git a/template/src/aspects/index.ts b/template/src/aspects/index.ts index dd8ff5f..39a4682 100644 --- a/template/src/aspects/index.ts +++ b/template/src/aspects/index.ts @@ -6,3 +6,7 @@ const aspectDict = { } as AspectDict; export default aspectDict; +export { + AspectDict, +}; + diff --git a/template/src/config/color.ts b/template/src/config/color.ts deleted file mode 100644 index 7cece1e..0000000 --- a/template/src/config/color.ts +++ /dev/null @@ -1,8 +0,0 @@ -import { ColorDict } from 'oak-domain/lib/types/Style'; -import { EntityDict } from '@oak-app-domain'; - -const colorDict: ColorDict = { - -}; - -export default colorDict; diff --git a/template/src/config/connector.ts b/template/src/config/connector.ts new file mode 100644 index 0000000..2efef79 --- /dev/null +++ b/template/src/config/connector.ts @@ -0,0 +1,9 @@ +import SimpleConnector from 'oak-domain/lib/utils/SimpleConnector'; +import accessConfiguration from '@project/configuration/access'; +import { makeException } from '@project/types/Exception'; +import { EntityDict } from '@project/oak-app-domain'; +import FrontendRuntimeContext from '@project/context/FrontendRuntimeContext'; + +const connector = new SimpleConnector(accessConfiguration, makeException); + +export default connector; \ No newline at end of file diff --git a/template/src/config/oakExternalLib.json b/template/src/config/oakExternalLib.json deleted file mode 100644 index 7aac1ea..0000000 --- a/template/src/config/oakExternalLib.json +++ /dev/null @@ -1 +0,0 @@ -["oak-general-business"] \ No newline at end of file diff --git a/template/src/configuration/access.dev.ts b/template/src/configuration/access.dev.ts new file mode 100644 index 0000000..4e09c44 --- /dev/null +++ b/template/src/configuration/access.dev.ts @@ -0,0 +1,10 @@ +import { AccessConfiguration } from 'oak-domain/lib/types/Configuration'; + +const accessConfiguration: AccessConfiguration = { + http: { + hostname: 'localhost', + port: 3001, + }, +}; + +export default accessConfiguration; diff --git a/template/src/configuration/access.prod.ts b/template/src/configuration/access.prod.ts new file mode 100644 index 0000000..f4d32f3 --- /dev/null +++ b/template/src/configuration/access.prod.ts @@ -0,0 +1,11 @@ +import { AccessConfiguration } from 'oak-domain/lib/types/Configuration'; + +const accessConfiguration: AccessConfiguration = { + http: { + hostname: 'www.oak-framework.test', + ssl: true, + path: 'oak-api', // 配置在nginx中的映射 + }, +}; + +export default accessConfiguration; diff --git a/template/src/configuration/access.ts b/template/src/configuration/access.ts new file mode 100644 index 0000000..7cdf47a --- /dev/null +++ b/template/src/configuration/access.ts @@ -0,0 +1,3 @@ +import accessConfiguration from './access.dev'; +export default accessConfiguration; +console.log('不应该跑到这里'); \ No newline at end of file diff --git a/template/src/configuration/attrUpdateMatrix.ts b/template/src/configuration/attrUpdateMatrix.ts new file mode 100644 index 0000000..1e6e4a5 --- /dev/null +++ b/template/src/configuration/attrUpdateMatrix.ts @@ -0,0 +1,15 @@ +import { AttrUpdateMatrix } from 'oak-domain/lib/types/EntityDesc'; +import { EntityDict } from '@project/oak-app-domain'; + + +const attrUpdateMatrix: AttrUpdateMatrix = { + store: { + name: { + filter: { + iState: 'offline', + }, + }, + }, +} + +export default attrUpdateMatrix; \ No newline at end of file diff --git a/template/src/config/cache.ts b/template/src/configuration/cache.ts similarity index 75% rename from template/src/config/cache.ts rename to template/src/configuration/cache.ts index 0ee019d..730d9fb 100644 --- a/template/src/config/cache.ts +++ b/template/src/configuration/cache.ts @@ -1,4 +1,4 @@ import { EntityDict } from '@project/oak-app-domain'; const cacheSavedEntities: (keyof EntityDict)[] = []; -export default cacheSavedEntities; \ No newline at end of file +export default cacheSavedEntities; diff --git a/template/src/configuration/dependency.ts b/template/src/configuration/dependency.ts new file mode 100644 index 0000000..fac4af2 --- /dev/null +++ b/template/src/configuration/dependency.ts @@ -0,0 +1,5 @@ +import { DependencyConfiguration } from 'oak-domain/lib/types/Configuration'; + +const dependencyConfiguration: DependencyConfiguration = ['oak-general-business']; + +export default dependencyConfiguration; diff --git a/template/src/configuration/index.ts b/template/src/configuration/index.ts index 5f1504c..d902eb7 100644 --- a/template/src/configuration/index.ts +++ b/template/src/configuration/index.ts @@ -1,6 +1,19 @@ -import { AttrUpdateMatrix } from 'oak-domain/lib/types/EntityDesc'; +/** + * index中汇总了前端启动需要的引用配置 + */ +import attrUpdateMatrix from './attrUpdateMatrix'; +import { CommonConfiguration } from 'oak-domain/lib/types/Configuration'; +import { actionDefDict } from '@project/oak-app-domain/ActionDefDict'; +import { selectFreeEntities, authDeduceRelationMap, updateFreeDict } from './relation'; +import cacheSavedEntities from './cache'; import { EntityDict } from '@project/oak-app-domain'; -export const attrUpdateMatrix: AttrUpdateMatrix = { - -} \ No newline at end of file +export default { + attrUpdateMatrix, + actionDefDict, + authDeduceRelationMap, + selectFreeEntities, + updateFreeDict, + cacheSavedEntities, + // cacheKeepFreshPeriod: 600 * 1000, // cache默认对缓存对象的刷新间隔时长(在这个间隔内不刷新) +} as CommonConfiguration; \ No newline at end of file diff --git a/template/src/config/relation.ts b/template/src/configuration/relation.ts similarity index 58% rename from template/src/config/relation.ts rename to template/src/configuration/relation.ts index 3a3556d..365d73d 100644 --- a/template/src/config/relation.ts +++ b/template/src/configuration/relation.ts @@ -1,16 +1,13 @@ import { AuthDeduceRelationMap, SelectFreeEntities, UpdateFreeDict } from 'oak-domain/lib/types/Entity'; -import { selectFreeEntities as ogbSFF, authDeduceRelationMap as ogbADR, updateFreeDict as obgUFD } from 'oak-general-business/lib/config/relation'; import { EntityDict } from '@project/oak-app-domain'; // 此对象所标识的entity的权限由其外键指向的父对象判定 export const authDeduceRelationMap: AuthDeduceRelationMap = { - ...ogbADR, }; -export const selectFreeEntities = (ogbSFF as SelectFreeEntities).concat([ - -]); +export const selectFreeEntities = [ + 'store', +]; export const updateFreeDict: UpdateFreeDict = { - ...obgUFD }; \ No newline at end of file diff --git a/template/src/configuration/render.ts b/template/src/configuration/render.ts new file mode 100644 index 0000000..2956820 --- /dev/null +++ b/template/src/configuration/render.ts @@ -0,0 +1,7 @@ +import { RenderConfiguration } from 'oak-domain/lib/types/Configuration'; +import { styleDict } from '@project/oak-app-domain/StyleDict'; +import { EntityDict } from '@project/oak-app-domain'; + +export default { + styleDict, +} as RenderConfiguration; diff --git a/template/src/configuration/server.ts b/template/src/configuration/server.ts new file mode 100644 index 0000000..4af294d --- /dev/null +++ b/template/src/configuration/server.ts @@ -0,0 +1,13 @@ +import { ServerConfiguration } from 'oak-domain/lib/types/Configuration'; +import { EntityDict } from '@project/oak-app-domain'; +import { BackendRuntimeContext } from '@project/context/BackendRuntimeContext'; +import { join } from 'path'; + +const serverConfiguration: ServerConfiguration = { + database: require('../../configuration/mysql.json'), + workDir: { + path: join(__dirname, '..', '..'), + }, +}; + +export default serverConfiguration; diff --git a/template/src/context/BackendRuntimeContext.ts b/template/src/context/BackendRuntimeContext.ts index 3a49623..262dceb 100644 --- a/template/src/context/BackendRuntimeContext.ts +++ b/template/src/context/BackendRuntimeContext.ts @@ -1,27 +1,12 @@ -import { EntityDict } from '@oak-app-domain'; -import { AsyncRowStore } from 'oak-domain/lib/store/AsyncRowStore'; +import { EntityDict } from '@project/oak-app-domain'; import { RuntimeContext } from './RuntimeContext'; -import { BackendRuntimeContext as GeneralBackendRuntimeContext } from 'oak-general-business'; -import { IncomingHttpHeaders } from 'http'; +import { BackendRuntimeContext as GeneralBackendRuntimeContext } from './DependentContext'; -export class BackendRuntimeContext - extends GeneralBackendRuntimeContext - implements RuntimeContext -{ - static FromSerializedString(str?: string) { - const data = str && JSON.parse(str); - - return async ( - store: AsyncRowStore - ) => { - const context = new BackendRuntimeContext(store); - await context.initialize(data); - return context; - }; - } - - async toString(): Promise { +export class BackendRuntimeContext extends GeneralBackendRuntimeContext implements RuntimeContext { + async toString() { const data = await this.getSerializedData(); return JSON.stringify(data); } -} +}; + +export default BackendRuntimeContext; \ No newline at end of file diff --git a/template/src/context/FrontendRuntimeContext.ts b/template/src/context/FrontendRuntimeContext.ts index e5c032d..7b051b3 100644 --- a/template/src/context/FrontendRuntimeContext.ts +++ b/template/src/context/FrontendRuntimeContext.ts @@ -1,28 +1,17 @@ -import { EntityDict } from '@oak-app-domain'; +import { EntityDict } from '@project/oak-app-domain'; import { FrontendRuntimeContext as GeneralFrontendRuntimeContext, - GeneralAspectDict, -} from 'oak-general-business'; -import { CommonAspectDict } from 'oak-common-aspect/lib/AspectDict'; +} from './DependentContext'; import { RuntimeContext } from './RuntimeContext'; -import { AspectDict } from '../aspects/AspectDict'; -import { BackendRuntimeContext } from './BackendRuntimeContext'; -import { SyncContext, SyncRowStore } from 'oak-domain/lib/store/SyncRowStore'; - -type FullAspectDict = CommonAspectDict & - AspectDict & - GeneralAspectDict; export class FrontendRuntimeContext - extends GeneralFrontendRuntimeContext< - EntityDict, - BackendRuntimeContext, - FullAspectDict - > + extends GeneralFrontendRuntimeContext implements RuntimeContext { - async toString(): Promise { + async toString() { const data = await this.getSerializedData(); return JSON.stringify(data); } } + +export default FrontendRuntimeContext; \ No newline at end of file diff --git a/template/src/data/i18n.ts b/template/src/data/i18n.ts index b8d7649..4ed525c 100644 --- a/template/src/data/i18n.ts +++ b/template/src/data/i18n.ts @@ -1,6 +1,5 @@ // 本文件为自动编译产生,请勿直接修改 import { CreateOperationData as I18n } from "../oak-app-domain/I18n/Schema"; -import i18ns0 from "oak-general-business/lib/data/i18n"; const i18ns: I18n[] = []; -export default i18ns.concat(i18ns0); \ No newline at end of file +export default i18ns; \ No newline at end of file diff --git a/template/src/entities/Store.ts b/template/src/entities/Store.ts index 4ca8be5..840e007 100644 --- a/template/src/entities/Store.ts +++ b/template/src/entities/Store.ts @@ -18,14 +18,14 @@ export interface Schema extends EntityShape { files: Array; //封面图 } -type IAction = 'online' | 'offline' | 'disabled'; +type IAction = 'online' | 'offline' | 'disable'; type IState = 'online' | 'offline' | 'disabled'; const IActionDef: ActionDef = { stm: { online: ['offline', 'online'], offline: ['online', 'offline'], - disabled: [['online', 'offline'], 'disabled'], + disable: [['online', 'offline'], 'disabled'], }, is: 'offline', }; @@ -67,7 +67,7 @@ const entityDesc: EntityDesc< action: { online: '上线', offline: '下线', - disabled: '禁用', + disable: '禁用', }, v: { iState: { @@ -78,4 +78,18 @@ const entityDesc: EntityDesc< }, }, }, + style: { + icon: { + offline: '', + online: '', + disable: '' + }, + color: { + iState: { + offline: '#FFFFFF', + online: '#FF0000', + disabled: '#00FF00', + } + } + } }; diff --git a/template/src/features/Console.ts b/template/src/features/Console.ts index 72ee710..e1bdee6 100644 --- a/template/src/features/Console.ts +++ b/template/src/features/Console.ts @@ -1,15 +1,11 @@ import { EntityDict } from '@project/oak-app-domain'; import { Feature } from 'oak-frontend-base'; -import { CommonAspectDict } from 'oak-common-aspect'; -import { AspectDict } from '../aspects/AspectDict'; -import { BackendRuntimeContext } from '@project/context/BackendRuntimeContext'; -import { FrontendRuntimeContext } from '@project/context/FrontendRuntimeContext'; import { Cache } from 'oak-frontend-base/es/features/cache'; export default class Console extends Feature { - private cache: Cache>; + private cache: Cache; - constructor(cache: Cache>) { + constructor(cache: Cache) { super(); this.cache = cache; } diff --git a/template/src/features/Menu.ts b/template/src/features/Menu.ts index cbe4227..3c5dd20 100644 --- a/template/src/features/Menu.ts +++ b/template/src/features/Menu.ts @@ -1,10 +1,5 @@ import { EntityDict } from '@project/oak-app-domain'; import { Feature } from 'oak-frontend-base'; -import { CommonAspectDict } from 'oak-common-aspect'; -import { AspectDict } from '../aspects/AspectDict'; -import { BackendRuntimeContext } from '@project/context/BackendRuntimeContext'; -import { FrontendRuntimeContext } from '@project/context/FrontendRuntimeContext'; -import { groupBy } from 'oak-domain/lib/utils/lodash'; import { ContextMenuFactory } from 'oak-frontend-base/es/features/contextMenuFactory'; import Console from './Console'; @@ -58,18 +53,12 @@ const menus: IMenu[] = [ ]; export default class Menu extends Feature { - private contextMenuFactory: ContextMenuFactory>; + private contextMenuFactory: ContextMenuFactory; private console: Console; private menus?: OMenu[]; constructor( - contextMenuFactory: ContextMenuFactory>, + contextMenuFactory: ContextMenuFactory, console: Console ) { super(); diff --git a/template/src/features/Sample.ts b/template/src/features/Sample.ts index 93566ab..1c68e3d 100644 --- a/template/src/features/Sample.ts +++ b/template/src/features/Sample.ts @@ -1,9 +1,5 @@ import { EntityDict } from '@oak-app-domain'; import { BasicFeatures, Feature } from 'oak-frontend-base'; -import { CommonAspectDict } from 'oak-common-aspect/lib/AspectDict'; -import { AspectDict } from '../aspects/AspectDict'; -import { BackendRuntimeContext } from '@project/context/BackendRuntimeContext'; -import { FrontendRuntimeContext } from '@project/context/FrontendRuntimeContext'; type DoSthAcion = { type: 'doSth'; @@ -19,20 +15,10 @@ export default class Sample extends Feature { action(action: DoSthAcion) { throw new Error('Method not implemented.'); } - cache: BasicFeatures< - EntityDict, - BackendRuntimeContext, - FrontendRuntimeContext, - AspectDict & CommonAspectDict - >['cache']; + cache: BasicFeatures['cache']; constructor( - cache: BasicFeatures< - EntityDict, - BackendRuntimeContext, - FrontendRuntimeContext, - AspectDict & CommonAspectDict - >['cache'] + cache: BasicFeatures['cache'] ) { super(); this.cache = cache; diff --git a/template/src/features/index.ts b/template/src/features/index.ts index 1ff48aa..8f64398 100644 --- a/template/src/features/index.ts +++ b/template/src/features/index.ts @@ -1,32 +1,12 @@ import { EntityDict } from '@oak-app-domain'; import { BasicFeatures } from 'oak-frontend-base'; -import { GeneralFeatures, GeneralAspectDict } from 'oak-general-business'; -import { CommonAspectDict } from 'oak-common-aspect/lib/AspectDict'; -import { AspectDict } from '../aspects/AspectDict'; -import { BackendRuntimeContext } from '../context/BackendRuntimeContext'; -import { FrontendRuntimeContext } from '../context/FrontendRuntimeContext'; -import { AAD, AFD } from '@project/types/RuntimeCxt'; +import { FeatureDict as GeneralFeatureDict } from 'oak-general-business'; import Sample from './Sample'; import Console from './Console'; import Menu from './Menu'; -export function initialize( - generalFeatures: BasicFeatures< - EntityDict, - BackendRuntimeContext, - FrontendRuntimeContext, - AspectDict & - CommonAspectDict & - GeneralAspectDict - > & - GeneralFeatures< - EntityDict, - BackendRuntimeContext, - FrontendRuntimeContext, - AspectDict & - CommonAspectDict & - GeneralAspectDict - > +export function create( + generalFeatures: BasicFeatures & GeneralFeatureDict ) { const { cache, @@ -48,4 +28,4 @@ export function initialize( }; } -export type FeatureDict = ReturnType; +export type FeatureDict = ReturnType; diff --git a/template/src/initialize.dev.ts b/template/src/initialize.dev.ts deleted file mode 100644 index e78be1b..0000000 --- a/template/src/initialize.dev.ts +++ /dev/null @@ -1,74 +0,0 @@ -import { initialize as init } from 'oak-general-business/es/initialize.dev'; -import { GFD, GAD } from 'oak-general-business'; - -import { EntityDict, storageSchema, ActionDefDict } from '@oak-app-domain'; -import { BackendRuntimeContext } from './context/BackendRuntimeContext'; -import { FrontendRuntimeContext } from './context/FrontendRuntimeContext'; - -import { initialize as initializeFeatures, FeatureDict } from './features'; - -// dev需要将下面内容也传入 -import { AspectDict } from './aspects/AspectDict'; -import aspectDict from './aspects'; -import triggers from './triggers'; -import watchers from './watchers'; -import data from './data'; -import checkers from './checkers'; -import timers from './timers'; -import { importations, exportations } from './ports'; -import startRoutines from './routines/start'; -import colorDict from './config/color'; -import cacheSavedEntities from './config/cache'; -import { - selectFreeEntities, - updateFreeDict, - authDeduceRelationMap, -} from './config/relation'; - -import { AppType } from '@oak-app-domain/Application/Schema'; - -export default function initialize(type: AppType, hostname: string) { - const wholeFeatures = {} as GFD< - EntityDict, - BackendRuntimeContext, - FrontendRuntimeContext, - AspectDict & GAD - > & - FeatureDict; - const { features } = init< - EntityDict, - BackendRuntimeContext, - AspectDict, - FrontendRuntimeContext - >( - type, - hostname, - storageSchema, - (store) => new FrontendRuntimeContext(store, wholeFeatures), - (store) => new BackendRuntimeContext(store), - aspectDict, - triggers, - checkers, - watchers, - timers, - startRoutines, - data as any, - { - actionDict: ActionDefDict, - colorDict, - importations, - exportations, - authDeduceRelationMap, - selectFreeEntities, - updateFreeDict, - cacheSavedEntities, - } - ); - - const appFeatures = initializeFeatures(features); - - Object.assign(wholeFeatures, appFeatures, features); - return { - features: wholeFeatures, - }; -} diff --git a/template/src/initialize.prod.ts b/template/src/initialize.prod.ts deleted file mode 100644 index 10efc09..0000000 --- a/template/src/initialize.prod.ts +++ /dev/null @@ -1,74 +0,0 @@ -import { initialize as init } from 'oak-general-business/es/initialize.prod'; - -import { SimpleConnector } from 'oak-domain/lib/utils/SimpleConnector'; -import { - EntityDict, - storageSchema, - ActionDefDict, -} from '@oak-app-domain'; -import { BackendRuntimeContext } from './context/BackendRuntimeContext'; -import { FrontendRuntimeContext } from './context/FrontendRuntimeContext'; - -import { initialize as initializeFeatures } from './features'; -import checkers from './checkers'; -import { makeException } from './types/Exception'; -import { AspectDict } from './aspects/AspectDict'; -import colorDict from './config/color'; -import cacheSavedEntities from './config/cache'; -import { selectFreeEntities, updateFreeDict, authDeduceRelationMap } from './config/relation'; - -import { AppType } from '@oak-app-domain/Application/Schema'; -import { AFD } from '@project/types/RuntimeCxt'; - -const NGINX_PROXY_PATH = '/oak-api'; // nginx反射代理到系统的映射 - -export default function initialize( - type: AppType, - hostname: string, - protocol?: 'http:' | 'https:', - apiPath?: string, - port?: number -) { - const connector = new SimpleConnector( - { - protocol: protocol || 'http:', - hostname, - port, - apiPath: typeof apiPath === 'string' ? apiPath : NGINX_PROXY_PATH, - }, - makeException - ); - const wholeFeatures = {} as AFD; - const { features } = init< - EntityDict, - BackendRuntimeContext, - AspectDict, - FrontendRuntimeContext - >( - type, - hostname, - storageSchema, - (store) => - new FrontendRuntimeContext( - store, - wholeFeatures - ), - connector, - checkers, - { - actionDict: ActionDefDict, - colorDict, - authDeduceRelationMap, - selectFreeEntities, - updateFreeDict, - cacheSavedEntities, - } - ); - - const appFeatures = initializeFeatures(features); - - Object.assign(wholeFeatures, appFeatures, features); - return { - features: wholeFeatures, - }; -} diff --git a/template/src/page.mp.ts b/template/src/page.mp.ts index 035b84d..9add80d 100644 --- a/template/src/page.mp.ts +++ b/template/src/page.mp.ts @@ -1 +1 @@ -export { createComponent } from 'oak-general-business/es/page.mp'; \ No newline at end of file +export { createComponent } from 'oak-frontend-base/es/page.mp'; \ No newline at end of file diff --git a/template/src/page.native.ts b/template/src/page.native.ts new file mode 100644 index 0000000..038039d --- /dev/null +++ b/template/src/page.native.ts @@ -0,0 +1 @@ +export { createComponent } from 'oak-frontend-base/es/page.native'; \ No newline at end of file diff --git a/template/src/page.ts b/template/src/page.ts index 6f550f1..772c56f 100644 --- a/template/src/page.ts +++ b/template/src/page.ts @@ -1,2 +1,2 @@ // for 编译 -export { createComponent } from 'oak-general-business/es/page.web'; \ No newline at end of file +export { createComponent } from 'oak-frontend-base/es/page.web'; \ No newline at end of file diff --git a/template/src/page.web.ts b/template/src/page.web.ts index 96ddf07..62ab72c 100644 --- a/template/src/page.web.ts +++ b/template/src/page.web.ts @@ -1 +1 @@ -export { createComponent } from 'oak-general-business/es/page.web'; \ No newline at end of file +export { createComponent } from 'oak-frontend-base/es/page.web'; \ No newline at end of file diff --git a/template/src/types/Exception.ts b/template/src/types/Exception.ts index eed4865..7fc4342 100644 --- a/template/src/types/Exception.ts +++ b/template/src/types/Exception.ts @@ -1,5 +1,5 @@ import { OakException } from 'oak-domain/lib/types'; -import { EntityDict } from '@oak-app-domain'; +import { EntityDict } from '@project/oak-app-domain'; import { makeException as makeGeneralException } from 'oak-general-business'; export class ExampleException extends OakException {} @@ -7,7 +7,7 @@ export class ExampleException extends OakException {} export function makeException(msg: string | object) { const data = typeof msg === 'string' ? JSON.parse(msg) : msg; - const exception = makeGeneralException(data); + const exception = makeGeneralException(data); if (exception) { return exception; } diff --git a/template/src/types/RuntimeCxt.ts b/template/src/types/RuntimeCxt.ts deleted file mode 100644 index 55a0419..0000000 --- a/template/src/types/RuntimeCxt.ts +++ /dev/null @@ -1,15 +0,0 @@ -import { AspectDict } from "@project/aspects/AspectDict"; -import { FeatureDict } from "@project/features"; -import { EntityDict } from "@oak-app-domain"; -import { BasicFeatures } from "oak-frontend-base"; -import { GFD, GAD } from "oak-general-business"; -import { BackendRuntimeContext } from "../context/BackendRuntimeContext"; -import { FrontendRuntimeContext } from "../context/FrontendRuntimeContext"; - - -type BRC = BackendRuntimeContext; -type FRC = FrontendRuntimeContext; -export type RuntimeCxt = FRC | BRC; - -export type AAD = AspectDict & GAD; -export type AFD = FeatureDict & GFD; \ No newline at end of file diff --git a/template/web/src/index.tsx b/template/web/src/index.tsx index 4355645..b4f5b6d 100644 --- a/template/web/src/index.tsx +++ b/template/web/src/index.tsx @@ -4,10 +4,7 @@ import ReactDOM from 'react-dom/client'; import { createBrowserHistory } from 'history'; import { unstable_HistoryRouter as HistoryRouter } from 'react-router-dom'; import { ConfigProvider } from 'antd'; -import { - StyleProvider, - legacyLogicalPropertiesTransformer, -} from '@ant-design/cssinjs'; +import { StyleProvider, legacyLogicalPropertiesTransformer } from '@ant-design/cssinjs'; import dayjs from 'dayjs'; import 'dayjs/locale/zh-cn'; import zhCN from 'antd/locale/zh_CN'; @@ -20,6 +17,7 @@ import './index.less'; import App from './App'; import reportWebVitals from './reportWebVitals'; import { handler as exceptionHandler } from '@project/exceptionHandler'; +import initializeFeatures from '@project/initializeFeatures'; import { features } from './initialize'; dayjs.locale('zh-cn'); @@ -42,11 +40,8 @@ features.navigator.setHistory(history); const init = async () => { let error; - const location = features.navigator.getLocation(); - const searchParams = new URLSearchParams(location.search); - const appId = searchParams.get('appId'); try { - await features.application.initialize(appId); + await initializeFeatures(features); } catch (err) { error = err; } @@ -54,18 +49,20 @@ const init = async () => { const application = features.application.getApplication(); const folder = application?.system?.folder; - //微信JSSDK验签时, 在IOS上,无论路由切换到哪个页面,实际真正有效的的签名URL是【第一次进入应用时的URL】 - features.weiXinJsSdk.setLandingUrl(window.location.href); - // 抓到异常处理 1、token过期 2、网络断了 3、接口请求失败 root.render( - + + diff --git a/template/web/src/initialize.ts b/template/web/src/initialize.ts index 4e53bc4..5b39788 100644 --- a/template/web/src/initialize.ts +++ b/template/web/src/initialize.ts @@ -1,26 +1,15 @@ -import { getAppType } from './utils/env'; import initialize from '@project/initialize'; import { createComponent } from '@project/page'; -// import { port } from '../../configuration/server.json'; -const configuration = require('../../configuration/server.json'); -const appType = getAppType(); - -const { features } = initialize( - appType, - window.location.hostname, - // 以下三行打开为dev模式 - undefined, - '', - configuration.port, -); +const { features } = initialize(); Object.assign(global, { features, OakComponent: (options: any) => createComponent(options, features), }); + export { features, }; diff --git a/templateFiles/RuntimeCxt.ts b/templateFiles/RuntimeCxt.ts new file mode 100644 index 0000000..44a9e61 --- /dev/null +++ b/templateFiles/RuntimeCxt.ts @@ -0,0 +1,14 @@ +import { AspectDict } from "@project/aspects/AspectDict"; +import { FeatureDict } from "@project/features"; +import { EntityDict } from "@project/oak-app-domain"; +import { BasicFeatures } from "oak-frontend-base"; +import { BackendRuntimeContext } from "@project/context/BackendRuntimeContext"; +import { FrontendRuntimeContext } from "@project/context/FrontendRuntimeContext"; + + +type BRC = BackendRuntimeContext; +type FRC = FrontendRuntimeContext; +export type RuntimeCxt = FRC | BRC; + +export type AAD = AspectDict; +export type AFD = FeatureDict & BasicFeatures; \ No newline at end of file diff --git a/templateFiles/initialize.dev.ts b/templateFiles/initialize.dev.ts index c31d6b3..9fcd380 100644 --- a/templateFiles/initialize.dev.ts +++ b/templateFiles/initialize.dev.ts @@ -11,7 +11,7 @@ import data from '@project/data'; import startRoutines from '@project/routines/start'; import { importations, exportations } from '@project/ports'; import { create as createFeatures, FeatureDict } from '@project/features'; -import aspects, { AspectDict } from '@project/aspects'; +import aspects from '@project/aspects'; import common from '@project/configuration'; import render from '@project/configuration/render'; @@ -48,7 +48,7 @@ export default function initialize() { ); const totalFeatures = {} as FeatureDict & BasicFeatures; - const { features } = initFrontend( + const { features } = initFrontend( storageSchema, (store) => new FrontendRuntimeContext(store, totalFeatures), debugConnector, diff --git a/templateFiles/initialize.prod.ts b/templateFiles/initialize.prod.ts index 437384f..19cec35 100644 --- a/templateFiles/initialize.prod.ts +++ b/templateFiles/initialize.prod.ts @@ -1,7 +1,7 @@ import { mergeConcatMany } from 'oak-domain/lib/utils/lodash'; import BackendRuntimeContext from '@project/context/BackendRuntimeContext'; import FrontendRuntimeContext from '@project/context/FrontendRuntimeContext'; -import Connector from '@project/connector'; +import connector from '@project/config/connector'; import { EntityDict, storageSchema } from '@project/oak-app-domain'; import checkers from '@project/checkers'; @@ -17,7 +17,6 @@ import render from '@project/configuration/render'; import { initialize as initFrontend } from 'oak-frontend-base/es/initialize'; import { BasicFeatures } from 'oak-frontend-base/es/features'; -import { AspectDict } from './aspects'; export default function initialize() { const totalCheckers = mergeConcatMany([checkers] as Array), @@ -25,10 +24,10 @@ export default function initialize() { totalRender = mergeConcatMany([render] as Array); const totalFeatures = {} as FeatureDict & BasicFeatures; - const { features } = initFrontend( + const { features } = initFrontend( storageSchema, (store) => new FrontendRuntimeContext(store, totalFeatures), - Connector, + connector, totalCheckers, totalCommon, totalRender