cellsysBase/cellsysExtension.js

245 lines
7.1 KiB
JavaScript
Raw Normal View History

2024-08-14 16:20:56 +08:00
/*
* @Author: ag
* @LastEditTime: 2022-06-29 11:36:20
* @LastEditors: ag 2663588772@qq.com
* @Description:
*/
2024-12-26 11:21:07 +08:00
import { get, post } from './utils/axios';
2024-08-14 16:20:56 +08:00
//第三方数据元数据
class CellsysExtensionMeta {
constructor(metaData) {
this.fieldName = metaData.fieldName;
this.aliasName = metaData.aliasName;
this.fieldType = metaData.fieldType;
this.fieldTypeOptions = metaData.fieldTypeOptions;
this.length = metaData.length;
this.isReadOnly = metaData.isReadOnly;
this.isNotNull = metaData.isNotNull;
this.description = metaData.description;
this.isPrimaryKey = metaData.isPrimaryKey;
this.defaultValue = metaData.defaultValue;
}
transformFormData(fieldValue) {
//根据filedType转化表单数据
let _val = fieldValue;
switch (this.fieldType) {
// case 'select':
// //根据fieldTypeOptions匹配下拉框的值
// _val = this.getSelectValue(_val);
// break;
default:
break;
}
return _val;
}
getRule() {
if (this.length) {
return `不能超过${this.length}个字符`;
}
if (this.isNotNull) {
return '不能为空';
}
}
getSelectValue(fieldValue) {
if (!this.fieldTypeOptions) {
return fieldValue;
}
for (let item of this.fieldTypeOptions) {
if (item.label === fieldValue) {
return item.value;
}
}
}
transformSubmitData(fieldValue) {
let _val = fieldValue;
switch (this.fieldType) {
case 'image':
//根据fieldTypeOptions匹配下拉框的值
_val = this.getImageValue(_val);
break;
default:
break;
}
return _val;
}
getImageValue(fieldValue) {}
}
//第三方数据记录
class CellsysExtensionRecord {
constructor(params) {
if (!params) {
params = {};
}
this.id = params.id;
this.orgId = params.org_id;
this.objectType = params.object_type;
this.typeId = params.type_id;
this.apiName = params.api_name;
this.apiUrl = params.api_url;
this.apiDescription = params.api_description;
this.apiIsPublish = params.api_is_publish;
this.createBy = params.create_by;
this.createTime = params.create_time;
this.updateBy = params.update_by;
this.updateTime = params.update_time;
// this.data = null;
}
queryThirdpartyData() {
let apiUrl = this.apiUrl;
return new Promise((resolve, reject) => {
2024-12-26 11:21:07 +08:00
get(apiUrl)
2024-08-14 16:20:56 +08:00
.then((res) => {
this.data = res;
resolve(res);
})
.catch((error) => {
reject(error);
});
});
}
}
//第三方数据类型
class CellsysExtensionType {
constructor(params) {
if (!params) {
params = {};
}
this.orgId = params.org_id;
this.orgName = params.org_name;
this.id = params.id;
this.name = params.name;
this.metadataUrl = params.metadata_url; //元数据
this.selectUrl = params.select_url; //查询
this.filterUrl = params.filter_url; //筛选
this.insertUrl = params.insert_url; //插入
this.updateUrl = params.update_url; //更新
this.deleteUrl = params.delete_url; //删除
this.createBy = params.create_by;
this.createTime = params.create_time;
this.updateBy = params.update_by;
this.updateTime = params.update_time;
this.description = params.description;
}
metadata() {
//表格头数据
let metadataUrl = this.metadataUrl;
return new Promise((resolve, reject) => {
2024-12-26 11:21:07 +08:00
get(metadataUrl)
2024-08-14 16:20:56 +08:00
.then((res) => {
// this.data = res;
resolve(res);
})
.catch((error) => {
reject(error);
});
});
}
select(pageInfo) {
//表格内容
let selectUrl = this.selectUrl;
return new Promise((resolve, reject) => {
2024-12-26 11:21:07 +08:00
post(selectUrl, pageInfo)
2024-08-14 16:20:56 +08:00
.then((res) => {
// this.data = res;
resolve(res);
})
.catch((error) => {
reject(error);
});
});
}
insert(params) {
//插入
let insertUrl = this.insertUrl;
return new Promise((resolve, reject) => {
2024-12-26 11:21:07 +08:00
post(insertUrl, params)
2024-08-14 16:20:56 +08:00
.then((res) => {
// this.data = res;
resolve(res);
})
.catch((error) => {
reject(error);
});
});
}
update(params) {
//更新
let updateUrl = this.updateUrl;
return new Promise((resolve, reject) => {
2024-12-26 11:21:07 +08:00
post(updateUrl, params)
2024-08-14 16:20:56 +08:00
.then((res) => {
// this.data = res;
resolve(res);
})
.catch((error) => {
reject(error);
});
});
}
delete(param) {
//删除
let deleteUrl = this.deleteUrl;
return new Promise((resolve, reject) => {
2024-12-26 11:21:07 +08:00
post(deleteUrl, param)
2024-08-14 16:20:56 +08:00
.then((res) => {
// this.data = res;
resolve(res);
})
.catch((error) => {
reject(error);
});
});
}
2024-12-26 11:21:07 +08:00
uploadImg(param, progressCallBack) {
2024-08-14 16:20:56 +08:00
return new Promise((resolve, reject) => {
let config = {
headers: {
2024-12-26 11:21:07 +08:00
'Content-Type': 'multipart/form-data',
2024-08-14 16:20:56 +08:00
},
2024-12-26 11:21:07 +08:00
onUploadProgress: (progressEvent) => {
//用于上传进度
2024-08-14 16:20:56 +08:00
let loaded = progressEvent.loaded,
total = progressEvent.total;
2024-12-26 11:21:07 +08:00
progressCallBack(loaded / total); //上传进度回调
},
};
post(
`${window.GLOBAL['CORS_API']}/ThirdpartyApi/artwork/api/picture/upload`,
param,
config,
)
2024-08-14 16:20:56 +08:00
.then((res) => {
resolve(res);
})
.catch((error) => {
reject(error);
});
});
}
}
//第三方数据
class CellsysExtensionData {
constructor(params) {
if (!params) {
params = {};
}
this.fieldName = params.fieldName;
this.aliName = params.aliName;
this.type = params.type;
this.value = params.value;
this.meta = null;
}
setMeta(cellsysExtensionMeta) {
this.meta = cellsysExtensionMeta;
}
}
export { CellsysExtensionMeta, CellsysExtensionRecord, CellsysExtensionType, CellsysExtensionData };