物管理前端
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

377 lines
50 KiB

  1. const e="6a4f3583-cfab-4569-8739-e33302568b48",a="custom-button-node",t="按钮",n='<?xml version="1.0" standalone="no"?><!DOCTYPE svg PUBLIC "-//W3C//DTD SVG 1.1//EN" "http://www.w3.org/Graphics/SVG/1.1/DTD/svg11.dtd"><svg t="1688107204717" class="icon" viewBox="0 0 1024 1024" version="1.1" xmlns="http://www.w3.org/2000/svg" p-id="9101" xmlns:xlink="http://www.w3.org/1999/xlink" width="200" height="200"><path d="M883.3 745H142.7c-41.9 0-76-34.1-76-76V351.6c0-41.9 34.1-76 76-76h740.6c41.9 0 76 34.1 76 76V669c0 41.9-34.1 76-76 76zM142.7 321.8c-16.4 0-29.8 13.3-29.8 29.8V669c0 16.4 13.3 29.8 29.8 29.8h740.6c16.4 0 29.8-13.3 29.8-29.8V351.6c0-16.4-13.3-29.8-29.8-29.8H142.7z" fill="#707070" p-id="9102"></path><path d="M191.3 576c-10.1 0-13.9 0.1-19.6 0.4 0.8-5.7 1.1-10.2 1.1-19.4v-72.4c0-7-0.3-12.7-1.1-19 6.7 0.4 8.6 0.4 19.4 0.4h34.7c21.4 0 34 10.3 34 27.8 0 8.1-2.6 14.4-7.7 18.9-2.9 2.5-5.3 3.8-10.7 5.8 6.5 1.5 9.9 3 13.8 6.4 5.7 5 8.6 12.2 8.6 20.9 0 19-13.5 30.3-36.5 30.3h-36z m30.6-67.6c7 0 11.4-4.1 11.4-10.6s-4.1-10.2-11.6-10.2h-23v20.8h23.2z m-23.2 45.8H223c8.3 0 13.4-4.6 13.4-12.4 0-7.7-5-12.2-13.5-12.2h-24.2v24.6zM384.9 465.9c-0.8 5.7-1.1 10.4-1.1 20v45.5c0 30.2-18.1 47.2-50 47.2-16.4 0-29.8-4.6-37.7-13-7.7-8.2-11.6-19.7-11.6-34.5v-45.2c0-9.1-0.3-14.9-1.1-20H312c-0.8 4.9-1.1 10.2-1.1 20v45.5c0 16.7 7.5 24.6 23 24.6 15.9 0 23.4-7.9 23.4-24.6v-45.5c0-9.9-0.3-14-1.1-20h28.7zM464.1 556c0 7.9 0.3 13.8 1.1 20H436c0.8-6.2 1.1-11.6 1.1-20v-66.7h-15.6c-8.3 0-10.6 0.1-20 0.9V465c4.4 0.5 11.6 0.9 19.7 0.9H479c9.3 0 14.5-0.3 20.6-0.9v25.3c-6-0.7-11.1-0.9-20.6-0.9h-14.9V556zM572.9 556c0 7.9 0.3 13.8 1.1 20h-29.2c0.8-6.2 1.1-11.6 1.1-20v-66.7h-15.6c-8.3 0-10.6 0.1-20 0.9V465c4.4 0.5 11.6 0.9 19.7 0.9h57.9c9.3 0 14.5-0.3 20.6-0.9v25.3c-6-0.7-11.1-0.9-20.6-0.9H573V556zM728.7 520.4c0 34.9-21.3 58.1-53.4 58.1-32.4 0-53.3-22.6-53.3-57.7 0-34.9 20.9-57.3 53.4-57.3 32.6 0 53.3 22.3 53.3 56.9z m-27.5 0.3c0-21.4-9.8-34.4-25.8-34.4-16.1 0-26.1 13.1-26.1 34.4 0 21.6 9.9 34.9 26.1 34.9 16 0 25.8-13.2 25.8-34.9zM811.8 520c3.8 5.7 6.3 9.9 9.5 15.7-0.5-6.1-0.8-12.2-0.8-19.6V486c0-8.7-0.3-14-1.1-20.1h28.2c-0.8 6-1.1 11.5-1.1 20.1v70.2c0 8.1 0.4 14.2 1.1 19.7h-29c-2.4-5-5.4-9.9-9.9-16.8l-24.5-36.9c-3.6-5.3-5.8-9.3-9.5-16.3 0.7 6 0.9 13.2 0.9 19.7v29.6c0 9.1 0.3 14.9 1.1 20.6h-28.2c0.8-5.2 1.1-11 1.1-20.8v-69.6c0-7.7-0.3-13.6-1.1-19.7h28.7c1.3 3.6 4.2 8.9 9.4 16.5l25.2 37.8z" fill="#707070" p-id="9103"></path></svg>',l="svg",o="基础",i="常用",r=!1,u=!0,d="控制",s=`{"type":"page","id":"u:270584784ce1","name":"page1","asideResizor":false,"style":{"boxShadow":" 0px 0px 0px 0px transparent"},"pullRefresh":{"disabled":true},"body":[{"type":"tabs","name":"tab","tabs":[{"title":"样式","icon":"fa fa-th-large","body":[{"type":"form","title":"","name":"basicPropForm","body":[{"type":"input-text","label":"名称","name":"nodeAlias","id":"u:6b126f0520cb","size":"full","mode":"horizontal","inputControlClassName":"w-100","className":"m-b"},{"type":"input-text","label":"ID&nbsp;&nbsp;&nbsp;&nbsp;","name":"id","id":"u:6232710ac003","size":"full","mode":"horizontal","inputControlClassName":"w-100","className":"m-b"},{"type":"grid","id":"u:1954dc15dd5b","className":"m-b","columns":[{"body":[{"type":"input-number","label":"宽度","name":"width","keyboard":true,"id":"u:656efdb758ad","step":1,"suffix":"px","placeholder":"组件宽度","size":"full","mode":"horizontal","className":"m-b","value":100,"labelClassName":"w-8","labelAlign":"left","precision":2,"inputClassName":"w-full"}],"id":"u:4274c47a4ef5","md":6},{"body":[{"type":"input-number","label":"高度","name":"height","keyboard":true,"id":"u:1ed6dcd98c1a","step":1,"suffix":"px","placeholder":"组件高度","size":"full","mode":"horizontal","className":"m-b","value":100,"labelAlign":"left","labelClassName":"w-8","precision":2,"inputClassName":"w-full"}],"id":"u:3e9d1e71a69f","md":6}]},{"type":"grid","id":"u:c605398a724c","className":"m-b","columns":[{"body":[{"type":"input-number","label":"X 轴","name":"x","keyboard":true,"id":"u:dcc0c21d16f6","step":1,"suffix":"px","placeholder":"组件左边距","siz
  2. "nodes": [
  3. {
  4. "id": "294b013f-14d3-429e-a078-048da5f0261e",
  5. "type": "custom-button-node",
  6. "x": 200,
  7. "y": 200,
  8. "text": {
  9. "value": "测试按钮",
  10. "x": 200,
  11. "y": 200
  12. },
  13. "properties": {
  14. "id": "294b013f-14d3-429e-a078-048da5f0261e",
  15. "width": 80,
  16. "height": 35,
  17. "x": 200,
  18. "y": 200,
  19. "rotation": 0,
  20. "opacity": 1,
  21. "strokeWidth": 1,
  22. "fontSize": 14,
  23. "boxShadow": "0 2px 0 rgba(0, 0, 0, 0.45)",
  24. "nodeAlias": "按钮",
  25. "fontColor": "#ffffff",
  26. "strokeColor": "",
  27. "content": "测试按钮",
  28. "lineHeight": 35,
  29. "fontStyle": "",
  30. "fill": "rgb(24, 144, 255)",
  31. "background": "",
  32. "borderRadius": 6,
  33. "backgroundSize": "100% 100%",
  34. "dynamic": {
  35. "normalData": {
  36. "dataPoint": "",
  37. "compareType": "",
  38. "conditionVariables": [],
  39. "defaultValue": "",
  40. "unit": ""
  41. },
  42. "eventsData": {
  43. "eventCombo": [
  44. {
  45. "eventType": "click",
  46. "config": "{\\"globalInputParamsCalculated\\":[],\\"eventAction\\":\\"sendCommand\\",\\"sendCommandMethod\\":\\"config\\",\\"inputParamsCalculate\\":\\"// console.log('deviceInfo', deviceInfo, 'command', command, 'event', event);\\\\n// 入参提示: deviceInfo -- 设备信息,command -- 指令信息, event -- 事件传参(当前部件所绑定的立即值,或当前部件经过计算后的自定义值), 入参计算。。。然后返回出参\\\\nconst condition = {\\\\n deviceName: deviceInfo.code,\\\\n attrCode: command.controlDeviceAttr,\\\\n value: event == 0 ? 1 : event == 1 ? 0 : event\\\\n}\\\\nreturn {\\\\n \\\\\\"condition\\\\\\": JSON.stringify(condition),\\\\n \\\\\\"controlId\\\\\\": command.id\\\\n}\\",\\"requestMethod\\":\\"post\\",\\"requestUrl\\":\\"/thing/device/control/control\\"}",
  47. "users": ""
  48. }
  49. ]
  50. },
  51. "uiData": {
  52. "dataPoint": "",
  53. "compareType": "",
  54. "conditionVariables": [
  55. {
  56. "type": "equal",
  57. "label": "相等",
  58. "name": ""
  59. }
  60. ]
  61. },
  62. "animationData": {
  63. "animationCombo": [
  64. {
  65. "dataPoint": "",
  66. "min": "",
  67. "max": "",
  68. "animationName": "旋转",
  69. "animationTime": 3
  70. }
  71. ]
  72. },
  73. "hiddenData": {
  74. "hiddenCombo": [
  75. {
  76. "dataPoint": "",
  77. "min": "",
  78. "max": "",
  79. "showOrHiddenName": "隐藏"
  80. }
  81. ]
  82. }
  83. }
  84. }
  85. }
  86. ]
  87. }`,javascript:`
  88. const { createApp, createVNode, render } = Vue;
  89. const app = createApp({})
  90. const Button = {
  91. template: '<div :style="getStyle" @click="clickHandler" @dblclick="dblClickHandler">{{name}}</div>',
  92. props: {
  93. name: {
  94. type: String,
  95. default: '按钮11'
  96. },
  97. fontColor: {
  98. type: String,
  99. default: '#ffffff'
  100. },
  101. fontSize: {
  102. type: Number,
  103. default: 14
  104. },
  105. fontFamily: {
  106. type: String,
  107. default: '宋体'
  108. },
  109. fontStyle: {
  110. type: String,
  111. default: 'normal'
  112. },
  113. width: {
  114. type: Number,
  115. default: 80
  116. },
  117. height: {
  118. type: Number,
  119. default: 35
  120. },
  121. lineHeight: {
  122. type: Number,
  123. default: 35,
  124. },
  125. backgroundColor: {
  126. type: String,
  127. default: '#1890ff',
  128. },
  129. strokeColor: {
  130. type: String,
  131. default: '#1890ff',
  132. },
  133. strokeWidth: {
  134. type: Number,
  135. default: 1,
  136. },
  137. opacity: {
  138. type: Number,
  139. default: 1,
  140. },
  141. background: {
  142. type: String,
  143. default: '',
  144. },
  145. backgroundSize: {
  146. type: String,
  147. default: '100% 100%',
  148. },
  149. boxShadow: {
  150. type: String,
  151. default: '',
  152. },
  153. borderRadius: {
  154. type: Number,
  155. default: 6,
  156. },
  157. realValue: {
  158. type: [String, Number],
  159. default: ''
  160. }
  161. },
  162. computed: {
  163. getStyle () {
  164. const { fontColor, fontSize, fontFamily, fontStyle, width, height, lineHeight, backgroundColor,strokeColor,strokeWidth, opacity, background, backgroundSize, boxShadow, borderRadius } = this
  165. const style = {}
  166. if(fontStyle) {
  167. if (fontStyle.includes('bold')) {
  168. style.fontWeight = 'bolder';
  169. }
  170. if(fontStyle.includes('italic')) {
  171. style.fontStyle = 'italic'
  172. }
  173. if (fontStyle.includes('underline,line-through')) {
  174. style.textDecoration = 'underline line-through'
  175. } else if (fontStyle.includes('line-through,underline')) {
  176. style.textDecoration = 'line-through underline'
  177. } else if (fontStyle.includes('underline')) {
  178. style.textDecoration = 'underline'
  179. } else if (fontStyle.includes('line-through')) {
  180. style.textDecoration = 'line-through'
  181. }
  182. }
  183. let back = background;
  184. if (back && !back.includes('url')) {
  185. back = \`url(\${back})\`
  186. }
  187. return {
  188. color: fontColor,
  189. "font-size": parseInt(fontSize) + 'px',
  190. "font-family": fontFamily,
  191. "font-style": style.fontStyle,
  192. "font-weight": style.fontWeight,
  193. "text-decoration": style.textDecoration,
  194. width: parseInt(width) - parseInt(strokeWidth) * 2 + 'px',
  195. height: parseInt(height) - parseInt(strokeWidth) * 2 + 'px',
  196. lineHeight: parseInt(lineHeight) - parseInt(strokeWidth) * 2 + 'px',
  197. "text-align": 'center',
  198. 'background': backgroundColor || back,
  199. 'background-size': backgroundSize,
  200. "border-radius": borderRadius + 'px',
  201. "box-shadow": boxShadow,
  202. "border-color": strokeColor,
  203. "border-style": "solid",
  204. "border-width": parseInt(strokeWidth) + 'px',
  205. "opacity": opacity,
  206. cursor: 'pointer'
  207. }
  208. }
  209. },
  210. emits: ['click', 'dblClick'],
  211. setup(props, { emit } ) {
  212. const {ref, toRefs, computed, watch} = Vue
  213. const { realValue } = toRefs(props);
  214. const clickHandler = () => {
  215. emit('click', realValue.value)
  216. }
  217. const dblClickHandler = () => {
  218. emit('dblClick', realValue.value)
  219. }
  220. return {
  221. clickHandler,
  222. dblClickHandler,
  223. }
  224. }
  225. }
  226. class CustomButtonNode extends HtmlResize.view {
  227. clickTime = ''
  228. setHtml(rootEl) {
  229. const { graphModel } = this.props;
  230. const { properties, width, height, } = this.props.model;
  231. const { content, fontColor, fontSize, fontFamily, fontStyle, lineHeight, fill, strokeColor,strokeWidth, opacity, background, boxShadow, borderRadius } = properties;
  232. const { model } = this.props;
  233. const el = document.createElement('div');
  234. rootEl.innerHTML = '';
  235. const { uiData, eventsData } = properties.dynamic || {};
  236. const findClick = eventsData?.eventCombo.find( i => i.eventType === 'click');
  237. const clickHandler = (e) => {
  238. if(uiData.dataPoint && findClick && findClick.enable) {
  239. const now = new Date().getTime();
  240. if (this.clickTime) {
  241. if (now - this.clickTime <= 10000) {
  242. messageFn('10秒之内不能重复触发')
  243. return;
  244. }
  245. }
  246. this.clickTime = now;
  247. }
  248. const cacheToken = sessionStorage.getItem('v1@CacheToken');
  249. if(!cacheToken) {
  250. return window.createLoginDialog();
  251. }
  252. const tokenParsed = JSON.parse(cacheToken || '{}');
  253. if (findClick.users && !findClick.users.includes(tokenParsed.userid)) {
  254. return messageFn('无用户权限')
  255. }
  256. graphModel.eventCenter.emit("myNode:click", {
  257. data: this.props.model,
  258. e,
  259. });
  260. }
  261. const dblClickHandler = (e) => {
  262. graphModel.eventCenter.emit("myNode:dbclick", {
  263. data: this.props.model,
  264. e,
  265. });
  266. }
  267. let dynamicBack = background;
  268. let dynamicName = content
  269. let fillColor = fill
  270. let fontC = fontColor
  271. let realValue = ''
  272. if (uiData) {
  273. realValue = window.resolveScadaNewValue(uiData.defaultValue)
  274. if (realValue !== '') {
  275. uiData.conditionVariables.forEach((item) => {
  276. if (item.type === 'rangeColor') {
  277. let from = item.from;
  278. let to = item.to;
  279. if (item.from >= item.to) {
  280. from = item.to;
  281. to = item.from;
  282. }
  283. if (item.backColor && Number(realValue) >= from && Number(realValue) <= to) {
  284. fillColor = item.backColor
  285. }
  286. if (item.fontColor && Number(realValue) >= from && Number(realValue) <= to) {
  287. fontC = item.fontColor
  288. }
  289. if (item.background && Number(realValue) >= from && Number(realValue) <= to) {
  290. dynamicBack = item.background
  291. }
  292. } else if (item.type === 'equal') {
  293. if(Number(realValue) === Number(item.value)) {
  294. item.backColor && (fillColor = item.backColor);
  295. item.fontColor && (fontC = item.fontColor);
  296. dynamicName = item.valueLabel;
  297. item.background && (dynamicBack = item.background);
  298. }
  299. } else if (item.type === 'boolean') {
  300. const trueFlags = ['true', true]
  301. const falseFlags = ['false', false]
  302. const truetrue = trueFlags.includes(item.value) && trueFlags.includes(realValue)
  303. const falsefalse = falseFlags.includes(item.value) && falseFlags.includes(realValue)
  304. if (truetrue || falsefalse) {
  305. item.backColor && (fillColor = item.backColor);
  306. item.fontColor && (fontC = item.fontColor);
  307. dynamicName = item.valueLabel;
  308. item.background && (dynamicBack = item.background);
  309. }
  310. }
  311. })
  312. }
  313. }
  314. const instance = createVNode(Button, {
  315. name: dynamicName,
  316. fontColor: fontC,
  317. fontSize, fontFamily, fontStyle,width, height, lineHeight,
  318. backgroundColor: fillColor,
  319. strokeColor,strokeWidth,
  320. opacity,
  321. background: dynamicBack,
  322. boxShadow,
  323. borderRadius,
  324. realValue,
  325. onClick: clickHandler,
  326. onDblClick: dblClickHandler,
  327. })
  328. instance.appContext = app._context
  329. render(instance, el)
  330. rootEl.appendChild(el);
  331. }
  332. }
  333. class CustomButtonModel extends HtmlResize.model {
  334. initNodeData(data) {
  335. // 自定义组件,需最开始重置一下text 。
  336. data.text = {
  337. value: "",
  338. x: data.x,
  339. y: data.y,
  340. };
  341. super.initNodeData(data);
  342. const { properties } = this;
  343. this.width = properties.width || 80;
  344. this.height = properties.height || 35;
  345. this.text.editable = false; // 不允许文本被编辑
  346. }
  347. setAttributes() {
  348. // 自定义组件需重置 text
  349. const { x, y, properties } = this;
  350. const { textHorizontalMove = 0, textVerticalMove = 0 } = properties;
  351. this.text = {
  352. ...this.text,
  353. x: x + textHorizontalMove,
  354. y: y + textVerticalMove,
  355. value: "",
  356. }
  357. }
  358. }
  359. lf.register({
  360. type: 'custom-button-node',
  361. view: CustomButtonNode,
  362. model: CustomButtonModel,
  363. })
  364. `,css:"",fakeData:""},m={id:e,name:a,aliasName:t,image:n,imageType:l,groupName:o,groupType:i,isRemote:!1,isDefault:!0,sectionType:d,config:s,files:c};export{t as aliasName,s as config,m as default,c as files,o as groupName,i as groupType,e as id,n as image,l as imageType,u as isDefault,r as isRemote,a as name,d as sectionType};