From f0699229a53cc65a9524b0995b412cd4a6473598 Mon Sep 17 00:00:00 2001 From: fangxiang Date: Thu, 26 Aug 2021 11:19:31 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BF=AE=E5=A4=8D=E9=83=A8=E5=88=86=E6=95=B0?= =?UTF-8?q?=E6=8D=AE=E4=B8=8D=E6=9B=B4=E6=96=B0=E7=9A=84BUG?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/components/ModeTree.vue | 95 --------- src/components/PlanDialog.vue | 37 ++-- src/components/PlanTree.vue | 91 --------- src/components/SignalSourceTree.vue | 93 --------- src/pages/Index.vue | 302 +++++++++++++++++++++++++++- src/pages/TopToolBar.vue | 23 --- src/pages/WallPage.vue | 16 +- 7 files changed, 329 insertions(+), 328 deletions(-) diff --git a/src/components/ModeTree.vue b/src/components/ModeTree.vue index 89d1350..f13db5a 100644 --- a/src/components/ModeTree.vue +++ b/src/components/ModeTree.vue @@ -121,10 +121,7 @@ import { Common } from "src/common/Common"; import GlobalData from "src/common/GlobalData"; import { useQuasar } from "quasar"; import { useI18n } from "vue-i18n"; -import EventBus, { EventNamesDefine } from "src/common/EventBus"; -import { Protocol } from "src/entities/WSProtocol"; import { ModeEntity } from "src/entities/ModeEntity"; -import { NotifyMessage } from "src/common/ClientConnection"; export default defineComponent({ name: "PageModeTree", @@ -150,98 +147,6 @@ export default defineComponent({ tree.value?.setExpanded("", true); }); - EventBus.getInstance().on( - EventNamesDefine.NotifyMessage, - (response: NotifyMessage) => { - if (response) { - switch (response.packet.command) { - case Protocol.Commands.kRpcAddMode: - { - const temp = JSON.parse( - response.data - ) as Protocol.ModeAddNotifyEntity; - if (temp) { - GlobalData.getInstance().modes.push(temp.mode); - $store.commit("addModeTreeItem", { - parent: temp.mode.group_uuid, - is_group: false, - item_data: temp.mode, - }); - } - } - break; - case Protocol.Commands.kRpcDeleteMode: - { - const temp = JSON.parse( - response.data - ) as Protocol.ModeDeleteNotifyEntity; - console.log(temp); - if (temp) { - $store.commit("deleteModeTreeItem", { - is_group: false, - uuid: temp.uuid, - }); - } - } - break; - case Protocol.Commands.kRpcEditMode: - { - const temp = JSON.parse( - response.data - ) as Protocol.ModeEditNotifyEntity; - if (temp) { - $store.commit("setModeTreeItem", { - is_group: false, - item_data: temp.mode, - }); - } - } - break; - case Protocol.Commands.kRpcAddModeGroup: - { - const temp = JSON.parse( - response.data - ) as Protocol.ModeGroupAddNotifyEntity; - if (temp) { - $store.commit("addModeTreeItem", { - parent: temp.mode_group.parent_uuid, - is_group: true, - item_data: temp.mode_group, - }); - } - } - break; - case Protocol.Commands.kRpcDeleteModeGroup: - { - const temp = JSON.parse( - response.data - ) as Protocol.ModeGroupDeleteNotifyEntity; - if (temp) { - $store.commit("deleteModeTreeItem", { - is_group: true, - uuid: temp.uuid, - }); - } - } - break; - case Protocol.Commands.kRpcEditModeGroup: - { - const temp = JSON.parse( - response.data - ) as Protocol.ModeGroupEditNotifyEntity; - if (temp) { - $store.commit("setModeTreeItem", { - is_group: true, - item_data: temp.mode_group, - }); - } - } - break; - } - } - } - ); - return { tree, tree_nodes, diff --git a/src/components/PlanDialog.vue b/src/components/PlanDialog.vue index f219c56..2049813 100644 --- a/src/components/PlanDialog.vue +++ b/src/components/PlanDialog.vue @@ -358,10 +358,8 @@ export default defineComponent({ }, showDialog(options: any) { if (options) { - console.log(options); type.value = options.type ?? 1; if (type.value == 2) { - console.log(options); name.value = options.data?.name ?? null; selected.value = options.data?.item_data?.group_uuid ?? null; uuid.value = options.data?.item_data?.uuid ?? null; @@ -375,26 +373,37 @@ export default defineComponent({ datas.value = options.data?.item_data?.datas ?? []; } modes.value = GlobalData.getInstance().modes; - const datas_length = datas.value.length; - datas.value = datas.value.filter((item) => { - if (item) { - if (item.key == "operator") { - return GlobalData.getInstance().modes.find( - (element) => element && element.uuid == item.value - ); + + let temp = []; + for ( + let i = 0; + i < + (datas.value.length % 2 + ? datas.value.length - 1 + : datas.value.length); + i += 2 + ) { + const item = datas.value[i]; + console.log(item); + if (item && item.key.startsWith("operator_")) { + const item_value = GlobalData.getInstance().modes.find( + (element) => element && element.uuid == item.value + ); + if (item_value) { + temp.push(datas.value[i]); + temp.push(datas.value[i + 1]); } - return true; } - return false; - }); - if (datas_length != datas.value.length) { + } + if (temp.length != datas.value.length) { $q.notify({ - type: "success", + type: "warning", message: $t.t("auto delete unknow mode success"), position: "top", timeout: 1000, }); } + datas.value = temp; } show_dialog.value = true; }, diff --git a/src/components/PlanTree.vue b/src/components/PlanTree.vue index 69a4000..5e8328d 100644 --- a/src/components/PlanTree.vue +++ b/src/components/PlanTree.vue @@ -150,97 +150,6 @@ export default defineComponent({ tree.value?.setExpanded("", true); }); - EventBus.getInstance().on( - EventNamesDefine.NotifyMessage, - (response: NotifyMessage) => { - if (response) { - switch (response.packet.command) { - case Protocol.Commands.kRpcAddPlan: - { - const temp = JSON.parse( - response.data - ) as Protocol.PlanAddNotifyEntity; - if (temp) { - GlobalData.getInstance().plans.push(temp.plan); - $store.commit("addPlanTreeItem", { - parent: temp.plan.group_uuid, - is_group: false, - item_data: temp.plan, - }); - } - } - break; - case Protocol.Commands.kRpcDeletePlan: - { - const temp = JSON.parse( - response.data - ) as Protocol.PlanDeleteNotifyEntity; - if (temp) { - $store.commit("deletePlanTreeItem", { - is_group: false, - uuid: temp.uuid, - }); - } - } - break; - case Protocol.Commands.kRpcEditPlan: - { - const temp = JSON.parse( - response.data - ) as Protocol.PlanEditNotifyEntity; - if (temp) { - $store.commit("setPlanTreeItem", { - is_group: false, - item_data: temp.plan, - }); - } - } - break; - case Protocol.Commands.kRpcAddPlanGroup: - { - const temp = JSON.parse( - response.data - ) as Protocol.PlanGroupAddNotifyEntity; - if (temp) { - $store.commit("addPlanTreeItem", { - parent: temp.plan_group.parent_uuid, - is_group: true, - item_data: temp.plan_group, - }); - } - } - break; - case Protocol.Commands.kRpcDeletePlanGroup: - { - const temp = JSON.parse( - response.data - ) as Protocol.PlanGroupDeleteNotifyEntity; - if (temp) { - $store.commit("deletePlanTreeItem", { - is_group: true, - uuid: temp.uuid, - }); - } - } - break; - case Protocol.Commands.kRpcEditPlanGroup: - { - const temp = JSON.parse( - response.data - ) as Protocol.PlanGroupEditNotifyEntity; - if (temp) { - $store.commit("setPlanTreeItem", { - is_group: true, - item_data: temp.plan_group, - }); - } - } - break; - } - } - } - ); - return { tree, tree_nodes, diff --git a/src/components/SignalSourceTree.vue b/src/components/SignalSourceTree.vue index fc6df93..15ea1e7 100644 --- a/src/components/SignalSourceTree.vue +++ b/src/components/SignalSourceTree.vue @@ -159,99 +159,6 @@ export default defineComponent({ tree.value?.setExpanded("", true); }); - EventBus.getInstance().on( - EventNamesDefine.NotifyMessage, - (response: NotifyMessage) => { - if (response) { - switch (response.packet.command) { - case Protocol.Commands.kRpcAddSignalSource: - { - const temp = JSON.parse( - response.data - ) as Protocol.SignalSourceAddNotifyEntity; - if (temp) { - GlobalData.getInstance().signal_source.push( - temp.signal_source - ); - $store.commit("addSignalSourceTreeItem", { - parent: temp.signal_source.group_uuid, - is_group: false, - item_data: temp.signal_source, - }); - } - } - break; - case Protocol.Commands.kRpcDeleteSignalSource: - { - const temp = JSON.parse( - response.data - ) as Protocol.SignalSourceDeleteNotifyEntity; - if (temp) { - $store.commit("deleteSignalSourceTreeItem", { - is_group: false, - uuid: temp.uuid, - }); - } - } - break; - case Protocol.Commands.kRpcEditSignalSource: - { - const temp = JSON.parse( - response.data - ) as Protocol.SignalSourceEditNotifyEntity; - if (temp) { - $store.commit("setSignalSourceTreeItem", { - is_group: false, - item_data: temp.signal_source, - }); - } - } - break; - case Protocol.Commands.kRpcAddSignalSourceGroup: - { - const temp = JSON.parse( - response.data - ) as Protocol.SignalSourceGroupAddNotifyEntity; - if (temp) { - $store.commit("addSignalSourceTreeItem", { - parent: temp.signal_source_group.parent_uuid, - is_group: true, - item_data: temp.signal_source_group, - }); - } - } - break; - case Protocol.Commands.kRpcDeleteSignalSourceGroup: - { - const temp = JSON.parse( - response.data - ) as Protocol.SignalSourceGroupDeleteNotifyEntity; - if (temp) { - $store.commit("deleteSignalSourceTreeItem", { - is_group: true, - uuid: temp.uuid, - }); - } - } - break; - case Protocol.Commands.kRpcEditSignalSourceGroup: - { - const temp = JSON.parse( - response.data - ) as Protocol.SignalSourceGroupEditNotifyEntity; - if (temp) { - $store.commit("setSignalSourceTreeItem", { - is_group: true, - item_data: temp.signal_source_group, - }); - } - } - break; - } - } - } - ); - return { tree, tree_nodes, diff --git a/src/pages/Index.vue b/src/pages/Index.vue index b2ea501..3670670 100644 --- a/src/pages/Index.vue +++ b/src/pages/Index.vue @@ -10,13 +10,16 @@ import WallPage from "src/pages/WallPage.vue"; import EventBus, { EventNamesDefine } from "src/common/EventBus"; import { useQuasar } from "quasar"; import { useI18n } from "vue-i18n"; +import { useStore } from "src/store"; import { NotifyMessage } from "src/common/ClientConnection"; import { Protocol } from "src/entities/WSProtocol"; +import GlobalData from "src/common/GlobalData"; export default defineComponent({ name: "PageIndex", components: { WallPage }, setup() { + const $store = useStore(); const $q = useQuasar(); const $t = useI18n(); @@ -33,13 +36,36 @@ export default defineComponent({ EventBus.getInstance().on( EventNamesDefine.NotifyMessage, - (response: NotifyMessage) => { + (notify: NotifyMessage) => { try { - switch (response.packet.command) { + switch (notify.packet.command) { + case Protocol.Commands.kSetApplicationConfig: + { + let temp = JSON.parse( + notify.data + ) as Protocol.ApplicationConfigChangeNotifyEntity; + if (temp) { + let global_data = GlobalData.getInstance(); + if (global_data && global_data.applicationConfig) { + (GlobalData.getInstance().applicationConfig)[ + temp.key + ] = temp.value; + $store.commit( + "setWallCol", + global_data.applicationConfig.wall_col + ); + $store.commit( + "setWallRow", + global_data.applicationConfig.wall_row + ); + } + } + } + break; case Protocol.Commands.kCurrentRunningPlanStateChanged: { const temp = JSON.parse( - response.data + notify.data ) as Protocol.PlanRunningStateChangeNotifyEntity; if (temp && temp.plan) { $q.notify({ @@ -57,6 +83,276 @@ export default defineComponent({ } } break; + case Protocol.Commands.kRpcAddMode: + { + const temp = JSON.parse( + notify.data + ) as Protocol.ModeAddNotifyEntity; + if (temp) { + GlobalData.getInstance().modes.push(temp.mode); + $store.commit("addModeTreeItem", { + parent: temp.mode.group_uuid, + is_group: false, + item_data: temp.mode, + }); + } + } + break; + case Protocol.Commands.kRpcDeleteMode: + { + const temp = JSON.parse( + notify.data + ) as Protocol.ModeDeleteNotifyEntity; + if (temp) { + let pos = GlobalData.getInstance().modes.findIndex( + (element) => element && element.uuid == temp.uuid + ); + if (pos != -1) { + GlobalData.getInstance().modes.splice(pos, 1); + } + $store.commit("deleteModeTreeItem", { + is_group: false, + uuid: temp.uuid, + }); + } + } + break; + case Protocol.Commands.kRpcEditMode: + { + const temp = JSON.parse( + notify.data + ) as Protocol.ModeEditNotifyEntity; + if (temp) { + let pos = GlobalData.getInstance().modes.findIndex( + (element) => element && element.uuid == temp.mode.uuid + ); + if (pos != -1) { + GlobalData.getInstance().modes[pos] = temp.mode; + } + $store.commit("setModeTreeItem", { + is_group: false, + item_data: temp.mode, + }); + } + } + break; + case Protocol.Commands.kRpcAddModeGroup: + { + const temp = JSON.parse( + notify.data + ) as Protocol.ModeGroupAddNotifyEntity; + if (temp) { + $store.commit("addModeTreeItem", { + parent: temp.mode_group.parent_uuid, + is_group: true, + item_data: temp.mode_group, + }); + } + } + break; + case Protocol.Commands.kRpcDeleteModeGroup: + { + const temp = JSON.parse( + notify.data + ) as Protocol.ModeGroupDeleteNotifyEntity; + if (temp) { + $store.commit("deleteModeTreeItem", { + is_group: true, + uuid: temp.uuid, + }); + } + } + break; + case Protocol.Commands.kRpcEditModeGroup: + { + const temp = JSON.parse( + notify.data + ) as Protocol.ModeGroupEditNotifyEntity; + if (temp) { + $store.commit("setModeTreeItem", { + is_group: true, + item_data: temp.mode_group, + }); + } + } + break; + case Protocol.Commands.kRpcAddPlan: + { + const temp = JSON.parse( + notify.data + ) as Protocol.PlanAddNotifyEntity; + if (temp) { + GlobalData.getInstance().plans.push(temp.plan); + $store.commit("addPlanTreeItem", { + parent: temp.plan.group_uuid, + is_group: false, + item_data: temp.plan, + }); + } + } + break; + case Protocol.Commands.kRpcDeletePlan: + { + const temp = JSON.parse( + notify.data + ) as Protocol.PlanDeleteNotifyEntity; + if (temp) { + let pos = GlobalData.getInstance().plans.findIndex( + (element) => element && element.uuid == temp.uuid + ); + if (pos != -1) { + GlobalData.getInstance().plans.splice(pos, 1); + } + $store.commit("deletePlanTreeItem", { + is_group: false, + uuid: temp.uuid, + }); + } + } + break; + case Protocol.Commands.kRpcEditPlan: + { + const temp = JSON.parse( + notify.data + ) as Protocol.PlanEditNotifyEntity; + if (temp) { + let pos = GlobalData.getInstance().plans.findIndex( + (element) => element && element.uuid == temp.plan.uuid + ); + if (pos != -1) { + GlobalData.getInstance().plans[pos] = temp.plan; + } + $store.commit("setPlanTreeItem", { + is_group: false, + item_data: temp.plan, + }); + } + } + break; + case Protocol.Commands.kRpcAddPlanGroup: + { + const temp = JSON.parse( + notify.data + ) as Protocol.PlanGroupAddNotifyEntity; + if (temp) { + $store.commit("addPlanTreeItem", { + parent: temp.plan_group.parent_uuid, + is_group: true, + item_data: temp.plan_group, + }); + } + } + break; + case Protocol.Commands.kRpcDeletePlanGroup: + { + const temp = JSON.parse( + notify.data + ) as Protocol.PlanGroupDeleteNotifyEntity; + if (temp) { + $store.commit("deletePlanTreeItem", { + is_group: true, + uuid: temp.uuid, + }); + } + } + break; + case Protocol.Commands.kRpcEditPlanGroup: + { + const temp = JSON.parse( + notify.data + ) as Protocol.PlanGroupEditNotifyEntity; + if (temp) { + $store.commit("setPlanTreeItem", { + is_group: true, + item_data: temp.plan_group, + }); + } + } + break; + + case Protocol.Commands.kRpcAddSignalSource: + { + const temp = JSON.parse( + notify.data + ) as Protocol.SignalSourceAddNotifyEntity; + if (temp) { + GlobalData.getInstance().signal_source.push( + temp.signal_source + ); + $store.commit("addSignalSourceTreeItem", { + parent: temp.signal_source.group_uuid, + is_group: false, + item_data: temp.signal_source, + }); + } + } + break; + case Protocol.Commands.kRpcDeleteSignalSource: + { + const temp = JSON.parse( + notify.data + ) as Protocol.SignalSourceDeleteNotifyEntity; + if (temp) { + $store.commit("deleteSignalSourceTreeItem", { + is_group: false, + uuid: temp.uuid, + }); + } + } + break; + case Protocol.Commands.kRpcEditSignalSource: + { + const temp = JSON.parse( + notify.data + ) as Protocol.SignalSourceEditNotifyEntity; + if (temp) { + $store.commit("setSignalSourceTreeItem", { + is_group: false, + item_data: temp.signal_source, + }); + } + } + break; + case Protocol.Commands.kRpcAddSignalSourceGroup: + { + const temp = JSON.parse( + notify.data + ) as Protocol.SignalSourceGroupAddNotifyEntity; + if (temp) { + $store.commit("addSignalSourceTreeItem", { + parent: temp.signal_source_group.parent_uuid, + is_group: true, + item_data: temp.signal_source_group, + }); + } + } + break; + case Protocol.Commands.kRpcDeleteSignalSourceGroup: + { + const temp = JSON.parse( + notify.data + ) as Protocol.SignalSourceGroupDeleteNotifyEntity; + if (temp) { + $store.commit("deleteSignalSourceTreeItem", { + is_group: true, + uuid: temp.uuid, + }); + } + } + break; + case Protocol.Commands.kRpcEditSignalSourceGroup: + { + const temp = JSON.parse( + notify.data + ) as Protocol.SignalSourceGroupEditNotifyEntity; + if (temp) { + $store.commit("setSignalSourceTreeItem", { + is_group: true, + item_data: temp.signal_source_group, + }); + } + } + break; } } catch {} } diff --git a/src/pages/TopToolBar.vue b/src/pages/TopToolBar.vue index ddb19a1..28ced32 100644 --- a/src/pages/TopToolBar.vue +++ b/src/pages/TopToolBar.vue @@ -156,29 +156,6 @@ export default defineComponent({ } } break; - case Protocol.Commands.kSetApplicationConfig: - { - let temp = JSON.parse( - notify.data - ) as Protocol.ApplicationConfigChangeNotifyEntity; - if (temp) { - let global_data = GlobalData.getInstance(); - if (global_data && global_data.applicationConfig) { - (GlobalData.getInstance().applicationConfig)[ - temp.key - ] = temp.value; - $store.commit( - "setWallCol", - global_data.applicationConfig.wall_col - ); - $store.commit( - "setWallRow", - global_data.applicationConfig.wall_row - ); - } - } - } - break; } } } diff --git a/src/pages/WallPage.vue b/src/pages/WallPage.vue index 2117a0f..03c1f53 100644 --- a/src/pages/WallPage.vue +++ b/src/pages/WallPage.vue @@ -306,12 +306,12 @@ export default defineComponent({ EventBus.getInstance().on( EventNamesDefine.NotifyMessage, - (response: NotifyMessage) => { + (notify: NotifyMessage) => { try { - switch (response.packet.command) { + switch (notify.packet.command) { case Protocol.Commands.kCloseWindow: { - const temp = JSON.parse(response.data); + const temp = JSON.parse(notify.data); if (temp && temp.window_id) { $store.commit("removeWindow", { window_id: temp.window_id, @@ -321,7 +321,7 @@ export default defineComponent({ break; case Protocol.Commands.kMoveWindow: { - const temp = JSON.parse(response.data); + const temp = JSON.parse(notify.data); if (temp && temp.window_id) { const window = $store.state.windows.find( (item) => item.window_id == temp.window_id @@ -345,7 +345,7 @@ export default defineComponent({ break; case Protocol.Commands.kResizeWindow: { - const temp = JSON.parse(response.data); + const temp = JSON.parse(notify.data); if (temp && temp.window_id) { const window = $store.state.windows.find( (item) => item.window_id == temp.window_id @@ -369,9 +369,7 @@ export default defineComponent({ break; case Protocol.Commands.kOpenWindow: { - const temp = JSON.parse( - response.data - ) as WindowOpenNotifyEntity; + const temp = JSON.parse(notify.data) as WindowOpenNotifyEntity; if (temp) { $store.commit("pushWindow", temp); } @@ -380,7 +378,7 @@ export default defineComponent({ case Protocol.Commands.kWindowOtherStateChanged: { const temp = JSON.parse( - response.data + notify.data ) as WindowOtherStateChangeNotifyEntity; if (temp && temp.window_id) { const window = $store.state.windows.find(