/* * @Author: ag * @LastEditTime: 2022-11-14 10:20:03 * @LastEditors: ag 2663588772@qq.com * @Description: */ import { BASE_URL, CellsysType, IMAGE_URL, Operator, Query, QueryTask, QueryType, } from './cellsysUtil.js'; import CellsysElement from './cellsysElement.js'; const getBaseUrl = function () { let hostName = window.location.hostname; let protocol = window.location.protocol; let port = window.location.port; let path = protocol + '//' + hostName; return port ? path + ':' + port : path; }; class CellsysEvent extends CellsysElement { constructor(params) { super(params); this.cellsysType = CellsysType.Event; if (!params) { params = {}; } this.id = params.id; this.name = params.name; this.description = params.description; this.type = params.type; this.geometry = params.geometry; this.filePath = params.file_path || []; this.fileName = params.file_name; this.userId = params.user_id; this.orgId = params.org_id; this.appId = params.app_id; this.typeName = params.type_name; this.style = params.style ? params.style : {}; this.realname = params.realname; this.pictures = params.pictures || []; /*this.createdId = params.create_by;*/ this.createdTime = params.create_time; /*this.updatedId = params.update_by;*/ this.updatedTime = params.update_time; this.dateTime = params.datetime; this.eventImages = []; //事件图片,这个才是最合理的 this.typeIsUnlock = params.type_is_unlock; this.typeIsUpdate = params.type_is_update; this.creator = { userId: params.create_by, name: params.realname, }; this.updater = { userId: params.update_by, name: params.realname, }; // this.imgPath = []; //原图路径 // if(params.img_path && params.img_path.length > 0){ // this.imgPath = params.img_path; // } // //this.litimgPath = []; //压缩版图片路径 if (params.litimg_path && params.litimg_path.length > 0) { let { litimg_path, img_path } = params; this.eventImages = litimg_path.map((item, index) => { return { imgPath: img_path[index], //原图路径 litimgPath: litimg_path[index] ? litimg_path[index] : img_path[index], //压缩版图片路径 }; }); } this.formatPath = []; //用拼接路径方式的字段比较古老,建议不再使用该字段,后续会慢慢废弃 if (this.filePath.length > 0) { this.formatPath = this.filePath.map((item) => { if (item && item.indexOf('/resources/basePic/') > -1) { // 兼容显示以前存储的图片路径 return { fileName: item.slice(item.lastIndexOf('/') + 1), url: item, }; } else if (item) { return { fileName: item, url: BASE_URL + IMAGE_URL + '/' + this.orgId + '/event/' + this.id + '/' + item, }; } }); } } setId(value) { this.id = value; } setName(value) { this.name = value; } setDescription(value) { this.description = value; } getIcon() { return this.style ? this.style.icon : null; } getIconUrl() { return this.style ? this.style.path : null; } getColor() { return this.style ? this.style.color : null; } queryUserInfo() { let query = new Query(); query.addFilter('org_id', Operator.Equals, this.orgId); query.addFilter('user_id', Operator.Equals, this.userId); let queryTask = new QueryTask(QueryType.OrgMember, false); return queryTask.execute(query); } } //转化预览图路径 function formatPreview(url) { let splitList = url.split('/'); let fileName = splitList[splitList.length - 1]; fileName = fileName.split('.')[0] + '.jpg'; //图片服务压缩过的图片统一都是jpg格式,因此这里需要更换图片后缀 splitList.pop(); //移除掉文件名部分 return splitList.join('/') + '/preview/' + fileName; } export default CellsysEvent;