diff --git a/src/common/ClientConnection.ts b/src/common/ClientConnection.ts index 3e0bfc2..d73e440 100644 --- a/src/common/ClientConnection.ts +++ b/src/common/ClientConnection.ts @@ -1,5 +1,6 @@ import { ModeEntity } from "src/entities/ModeEntity"; import NormalWindowRequestEntity from "src/entities/NormalWindowRequestEntity"; +import { PlanEntity } from "src/entities/PlanEntity"; import { SignalSourceEntity } from "src/entities/SignalSourceEntity"; import { Protocol } from "src/entities/WSProtocol"; import EventBus, { EventNamesDefine } from "./EventBus"; @@ -352,20 +353,20 @@ export default class ClientConnection { } } - public async addPlan(group_uuid?: string, name?: string) { + public async addPlan(entity?: PlanEntity) { try { return await this.doRpc( - new Protocol.AddPlanRequestEntity(0, name, group_uuid) + new Protocol.AddPlanRequestEntity(0, entity) ); } catch (e) { console.error(e); } } - public async editPlan(uuid?: string, name?: string) { + public async editPlan(entity?: PlanEntity) { try { return await this.doRpc( - new Protocol.EditPlanRequestEntity(0, name, uuid) + new Protocol.EditPlanRequestEntity(0, entity) ); } catch (e) { console.error(e); @@ -396,6 +397,12 @@ export default class ClientConnection { this.ws?.send(JSON.stringify(new Protocol.RunPlanRequestEntity(uuid))); } + public stopCurrentRunningPlan() { + this.ws?.send( + JSON.stringify(new Protocol.StopCurrentRunningPlanRequestEntity()) + ); + } + public async getPlans() { try { return await this.doRpc( diff --git a/src/components/ModeTree.vue b/src/components/ModeTree.vue index 768e075..89d1350 100644 --- a/src/components/ModeTree.vue +++ b/src/components/ModeTree.vue @@ -175,6 +175,7 @@ export default defineComponent({ const temp = JSON.parse( response.data ) as Protocol.ModeDeleteNotifyEntity; + console.log(temp); if (temp) { $store.commit("deleteModeTreeItem", { is_group: false, diff --git a/src/components/PlanDialog.vue b/src/components/PlanDialog.vue index 291f674..f219c56 100644 --- a/src/components/PlanDialog.vue +++ b/src/components/PlanDialog.vue @@ -134,14 +134,41 @@
{{ props.value }}{{ $t("s") }} + + + + +
- - {{ props.value }} + + + + + {{ + modes.find( + (element) => + element && element.uuid == props.row.value + )?.name ?? "" + }}
- {{ props.value }} + {{ $t(props.value) }}
@@ -213,6 +240,7 @@ import GlobalData from "src/common/GlobalData"; import { useQuasar } from "quasar"; import { useI18n } from "vue-i18n"; import { StringKeyValueEntity } from "src/entities/StringKeyValueEntity"; +import { PlanEntity } from "src/entities/PlanEntity"; export default defineComponent({ name: "ComponentPlanDialog", @@ -229,6 +257,7 @@ export default defineComponent({ const selected: any = ref(null); let loading = ref(false); let datas: Ref = ref([]); + let modes = ref(GlobalData.getInstance().modes); const columns = [ { align: "left", @@ -236,14 +265,14 @@ export default defineComponent({ required: true, label: $t.t("operator"), field: "key", - sortable: true, + sortable: false, }, { align: "left", name: "value", label: $t.t("operator value"), field: "value", - sortable: true, + sortable: false, }, ]; @@ -266,9 +295,14 @@ export default defineComponent({ ); const requestAddPlan = async () => { + let entity = new PlanEntity(); + entity.group_uuid = selected.value; + entity.uuid = uuid.value; + entity.name = name.value ?? ""; + entity.datas = datas.value; let response = await GlobalData.getInstance() .getCurrentClient() - ?.addPlan(selected.value, name.value ?? ""); + ?.addPlan(entity); if (response) { $q.notify({ color: response.success ? "positive" : "negative", @@ -284,9 +318,14 @@ export default defineComponent({ }; const requestEditPlan = async () => { + let entity = new PlanEntity(); + entity.group_uuid = selected.value; + entity.uuid = uuid.value; + entity.name = name.value ?? ""; + entity.datas = datas.value; let response = await GlobalData.getInstance() .getCurrentClient() - ?.editPlan(uuid.value, name.value ?? ""); + ?.editPlan(entity); if (response) { $q.notify({ color: response.success ? "positive" : "negative", @@ -313,17 +352,48 @@ export default defineComponent({ show_context_menu, target_dom, tree_nodes, + modes, + loga(a: any) { + console.log(a); + }, 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; + datas.value = JSON.parse( + JSON.stringify(options.data?.item_data?.datas ?? []) + ); } else { + name.value = options.data?.name ?? null; selected.value = options.data?.uuid ?? null; uuid.value = options.data?.uuid ?? null; + 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 + ); + } + return true; + } + return false; + }); + if (datas_length != datas.value.length) { + $q.notify({ + type: "success", + message: $t.t("auto delete unknow mode success"), + position: "top", + timeout: 1000, + }); } } show_dialog.value = true; @@ -338,13 +408,13 @@ export default defineComponent({ }, addRow() { datas.value.push({ - key: $t.t("call mode"), - value: "222", + key: "operator_call_mode", + value: GlobalData.getInstance().modes[0].uuid, }); datas.value.push({ - key: $t.t("delay") + "(" + $t.t("s") + ")", - value: "444", + key: "param_delay", + value: "3000", }); }, onContextMenu( diff --git a/src/entities/WSProtocol.ts b/src/entities/WSProtocol.ts index 38140c1..13cc3b5 100644 --- a/src/entities/WSProtocol.ts +++ b/src/entities/WSProtocol.ts @@ -159,8 +159,12 @@ export namespace Protocol { return Commands.PROTOCOL_PREFIX + "RpcGetCurrentRunningPlan"; } - public static get kPlanRunningStateChanged() { - return Commands.PROTOCOL_PREFIX + "PlanRunningStateChanged"; + public static get kCurrentRunningPlanStateChanged() { + return Commands.PROTOCOL_PREFIX + "CurrentRunningPlanStateChanged"; + } + + public static get kStopCurrentRunningPlan() { + return Commands.PROTOCOL_PREFIX + "StopCurrentRunningPlan"; } public static get kSetApplicationConfig() { @@ -202,7 +206,7 @@ export namespace Protocol { Commands.kRpcDeleteMode, Commands.kRpcEditMode, Commands.kRpcGetCurrentRunningPlan, - Commands.kPlanRunningStateChanged, + Commands.kCurrentRunningPlanStateChanged, Commands.kRpcAddPlanGroup, Commands.kRpcDeletePlanGroup, Commands.kRpcEditPlanGroup, @@ -847,14 +851,14 @@ export namespace Protocol { } export class AddPlanRequestEntity extends Protocol.PacketEntity { - name: string; - group_uuid: string; - constructor(rcp_id?: number, name?: string, group_uuid?: string) { + entity: PlanEntity = new PlanEntity(); + constructor(rcp_id?: number, entity?: PlanEntity) { super(); this.rpc_id = rcp_id ?? 0; this.command = Protocol.Commands.kRpcAddPlan; - this.name = name ?? ""; - this.group_uuid = group_uuid ?? ""; + if (entity) { + this.entity = entity; + } } } @@ -868,14 +872,14 @@ export namespace Protocol { } export class EditPlanRequestEntity extends Protocol.PacketEntity { - name: string; - uuid: string; - constructor(rcp_id?: number, name?: string, uuid?: string) { + entity: PlanEntity = new PlanEntity(); + constructor(rcp_id?: number, entity?: PlanEntity) { super(); this.rpc_id = rcp_id ?? 0; this.command = Protocol.Commands.kRpcEditPlan; - this.name = name ?? ""; - this.uuid = uuid ?? ""; + if (entity) { + this.entity = entity; + } } } @@ -941,6 +945,16 @@ export namespace Protocol { } } + export class StopCurrentRunningPlanRequestEntity extends Protocol.PacketEntity { + timestamp = new Date().getMilliseconds(); + + constructor() { + super(); + this.command = Protocol.Commands.kStopCurrentRunningPlan; + this.flag = Protocol.PacketEntity.FLAG_REQUEST; + } + } + export class PlanAddNotifyEntity extends Protocol.PacketEntity { plan: PlanEntity = new PlanEntity(); } diff --git a/src/i18n/zh-CN/index.ts b/src/i18n/zh-CN/index.ts index 5f64f97..b421007 100644 --- a/src/i18n/zh-CN/index.ts +++ b/src/i18n/zh-CN/index.ts @@ -146,4 +146,11 @@ export default { s: "秒", "call mode": "模式调用", "plan data": "预案数据", + send: "发送", + directives: "指令", + "stop plan": "停止预案", + update: "更新", + operator_call_mode: "模式调用", + param_delay: "延时", + "auto delete unknow mode success": "已经自动删除未知模式", }; diff --git a/src/pages/Index.vue b/src/pages/Index.vue index ef8a359..b2ea501 100644 --- a/src/pages/Index.vue +++ b/src/pages/Index.vue @@ -36,7 +36,7 @@ export default defineComponent({ (response: NotifyMessage) => { try { switch (response.packet.command) { - case Protocol.Commands.kPlanRunningStateChanged: + case Protocol.Commands.kCurrentRunningPlanStateChanged: { const temp = JSON.parse( response.data @@ -52,7 +52,7 @@ export default defineComponent({ " '" + (temp.running ? $t.t("is running") : $t.t("is stopping")), position: "top", - timeout: 1500, + timeout: 2000, }); } } diff --git a/src/pages/TopToolBar.vue b/src/pages/TopToolBar.vue index 4b9039c..ddb19a1 100644 --- a/src/pages/TopToolBar.vue +++ b/src/pages/TopToolBar.vue @@ -67,6 +67,16 @@ @click="backupDB" /> + + { if (notify) { switch (notify.packet.command) { + case Protocol.Commands.kCurrentRunningPlanStateChanged: + { + const temp = JSON.parse( + notify.data + ) as Protocol.PlanRunningStateChangeNotifyEntity; + if (temp && temp.plan) { + show_stop_plan.value = temp.running; + } + } + break; case Protocol.Commands.kSetApplicationConfig: { let temp = JSON.parse( @@ -165,6 +186,8 @@ export default defineComponent({ return { show_advanced_menu, + show_stop_plan, + async backupDB() { let client = GlobalData.getInstance().getCurrentClient(); if (client) { @@ -194,6 +217,20 @@ export default defineComponent({ handleHold() { show_advanced_menu.value = true; }, + stopPlan() { + GlobalData.getInstance().getCurrentClient()?.stopCurrentRunningPlan(); + $q.notify({ + color: "positive", + icon: "done", + message: + $t.t("send") + + $t.t("stop plan") + + $t.t("directives") + + $t.t("success"), + position: "top", + timeout: 1000, + }); + }, }; }, }); diff --git a/src/pages/WallPage.vue b/src/pages/WallPage.vue index a4e07f5..2117a0f 100644 --- a/src/pages/WallPage.vue +++ b/src/pages/WallPage.vue @@ -212,6 +212,21 @@ const _getWindows = async (options: _OptionsType) => { } }; +const _getCurrentRunningPlan = async (options: _OptionsType) => { + const plan_response = await GlobalData.getInstance() + .getCurrentClient() + ?.getCurrentRunningPlan(); + if (plan_response && plan_response.running && plan_response.plan) { + const packet = new Protocol.PacketEntity(); + packet.flag = Protocol.PacketEntity.FLAG_NOTIFY; + packet.command = Protocol.Commands.kCurrentRunningPlanStateChanged; + EventBus.getInstance().emit(EventNamesDefine.NotifyMessage, { + packet, + data: JSON.stringify(plan_response), + }); + } +}; + const _initialize = async (options: _OptionsType) => { const global_data = GlobalData.getInstance(); let client = global_data.getCurrentClient(); @@ -222,9 +237,10 @@ const _initialize = async (options: _OptionsType) => { await _getApplicationConfig(options); - /* await */ _initSignalSourceTree(options); - /* await */ _initModeTree(options); - /* await */ _initPlanTree(options); + _initSignalSourceTree(options); + _initModeTree(options); + _initPlanTree(options); + _getCurrentRunningPlan(options); _getWindows(options); } };