import { CellsysPolygonStyle } from './cellsysStyle'; import CellsysElementType from './cellsysElementType'; import { CellsysType, EditTask, EditType, Query, QueryTask, QueryType } from './cellsysUtil.js'; import { PublishTarget } from './cellsysEnum'; import { hexColorToRgba } from './utils/utils'; class CellsysOfflinePolygonType extends CellsysElementType { constructor(params) { super(params); this.cellsysType = CellsysType.OfflinePolygonType; if (!params) { params = {}; } this.id = params.id; this.name = params.name; this.description = params.description; this.orgId = params.org_id; this.orgName = params.org_name; this.style = params.style ? params.style : CellsysPolygonStyle.getDefaultStyle(); this.action = params.action; this.typeCount = params.type_count || 0; this.isPublish = params.is_publish || 0; } setId(value) { this.id = value; } setName(value) { this.name = value; } setDescription(value) { this.description = value; } setStyle(value) { this.style = value; } getColor() { return this.style ? this.style.color : '#000000'; } getFillColor() { return this.style ? this.style.fillColor : null; } getFillOpacity() { return this.style ? this.style.fillOpacity : null; } getCssStyle() { // return formatterPolygonStyle(this.style) if (this.style) { let strokeOpacity = this.style.strokeOpacity; strokeOpacity = strokeOpacity === null || strokeOpacity === undefined ? 0 : strokeOpacity; let colors = hexColorToRgba(this.style.strokeColor || '#000000'); colors.push(strokeOpacity); let border = this.style.weight + 'px ' + 'solid rgba(' + colors.join(',') + ')'; let fillOpacity = this.style.fillOpacity; fillOpacity = fillOpacity === null || fillOpacity === undefined ? 0 : fillOpacity; let colors2 = hexColorToRgba(this.style.fillColor || '#000000'); colors2.push(fillOpacity); let backgroundColor = 'rgba(' + colors2.join(',') + ')'; return { border: border, 'background-color': backgroundColor, cursor: 'text', }; } return null; } //发布功能 setPublish(publishStatus, range, ids, isEditable, remark) { let editTask = new EditTask(EditType.OfflinePublish); editTask.addParam('_id', this.id); editTask.addParam('_offline_fence_type_name', this.name); editTask.addParam('_is_publish', PublishTarget[publishStatus]); editTask.addParam('_remark', remark); if (publishStatus !== 'noPublish') { if (range === 1) { //发布到组织 editTask.addParam('_publish_org', ids); } else { editTask.addParam('_publish_group', ids); } editTask.addParam('_publish_range', range); } if (isEditable) { editTask.addParam('_is_update', 1); } else { editTask.addParam('_is_update', 0); } return editTask.execute(); } //查询协同数据发布记录列表 synergyDataPublishRecord(dataId, type) { let query = new Query(); query.setOrder({ create_time: 'desc' }); query.addFilter('data_type', '=', 4); query.setCurrPage(1); query.setPageSize(1); if (dataId) { query.addFilter('data_id', '=', dataId); } if (type) { query.addFilter('type', '=', type); } let queryTask = new QueryTask(QueryType.synergyDataPublishRecord, true); return new Promise((resolve, reject) => { queryTask .execute(query) .then((res) => { resolve(res); }) .catch((err) => { reject(err); }); }); } //锁定/解锁 setLock(params) { let editTask = new EditTask(EditType.OfflineLock); editTask.addParam('_id', params.id); editTask.addParam('_is_unlock', params.isUnlock); return editTask.execute(); } } export default CellsysOfflinePolygonType;