Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
54 changes: 54 additions & 0 deletions app/controller/material-center/ComponentLibrary.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
/**
* Copyright (c) 2023 - present TinyEngine Authors.
* Copyright (c) 2023 - present Huawei Cloud Computing Technologies Co., Ltd.
*
* Use of this source code is governed by an MIT-style license.
*
* THE OPEN SOURCE SOFTWARE IN THIS PRODUCT IS DISTRIBUTED IN THE HOPE THAT IT WILL BE USEFUL,
* BUT WITHOUT ANY WARRANTY, WITHOUT EVEN THE IMPLIED WARRANTY OF MERCHANTABILITY OR FITNESS FOR
* A PARTICULAR PURPOSE. SEE THE APPLICABLE LICENSES FOR MORE DETAILS.
*
*/
import { Controller } from 'egg';
import { I_CreateComponentLibrary } from '../../lib/interface';

export default class ComponentController extends Controller {

/**
* @summary 注册组件库
* @router POST /api/componentLibrary/create
*/
async create(){
const data: I_CreateComponentLibrary = this.ctx.request.body;
this.ctx.body = await this.service.materialCenter.componentLibrary.create(data);
}

/**
* @summary 查询组件库
* @router GET
*/
async find(){
this.ctx.body = await this.service.materialCenter.componentLibrary.find(this.ctx.query);
}

/**
* @summary 更新组件库
* @router PUT
*/
async update(){
const { id } = this.ctx.params;
const params = this.ctx.request.body;
this.ctx.body = await this.service.materialCenter.componentLibrary.update({id, ...params });
}


/**
* @summary 删除组件库
* @router DELETE
*/
async delete(){
const { id } = this.ctx.params;
this.ctx.body = await this.service.materialCenter.componentLibrary.delete({ id });
}

}
30 changes: 30 additions & 0 deletions app/controller/material-center/UserComponents.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
/**
* Copyright (c) 2023 - present TinyEngine Authors.
* Copyright (c) 2023 - present Huawei Cloud Computing Technologies Co., Ltd.
*
* Use of this source code is governed by an MIT-style license.
*
* THE OPEN SOURCE SOFTWARE IN THIS PRODUCT IS DISTRIBUTED IN THE HOPE THAT IT WILL BE USEFUL,
* BUT WITHOUT ANY WARRANTY, WITHOUT EVEN THE IMPLIED WARRANTY OF MERCHANTABILITY OR FITNESS FOR
* A PARTICULAR PURPOSE. SEE THE APPLICABLE LICENSES FOR MORE DETAILS.
*
*/
import { Controller } from 'egg';

export default class UserComponentController extends Controller {

/**
* @summary 创建组件库
* @router POST /component/bundle/create
*/
async bundleCreate(){
const ctx = this.ctx;
try {
const fileStream = await ctx.getFileStream();
this.ctx.body = await this.ctx.service.materialCenter.userComponents.bundleCreate(fileStream);
} catch (error) {
ctx.logger.error('[UserComponentController] bundleCreate error:', error);
};
}

}
10 changes: 10 additions & 0 deletions app/router/materialCenter/base.ts
Original file line number Diff line number Diff line change
Expand Up @@ -62,4 +62,14 @@ export default (app: Application) => {
subRouter.get('/tasks/status', controller.materialCenter.task.status);
subRouter.get('/tasks/:id', controller.materialCenter.task.findById);

//组件库
subRouter.post('/component-library/update/:id',controller.materialCenter.componentLibrary.update);
subRouter.post('/component-library/create',controller.materialCenter.componentLibrary.create);
subRouter.delete('/component-library/delete/:id',controller.materialCenter.componentLibrary.delete);
subRouter.get('/component-library/find',controller.materialCenter.componentLibrary.find);


// 拆分bundle.json
subRouter.post('/component/bundle/create',controller.materialCenter.userComponents.bundleCreate);

};
21 changes: 20 additions & 1 deletion app/service/app-center/appSchema.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,8 @@ class AppSchema extends SchemaService {
['dataSource', this.getSchemaDataSource],
['i18n', this.getSchemaI18n],
['componentsTree', this.getSchemaComponentsTree],
['componentsMap', this.getSchemaComponentsMap]
['componentsMap', this.getSchemaComponentsMap],
['packages', this.getPackages]
]);

// 获取schema数据
Expand Down Expand Up @@ -79,10 +80,28 @@ class AppSchema extends SchemaService {
// 获取应用信息
private async setMeta(query?): Promise<I_Response> {
const metaData: I_Response = await this.service.appCenter.apps.schemaMeta(this.appId, query);
const componentLibraryData = await this.service.materialCenter.componentLibrary.list();
this.meta = metaData.data;
this.meta.componentLibrary = componentLibraryData.data;
return metaData;
}

private getPackages() {
const {componentLibrary} = this.meta;
if(!Array.isArray(componentLibrary)) {
return this.ctx.helper.getResponseData([]);
}
const packages = componentLibrary.map((item) => ({
name: item.name,
package: item.packageName,
version: item.version,
script: item.script,
css: item.css,
others: item.others
}));
return this.ctx.helper.getResponseData(packages);
}

// 获取元数据
private getSchemaMeta(): I_Response {
const appData = this.meta.app;
Expand Down
53 changes: 53 additions & 0 deletions app/service/material-center/ComponentLibrary.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
/**
* Copyright (c) 2023 - present TinyEngine Authors.
* Copyright (c) 2023 - present Huawei Cloud Computing Technologies Co., Ltd.
*
* Use of this source code is governed by an MIT-style license.
*
* THE OPEN SOURCE SOFTWARE IN THIS PRODUCT IS DISTRIBUTED IN THE HOPE THAT IT WILL BE USEFUL,
* BUT WITHOUT ANY WARRANTY, WITHOUT EVEN THE IMPLIED WARRANTY OF MERCHANTABILITY OR FITNESS FOR
* A PARTICULAR PURPOSE. SEE THE APPLICABLE LICENSES FOR MORE DETAILS.
*
*/
import { E_Method } from '../../lib/enum';
import { I_CreateComponentLibrary } from '../../lib/interface';
import * as qs from 'querystring';
import DataService from '../dataService';

export default class ComponentLibrary extends DataService{

async create(param: I_CreateComponentLibrary) {
return this.query({
url: 'component-library' ,
method: E_Method.Post,
data: param
});
}

async find(param){
const query = qs.stringify(param);
return this.query({
url: `component-library?${query}`
});
}

async list() {
return this.query({ url: 'component-library' });
}

async update(param) {
const { id } = param;
return this.query({
url: `component-library/${id}`,
method: E_Method.Put,
data: param
});
}

delete({ id }){
return this.query({
url: `component-library/${id}`,
method: E_Method.Delete
});
}
}
37 changes: 37 additions & 0 deletions app/service/material-center/Material.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
/**
* Copyright (c) 2023 - present TinyEngine Authors.
* Copyright (c) 2023 - present Huawei Cloud Computing Technologies Co., Ltd.
*
* Use of this source code is governed by an MIT-style license.
*
* THE OPEN SOURCE SOFTWARE IN THIS PRODUCT IS DISTRIBUTED IN THE HOPE THAT IT WILL BE USEFUL,
* BUT WITHOUT ANY WARRANTY, WITHOUT EVEN THE IMPLIED WARRANTY OF MERCHANTABILITY OR FITNESS FOR
* A PARTICULAR PURPOSE. SEE THE APPLICABLE LICENSES FOR MORE DETAILS.
*
*/
import { E_Method } from '../../lib/enum';
import DataService from '../dataService';
import * as qs from 'querystring';

export default class Material extends DataService{

private base = 'materials';

async update(param) {
const {id} = param;
return this.query({
url: `materials/${id}`,
method: E_Method.Put,
data: param
});

}

async find(param) {
const query = typeof param === 'string' ? param : qs.stringify(param);
return this.fQuery({
url: `${this.base}?${query}`
});
}

}
45 changes: 45 additions & 0 deletions app/service/material-center/MaterialHistories.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
/**
* Copyright (c) 2023 - present TinyEngine Authors.
* Copyright (c) 2023 - present Huawei Cloud Computing Technologies Co., Ltd.
*
* Use of this source code is governed by an MIT-style license.
*
* THE OPEN SOURCE SOFTWARE IN THIS PRODUCT IS DISTRIBUTED IN THE HOPE THAT IT WILL BE USEFUL,
* BUT WITHOUT ANY WARRANTY, WITHOUT EVEN THE IMPLIED WARRANTY OF MERCHANTABILITY OR FITNESS FOR
* A PARTICULAR PURPOSE. SEE THE APPLICABLE LICENSES FOR MORE DETAILS.
*
*/
import { E_Method } from '../../lib/enum';
import DataService from '../dataService';
import * as qs from 'querystring';

export default class MaterialHistories extends DataService{

private base = 'material-histories';

async create(param) {
return this.fQuery({
url: 'material-histories',
method: E_Method.Post,
data: param
});
}

async update(param) {
const {id} = param;
return this.query({
url: `material-histories/${id}`,
method: E_Method.Put,
data: param
});

}

async find(param) {
const query = typeof param === 'string' ? param : qs.stringify(param);
return this.fQuery({
url: `${this.base}?${query}`
});
}

}
Loading