feat: init support notice area (#1216)
Reviewed-on: daoyoucloud/tachybase#1216
This commit is contained in:
parent
d2dbcf8799
commit
a9acc4badc
@ -252,7 +252,7 @@ export class Application {
|
|||||||
});
|
});
|
||||||
this.ws.on('serverDown', () => {
|
this.ws.on('serverDown', () => {
|
||||||
this.maintaining = true;
|
this.maintaining = true;
|
||||||
this.maintained = false;
|
this.maintained = true;
|
||||||
});
|
});
|
||||||
this.ws.connect();
|
this.ws.connect();
|
||||||
try {
|
try {
|
||||||
|
@ -1,4 +1,5 @@
|
|||||||
import React, { createContext, ReactNode, useContext, useEffect } from 'react';
|
import React, { createContext, ReactNode, useContext, useEffect } from 'react';
|
||||||
|
import { define, observable } from '@tachybase/schema';
|
||||||
|
|
||||||
import { message, notification } from 'antd';
|
import { message, notification } from 'antd';
|
||||||
import mitt, { Emitter, EventType } from 'mitt';
|
import mitt, { Emitter, EventType } from 'mitt';
|
||||||
@ -54,7 +55,11 @@ export class NoticeManager {
|
|||||||
constructor(private app: Application) {
|
constructor(private app: Application) {
|
||||||
this.ws = app.ws;
|
this.ws = app.ws;
|
||||||
this.emitter = mitt();
|
this.emitter = mitt();
|
||||||
|
define(this, {
|
||||||
|
currentStatus: observable.ref,
|
||||||
|
});
|
||||||
}
|
}
|
||||||
|
currentStatus = '';
|
||||||
|
|
||||||
on(data: { type: NoticeType; title?: string; content: string; level: NoticeLevel; eventType?: string; event?: any }) {
|
on(data: { type: NoticeType; title?: string; content: string; level: NoticeLevel; eventType?: string; event?: any }) {
|
||||||
if (data.type === NoticeType.NOTIFICATION) {
|
if (data.type === NoticeType.NOTIFICATION) {
|
||||||
@ -68,6 +73,7 @@ export class NoticeManager {
|
|||||||
|
|
||||||
status(content: string, level: NoticeLevel) {
|
status(content: string, level: NoticeLevel) {
|
||||||
// 常驻消息
|
// 常驻消息
|
||||||
|
this.currentStatus = content;
|
||||||
}
|
}
|
||||||
|
|
||||||
toast(content: string, level: NoticeLevel) {
|
toast(content: string, level: NoticeLevel) {
|
||||||
|
@ -0,0 +1,12 @@
|
|||||||
|
import React from 'react';
|
||||||
|
import { observer } from '@tachybase/schema';
|
||||||
|
|
||||||
|
import { useNoticeManager } from '../../application';
|
||||||
|
|
||||||
|
export const NoticeArea = observer(
|
||||||
|
(props: React.HTMLAttributes<HTMLDivElement>) => {
|
||||||
|
const nm = useNoticeManager();
|
||||||
|
return <div {...props}>{nm.manager.currentStatus ? nm.manager.currentStatus : null}</div>;
|
||||||
|
},
|
||||||
|
{ displayName: 'NoticeArea' },
|
||||||
|
);
|
@ -25,6 +25,7 @@ import {
|
|||||||
} from '../..';
|
} from '../..';
|
||||||
import { Plugin } from '../../application/Plugin';
|
import { Plugin } from '../../application/Plugin';
|
||||||
import { VariablesProvider } from '../../variables';
|
import { VariablesProvider } from '../../variables';
|
||||||
|
import { NoticeArea } from './NoticeArea';
|
||||||
|
|
||||||
const useStyles = createStyles(({ css, token }) => {
|
const useStyles = createStyles(({ css, token }) => {
|
||||||
return {
|
return {
|
||||||
@ -104,6 +105,10 @@ const useStyles = createStyles(({ css, token }) => {
|
|||||||
editor: css`
|
editor: css`
|
||||||
flex: 1 1 auto;
|
flex: 1 1 auto;
|
||||||
width: 0;
|
width: 0;
|
||||||
|
display: flex;
|
||||||
|
`,
|
||||||
|
notice: css`
|
||||||
|
flex: 1;
|
||||||
`,
|
`,
|
||||||
sider: css`
|
sider: css`
|
||||||
height: 100%;
|
height: 100%;
|
||||||
@ -411,6 +416,7 @@ export const InternalAdminLayout = (props: any) => {
|
|||||||
<h1 className={styles.title}>{result?.data?.data?.title}</h1>
|
<h1 className={styles.title}>{result?.data?.data?.title}</h1>
|
||||||
</div>
|
</div>
|
||||||
<div className={styles.editor}>
|
<div className={styles.editor}>
|
||||||
|
<NoticeArea className={styles.notice} />
|
||||||
<SetThemeOfHeaderSubmenu>
|
<SetThemeOfHeaderSubmenu>
|
||||||
<MenuEditor sideMenuRef={sideMenuRef} />
|
<MenuEditor sideMenuRef={sideMenuRef} />
|
||||||
</SetThemeOfHeaderSubmenu>
|
</SetThemeOfHeaderSubmenu>
|
||||||
@ -472,3 +478,5 @@ export class AdminLayoutPlugin extends Plugin {
|
|||||||
this.app.addComponents({ AdminLayout });
|
this.app.addComponents({ AdminLayout });
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
export * from './NoticeArea';
|
||||||
|
@ -3,13 +3,13 @@ import { observer } from '@tachybase/schema';
|
|||||||
import { getSubAppName } from '@tachybase/sdk';
|
import { getSubAppName } from '@tachybase/sdk';
|
||||||
|
|
||||||
import { DisconnectOutlined, LoadingOutlined } from '@ant-design/icons';
|
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 { createStyles } from 'antd-style';
|
||||||
import { useTranslation } from 'react-i18next';
|
import { useTranslation } from 'react-i18next';
|
||||||
import { Navigate, useNavigate } from 'react-router-dom';
|
import { Navigate, useNavigate } from 'react-router-dom';
|
||||||
|
|
||||||
import { useAPIClient } from '../api-client';
|
import { useAPIClient } from '../api-client';
|
||||||
import { Application, useApp } from '../application';
|
import { Application, NoticeLevel, useApp } from '../application';
|
||||||
import { Plugin } from '../application/Plugin';
|
import { Plugin } from '../application/Plugin';
|
||||||
import { BlockSchemaComponentPlugin } from '../block-provider';
|
import { BlockSchemaComponentPlugin } from '../block-provider';
|
||||||
import { CollectionPlugin } from '../collection-manager';
|
import { CollectionPlugin } from '../collection-manager';
|
||||||
@ -28,7 +28,7 @@ import { PinnedListPlugin } from './pinned-list';
|
|||||||
import { PMPlugin } from './pm';
|
import { PMPlugin } from './pm';
|
||||||
import { SystemSettingsPlugin } from './system-settings';
|
import { SystemSettingsPlugin } from './system-settings';
|
||||||
|
|
||||||
export { AdminProvider } from './admin-layout';
|
export { AdminProvider, NoticeArea } from './admin-layout';
|
||||||
|
|
||||||
interface AppStatusProps {
|
interface AppStatusProps {
|
||||||
error: Error;
|
error: Error;
|
||||||
@ -248,11 +248,9 @@ const AppMaintaining = observer(
|
|||||||
const AppMaintainingDialog = observer(
|
const AppMaintainingDialog = observer(
|
||||||
({ app }: AppStatusProps) => {
|
({ app }: AppStatusProps) => {
|
||||||
const { icon, status, title, subTitle } = getProps(app);
|
const { icon, status, title, subTitle } = getProps(app);
|
||||||
return (
|
const manager = app.noticeManager;
|
||||||
<Modal open={true} footer={null} closable={false}>
|
manager.status(app.i18n.t(title) + app.i18n.t(subTitle), NoticeLevel.INFO);
|
||||||
<Result icon={icon} status={status} title={app.i18n.t(title)} subTitle={app.i18n.t(subTitle)} />
|
return null;
|
||||||
</Modal>
|
|
||||||
);
|
|
||||||
},
|
},
|
||||||
{ displayName: 'AppMaintainingDialog' },
|
{ displayName: 'AppMaintainingDialog' },
|
||||||
);
|
);
|
||||||
|
@ -5,6 +5,7 @@ import {
|
|||||||
CurrentUser,
|
CurrentUser,
|
||||||
findByUid,
|
findByUid,
|
||||||
findMenuItem,
|
findMenuItem,
|
||||||
|
NoticeArea,
|
||||||
PinnedPluginList,
|
PinnedPluginList,
|
||||||
SchemaComponent,
|
SchemaComponent,
|
||||||
useACLRoleContext,
|
useACLRoleContext,
|
||||||
@ -17,7 +18,7 @@ import {
|
|||||||
} from '@tachybase/client';
|
} from '@tachybase/client';
|
||||||
|
|
||||||
import { useSessionStorageState } from 'ahooks';
|
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 { Link, Outlet, useMatch, useNavigate, useParams } from 'react-router-dom';
|
||||||
|
|
||||||
import { MobileLink } from '../components/system/MobileLink';
|
import { MobileLink } from '../components/system/MobileLink';
|
||||||
@ -287,8 +288,14 @@ export const InternalAdminLayout = () => {
|
|||||||
className={css`
|
className={css`
|
||||||
flex: 1 1 auto;
|
flex: 1 1 auto;
|
||||||
width: 0;
|
width: 0;
|
||||||
|
display: flex;
|
||||||
`}
|
`}
|
||||||
>
|
>
|
||||||
|
<NoticeArea
|
||||||
|
className={css`
|
||||||
|
flex: 1;
|
||||||
|
`}
|
||||||
|
/>
|
||||||
<MenuEditor sideMenuRef={sideMenuRef} />
|
<MenuEditor sideMenuRef={sideMenuRef} />
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
@ -20,6 +20,7 @@ export class PluginCoreServer extends Plugin {
|
|||||||
});
|
});
|
||||||
this.addFeature(DepartmentsPlugin);
|
this.addFeature(DepartmentsPlugin);
|
||||||
}
|
}
|
||||||
|
|
||||||
async load() {
|
async load() {
|
||||||
try {
|
try {
|
||||||
await Container.get(ConnectionManager).load();
|
await Container.get(ConnectionManager).load();
|
||||||
@ -35,8 +36,5 @@ export class PluginCoreServer extends Plugin {
|
|||||||
console.warn(err);
|
console.warn(err);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
async afterEnable() {}
|
|
||||||
async afterDisable() {}
|
|
||||||
async remove() {}
|
|
||||||
}
|
}
|
||||||
export default PluginCoreServer;
|
export default PluginCoreServer;
|
||||||
|
Loading…
Reference in New Issue
Block a user