240 lines
7.1 KiB
JavaScript
240 lines
7.1 KiB
JavaScript
![]() |
/*
|
||
|
* @Author: ag
|
||
|
* @LastEditTime: 2022-06-29 11:36:20
|
||
|
* @LastEditors: ag 2663588772@qq.com
|
||
|
* @Description:
|
||
|
*/
|
||
|
import { thirdpartyGet, thirdpartyPost } from '@/api/axiosExtension.js';
|
||
|
|
||
|
//第三方数据元数据
|
||
|
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) => {
|
||
|
thirdpartyGet(apiUrl)
|
||
|
.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) => {
|
||
|
thirdpartyGet(metadataUrl)
|
||
|
.then((res) => {
|
||
|
// this.data = res;
|
||
|
resolve(res);
|
||
|
})
|
||
|
.catch((error) => {
|
||
|
reject(error);
|
||
|
});
|
||
|
});
|
||
|
}
|
||
|
select(pageInfo) {
|
||
|
//表格内容
|
||
|
let selectUrl = this.selectUrl;
|
||
|
return new Promise((resolve, reject) => {
|
||
|
thirdpartyPost(selectUrl, pageInfo)
|
||
|
.then((res) => {
|
||
|
// this.data = res;
|
||
|
resolve(res);
|
||
|
})
|
||
|
.catch((error) => {
|
||
|
reject(error);
|
||
|
});
|
||
|
});
|
||
|
}
|
||
|
insert(params) {
|
||
|
//插入
|
||
|
let insertUrl = this.insertUrl;
|
||
|
return new Promise((resolve, reject) => {
|
||
|
thirdpartyPost(insertUrl, params)
|
||
|
.then((res) => {
|
||
|
// this.data = res;
|
||
|
resolve(res);
|
||
|
})
|
||
|
.catch((error) => {
|
||
|
reject(error);
|
||
|
});
|
||
|
});
|
||
|
}
|
||
|
update(params) {
|
||
|
//更新
|
||
|
let updateUrl = this.updateUrl;
|
||
|
return new Promise((resolve, reject) => {
|
||
|
thirdpartyPost(updateUrl, params)
|
||
|
.then((res) => {
|
||
|
// this.data = res;
|
||
|
resolve(res);
|
||
|
})
|
||
|
.catch((error) => {
|
||
|
reject(error);
|
||
|
});
|
||
|
});
|
||
|
}
|
||
|
delete(param) {
|
||
|
//删除
|
||
|
let deleteUrl = this.deleteUrl;
|
||
|
return new Promise((resolve, reject) => {
|
||
|
thirdpartyPost(deleteUrl, param)
|
||
|
.then((res) => {
|
||
|
// this.data = res;
|
||
|
resolve(res);
|
||
|
})
|
||
|
.catch((error) => {
|
||
|
reject(error);
|
||
|
});
|
||
|
});
|
||
|
}
|
||
|
|
||
|
uploadImg(param, progressCallBack){
|
||
|
return new Promise((resolve, reject) => {
|
||
|
let config = {
|
||
|
headers: {
|
||
|
'Content-Type': 'multipart/form-data'
|
||
|
},
|
||
|
onUploadProgress:(progressEvent)=>{ //用于上传进度
|
||
|
let loaded = progressEvent.loaded,
|
||
|
total = progressEvent.total;
|
||
|
progressCallBack(loaded/total); //上传进度回调
|
||
|
}
|
||
|
}
|
||
|
thirdpartyPost(`${window.GLOBAL["CORS_API"]}/ThirdpartyApi/artwork/api/picture/upload`, param, config)
|
||
|
.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 };
|