feat: improve code

This commit is contained in:
chenos 2021-08-17 00:15:53 +08:00
parent 3d023fb3e4
commit 24d5d3cfad
4 changed files with 65 additions and 6 deletions

View File

@ -17,12 +17,13 @@ import * as uiSchema from './ui-schema';
// tables: ['collections', 'fields', 'actions', 'views', 'tabs'], // tables: ['collections', 'fields', 'actions', 'views', 'tabs'],
}); });
const config = require('@nocobase/plugin-users/src/collections/users').default; const config =
require('@nocobase/plugin-users/src/collections/users').default;
const Collection = database.getModel('collections'); const Collection = database.getModel('collections');
const collection = await Collection.create(config); const collection = await Collection.create(config);
await collection.updateAssociations({ await collection.updateAssociations({
generalFields: config.fields.filter(field => field.state !== 0), generalFields: config.fields.filter((field) => field.state !== 0),
systemFields: config.fields.filter(field => field.state === 0), systemFields: config.fields.filter((field) => field.state === 0),
}); });
await collection.migrate(); await collection.migrate();
@ -92,7 +93,54 @@ import * as uiSchema from './ui-schema';
// 导入地域数据 // 导入地域数据
const ChinaRegion = database.getModel('china_regions'); const ChinaRegion = database.getModel('china_regions');
ChinaRegion && await ChinaRegion.importData(); ChinaRegion && (await ChinaRegion.importData());
const SystemSetting = database.getModel('system_settings');
if (SystemSetting) {
const setting = await SystemSetting.create({
title: 'NocoBase',
showLogoOnly: true,
});
await setting.updateAssociations({
logo: {
title: 'nocobase-logo',
filename: '682e5ad037dd02a0fe4800a3e91c283b.png',
extname: '.png',
mimetype: 'image/png',
url: 'https://nocobase.oss-cn-beijing.aliyuncs.com/682e5ad037dd02a0fe4800a3e91c283b.png',
created_at: '2021-08-16T06:31:53.214Z',
updated_at: '2021-08-16T06:31:53.214Z',
storage_id: 2,
},
});
}
await database.close(); await database.close();
})(); })();
const a = {
data: {
id: 1,
title: 'NocoBase',
created_at: '2021-08-16T05:37:50.751Z',
updated_at: '2021-08-16T06:31:55.069Z',
logo_id: 3,
created_by_id: null,
updated_by_id: null,
logo: {
id: 3,
title: 'logo-white (1)',
filename: '682e5ad037dd02a0fe4800a3e91c283b.png',
extname: '.png',
size: null,
mimetype: 'image/png',
path: '',
meta: {},
url: 'https://nocobase.oss-cn-beijing.aliyuncs.com/682e5ad037dd02a0fe4800a3e91c283b.png',
created_at: '2021-08-16T06:31:53.214Z',
updated_at: '2021-08-16T06:31:53.214Z',
created_by_id: null,
updated_by_id: null,
storage_id: 2,
},
},
};

View File

@ -17,4 +17,11 @@ export default defineConfig({
{ path: '/', exact: false, component: '@/pages/index' }, { path: '/', exact: false, component: '@/pages/index' },
], ],
fastRefresh: {}, fastRefresh: {},
locale: {
default: 'zh-CN',
// antd: false,
// title: false,
baseNavigator: false,
baseSeparator: '-',
},
}); });

View File

@ -29,8 +29,8 @@ export const createOrUpdate = async (ctx: actions.Context, next: actions.Next) =
} else { } else {
await collection.update(values); await collection.update(values);
} }
if (values.fields) { if (values.generalFields) {
values.fields = values.fields.map((field, index) => { values.generalFields = values.generalFields.map((field, index) => {
return { return {
...field, ...field,
sort: index + 1, sort: index + 1,

View File

@ -7,6 +7,10 @@ export default {
type: 'string', type: 'string',
name: 'title', name: 'title',
}, },
{
type: 'boolean',
name: 'showLogoOnly',
},
{ {
type: 'belongsTo', type: 'belongsTo',
name: 'logo', name: 'logo',