150 lines
4.9 KiB
JavaScript
150 lines
4.9 KiB
JavaScript
![]() |
/*
|
|||
|
* @Author: ag
|
|||
|
* @LastEditTime: 2022-10-13 13:56:01
|
|||
|
* @LastEditors: ag 2663588772@qq.com
|
|||
|
* @Description:
|
|||
|
*/
|
|||
|
import { Query, QueryTask, QueryType, EditTask, EditType, Operator, CellsysType, QueryMG, ThirdpartyObjectType } from './cellsysUtil.js';
|
|||
|
import { CellsysExtensionRecord } from './cellsysExtension.js';
|
|||
|
|
|||
|
class CellsysElementType {
|
|||
|
constructor(params) {
|
|||
|
if (!params) {
|
|||
|
params = {};
|
|||
|
}
|
|||
|
this.id = params.id;
|
|||
|
this.orgId = params.org_id;
|
|||
|
this.orgName = params.org_name;
|
|||
|
this.createBy = params.create_by;
|
|||
|
this.createTime = params.create_time;
|
|||
|
this.updateBy = params.update_by;
|
|||
|
this.updateTime = params.update_time;
|
|||
|
this.tags = [];
|
|||
|
if(params.tag_name){
|
|||
|
this.tags = params.tag_name.map(name => {
|
|||
|
return {"name":name}
|
|||
|
})
|
|||
|
}
|
|||
|
let creator = params.creator;
|
|||
|
this.creator = {
|
|||
|
memberId: null,
|
|||
|
name: null
|
|||
|
}
|
|||
|
if (creator) {
|
|||
|
this.creator = {
|
|||
|
memberId: creator.member_id,
|
|||
|
name: creator.name
|
|||
|
}
|
|||
|
}
|
|||
|
let updater = params.updater;
|
|||
|
this.updater = {
|
|||
|
memberId: null,
|
|||
|
name: null
|
|||
|
}
|
|||
|
if (updater) {
|
|||
|
this.updater = {
|
|||
|
memberId: updater.member_id,
|
|||
|
name: updater.name
|
|||
|
}
|
|||
|
}
|
|||
|
this.isPublish = params.is_publish;
|
|||
|
this.publishRange = params.publish_range; //发布范围 0-群组 1-组织
|
|||
|
this.publishGroup = params.publish_group ? params.publish_group : []; //发布的群组
|
|||
|
this.isEditable = params.is_update === 1 ? true : false; //is_update表示是否允许其他人编辑 0-不允许 1-允许
|
|||
|
this.isUnlock = params.is_unlock;//是否未锁定,0-已锁定,1-未锁定
|
|||
|
}
|
|||
|
/**
|
|||
|
*
|
|||
|
* 查询(类型)API
|
|||
|
* @returns
|
|||
|
*/
|
|||
|
|
|||
|
queryAPI(pageInfo, filters, order) {
|
|||
|
let query = new Query();
|
|||
|
if (pageInfo) {
|
|||
|
query.setCurrPage(pageInfo.currPage);
|
|||
|
query.setPageSize(pageInfo.pageSize);
|
|||
|
}
|
|||
|
if (filters && filters.length > 0) {
|
|||
|
filters.forEach((item) => {
|
|||
|
query.addFilter(item['name'], item['operator'], item['value']);
|
|||
|
});
|
|||
|
}
|
|||
|
if (order) {
|
|||
|
query.setOrder(order)
|
|||
|
} else {
|
|||
|
query.setOrder({ id: 'desc' });
|
|||
|
}
|
|||
|
query.addFilter('type_id', Operator.Equals, this.id);
|
|||
|
query.addFilter('object_type', Operator.Equals, ThirdpartyObjectType[this.cellsysType]);
|
|||
|
let queryTask = new QueryTask(QueryType.ThirdpartyTypeRel, pageInfo);
|
|||
|
// return queryTask.execute(query);
|
|||
|
return new Promise((resolve, reject) => {
|
|||
|
queryTask
|
|||
|
.execute(query)
|
|||
|
.then((res) => {
|
|||
|
if (pageInfo) {
|
|||
|
if (res.data) {
|
|||
|
res.data = res.data.map((item) => {
|
|||
|
return new CellsysExtensionRecord(item);
|
|||
|
});
|
|||
|
resolve(res);
|
|||
|
}
|
|||
|
} else {
|
|||
|
let resArr = res.map((item) => {
|
|||
|
return new CellsysExtensionRecord(item);
|
|||
|
});
|
|||
|
resolve(resArr);
|
|||
|
}
|
|||
|
})
|
|||
|
.catch((err) => {
|
|||
|
reject(err);
|
|||
|
});
|
|||
|
});
|
|||
|
}
|
|||
|
|
|||
|
/**
|
|||
|
* 新增类型关联API
|
|||
|
* @param
|
|||
|
*/
|
|||
|
typeAddAPI(params) {
|
|||
|
let editTask = new EditTask(EditType.TypeAddAPI);
|
|||
|
editTask.addParam('_object_type', ThirdpartyObjectType[this.cellsysType]);
|
|||
|
editTask.addParam('_api_is_publish', 1);
|
|||
|
editTask.addParam('_type_id', this.id);
|
|||
|
editTask.addParam('_api_name', params.apiName);
|
|||
|
editTask.addParam('_api_url', params.apiUrl);
|
|||
|
editTask.addParam('_api_description', params.apiDescription);
|
|||
|
return editTask.execute();
|
|||
|
}
|
|||
|
/**
|
|||
|
* 修改类型关联API
|
|||
|
* @param
|
|||
|
*/
|
|||
|
typeUpdateAPI(params) {
|
|||
|
let editTask = new EditTask(EditType.TypeUpdateAPI);
|
|||
|
editTask.addParam('_api_is_publish', params.apiIsPublish);
|
|||
|
editTask.addParam('type_id', this.id);
|
|||
|
editTask.addParam('_id', params.id);
|
|||
|
editTask.addParam('_api_name', params.apiName);
|
|||
|
editTask.addParam('_api_url', params.apiUrl);
|
|||
|
editTask.addParam('_api_description', params.apiDescription);
|
|||
|
return editTask.execute();
|
|||
|
}
|
|||
|
|
|||
|
/**
|
|||
|
* 删除类型关联API
|
|||
|
* @param {*} params
|
|||
|
*/
|
|||
|
typeDeleteAPI(params) {
|
|||
|
// EditType.TokenDelete
|
|||
|
let editTask = new EditTask(EditType.TypeDeleteAPI);
|
|||
|
editTask.addParam('_id', params);
|
|||
|
return editTask.execute();
|
|||
|
}
|
|||
|
|
|||
|
|
|||
|
}
|
|||
|
|
|||
|
export default CellsysElementType;
|