From a9acc4badc7dc9cb6d30745bfe043654e4e2fea8 Mon Sep 17 00:00:00 2001 From: sealday Date: Thu, 20 Jun 2024 15:48:12 +0800 Subject: [PATCH] feat: init support notice area (#1216) Reviewed-on: https://git.daoyoucloud.com/daoyoucloud/tachybase/pulls/1216 --- .../core/client/src/application/Application.tsx | 2 +- .../core/client/src/application/NoticesManager.tsx | 6 ++++++ .../src/built-in/admin-layout/NoticeArea.tsx | 12 ++++++++++++ .../client/src/built-in/admin-layout/index.tsx | 8 ++++++++ packages/core/client/src/built-in/index.tsx | 14 ++++++-------- .../plugin-core/src/client/pages/AdminLayout.tsx | 9 ++++++++- .../plugins/@hera/plugin-core/src/server/plugin.ts | 4 +--- 7 files changed, 42 insertions(+), 13 deletions(-) create mode 100644 packages/core/client/src/built-in/admin-layout/NoticeArea.tsx diff --git a/packages/core/client/src/application/Application.tsx b/packages/core/client/src/application/Application.tsx index e8dbf4ac3..06ab1db8d 100644 --- a/packages/core/client/src/application/Application.tsx +++ b/packages/core/client/src/application/Application.tsx @@ -252,7 +252,7 @@ export class Application { }); this.ws.on('serverDown', () => { this.maintaining = true; - this.maintained = false; + this.maintained = true; }); this.ws.connect(); try { diff --git a/packages/core/client/src/application/NoticesManager.tsx b/packages/core/client/src/application/NoticesManager.tsx index 74833195d..e1cefb021 100644 --- a/packages/core/client/src/application/NoticesManager.tsx +++ b/packages/core/client/src/application/NoticesManager.tsx @@ -1,4 +1,5 @@ import React, { createContext, ReactNode, useContext, useEffect } from 'react'; +import { define, observable } from '@tachybase/schema'; import { message, notification } from 'antd'; import mitt, { Emitter, EventType } from 'mitt'; @@ -54,7 +55,11 @@ export class NoticeManager { constructor(private app: Application) { this.ws = app.ws; this.emitter = mitt(); + define(this, { + currentStatus: observable.ref, + }); } + currentStatus = ''; on(data: { type: NoticeType; title?: string; content: string; level: NoticeLevel; eventType?: string; event?: any }) { if (data.type === NoticeType.NOTIFICATION) { @@ -68,6 +73,7 @@ export class NoticeManager { status(content: string, level: NoticeLevel) { // 常驻消息 + this.currentStatus = content; } toast(content: string, level: NoticeLevel) { diff --git a/packages/core/client/src/built-in/admin-layout/NoticeArea.tsx b/packages/core/client/src/built-in/admin-layout/NoticeArea.tsx new file mode 100644 index 000000000..30b4bf585 --- /dev/null +++ b/packages/core/client/src/built-in/admin-layout/NoticeArea.tsx @@ -0,0 +1,12 @@ +import React from 'react'; +import { observer } from '@tachybase/schema'; + +import { useNoticeManager } from '../../application'; + +export const NoticeArea = observer( + (props: React.HTMLAttributes) => { + const nm = useNoticeManager(); + return
{nm.manager.currentStatus ? nm.manager.currentStatus : null}
; + }, + { displayName: 'NoticeArea' }, +); diff --git a/packages/core/client/src/built-in/admin-layout/index.tsx b/packages/core/client/src/built-in/admin-layout/index.tsx index 6b02f61d3..6bc37b4f6 100644 --- a/packages/core/client/src/built-in/admin-layout/index.tsx +++ b/packages/core/client/src/built-in/admin-layout/index.tsx @@ -25,6 +25,7 @@ import { } from '../..'; import { Plugin } from '../../application/Plugin'; import { VariablesProvider } from '../../variables'; +import { NoticeArea } from './NoticeArea'; const useStyles = createStyles(({ css, token }) => { return { @@ -104,6 +105,10 @@ const useStyles = createStyles(({ css, token }) => { editor: css` flex: 1 1 auto; width: 0; + display: flex; + `, + notice: css` + flex: 1; `, sider: css` height: 100%; @@ -411,6 +416,7 @@ export const InternalAdminLayout = (props: any) => {

{result?.data?.data?.title}

+ @@ -472,3 +478,5 @@ export class AdminLayoutPlugin extends Plugin { this.app.addComponents({ AdminLayout }); } } + +export * from './NoticeArea'; diff --git a/packages/core/client/src/built-in/index.tsx b/packages/core/client/src/built-in/index.tsx index 6077364fc..993987158 100644 --- a/packages/core/client/src/built-in/index.tsx +++ b/packages/core/client/src/built-in/index.tsx @@ -3,13 +3,13 @@ import { observer } from '@tachybase/schema'; import { getSubAppName } from '@tachybase/sdk'; import { DisconnectOutlined, LoadingOutlined } from '@ant-design/icons'; -import { Button, Modal, Result, Spin } from 'antd'; +import { Button, Result, Spin } from 'antd'; import { createStyles } from 'antd-style'; import { useTranslation } from 'react-i18next'; import { Navigate, useNavigate } from 'react-router-dom'; import { useAPIClient } from '../api-client'; -import { Application, useApp } from '../application'; +import { Application, NoticeLevel, useApp } from '../application'; import { Plugin } from '../application/Plugin'; import { BlockSchemaComponentPlugin } from '../block-provider'; import { CollectionPlugin } from '../collection-manager'; @@ -28,7 +28,7 @@ import { PinnedListPlugin } from './pinned-list'; import { PMPlugin } from './pm'; import { SystemSettingsPlugin } from './system-settings'; -export { AdminProvider } from './admin-layout'; +export { AdminProvider, NoticeArea } from './admin-layout'; interface AppStatusProps { error: Error; @@ -248,11 +248,9 @@ const AppMaintaining = observer( const AppMaintainingDialog = observer( ({ app }: AppStatusProps) => { const { icon, status, title, subTitle } = getProps(app); - return ( - - - - ); + const manager = app.noticeManager; + manager.status(app.i18n.t(title) + app.i18n.t(subTitle), NoticeLevel.INFO); + return null; }, { displayName: 'AppMaintainingDialog' }, ); diff --git a/packages/plugins/@hera/plugin-core/src/client/pages/AdminLayout.tsx b/packages/plugins/@hera/plugin-core/src/client/pages/AdminLayout.tsx index c99baaf75..4b7374d45 100644 --- a/packages/plugins/@hera/plugin-core/src/client/pages/AdminLayout.tsx +++ b/packages/plugins/@hera/plugin-core/src/client/pages/AdminLayout.tsx @@ -5,6 +5,7 @@ import { CurrentUser, findByUid, findMenuItem, + NoticeArea, PinnedPluginList, SchemaComponent, useACLRoleContext, @@ -17,7 +18,7 @@ import { } from '@tachybase/client'; import { useSessionStorageState } from 'ahooks'; -import { Alert, App, Layout } from 'antd'; +import { App, Layout } from 'antd'; import { Link, Outlet, useMatch, useNavigate, useParams } from 'react-router-dom'; import { MobileLink } from '../components/system/MobileLink'; @@ -287,8 +288,14 @@ export const InternalAdminLayout = () => { className={css` flex: 1 1 auto; width: 0; + display: flex; `} > +
diff --git a/packages/plugins/@hera/plugin-core/src/server/plugin.ts b/packages/plugins/@hera/plugin-core/src/server/plugin.ts index 2cadfdde3..6f0527fc9 100644 --- a/packages/plugins/@hera/plugin-core/src/server/plugin.ts +++ b/packages/plugins/@hera/plugin-core/src/server/plugin.ts @@ -20,6 +20,7 @@ export class PluginCoreServer extends Plugin { }); this.addFeature(DepartmentsPlugin); } + async load() { try { await Container.get(ConnectionManager).load(); @@ -35,8 +36,5 @@ export class PluginCoreServer extends Plugin { console.warn(err); } } - async afterEnable() {} - async afterDisable() {} - async remove() {} } export default PluginCoreServer;