Commit ece0f715991aee8768b6944cd70afb027065711c
1 parent
9beebc38
feat: implement real time && trigger event
Showing
2 changed files
with
247 additions
and
75 deletions
1 | -(function() | |
2 | -{ | |
3 | - // Adds Atlassian shapes | |
4 | - Sidebar.prototype.addBasicComponentsPalette = function() | |
5 | - { | |
6 | - var sb = this; | |
7 | - var gn = 'mxgraph.component'; | |
8 | - var dt = 'component '; | |
9 | - var lineTags = 'line lines connector connectors connection connections arrow arrows ' | |
10 | - this.setCurrentSearchEntryLibrary('general', 'component'); | |
11 | - var currentDate = getCurrentDate(); | |
12 | - var fns = [ | |
13 | - this.createVertexTemplateEntry('text;strokeColor=none;fillColor=none;html=1;fontSize=24;fontStyle=1;verticalAlign=middle;align=center;', 100, 40, 'Title', 'Title', null, null, 'text heading title'), | |
14 | - this.createEdgeTemplateEntry('shape=filledEdge;rounded=1;fixDash=1;endArrow=none;strokeWidth=10;fillColor=#BAFDFF;edgeStyle=orthogonalEdgeStyle;flowAnimation=1;strokeColor=#6666FF;endFill=1;metaEdit=0;backgroundOutline=0;', 60, 40, '', '线条'), | |
15 | - this.addEntry('timestamp date time text label', mxUtils.bind(this, function() | |
16 | - { | |
17 | - var cell = new mxCell('%date{yyyy-mm-dd ddd HH:MM:ss}%', new mxGeometry(0, 0, 160, 20), 'text;html=1;strokeColor=none;fillColor=none;align=center;verticalAlign=middle;whiteSpace=wrap;overflow=hidden;'); | |
18 | - cell.vertex = true; | |
19 | - this.graph.setAttributeForCell(cell, 'placeholders', '1'); | |
20 | - this.graph.setAttributeForCell(cell, 'date', "成都云腾五洲科技有限公司"); | |
21 | - return this.createVertexTemplateFromCells([cell], cell.geometry.width, cell.geometry.height, 'Timestamps'); | |
22 | - })), | |
23 | - this.addEntry('动态时间', mxUtils.bind(this, function() | |
24 | - { | |
25 | - var cell = new mxCell('<div>%currentDate%</div><div style="font-size:30px">%date{HH:MM:ss}%</div>', new mxGeometry(0, 0, 180, 60), 'text;html=1;strokeColor=none;fillColor=none;align=center;verticalAlign=middle;whiteSpace=wrap;overflow=hidden;'); | |
26 | - cell.vertex = true; | |
27 | - this.graph.setAttributeForCell(cell, 'placeholders', '1'); | |
28 | - this.graph.setAttributeForCell(cell, 'currentDate', currentDate); | |
29 | - return this.createVertexTemplateFromCells([cell], cell.geometry.width, cell.geometry.height, 'Variable'); | |
30 | - })), | |
31 | - ]; | |
1 | +(function () { | |
2 | + // Adds Atlassian shapes | |
3 | + Sidebar.prototype.addBasicComponentsPalette = function () { | |
4 | + var sb = this; | |
5 | + var gn = 'mxgraph.component'; | |
6 | + var dt = 'component '; | |
7 | + var lineTags = 'line lines connector connectors connection connections arrow arrows ' | |
8 | + this.setCurrentSearchEntryLibrary('general', 'component'); | |
9 | + var currentDate = getCurrentDate(); | |
10 | + var fns = [ | |
11 | + this.createVertexTemplateEntry('text;strokeColor=none;fillColor=none;html=1;fontSize=24;fontStyle=1;verticalAlign=middle;align=center;', 100, 40, 'Title', 'Title', null, null, 'text heading title'), | |
12 | + this.createEdgeTemplateEntry('shape=filledEdge;rounded=1;fixDash=1;endArrow=none;strokeWidth=10;fillColor=#BAFDFF;edgeStyle=orthogonalEdgeStyle;flowAnimation=1;strokeColor=#6666FF;endFill=1;metaEdit=0;backgroundOutline=0;', 60, 40, '', '线条'), | |
13 | + this.addEntry('timestamp date time text label', mxUtils.bind(this, function () { | |
14 | + var cell = new mxCell('%date{yyyy-mm-dd ddd HH:MM:ss}%', new mxGeometry(0, 0, 160, 20), 'text;html=1;strokeColor=none;fillColor=none;align=center;verticalAlign=middle;whiteSpace=wrap;overflow=hidden;'); | |
15 | + cell.vertex = true; | |
16 | + this.graph.setAttributeForCell(cell, 'placeholders', '1'); | |
17 | + this.graph.setAttributeForCell(cell, 'date', "成都云腾五洲科技有限公司"); | |
18 | + return this.createVertexTemplateFromCells([cell], cell.geometry.width, cell.geometry.height, 'Timestamps'); | |
19 | + })), | |
20 | + this.addEntry('动态时间', mxUtils.bind(this, function () { | |
21 | + var cell = new mxCell('<div>%currentDate%</div><div style="font-size:30px">%date{HH:MM:ss}%</div>', new mxGeometry(0, 0, 180, 60), 'text;html=1;strokeColor=none;fillColor=none;align=center;verticalAlign=middle;whiteSpace=wrap;overflow=hidden;'); | |
22 | + cell.vertex = true; | |
23 | + this.graph.setAttributeForCell(cell, 'placeholders', '1'); | |
24 | + this.graph.setAttributeForCell(cell, 'currentDate', currentDate); | |
25 | + return this.createVertexTemplateFromCells([cell], cell.geometry.width, cell.geometry.height, 'Variable'); | |
26 | + })), | |
27 | + this.addEntry('real time', mxUtils.bind(this, function () { | |
28 | + const template = `<div class="thingKit-component__real-time"><div class="real-time__date">%currentDate%</div> <div style="font-size:30px" class="real-time__now">%date{HH:MM:ss}%</div></div>` | |
29 | + const cell = new mxCell(template, new mxGeometry(0, 0, 180, 60), 'text;html=1;strokeColor=none;fillColor=none;align=center;verticalAlign=middle;whiteSpace=wrap;overflow=hidden;'); | |
30 | + cell.vertex = true; | |
31 | + this.graph.setAttributeForCell(cell, 'placeholders', '1'); | |
32 | + this.graph.setAttributeForCell(cell, 'currentDate', currentDate); | |
33 | + return this.createVertexTemplateFromCells([cell], cell.geometry.width, cell.geometry.height, 'realTime'); | |
34 | + })), | |
35 | + ]; | |
32 | 36 | |
33 | - this.addPaletteFunctions('component', '基础元件', false, fns); | |
34 | - this.setCurrentSearchEntryLibrary(); | |
35 | - }; | |
37 | + this.addPaletteFunctions('component', '基础元件', false, fns); | |
38 | + this.setCurrentSearchEntryLibrary(); | |
39 | + }; | |
36 | 40 | |
37 | - //封装日期函数 | |
38 | - function getCurrentDate() { | |
39 | - var date = new Date(); //创建日期对象 | |
40 | - var year = date.getFullYear(); | |
41 | - var month = date.getMonth() + 1; | |
42 | - var dates = date.getDate(); | |
43 | - arr = ['星期日', '星期一', '星期二', '星期三', '星期四', '星期五', '星期六', ] | |
44 | - var day = date.getDay(); | |
45 | - return year + '年' + month + '月' + dates + '日 ' + arr[day]; | |
46 | - } | |
41 | + //封装日期函数 | |
42 | + function getCurrentDate() { | |
43 | + var date = new Date(); //创建日期对象 | |
44 | + var year = date.getFullYear(); | |
45 | + var month = date.getMonth() + 1; | |
46 | + var dates = date.getDate(); | |
47 | + arr = ['星期日', '星期一', '星期二', '星期三', '星期四', '星期五', '星期六',] | |
48 | + var day = date.getDay(); | |
49 | + return year + '年' + month + '月' + dates + '日 ' + arr[day]; | |
50 | + } | |
47 | 51 | })(); | ... | ... |
... | ... | @@ -4879,7 +4879,8 @@ DataFormatPanel.prototype.addDataFont = function (container) { |
4879 | 4879 | const ss = ui.getSelectionState(); |
4880 | 4880 | const vertices = ss.vertices || [] |
4881 | 4881 | |
4882 | - console.log(vertices) | |
4882 | + console.log(this.editorUi) | |
4883 | + console.log(ss.vertices) | |
4883 | 4884 | /** |
4884 | 4885 | * @description 不是单一节点则不进入数据绑定 |
4885 | 4886 | */ |
... | ... | @@ -5404,9 +5405,13 @@ DataFormatPanel.prototype.addDataFont = function (container) { |
5404 | 5405 | type: item.type, |
5405 | 5406 | enabled: true |
5406 | 5407 | }) |
5408 | + } else { | |
5409 | + value[item.category].push({ | |
5410 | + type: item.type, | |
5411 | + enabled: false | |
5412 | + }) | |
5407 | 5413 | } |
5408 | 5414 | } |
5409 | - | |
5410 | 5415 | const [err, res] = await to(ConfigurationNodeApi.updateNodeInfo(value)) |
5411 | 5416 | if (err) return |
5412 | 5417 | UseLayUi.successMsg() |
... | ... | @@ -6232,7 +6237,8 @@ DataFormatPanel.prototype.addDataFont = function (container) { |
6232 | 6237 | */ |
6233 | 6238 | function echoOrgTree(id) { |
6234 | 6239 | const node = UseLayUi.findTreeObjectByField(treeList, id) |
6235 | - $(`#${ enumActionEl.ORG_EL }`).find(`input[name="${ enumConst.ORG_ID }"]`).parent().find('span').html(node.name) | |
6240 | + console.log(node) | |
6241 | + $(`#${ enumActionEl.ORG_EL }`).find(`input[name="${ enumConst.ORG_ID }"]`).parent().find('span').html(node?.name) | |
6236 | 6242 | } |
6237 | 6243 | |
6238 | 6244 | async function submit(callback) { |
... | ... | @@ -10899,11 +10905,16 @@ class DispatchCenter { |
10899 | 10905 | |
10900 | 10906 | /** |
10901 | 10907 | * @description 节点映射 |
10902 | - * @type {Map<string, object>} | |
10908 | + * @type {Map<string, Map<string, object>>} | |
10903 | 10909 | */ |
10904 | 10910 | nodeMapping |
10905 | 10911 | |
10906 | 10912 | /** |
10913 | + * @description | |
10914 | + */ | |
10915 | + editorUi | |
10916 | + | |
10917 | + /** | |
10907 | 10918 | * @description 当前页信息 |
10908 | 10919 | */ |
10909 | 10920 | currentPage |
... | ... | @@ -10940,8 +10951,36 @@ class DispatchCenter { |
10940 | 10951 | */ |
10941 | 10952 | static rawContentId |
10942 | 10953 | |
10954 | + /** | |
10955 | + * @description 判断事件监听器时候已经绑定过 | |
10956 | + */ | |
10957 | + static eventListenerIsExist = false | |
10958 | + | |
10959 | + static enumEventType = { | |
10960 | + DOWN: 'DOWN', | |
10961 | + UP: 'UP', | |
10962 | + SINGLE: 'SINGLE', | |
10963 | + DOUBLE: 'DOUBLE', | |
10964 | + } | |
10965 | + | |
10966 | + static enumDynamicEffectType = { | |
10967 | + DISPLAY: 'DISPLAY', | |
10968 | + FLASH: 'FLASH', | |
10969 | + ROTATE: 'ROTATE', | |
10970 | + } | |
10971 | + | |
10972 | + static enumPageType = { | |
10973 | + PAGE: 'PAGE', | |
10974 | + LINK: 'LINK' | |
10975 | + | |
10976 | + } | |
10977 | + | |
10978 | + | |
10943 | 10979 | constructor(editorUi, currentPage) { |
10944 | 10980 | this.nodeMapping = new Map() |
10981 | + this.editorUi = editorUi | |
10982 | + | |
10983 | + // mxEvent.addListener(document, (mxClient.IS_POINTER) ? 'pointerup' : 'mouseup', this.pointerUpHandler); | |
10945 | 10984 | this.init(editorUi, currentPage) |
10946 | 10985 | } |
10947 | 10986 | |
... | ... | @@ -10953,7 +10992,7 @@ class DispatchCenter { |
10953 | 10992 | init(editorUi, currentPage) { |
10954 | 10993 | this.createEventBus() |
10955 | 10994 | this.saveContentInfo(editorUi, currentPage) |
10956 | - // this.createGraphEventListener() | |
10995 | + this.createGraphEventListener() | |
10957 | 10996 | this.connectSocket() |
10958 | 10997 | this.getContentDataNode() |
10959 | 10998 | } |
... | ... | @@ -10996,30 +11035,33 @@ class DispatchCenter { |
10996 | 11035 | * @description 创建图层事件监听器 |
10997 | 11036 | */ |
10998 | 11037 | createGraphEventListener() { |
10999 | - console.log(mxEvent) | |
11000 | - // this.graph.addListener(mxEvent.MOUSE_DOWN, (sender, event) => { | |
11001 | - // console.log('down') | |
11002 | - // console.log(event) | |
11003 | - // console.log(sender) | |
11004 | - // }) | |
11005 | - // this.graph.addListener(mxEvent.MOUSE_UP, (sender, event) => { | |
11006 | - // console.log('up') | |
11007 | - // console.log(event) | |
11008 | - // console.log(sender) | |
11009 | - // }) | |
11010 | - console.log(this.contentAllCell) | |
11011 | - const node = this.contentAllCell.find(item => item.id === "xu8fz6ypefe3Lfq39emV-10") | |
11012 | - console.log(node) | |
11013 | - // node.addListener(mxEvent.CLICK, (sender, event) => { | |
11014 | - // console.log('click') | |
11015 | - // console.log(event) | |
11016 | - // console.log(sender) | |
11017 | - // }) | |
11018 | - // this.graph.addListener(mxEvent.DOUBLE_CLICK, (sender, event) => { | |
11019 | - // console.log('double click') | |
11020 | - // console.log(event) | |
11021 | - // console.log(sender) | |
11022 | - // }) | |
11038 | + if (DispatchCenter.eventListenerIsExist) return | |
11039 | + | |
11040 | + const graphDblClick = this.graph.dblClick; | |
11041 | + this.graph.dblClick = (...args) => { | |
11042 | + this.handleDoubleClickEvent(...args) | |
11043 | + graphDblClick.apply(this.graph, args) | |
11044 | + } | |
11045 | + | |
11046 | + | |
11047 | + const graphClick = this.graph.click; | |
11048 | + this.graph.click = (...args) => { | |
11049 | + this.handleClickEvent(...args) | |
11050 | + graphClick.apply(this.graph, args) | |
11051 | + } | |
11052 | + | |
11053 | + const graphFireMouseEvent = this.graph.fireMouseEvent; | |
11054 | + this.graph.fireMouseEvent = (eventName, event, sender) => { | |
11055 | + if (eventName === mxEvent.MOUSE_DOWN) { | |
11056 | + this.handleMouseDownEvent(eventName, event, sender) | |
11057 | + } | |
11058 | + if (eventName === mxEvent.MOUSE_UP) { | |
11059 | + this.handleMouseUpEvent(eventName, event, sender) | |
11060 | + } | |
11061 | + graphFireMouseEvent.apply(this.graph, [eventName, event, sender]); | |
11062 | + }; | |
11063 | + | |
11064 | + DispatchCenter.eventListenerIsExist = true | |
11023 | 11065 | } |
11024 | 11066 | |
11025 | 11067 | /** |
... | ... | @@ -11029,6 +11071,7 @@ class DispatchCenter { |
11029 | 11071 | */ |
11030 | 11072 | saveContentInfo(editorUi, currentPage) { |
11031 | 11073 | const editor = editorUi.editor |
11074 | + console.log(editorUi) | |
11032 | 11075 | this.graph = editor.graph |
11033 | 11076 | this.currentPage = currentPage |
11034 | 11077 | this.contentAllCell = this.graph.getDefaultParent().children |
... | ... | @@ -11041,11 +11084,14 @@ class DispatchCenter { |
11041 | 11084 | const { node: { id } = {} } = this.currentPage |
11042 | 11085 | if (!id) return |
11043 | 11086 | const [err, res] = await to(ConfigurationNodeApi.getConfigurationInfo('CONTENT', id)) |
11044 | - const { dataSources } = res | |
11087 | + const { dataSources, event, act } = res | |
11045 | 11088 | const sendMsg = { |
11046 | 11089 | tsSubCmds: this.generatorDataSourceMapping(dataSources) |
11047 | 11090 | } |
11091 | + this.generatorEventMapping(event) | |
11092 | + this.generatorActionEffectMapping(act) | |
11048 | 11093 | this.sendMessageToGetRealTimeData(sendMsg) |
11094 | + console.log(this.nodeMapping) | |
11049 | 11095 | } |
11050 | 11096 | |
11051 | 11097 | /** |
... | ... | @@ -11073,17 +11119,45 @@ class DispatchCenter { |
11073 | 11119 | } |
11074 | 11120 | |
11075 | 11121 | this.subscribeDataSources(datum, eventName, attr) |
11076 | - this.nodeMapping.set(deviceId, sendMsgTemplate) | |
11077 | 11122 | return sendMsgTemplate |
11078 | 11123 | }) |
11079 | 11124 | } |
11080 | 11125 | |
11081 | 11126 | /** |
11127 | + * @description 事件映射 | |
11128 | + * @param event | |
11129 | + */ | |
11130 | + generatorEventMapping(event = []) { | |
11131 | + for (const item of event) { | |
11132 | + const { content, id: nodeId, enabled, type } = item | |
11133 | + if (!enabled) continue | |
11134 | + if (!this.nodeMapping.has(nodeId)) this.nodeMapping.set(nodeId, new Map()) | |
11135 | + const temp = this.nodeMapping.get(nodeId) | |
11136 | + temp.set(type, content) | |
11137 | + } | |
11138 | + } | |
11139 | + | |
11140 | + /** | |
11141 | + * @description 动效映射 | |
11142 | + * @param act | |
11143 | + */ | |
11144 | + generatorActionEffectMapping(act = []) { | |
11145 | + for (const item of act) { | |
11146 | + const { condition, id: nodeId, enabled, type } = item | |
11147 | + if (!enabled) continue | |
11148 | + if (!this.nodeMapping.has(nodeId)) this.nodeMapping.set(nodeId, new Map()) | |
11149 | + const temp = this.nodeMapping.get(nodeId) | |
11150 | + temp.set(type, condition) | |
11151 | + } | |
11152 | + } | |
11153 | + | |
11154 | + /** | |
11082 | 11155 | * @description 分发事件 |
11083 | 11156 | */ |
11084 | 11157 | publishEvent(eventName, data) { |
11085 | 11158 | Object.keys(data).forEach(() => { |
11086 | 11159 | this.eventBus.emit(eventName, data) |
11160 | + | |
11087 | 11161 | }) |
11088 | 11162 | } |
11089 | 11163 | |
... | ... | @@ -11118,6 +11192,81 @@ class DispatchCenter { |
11118 | 11192 | } |
11119 | 11193 | } |
11120 | 11194 | |
11195 | + /** | |
11196 | + * @description 处理按下事件 | |
11197 | + * @param eventName | |
11198 | + * @param event | |
11199 | + * @param sender | |
11200 | + */ | |
11201 | + handleMouseDownEvent(eventName, event, sender) { | |
11202 | + const { state: { cell: { id } = {} } = {} } = event | |
11203 | + const temp = this.nodeMapping.get(id) | |
11204 | + if (temp && temp.has(DispatchCenter.enumEventType.DOWN)) { | |
11205 | + const content = temp.get(DispatchCenter.enumEventType.DOWN) | |
11206 | + console.log('mouse down event', content) | |
11207 | + } | |
11208 | + } | |
11209 | + | |
11210 | + /** | |
11211 | + * @description 处理抬起事件 | |
11212 | + * @param eventName | |
11213 | + * @param event | |
11214 | + * @param sender | |
11215 | + */ | |
11216 | + handleMouseUpEvent(eventName, event, sender) { | |
11217 | + const { state: { cell: { id } = {} } = {} } = event | |
11218 | + const temp = this.nodeMapping.get(id) | |
11219 | + if (temp && temp.has(DispatchCenter.enumEventType.UP)) { | |
11220 | + const content = temp.get(DispatchCenter.enumEventType.UP) | |
11221 | + console.log('mouse up event', content) | |
11222 | + } | |
11223 | + } | |
11224 | + | |
11225 | + /** | |
11226 | + * @description 鼠标双击事件 | |
11227 | + * @param event | |
11228 | + */ | |
11229 | + handleClickEvent(event) { | |
11230 | + const { state: { cell: { id } = {} } = {} } = event | |
11231 | + const temp = this.nodeMapping.get(id) | |
11232 | + if (temp && temp.has(DispatchCenter.enumEventType.SINGLE)) { | |
11233 | + const content = temp.get(DispatchCenter.enumEventType.SINGLE) | |
11234 | + const { type, value } = content | |
11235 | + if (type === DispatchCenter.enumPageType.PAGE) { | |
11236 | + this.jumpPage(value) | |
11237 | + } else if (type === DispatchCenter.enumPageType.LINK) { | |
11238 | + window.open(value) | |
11239 | + } | |
11240 | + } | |
11241 | + } | |
11242 | + | |
11243 | + /** | |
11244 | + * @description 鼠标单击事件 | |
11245 | + * @param event | |
11246 | + * @param cell | |
11247 | + */ | |
11248 | + handleDoubleClickEvent(event, cell = {}) { | |
11249 | + const { id } = cell | |
11250 | + const temp = this.nodeMapping.get(id) | |
11251 | + if (temp && temp.has(DispatchCenter.enumEventType.DOUBLE)) { | |
11252 | + const content = temp.get(DispatchCenter.enumEventType.DOUBLE) | |
11253 | + const { type, value } = content | |
11254 | + if (type === DispatchCenter.enumPageType.PAGE) { | |
11255 | + this.jumpPage(value) | |
11256 | + } else if (type === DispatchCenter.enumPageType.LINK) { | |
11257 | + window.open(value) | |
11258 | + } | |
11259 | + } | |
11260 | + } | |
11261 | + | |
11262 | + /** | |
11263 | + * @description 跳转页面 | |
11264 | + */ | |
11265 | + jumpPage(page) { | |
11266 | + // const page = 'ikp4NlRjQpI8WxeSibFj' | |
11267 | + this.editorUi.handleCustomLink(`data:page/id,${ page }`) | |
11268 | + } | |
11269 | + | |
11121 | 11270 | |
11122 | 11271 | /** |
11123 | 11272 | * @description 返回 DispatchCenter 实例 当contentID变化时重新创建实例 |
... | ... | @@ -11138,3 +11287,22 @@ class DispatchCenter { |
11138 | 11287 | |
11139 | 11288 | } |
11140 | 11289 | |
11290 | +function globalInit() { | |
11291 | + init() | |
11292 | + | |
11293 | + function init() { | |
11294 | + initRealTime() | |
11295 | + } | |
11296 | + | |
11297 | + function initRealTime() { | |
11298 | + setInterval(() => { | |
11299 | + const allTimeNode = document.querySelectorAll('.thingKit-component__real-time .real-time__now') | |
11300 | + for (const time of allTimeNode) { | |
11301 | + const date = new Date() | |
11302 | + time.innerHTML = `${ date.getHours() }:${ date.getMinutes() < 10 ? '0' : '' }${ date.getMinutes() }:${ date.getSeconds() < 10 ? '0' : '' }${ date.getSeconds() }` | |
11303 | + } | |
11304 | + }, 1000) | |
11305 | + } | |
11306 | +} | |
11307 | + | |
11308 | +globalInit() | ... | ... |