Commit 3024c4cae697bda16ccb074e0cbee65a07704b7b

Authored by ww
1 parent 01e2632e

feat: implement params setting button component

... ... @@ -240,6 +240,11 @@
240 240 SWITCH: 'switch',
241 241
242 242 /**
  243 + * @description 参数设置按钮
  244 + */
  245 + PARAMS_SETTING_BUTTON: 'paramsSettingButton',
  246 +
  247 + /**
243 248 * @description 默认类型
244 249 */
245 250 DEFAULT: 'default',
... ... @@ -315,7 +320,10 @@
315 320 */
316 321 SWITCH_STATE_SETTING: 'stateSetting',
317 322
318   -
  323 + /**
  324 + * @description 只有单机事件
  325 + */
  326 + ONLY_SINGLE_EVENT: 'onlySingleEvent'
319 327 }
320 328
321 329 /**
... ... @@ -672,8 +680,8 @@
672 680 //更多图形,显示出来的的标题跟id,同时包括图片
673 681
674 682 // TODO thingsKit 设置数据绑定展示面板
675   - const { LINE_CHART_EXPAND, BAR_CHART_EXPAND, DYNAMIC_EFFECT, DATA_SOURCE, VAR_IMAGE, INTERACTION, VIDEO: VIDEO_PANEL, SWITCH_STATE_SETTING } = this.enumPermissionPanel
676   - const { LINE, LINE_CHART, REAL_TIME, TITLE, VARIABLE, DEFAULT, BAR_CHART, VIDEO, SWITCH } = this.enumComponentType
  683 + const { LINE_CHART_EXPAND, BAR_CHART_EXPAND, DYNAMIC_EFFECT, DATA_SOURCE, VAR_IMAGE, INTERACTION, VIDEO: VIDEO_PANEL, SWITCH_STATE_SETTING, ONLY_SINGLE_EVENT } = this.enumPermissionPanel
  684 + const { LINE, LINE_CHART, REAL_TIME, TITLE, VARIABLE, DEFAULT, BAR_CHART, VIDEO, SWITCH, PARAMS_SETTING_BUTTON } = this.enumComponentType
677 685 this.setComponentPermission(LINE, [DYNAMIC_EFFECT])
678 686 this.setComponentPermission(DEFAULT, [DYNAMIC_EFFECT])
679 687 this.setComponentPermission(REAL_TIME, [DYNAMIC_EFFECT])
... ... @@ -684,6 +692,7 @@
684 692 this.setComponentPermission(LINE_CHART, [DATA_SOURCE, LINE_CHART_EXPAND])
685 693 this.setComponentPermission(VIDEO, [VIDEO_PANEL])
686 694 this.setComponentPermission(SWITCH, [DATA_SOURCE, SWITCH_STATE_SETTING])
  695 + this.setComponentPermission(PARAMS_SETTING_BUTTON, [DATA_SOURCE, ONLY_SINGLE_EVENT])
687 696
688 697 var thingskitEntries = [
689 698 { title: mxResources.get('general'), id: 'general', image: IMAGE_PATH + '/sidebar-general.png' },
... ...
... ... @@ -4,7 +4,7 @@
4 4 // Control Component 控制元件
5 5 Sidebar.prototype.addControlComponentsPalette = function () {
6 6 const { COMPONENT_TYPE } = this.enumCellBasicAttribute
7   - const { SWITCH } = this.enumComponentType
  7 + const { SWITCH, PARAMS_SETTING_BUTTON } = this.enumComponentType
8 8 const gn = 'mxgraph.control';
9 9 const dt = 'control';
10 10 const label = '控制元件'
... ... @@ -15,18 +15,29 @@
15 15 const defaultStyle = ';imageAspect=0;'
16 16 this.setCurrentSearchEntryLibrary(dt);
17 17
18   - // 自定义属性
19   - const cellAttribute = {
20   - [COMPONENT_TYPE]: SWITCH
21   - }
  18 +
22 19
23 20 const fns = [
24 21 this.addEntry(this.getTagsForStencil(gn, 'Switch', dt).join(' '), mxUtils.bind(this, function () {
25 22 const cell = new mxCell('', new mxGeometry(0, 0, 48, 48), `image;image=images/thingskit/switch-on.svg;${defaultStyle}`);
  23 + // 自定义属性
  24 + const cellAttribute = {
  25 + [COMPONENT_TYPE]: SWITCH
  26 + }
26 27 cell.setVertex(true)
27 28 this.setCellAttributes(cell, cellAttribute)
28 29 return this.createVertexTemplateFromCells([cell], cell.geometry.width, cell.geometry.height, '开关');
29 30 })),
  31 + this.addEntry(this.getTagsForStencil(gn, 'Params Setting', dt).join(' '), mxUtils.bind(this, function () {
  32 + const cell = new mxCell('<button class="param-setting-button">参数设置</button>', new mxGeometry(0, 0, 100, 60), 'text;html=1;strokeColor=none;fillColor=none;align=center;verticalAlign=middle;whiteSpace=wrap;overflow=hidden;');
  33 + // 自定义属性
  34 + const cellAttribute = {
  35 + [COMPONENT_TYPE]: PARAMS_SETTING_BUTTON
  36 + }
  37 + cell.setVertex(true)
  38 + this.setCellAttributes(cell, cellAttribute)
  39 + return this.createVertexTemplateFromCells([cell], cell.geometry.width, cell.geometry.height, '参数设置');
  40 + })),
30 41 ]
31 42
32 43
... ...
... ... @@ -5133,6 +5133,7 @@ DataFormatPanel.prototype.addDataFont = function (container) {
5133 5133 [permissionKey.VAR_IMAGE]: createVarImagePanel,
5134 5134 [permissionKey.VIDEO]: createVideoBindPanel,
5135 5135 [permissionKey.SWITCH_STATE_SETTING]: createSwitchStateSettingPanel,
  5136 + [permissionKey.ONLY_SINGLE_EVENT]: createParamsSettingButtonPanel
5136 5137 }
5137 5138
5138 5139
... ... @@ -5388,10 +5389,17 @@ DataFormatPanel.prototype.addDataFont = function (container) {
5388 5389 type: enumDynamicEffectType.SWITCH,
5389 5390 category: enumCategory.ACT,
5390 5391 })
  5392 + createDynamicEffectPanel()
  5393 + createParamsSettingButtonPanel()
  5394 + }
  5395 +
  5396 + /**
  5397 + * @description 参数设置按钮面板创建
  5398 + */
  5399 + function createParamsSettingButtonPanel() {
5391 5400 const singleClick = interactionList.find(item => item.type === enumInteractionType.SINGLE)
5392 5401 interactionList.length = 0
5393 5402 interactionList.push(singleClick)
5394   - createDynamicEffectPanel()
5395 5403 createInteractionPanel()
5396 5404 }
5397 5405
... ... @@ -5856,7 +5864,8 @@ DataFormatPanel.prototype.addDataFont = function (container) {
5856 5864 [componentType.BAR_CHART]: getSubmitValue,
5857 5865 [componentType.DEFAULT]: getSubmitValue,
5858 5866 [componentType.VIDEO]: getVideoSubmitValue,
5859   - [componentType.SWITCH]: getSwitchSubmitValue
  5867 + [componentType.SWITCH]: getSwitchSubmitValue,
  5868 + [componentType.PARAMS_SETTING_BUTTON]: getSwitchSubmitValue
5860 5869 }
5861 5870
5862 5871 const cell = vertices[0]
... ... @@ -6847,7 +6856,7 @@ DataFormatPanel.prototype.addDataFont = function (container) {
6847 6856 const basicAttr = sidebarInstance.enumCellBasicAttribute
6848 6857 const componentType = sidebarInstance.enumComponentType
6849 6858 const currentNodeType = nodeInfo.getAttribute(basicAttr.COMPONENT_TYPE)
6850   - const isControlComponent = [componentType.SWITCH].includes(currentNodeType)
  6859 + const isControlComponent = [componentType.SWITCH, componentType.PARAMS_SETTING_BUTTON].includes(currentNodeType)
6851 6860
6852 6861 const enumEventType = {
6853 6862 DOWN: "按下",
... ... @@ -13289,6 +13298,12 @@ class HandleDataSource {
13289 13298 this.handleSwitchComponent(message)
13290 13299 return
13291 13300 }
  13301 +
  13302 + if (type === this.componentType.PARAMS_SETTING_BUTTON) {
  13303 + this.handleParamSettingButton(message)
  13304 + return
  13305 + }
  13306 +
13292 13307 if (!data) return
13293 13308 const [[timespan, value]] = data[attr]
13294 13309 node.setValue(value)
... ... @@ -13323,6 +13338,14 @@ class HandleDataSource {
13323 13338 }
13324 13339 }
13325 13340
  13341 + handleParamSettingButton(message) {
  13342 + const { subscriptionId, data = {} } = message
  13343 + const node = this.getNodeByCmdId(subscriptionId)
  13344 + const { attr } = this.getBindData(subscriptionId)
  13345 + const [[timespan, receiveValue] = []] = data[attr] || []
  13346 + node.setAttribute('label', `<button class="param-setting-button">${receiveValue}</button>`)
  13347 + }
  13348 +
13326 13349 /**
13327 13350 * @description 更新实时数据
13328 13351 * @param {} message
... ... @@ -13964,7 +13987,7 @@ class HandleDataInteraction {
13964 13987 return false
13965 13988 }
13966 13989 const submitThrottle = this.throttle(submit)
13967   - async function submit() {
  13990 + async function submit(callback) {
13968 13991 const value = $(`#${enumActionEl.CONTAINER}`).parent().find(`textarea[name="${enumConst.VALUE}"]`).val() || ''
13969 13992 if (!isJson(value)) {
13970 13993 UseLayUi.topErrorMsg('下发值不正确')
... ... @@ -13989,6 +14012,7 @@ class HandleDataInteraction {
13989 14012 const [err, res] = await to(ConfigurationNodeApi.sendInstruction(way, deviceId, instructionData))
13990 14013 if (!err) {
13991 14014 UseLayUi.topSuccessMsg('操作成功')
  14015 + callback()
13992 14016 }
13993 14017 } else {
13994 14018 UseLayUi.topErrorMsg('设备不在线!')
... ... @@ -14003,7 +14027,9 @@ class HandleDataInteraction {
14003 14027 area: '600px',
14004 14028 btn: ["应用", "取消"],
14005 14029 yes(index) {
14006   - submitThrottle()
  14030 + submitThrottle(() => {
  14031 + layer.close(index)
  14032 + })
14007 14033 },
14008 14034 but2(index, layero) {
14009 14035
... ...
... ... @@ -447,7 +447,6 @@
447 447 }
448 448
449 449 #defaultImageEl {
450   -
451 450 }
452 451
453 452 /* ===== 数据动效 ========= */
... ... @@ -494,7 +493,7 @@
494 493 .video-panel-org__override .layui-form-item {
495 494 display: flex;
496 495 }
497   -.video-panel-org__override .layui-form-item label{
  496 +.video-panel-org__override .layui-form-item label {
498 497 width: 60px;
499 498 box-sizing: border-box;
500 499 }
... ... @@ -502,3 +501,33 @@
502 501 flex: auto;
503 502 margin-left: 0;
504 503 }
  504 +
  505 +/* 参数设置按钮 */
  506 +.param-setting-button {
  507 + color: #fff;
  508 + border-color: #1890ff;
  509 + background: #1890ff;
  510 + text-shadow: 0 -1px 0 rgb(0 0 0 / 12%);
  511 + box-shadow: 0 2px #0000000b;
  512 +
  513 + line-height: 1.5715;
  514 + position: relative;
  515 + display: inline-block;
  516 + font-weight: 400;
  517 + white-space: nowrap;
  518 + text-align: center;
  519 + background-image: none;
  520 + border: 1px solid transparent;
  521 + box-shadow: 0 2px #00000004;
  522 + cursor: pointer;
  523 + transition: all 0.3s cubic-bezier(0.645, 0.045, 0.355, 1);
  524 + -webkit-user-select: none;
  525 + -moz-user-select: none;
  526 + -ms-user-select: none;
  527 + user-select: none;
  528 + touch-action: manipulation;
  529 + height: 32px;
  530 + padding: 4px 15px;
  531 + font-size: 14px;
  532 + border-radius: 2px;
  533 +}
... ...