feat(samples): add sample plugin

This commit is contained in:
ruiling 2024-10-17 19:49:55 +08:00
parent a0981e2668
commit d7da48fcad
15 changed files with 133 additions and 0 deletions

View File

@ -0,0 +1,2 @@
/node_modules
/src

View File

@ -0,0 +1 @@
# @samples/plugin-replace-page

View File

@ -0,0 +1,2 @@
export * from './dist/client';
export { default } from './dist/client';

View File

@ -0,0 +1 @@
module.exports = require('./dist/client/index.js');

View File

@ -0,0 +1,15 @@
{
"name": "@samples/plugin-replace-page",
"version": "0.21.61",
"main": "dist/server/index.js",
"dependencies": {
"antd": "^5.18.3",
"react-router-dom": "^6.11.2"
},
"peerDependencies": {
"@tachybase/client": "workspace:*",
"@tachybase/plugin-auth": "workspace:*",
"@tachybase/server": "workspace:*",
"@tachybase/test": "workspace:*"
}
}

View File

@ -0,0 +1,2 @@
export * from './dist/server';
export { default } from './dist/server';

View File

@ -0,0 +1 @@
module.exports = require('./dist/server/index.js');

View File

@ -0,0 +1,65 @@
import React from 'react';
import { css, PoweredBy, useAPIClient, useRequest, useSystemSettings } from '@tachybase/client';
import { AuthenticatorsContext } from '@tachybase/plugin-auth/client';
import { Col, Row } from 'antd';
import { Outlet } from 'react-router-dom';
import authImg from './image.png';
export function CustomAuthLayout() {
const { data } = useSystemSettings();
const api = useAPIClient();
const { data: authenticators = [], error } = useRequest(() =>
api
.resource('authenticators')
.publicList()
.then((res) => {
return res?.data?.data || [];
}),
);
return (
<Row style={{ height: '100%' }}>
<Col xs={{ span: 0 }} md={{ span: 12 }}>
<img
src={authImg}
style={{
objectFit: 'cover',
objectPosition: 'center',
width: '100%',
height: '100%',
maxWidth: '100%',
display: 'block',
verticalAlign: 'middle',
}}
/>
</Col>
<Col xs={{ span: 24 }} md={{ span: 12 }}>
<div
style={{
maxWidth: 320,
margin: '0 auto',
paddingTop: '20vh',
}}
>
<h1>{data?.data?.title}</h1>
<AuthenticatorsContext.Provider value={authenticators as any}>
<Outlet />
</AuthenticatorsContext.Provider>
<div
className={css`
position: absolute;
bottom: 24px;
width: 100%;
left: 0;
text-align: center;
`}
>
<PoweredBy />
</div>
</div>
</Col>
</Row>
);
}

Binary file not shown.

After

Width:  |  Height:  |  Size: 3.8 MiB

View File

@ -0,0 +1,13 @@
import { Plugin } from '@tachybase/client';
import { CustomAuthLayout } from './AuthLayout';
export class PluginReplacePageClient extends Plugin {
async load() {
this.app.router.add('auth', {
Component: CustomAuthLayout,
});
}
}
export default PluginReplacePageClient;

View File

@ -0,0 +1,2 @@
export * from './server';
export { default } from './server';

View File

@ -0,0 +1 @@
export { default } from './plugin';

View File

@ -0,0 +1,28 @@
import { Plugin } from '@tachybase/server';
export class PluginReplacePageServer extends Plugin {
async afterAdd() {}
async beforeLoad() {}
async load() {
this.app.db.collection({
name: 'posts',
// 字段类型参考 packages/core/database/src/fields常见的有 string、text、integer 等
fields: [{ type: 'string', name: 'title' }],
});
await this.app.db.sync();
// 方便做测试,权限设置为公开
this.app.acl.allow('posts', '*', 'public');
}
async install() {}
async afterEnable() {}
async afterDisable() {}
async remove() {}
}
export default PluginReplacePageServer;

Binary file not shown.