Sidebar-FanComponent.js 2.04 KB

(function () {
	// Adds Atlassian shapes
	// fan 风机
	Sidebar.prototype.addThingsKitFanPalette = function () {

		const gn = 'mxgraph.fan';
		const dt = 'fan';
		const label = mxResources.get('fan')
		const width = 66;
		const height = 74;
		const prefix = `image;image=${window?.PROJECT_ENV.base}/webapp/images/thingskit/libs/`
		const defaultStyle = ';imageAspect=0;'
		this.setCurrentSearchEntryLibrary(dt);

		const { COMPONENT_KEY, CATEGORY } = window.CellAttributeKeyEnum

		function createUserObject(attribute) {
			attribute = Object.assign({ [COMPONENT_KEY]: '', [CATEGORY]: '' }, attribute || {})
			var xmlElement = mxUtils.createXmlDocument().createElement('UserObject');

			Object.keys(attribute).forEach(key => {
				xmlElement.setAttribute(key, attribute[key]);
			})
			return xmlElement
		}

		// 自定义属性
		const cellAttribute = {
			[COMPONENT_KEY]: 'Image',
			[CATEGORY]: 'DEFAULT'
		}

		const graphPathLib = [
			{ name:  mxResources.get('fan') +'1', path: 'fan/风机1.png' },
			{ name:  mxResources.get('fan') +'2', path: 'fan/风机2.png' },
			{ name:  mxResources.get('fan') +'3', path: 'fan/风机3.png' },
			{ name:  mxResources.get('fan') +'4', path: 'fan/风机4.png' },
			{ name:  mxResources.get('fan') +'5', path: 'fan/风机5.gif' },
			{ name:  mxResources.get('fan') +'6', path: 'fan/风机6.gif' },
			{ name:  mxResources.get('fan') +'7', path: 'fan/风机7.gif' },
			{ name:  mxResources.get('fan') +'8', path: 'fan/风机8.png' },
		]



		const fns = graphPathLib.map(item => {
			return this.addEntry(this.getTagsForStencil(gn, item.name, dt).join(' '), mxUtils.bind(this, function () {
				const cell = new mxCell(createUserObject(cellAttribute), new mxGeometry(0, 0, width, height), `${prefix}${item.path}${defaultStyle}`);
				cell.setVertex(true)
				
				return this.createVertexTemplateFromCells([cell], cell.geometry.width, cell.geometry.height, item.name);
			}));
		})

		
		this.setGalleryLib(dt, label, graphPathLib)

		this.addPaletteFunctions(dt, label, false, fns);

		this.setCurrentSearchEntryLibrary();
	};
})();