物管理前端
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.

439 lines
34 KiB

  1. const e="938ffb94-8afc-4c0d-95b1-66d0d59df174",a="custom-datetime-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="1688366518104" class="icon" viewBox="0 0 1024 1024" version="1.1" xmlns="http://www.w3.org/2000/svg" p-id="2918" xmlns:xlink="http://www.w3.org/1999/xlink" width="200" height="200"><path d="M694.832145 731.328581H767.925007c10.698955 0 19.398106 3.399668 26.297432 10.298994 6.899326 6.899326 10.298994 15.598477 10.298994 26.297432s-3.399668 19.398106-10.298994 26.297432c-6.899326 6.899326-15.598477 10.298994-26.297432 10.298994h-73.092862c-10.698955 0-19.398106-3.399668-26.297432-10.298994-6.899326-6.899326-10.298994-15.598477-10.298994-26.297432s3.399668-19.398106 10.298994-26.297432c6.799336-6.799336 15.598477-10.298994 26.297432-10.298994z m0-219.378576H767.925007c10.698955 0 19.398106 3.399668 26.297432 10.298994 6.899326 6.899326 10.298994 15.598477 10.298994 26.297432 0 10.698955-3.399668 19.398106-10.298994 26.297432-6.899326 6.899326-15.598477 10.298994-26.297432 10.298994h-73.092862c-10.698955 0-19.398106-3.399668-26.297432-10.298994-6.899326-6.899326-10.298994-15.598477-10.298994-26.297432 0-10.698955 3.399668-19.398106 10.298994-26.297432 6.799336-6.899326 15.598477-10.298994 26.297432-10.298994zM475.353579 731.328581h73.092862c10.698955 0 19.398106 3.399668 26.297432 10.298994 6.899326 6.899326 10.298994 15.598477 10.298994 26.297432s-3.399668 19.398106-10.298994 26.297432c-6.899326 6.899326-15.598477 10.298994-26.297432 10.298994h-73.092862c-10.698955 0-19.398106-3.399668-26.297432-10.298994-6.899326-6.899326-10.298994-15.598477-10.298994-26.297432s3.399668-19.398106 10.298994-26.297432c6.899326-6.799336 15.598477-10.298994 26.297432-10.298994z m0-219.378576h73.092862c10.698955 0 19.398106 3.399668 26.297432 10.298994 6.899326 6.899326 10.298994 15.598477 10.298994 26.297432 0 10.698955-3.399668 19.398106-10.298994 26.297432s-15.598477 10.298994-26.297432 10.298994h-73.092862c-10.698955 0-19.398106-3.399668-26.297432-10.298994s-10.298994-15.598477-10.298994-26.297432c0-10.698955 3.399668-19.398106 10.298994-26.297432 6.899326-6.899326 15.598477-10.298994 26.297432-10.298994zM255.975002 731.328581h73.092862c10.698955 0 19.398106 3.399668 26.297432 10.298994 6.899326 6.899326 10.298994 15.598477 10.298995 26.297432s-3.399668 19.398106-10.298995 26.297432c-6.899326 6.899326-15.598477 10.298994-26.297432 10.298994H255.975002c-10.698955 0-19.398106-3.399668-26.297431-10.298994-6.899326-6.899326-10.298994-15.598477-10.298995-26.297432s3.399668-19.398106 10.298995-26.297432c6.899326-6.799336 15.598477-10.298994 26.297431-10.298994z m0-219.378576h73.092862c10.698955 0 19.398106 3.399668 26.297432 10.298994 6.899326 6.899326 10.298994 15.598477 10.298995 26.297432 0 10.698955-3.399668 19.398106-10.298995 26.297432-6.899326 6.899326-15.598477 10.298994-26.297432 10.298994H255.975002c-10.698955 0-19.398106-3.399668-26.297431-10.298994-6.899326-6.899326-10.298994-15.598477-10.298995-26.297432 0-10.698955 3.399668-19.398106 10.298995-26.297432 6.899326-6.899326 15.598477-10.298994 26.297431-10.298994z m36.596427-438.857143h438.857142V36.596426c0-10.698955 3.399668-19.398106 10.298995-26.297432C748.526902 3.399668 757.226052 0 767.925007 0s19.398106 3.399668 26.297432 10.298994c6.899326 6.899326 10.298994 15.598477 10.298994 26.297432v36.596426h182.882141c10.698955 0 19.398106 3.399668 26.297432 10.298994 6.899326 6.899326 10.298994 15.598477 10.298994 26.297432v877.614296c0 10.698955-3.399668 19.398106-10.298994 26.297432-6.899326 6.899326-15.598477 10.298994-26.297432 10.298994H36.596426c-10.698955 0-19.398106-3.399668-26.297432-10.298994C3.399668 1006.80168 0 998.002539 0 987.303584V109.689288C0 98.990333 3.399668 90.291183 10.298994 83.391856c6.899326-6.899326 15.598477-10.298994 26.297432-10.298994h182.882141V36.596426c0-10.698955 3.399668-19.398106 10.298994-26.297432C236.576897 3.399668 245.276047 0 255.975002 0s19.398106 3.399668 26.297432 10.298994 10.298994 15.598477 10.298995 26.
  2. "nodes": [
  3. {
  4. "id": "ce04328f-02d5-4d08-8694-7e3408566165",
  5. "type": "custom-datetime-node",
  6. "x": 200,
  7. "y": 200,
  8. "text": {
  9. "value": "",
  10. "x": 200,
  11. "y": 200
  12. },
  13. "properties": {
  14. "id": "ce04328f-02d5-4d08-8694-7e3408566165",
  15. "width": 150,
  16. "height": 35,
  17. "x": 200,
  18. "y": 200,
  19. "rotation": 0,
  20. "opacity": 1,
  21. "strokeWidth": 1,
  22. "isRange": false,
  23. "darkTheme": true,
  24. "selectTheme": "molv",
  25. "fontSize": 13,
  26. "nodeAlias": "日期",
  27. "fontColor": "#ffffff",
  28. "fill": "rgba(74, 144, 226, 1)",
  29. "strokeColor": "rgba(74, 144, 226, 1)",
  30. "timeType": "datetime",
  31. "dateSelectBack": "rgba(13, 13, 45, 1)",
  32. "textAlign": "left",
  33. "dateSelectBorderColor": "rgba(23, 23, 81, 1)",
  34. "dynamic": {
  35. "normalData": {
  36. "dataPoint": "",
  37. "compareType": "",
  38. "conditionVariables": [],
  39. "defaultValue": "",
  40. "unit": ""
  41. },
  42. "eventsData": {
  43. "eventCombo": [
  44. {
  45. "eventType": "change",
  46. "enable": false,
  47. "config": "",
  48. "targetParamsType": "times",
  49. "targetParamsTimesType": "nearest"
  50. }
  51. ]
  52. },
  53. "uiData": {
  54. "dataPoint": "",
  55. "compareType": "",
  56. "conditionVariables": []
  57. }
  58. }
  59. }
  60. }
  61. ]
  62. }`,javascript:`
  63. const { createApp, createVNode, render } = Vue;
  64. const app = createApp({})
  65. const DateTime = {
  66. template: \`<div :style="getOuterStyle">
  67. <input type="text" class="layui-input" :id="getNodeId" :value="dateTime" :style="cssStyle" readOnly>
  68. </div>\`,
  69. props: {
  70. nodeId: {
  71. type: String,
  72. default: ''
  73. },
  74. defaultValue: {
  75. type: String,
  76. default: '[]'
  77. },
  78. isRange: {
  79. type: Boolean,
  80. default: false
  81. },
  82. fontColor: {
  83. type: String,
  84. default: '#333'
  85. },
  86. fontSize: {
  87. type: Number,
  88. default: 14
  89. },
  90. fontFamily: {
  91. type: String,
  92. default: '宋体'
  93. },
  94. fontStyle: {
  95. type: String,
  96. default: 'normal'
  97. },
  98. width: {
  99. type: Number,
  100. default: 150
  101. },
  102. height: {
  103. type: Number,
  104. default: 35
  105. },
  106. lineHeight: {
  107. type: Number,
  108. default: 35,
  109. },
  110. strokeWidth: {
  111. type: Number,
  112. default: 2,
  113. },
  114. borderColor: {
  115. type: String,
  116. default: '#666'
  117. },
  118. backgroundColor: {
  119. type: String,
  120. default: '#ffffff',
  121. },
  122. timeType: {
  123. type: String,
  124. default: 'datetime',
  125. },
  126. darkTheme: {
  127. type: Boolean,
  128. default: false
  129. },
  130. dateSelectBack: {
  131. type: String,
  132. default: '#ffffff'
  133. },
  134. textAlign: {
  135. type: String,
  136. default: 'left'
  137. },
  138. selectTheme: {
  139. type: String,
  140. default: 'molv'
  141. },
  142. dateSelectBorderColor: {
  143. type: String,
  144. default: '#e2e2e2'
  145. }
  146. },
  147. emits: ["change"],
  148. setup(props, { emit }) {
  149. const { ref, toRefs, computed, onMounted } = Vue;
  150. const dateTime = ref('');
  151. const getNodeId = computed(() => {
  152. return 'dateTimePicker'
  153. })
  154. const { width, height, lineHeight } = toRefs(props)
  155. const cssStyle = computed(() => {
  156. const borderWidths = props.strokeWidth * 6;
  157. const realWidth = parseInt(width.value);
  158. const realHeight = parseInt(height.value);
  159. return \`
  160. position: relative;
  161. color: \${props.fontColor};
  162. font-size: \${props.fontSize}px;
  163. text-align: \${props.textAlign};
  164. border-width: \${props.strokeWidth}px;
  165. border-style: solid;
  166. width: \${realWidth - borderWidths}px;
  167. height: \${realHeight - borderWidths}px;
  168. line-height: \${lineHeight.value - borderWidths}px;
  169. border-radius: 4px;
  170. border-color:\${props.borderColor};
  171. background-color:\${props.backgroundColor};
  172. padding-left: \${props.textAlign === 'left' ? 10 : 0}px;
  173. outline: none;\`
  174. })
  175. const getOuterStyle = computed(() => {
  176. const w = parseInt(width.value);
  177. const h = parseInt(height.value);
  178. return \`
  179. width: \${w}px;
  180. height: \${h}px;
  181. \`
  182. })
  183. onMounted(() => {
  184. setTimeout(() => {
  185. layui.use('laydate', function () {
  186. layui.laydate.index = Date.now();
  187. var laydate = layui.laydate;
  188. //执行一个laydate实例
  189. laydate.render({
  190. elem: '#' + getNodeId.value,
  191. theme: props.selectTheme,
  192. value: new Date(),
  193. type: props.timeType,
  194. range: props.isRange,
  195. trigger: 'click',
  196. done: function (value, date, endDate) {
  197. if (props.isRange) {
  198. emit('change', {
  199. start: date,
  200. end: endDate
  201. })
  202. } else {
  203. emit('change', {
  204. start: value,
  205. end: endDate
  206. })
  207. }
  208. },
  209. ready: function () {
  210. if (props.darkTheme && props.dateSelectBack && props.dateSelectBack !== '#ffffff') {
  211. const layDateDom = document.querySelector('.layui-laydate');
  212. layDateDom.classList.add('dark-custom-theme');
  213. const stylesheet = document.createElement('style');
  214. stylesheet.innerText = \`
  215. .layui-laydate.dark-custom-theme {
  216. background-color: \${props.dateSelectBack};
  217. border: none;
  218. }
  219. .layui-laydate.dark-custom-theme .layui-laydate-list {
  220. background-color: \${props.dateSelectBack};
  221. }
  222. .layui-laydate.dark-custom-theme .laydate-month-list {
  223. background-color: \${props.dateSelectBack};
  224. }
  225. .layui-laydate.dark-custom-theme .laydate-year-list {
  226. background-color: \${props.dateSelectBack};
  227. }
  228. .layui-laydate.dark-custom-theme .layui-laydate-footer span {
  229. background-color: \${props.dateSelectBack};
  230. }
  231. .layui-laydate.dark-custom-theme .layui-laydate-content {
  232. border-color: \${props.dateSelectBorderColor};
  233. }
  234. .layui-laydate.dark-custom-theme .layui-laydate-footer {
  235. border-color: \${props.dateSelectBorderColor};
  236. }
  237. .layui-laydate.dark-custom-theme .layui-laydate-footer span{
  238. border-color: \${props.dateSelectBorderColor};
  239. }
  240. \`;
  241. const head = document.getElementsByTagName('head')[0];
  242. head.appendChild(stylesheet);
  243. }
  244. },
  245. });
  246. // 初始化默认时间传给外部
  247. const timesFormat = {
  248. year: 'YYYY',
  249. month: 'YYYY-MM',
  250. datetime: 'YYYY-MM-DD HH:mm:ss'
  251. }
  252. if (props.isRange) {
  253. if (props.timeType === 'year') {
  254. emit('change', {
  255. start: window.dayjs(new Date().getTime()).startOf('year').subtract(1, ' year').format(timesFormat[props.timeType]),
  256. end: window.dayjs(new Date().getTime()).startOf('year').format(timesFormat[props.timeType]),
  257. })
  258. } else if (props.timeType === 'month') {
  259. emit('change', {
  260. start: window.dayjs(new Date().getTime()).startOf('month').subtract(1, ' month').format(timesFormat[props.timeType]),
  261. end: window.dayjs(new Date().getTime()).startOf('month').format(timesFormat[props.timeType]),
  262. })
  263. } else {
  264. emit('change', {
  265. start: window.dayjs(new Date().getTime()).startOf('day').format(timesFormat[props.timeType]),
  266. end: window.dayjs(new Date().getTime()).endOf('day').format(timesFormat[props.timeType]),
  267. })
  268. }
  269. } else {
  270. emit('change', {
  271. start: window.dayjs(new Date().getTime()).format(timesFormat[props.timeType]),
  272. end: ''
  273. })
  274. }
  275. });
  276. // if (props.darkTheme) {
  277. // document.getElementById('layui_theme_css').setAttribute('href', './plugins/layui/css/layui-theme-dark.css')
  278. // } else {
  279. // document.getElementById('layui_theme_css').removeAttribute('href')
  280. // }
  281. }, 200)
  282. })
  283. return {
  284. getNodeId,
  285. dateTime,
  286. cssStyle,
  287. getOuterStyle,
  288. }
  289. }
  290. }
  291. class CustomDateTimeNode extends HtmlResize.view {
  292. oldProperties = {}
  293. setHtml(rootEl) {
  294. const { graphModel } = this.props;
  295. const { properties, width, height } = this.props.model;
  296. const { isRange, fontColor, fontSize, fontFamily, fontStyle, strokeWidth, strokeColor,
  297. lineHeight, fill, id, timeType, darkTheme, dateSelectBack, textAlign, selectTheme, dateSelectBorderColor } = properties;
  298. const { normalData } = properties.dynamic || {};
  299. const { defaultValue } = normalData || {};
  300. const { model } = this.props;
  301. const el = document.createElement('div');
  302. rootEl.innerHTML = '';
  303. const changeHandler = (e) => {
  304. graphModel.eventCenter.emit("node:change", {
  305. data: this.props.model,
  306. e,
  307. });
  308. }
  309. const { uiData } = properties.dynamic || {};
  310. let fillColor = fill
  311. let fontC = fontColor
  312. let realValue = ''
  313. if (uiData) {
  314. realValue = window.resolveScadaNewValue(uiData.defaultValue)
  315. if (realValue !== '') {
  316. uiData.conditionVariables.forEach((item) => {
  317. if (item.type === 'rangeColor') {
  318. let from = item.from;
  319. let to = item.to;
  320. if (item.from >= item.to) {
  321. from = item.to;
  322. to = item.from;
  323. }
  324. if (item.backColor && Number(realValue) >= from && Number(realValue) <= to) {
  325. fillColor = item.backColor
  326. }
  327. if (item.fontColor && Number(realValue) >= from && Number(realValue) <= to) {
  328. fontC = item.fontColor
  329. }
  330. } else if (item.type === 'equal') {
  331. if (Number(realValue) === Number(item.value)) {
  332. item.backColor && (fillColor = item.backColor);
  333. item.fontColor && (fontC = item.fontColor);
  334. dynamicName = item.valueLabel;
  335. }
  336. } else if (item.type === 'boolean') {
  337. if (realValue === 'true' || realValue === true) {
  338. item.backColor && (fillColor = item.backColor);
  339. item.fontColor && (fontC = item.fontColor);
  340. dynamicName = item.valueLabel;
  341. }
  342. }
  343. })
  344. }
  345. }
  346. const instance = createVNode(DateTime, {
  347. nodeId: id,
  348. isRange: isRange,
  349. fontColor: fontC,
  350. fontSize, fontFamily, fontStyle, width: properties.width, height: properties.height, lineHeight,
  351. backgroundColor: fillColor,
  352. borderColor: strokeColor,
  353. strokeWidth,
  354. defaultValue,
  355. timeType: timeType,
  356. darkTheme,
  357. dateSelectBack,
  358. textAlign,
  359. selectTheme,
  360. dateSelectBorderColor,
  361. onChange: changeHandler
  362. })
  363. instance.appContext = app._context
  364. render(instance, el)
  365. rootEl.appendChild(el);
  366. }
  367. sameProps(properties) {
  368. const isSame = window._.isEqual(this.oldProperties, properties);
  369. if (isSame) return true;
  370. this.oldProperties = properties;
  371. return false
  372. }
  373. // 生命周期 支持重写内容, 但格式需一致
  374. shouldUpdate() {
  375. const { properties } = this.props.model;
  376. const propertiesBack = window._.cloneDeep(properties);
  377. // 由于事件change 会给properties 增加一个 event 属性(见目录scadaDashboard/Diagram/useDynamicEventsHandler),会引发属性的改变,导致组件重渲染。
  378. delete propertiesBack.event;
  379. if (this.sameProps(propertiesBack)) {
  380. return false
  381. }
  382. return true;
  383. }
  384. }
  385. class CustomDateTimeModel extends HtmlResize.model {
  386. initNodeData(data) {
  387. // 自定义组件,需最开始重置一下text 。
  388. data.text = {
  389. value: "",
  390. x: data.x,
  391. y: data.y,
  392. };
  393. super.initNodeData(data);
  394. const { properties } = this;
  395. this.width = properties.width || 80;
  396. this.height = properties.height || 35;
  397. this.text.editable = false; // 不允许文本被编辑
  398. }
  399. setAttributes() {
  400. // 自定义组件需重置 text
  401. const { x, y, properties } = this;
  402. const { textHorizontalMove = 0, textVerticalMove = 0 } = properties;
  403. this.text = {
  404. ...this.text,
  405. x: x + textHorizontalMove,
  406. y: y + textVerticalMove,
  407. value: "",
  408. }
  409. }
  410. }
  411. lf.register({
  412. type: 'custom-datetime-node',
  413. view: CustomDateTimeNode,
  414. model: CustomDateTimeModel,
  415. })
  416. `,css:"",fakeData:""},c={id:e,name:a,aliasName:t,image:n,imageType:l,groupName:o,groupType:i,isRemote:!1,isDefault:!0,sectionType:s,config:r,files:d};export{t as aliasName,r as config,c as default,d as files,o as groupName,i as groupType,e as id,n as image,l as imageType,u as isDefault,m as isRemote,a as name,s as sectionType};