feat: system settings

This commit is contained in:
chenos 2021-08-13 23:14:07 +08:00
parent 551b9ce45d
commit 9fd41ab33e
4 changed files with 64 additions and 0 deletions

View File

@ -0,0 +1,7 @@
node_modules
*.log
docs
__tests__
tsconfig.json
src
.fatherrc.ts

View 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"
}

View File

@ -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;

View 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();
});
}