mirror of
https://gitee.com/nocobase/nocobase.git
synced 2024-12-03 04:38:15 +08:00
feat: system settings
This commit is contained in:
parent
551b9ce45d
commit
9fd41ab33e
7
packages/plugin-system-settings/.npmignore
Normal file
7
packages/plugin-system-settings/.npmignore
Normal file
@ -0,0 +1,7 @@
|
||||
node_modules
|
||||
*.log
|
||||
docs
|
||||
__tests__
|
||||
tsconfig.json
|
||||
src
|
||||
.fatherrc.ts
|
15
packages/plugin-system-settings/package.json
Normal file
15
packages/plugin-system-settings/package.json
Normal file
@ -0,0 +1,15 @@
|
||||
{
|
||||
"name": "@nocobase/plugin-system-settings",
|
||||
"version": "0.4.0-alpha.7",
|
||||
"main": "lib/index.js",
|
||||
"license": "MIT",
|
||||
"dependencies": {
|
||||
"@nocobase/database": "^0.4.0-alpha.7",
|
||||
"@nocobase/resourcer": "^0.4.0-alpha.7",
|
||||
"@nocobase/server": "^0.4.0-alpha.7"
|
||||
},
|
||||
"devDependencies": {
|
||||
"@nocobase/actions": "^0.4.0-alpha.7"
|
||||
},
|
||||
"gitHead": "f0b335ac30f29f25c95d7d137655fa64d8d67f1e"
|
||||
}
|
@ -0,0 +1,16 @@
|
||||
import { TableOptions } from '@nocobase/database';
|
||||
|
||||
export default {
|
||||
name: 'system_settings',
|
||||
fields: [
|
||||
{
|
||||
type: 'string',
|
||||
name: 'title',
|
||||
},
|
||||
{
|
||||
type: 'belongsTo',
|
||||
name: 'logo',
|
||||
target: 'attachments',
|
||||
},
|
||||
],
|
||||
} as TableOptions;
|
26
packages/plugin-system-settings/src/server.ts
Normal file
26
packages/plugin-system-settings/src/server.ts
Normal file
@ -0,0 +1,26 @@
|
||||
import path from 'path';
|
||||
import { Application } from '@nocobase/server';
|
||||
|
||||
export default async function (this: Application, options = {}) {
|
||||
const database = this.database;
|
||||
const resourcer = this.resourcer;
|
||||
|
||||
database.import({
|
||||
directory: path.resolve(__dirname, 'collections'),
|
||||
});
|
||||
|
||||
resourcer.use(async (ctx, next) => {
|
||||
const { actionName, resourceName, resourceKey } = ctx.action.params;
|
||||
if (resourceName === 'system_settings' && actionName === 'get') {
|
||||
const SystemSetting = database.getModel('system_settings');
|
||||
let model = await SystemSetting.findOne();
|
||||
if (!model) {
|
||||
model = await SystemSetting.create();
|
||||
}
|
||||
ctx.action.mergeParams({
|
||||
resourceKey: model.id,
|
||||
});
|
||||
}
|
||||
await next();
|
||||
});
|
||||
}
|
Loading…
Reference in New Issue
Block a user