feat(samples): add sample plugin
This commit is contained in:
parent
a0981e2668
commit
d7da48fcad
2
packages/plugins/@samples/plugin-replace-page/.npmignore
Executable file
2
packages/plugins/@samples/plugin-replace-page/.npmignore
Executable file
@ -0,0 +1,2 @@
|
|||||||
|
/node_modules
|
||||||
|
/src
|
1
packages/plugins/@samples/plugin-replace-page/README.md
Executable file
1
packages/plugins/@samples/plugin-replace-page/README.md
Executable file
@ -0,0 +1 @@
|
|||||||
|
# @samples/plugin-replace-page
|
2
packages/plugins/@samples/plugin-replace-page/client.d.ts
vendored
Executable file
2
packages/plugins/@samples/plugin-replace-page/client.d.ts
vendored
Executable file
@ -0,0 +1,2 @@
|
|||||||
|
export * from './dist/client';
|
||||||
|
export { default } from './dist/client';
|
1
packages/plugins/@samples/plugin-replace-page/client.js
Executable file
1
packages/plugins/@samples/plugin-replace-page/client.js
Executable file
@ -0,0 +1 @@
|
|||||||
|
module.exports = require('./dist/client/index.js');
|
15
packages/plugins/@samples/plugin-replace-page/package.json
Executable file
15
packages/plugins/@samples/plugin-replace-page/package.json
Executable 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:*"
|
||||||
|
}
|
||||||
|
}
|
2
packages/plugins/@samples/plugin-replace-page/server.d.ts
vendored
Executable file
2
packages/plugins/@samples/plugin-replace-page/server.d.ts
vendored
Executable file
@ -0,0 +1,2 @@
|
|||||||
|
export * from './dist/server';
|
||||||
|
export { default } from './dist/server';
|
1
packages/plugins/@samples/plugin-replace-page/server.js
Executable file
1
packages/plugins/@samples/plugin-replace-page/server.js
Executable file
@ -0,0 +1 @@
|
|||||||
|
module.exports = require('./dist/server/index.js');
|
65
packages/plugins/@samples/plugin-replace-page/src/client/AuthLayout.tsx
Executable file
65
packages/plugins/@samples/plugin-replace-page/src/client/AuthLayout.tsx
Executable 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>
|
||||||
|
);
|
||||||
|
}
|
BIN
packages/plugins/@samples/plugin-replace-page/src/client/image.png
Executable file
BIN
packages/plugins/@samples/plugin-replace-page/src/client/image.png
Executable file
Binary file not shown.
After Width: | Height: | Size: 3.8 MiB |
13
packages/plugins/@samples/plugin-replace-page/src/client/index.tsx
Executable file
13
packages/plugins/@samples/plugin-replace-page/src/client/index.tsx
Executable 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;
|
2
packages/plugins/@samples/plugin-replace-page/src/index.ts
Executable file
2
packages/plugins/@samples/plugin-replace-page/src/index.ts
Executable file
@ -0,0 +1,2 @@
|
|||||||
|
export * from './server';
|
||||||
|
export { default } from './server';
|
1
packages/plugins/@samples/plugin-replace-page/src/server/index.ts
Executable file
1
packages/plugins/@samples/plugin-replace-page/src/server/index.ts
Executable file
@ -0,0 +1 @@
|
|||||||
|
export { default } from './plugin';
|
28
packages/plugins/@samples/plugin-replace-page/src/server/plugin.ts
Executable file
28
packages/plugins/@samples/plugin-replace-page/src/server/plugin.ts
Executable 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;
|
BIN
packages/plugins/@tachybase/plugin-todo-page.rar
Normal file
BIN
packages/plugins/@tachybase/plugin-todo-page.rar
Normal file
Binary file not shown.
Loading…
Reference in New Issue
Block a user