添加、修改预案功能

This commit is contained in:
fangxiang 2021-08-26 10:43:31 +08:00
parent 187d2fda0b
commit d122d437ca
8 changed files with 185 additions and 33 deletions

View File

@ -1,5 +1,6 @@
import { ModeEntity } from "src/entities/ModeEntity"; import { ModeEntity } from "src/entities/ModeEntity";
import NormalWindowRequestEntity from "src/entities/NormalWindowRequestEntity"; import NormalWindowRequestEntity from "src/entities/NormalWindowRequestEntity";
import { PlanEntity } from "src/entities/PlanEntity";
import { SignalSourceEntity } from "src/entities/SignalSourceEntity"; import { SignalSourceEntity } from "src/entities/SignalSourceEntity";
import { Protocol } from "src/entities/WSProtocol"; import { Protocol } from "src/entities/WSProtocol";
import EventBus, { EventNamesDefine } from "./EventBus"; 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 { try {
return await this.doRpc<Protocol.AddPlanResponseEntity>( return await this.doRpc<Protocol.AddPlanResponseEntity>(
new Protocol.AddPlanRequestEntity(0, name, group_uuid) new Protocol.AddPlanRequestEntity(0, entity)
); );
} catch (e) { } catch (e) {
console.error(e); console.error(e);
} }
} }
public async editPlan(uuid?: string, name?: string) { public async editPlan(entity?: PlanEntity) {
try { try {
return await this.doRpc<Protocol.EditPlanResponseEntity>( return await this.doRpc<Protocol.EditPlanResponseEntity>(
new Protocol.EditPlanRequestEntity(0, name, uuid) new Protocol.EditPlanRequestEntity(0, entity)
); );
} catch (e) { } catch (e) {
console.error(e); console.error(e);
@ -396,6 +397,12 @@ export default class ClientConnection {
this.ws?.send(JSON.stringify(new Protocol.RunPlanRequestEntity(uuid))); this.ws?.send(JSON.stringify(new Protocol.RunPlanRequestEntity(uuid)));
} }
public stopCurrentRunningPlan() {
this.ws?.send(
JSON.stringify(new Protocol.StopCurrentRunningPlanRequestEntity())
);
}
public async getPlans() { public async getPlans() {
try { try {
return await this.doRpc<Protocol.GetPlansResponseEntity>( return await this.doRpc<Protocol.GetPlansResponseEntity>(

View File

@ -175,6 +175,7 @@ export default defineComponent({
const temp = JSON.parse( const temp = JSON.parse(
response.data response.data
) as Protocol.ModeDeleteNotifyEntity; ) as Protocol.ModeDeleteNotifyEntity;
console.log(temp);
if (temp) { if (temp) {
$store.commit("deleteModeTreeItem", { $store.commit("deleteModeTreeItem", {
is_group: false, is_group: false,

View File

@ -134,14 +134,41 @@
<div v-if="props.col.name == 'value'"> <div v-if="props.col.name == 'value'">
<div v-if="props.pageIndex % 2"> <div v-if="props.pageIndex % 2">
{{ props.value }}{{ $t("s") }} {{ props.value }}{{ $t("s") }}
<q-popup-edit v-model="props.row.value">
<q-input
type="number"
v-model="props.row.value"
dense
autofocus
>
<template v-slot:append>
<span>{{ $t("s") }}</span>
</template>
</q-input>
</q-popup-edit>
</div> </div>
<div v-else> <div v-else>
<!-- <q-select></q-select> --> <q-popup-edit v-model="props.row.value">
{{ props.value }} <q-select
:options="modes"
option-label="name"
option-value="uuid"
emit-value
map-options
v-model="props.row.value"
>
</q-select>
</q-popup-edit>
{{
modes.find(
(element) =>
element && element.uuid == props.row.value
)?.name ?? ""
}}
</div> </div>
</div> </div>
<div v-else> <div v-else>
{{ props.value }} {{ $t(props.value) }}
</div> </div>
</q-td> </q-td>
</template> </template>
@ -213,6 +240,7 @@ import GlobalData from "src/common/GlobalData";
import { useQuasar } from "quasar"; import { useQuasar } from "quasar";
import { useI18n } from "vue-i18n"; import { useI18n } from "vue-i18n";
import { StringKeyValueEntity } from "src/entities/StringKeyValueEntity"; import { StringKeyValueEntity } from "src/entities/StringKeyValueEntity";
import { PlanEntity } from "src/entities/PlanEntity";
export default defineComponent({ export default defineComponent({
name: "ComponentPlanDialog", name: "ComponentPlanDialog",
@ -229,6 +257,7 @@ export default defineComponent({
const selected: any = ref(null); const selected: any = ref(null);
let loading = ref(false); let loading = ref(false);
let datas: Ref<StringKeyValueEntity[]> = ref([]); let datas: Ref<StringKeyValueEntity[]> = ref([]);
let modes = ref(GlobalData.getInstance().modes);
const columns = [ const columns = [
{ {
align: "left", align: "left",
@ -236,14 +265,14 @@ export default defineComponent({
required: true, required: true,
label: $t.t("operator"), label: $t.t("operator"),
field: "key", field: "key",
sortable: true, sortable: false,
}, },
{ {
align: "left", align: "left",
name: "value", name: "value",
label: $t.t("operator value"), label: $t.t("operator value"),
field: "value", field: "value",
sortable: true, sortable: false,
}, },
]; ];
@ -266,9 +295,14 @@ export default defineComponent({
); );
const requestAddPlan = async () => { 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() let response = await GlobalData.getInstance()
.getCurrentClient() .getCurrentClient()
?.addPlan(selected.value, name.value ?? ""); ?.addPlan(entity);
if (response) { if (response) {
$q.notify({ $q.notify({
color: response.success ? "positive" : "negative", color: response.success ? "positive" : "negative",
@ -284,9 +318,14 @@ export default defineComponent({
}; };
const requestEditPlan = async () => { 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() let response = await GlobalData.getInstance()
.getCurrentClient() .getCurrentClient()
?.editPlan(uuid.value, name.value ?? ""); ?.editPlan(entity);
if (response) { if (response) {
$q.notify({ $q.notify({
color: response.success ? "positive" : "negative", color: response.success ? "positive" : "negative",
@ -313,17 +352,48 @@ export default defineComponent({
show_context_menu, show_context_menu,
target_dom, target_dom,
tree_nodes, tree_nodes,
modes,
loga(a: any) {
console.log(a);
},
showDialog(options: any) { showDialog(options: any) {
if (options) { if (options) {
console.log(options); console.log(options);
type.value = options.type ?? 1; type.value = options.type ?? 1;
if (type.value == 2) { if (type.value == 2) {
console.log(options);
name.value = options.data?.name ?? null; name.value = options.data?.name ?? null;
selected.value = options.data?.item_data?.group_uuid ?? null; selected.value = options.data?.item_data?.group_uuid ?? null;
uuid.value = options.data?.item_data?.uuid ?? null; uuid.value = options.data?.item_data?.uuid ?? null;
datas.value = JSON.parse(
JSON.stringify(options.data?.item_data?.datas ?? [])
);
} else { } else {
name.value = options.data?.name ?? null;
selected.value = options.data?.uuid ?? null; selected.value = options.data?.uuid ?? null;
uuid.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; show_dialog.value = true;
@ -338,13 +408,13 @@ export default defineComponent({
}, },
addRow() { addRow() {
datas.value.push({ datas.value.push({
key: $t.t("call mode"), key: "operator_call_mode",
value: "222", value: GlobalData.getInstance().modes[0].uuid,
}); });
datas.value.push({ datas.value.push({
key: $t.t("delay") + "(" + $t.t("s") + ")", key: "param_delay",
value: "444", value: "3000",
}); });
}, },
onContextMenu( onContextMenu(

View File

@ -159,8 +159,12 @@ export namespace Protocol {
return Commands.PROTOCOL_PREFIX + "RpcGetCurrentRunningPlan"; return Commands.PROTOCOL_PREFIX + "RpcGetCurrentRunningPlan";
} }
public static get kPlanRunningStateChanged() { public static get kCurrentRunningPlanStateChanged() {
return Commands.PROTOCOL_PREFIX + "PlanRunningStateChanged"; return Commands.PROTOCOL_PREFIX + "CurrentRunningPlanStateChanged";
}
public static get kStopCurrentRunningPlan() {
return Commands.PROTOCOL_PREFIX + "StopCurrentRunningPlan";
} }
public static get kSetApplicationConfig() { public static get kSetApplicationConfig() {
@ -202,7 +206,7 @@ export namespace Protocol {
Commands.kRpcDeleteMode, Commands.kRpcDeleteMode,
Commands.kRpcEditMode, Commands.kRpcEditMode,
Commands.kRpcGetCurrentRunningPlan, Commands.kRpcGetCurrentRunningPlan,
Commands.kPlanRunningStateChanged, Commands.kCurrentRunningPlanStateChanged,
Commands.kRpcAddPlanGroup, Commands.kRpcAddPlanGroup,
Commands.kRpcDeletePlanGroup, Commands.kRpcDeletePlanGroup,
Commands.kRpcEditPlanGroup, Commands.kRpcEditPlanGroup,
@ -847,14 +851,14 @@ export namespace Protocol {
} }
export class AddPlanRequestEntity extends Protocol.PacketEntity { export class AddPlanRequestEntity extends Protocol.PacketEntity {
name: string; entity: PlanEntity = new PlanEntity();
group_uuid: string; constructor(rcp_id?: number, entity?: PlanEntity) {
constructor(rcp_id?: number, name?: string, group_uuid?: string) {
super(); super();
this.rpc_id = rcp_id ?? 0; this.rpc_id = rcp_id ?? 0;
this.command = Protocol.Commands.kRpcAddPlan; this.command = Protocol.Commands.kRpcAddPlan;
this.name = name ?? ""; if (entity) {
this.group_uuid = group_uuid ?? ""; this.entity = entity;
}
} }
} }
@ -868,14 +872,14 @@ export namespace Protocol {
} }
export class EditPlanRequestEntity extends Protocol.PacketEntity { export class EditPlanRequestEntity extends Protocol.PacketEntity {
name: string; entity: PlanEntity = new PlanEntity();
uuid: string; constructor(rcp_id?: number, entity?: PlanEntity) {
constructor(rcp_id?: number, name?: string, uuid?: string) {
super(); super();
this.rpc_id = rcp_id ?? 0; this.rpc_id = rcp_id ?? 0;
this.command = Protocol.Commands.kRpcEditPlan; this.command = Protocol.Commands.kRpcEditPlan;
this.name = name ?? ""; if (entity) {
this.uuid = uuid ?? ""; 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 { export class PlanAddNotifyEntity extends Protocol.PacketEntity {
plan: PlanEntity = new PlanEntity(); plan: PlanEntity = new PlanEntity();
} }

View File

@ -146,4 +146,11 @@ export default {
s: "秒", s: "秒",
"call mode": "模式调用", "call mode": "模式调用",
"plan data": "预案数据", "plan data": "预案数据",
send: "发送",
directives: "指令",
"stop plan": "停止预案",
update: "更新",
operator_call_mode: "模式调用",
param_delay: "延时",
"auto delete unknow mode success": "已经自动删除未知模式",
}; };

View File

@ -36,7 +36,7 @@ export default defineComponent({
(response: NotifyMessage) => { (response: NotifyMessage) => {
try { try {
switch (response.packet.command) { switch (response.packet.command) {
case Protocol.Commands.kPlanRunningStateChanged: case Protocol.Commands.kCurrentRunningPlanStateChanged:
{ {
const temp = JSON.parse( const temp = JSON.parse(
response.data response.data
@ -52,7 +52,7 @@ export default defineComponent({
" '" + " '" +
(temp.running ? $t.t("is running") : $t.t("is stopping")), (temp.running ? $t.t("is running") : $t.t("is stopping")),
position: "top", position: "top",
timeout: 1500, timeout: 2000,
}); });
} }
} }

View File

@ -67,6 +67,16 @@
@click="backupDB" @click="backupDB"
/> />
<q-btn
stretch
flat
icon="stop"
:label="$t('stop plan')"
class="q-mr-sm"
v-if="show_stop_plan"
@click="stopPlan"
/>
<q-space /> <q-space />
<q-btn-dropdown <q-btn-dropdown
stretch stretch
@ -129,12 +139,23 @@ export default defineComponent({
let $t = useI18n(); let $t = useI18n();
let show_advanced_menu = ref(false); let show_advanced_menu = ref(false);
let show_stop_plan = ref(false);
EventBus.getInstance().on( EventBus.getInstance().on(
EventNamesDefine.NotifyMessage, EventNamesDefine.NotifyMessage,
(notify: NotifyMessage) => { (notify: NotifyMessage) => {
if (notify) { if (notify) {
switch (notify.packet.command) { 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: case Protocol.Commands.kSetApplicationConfig:
{ {
let temp = JSON.parse( let temp = JSON.parse(
@ -165,6 +186,8 @@ export default defineComponent({
return { return {
show_advanced_menu, show_advanced_menu,
show_stop_plan,
async backupDB() { async backupDB() {
let client = GlobalData.getInstance().getCurrentClient(); let client = GlobalData.getInstance().getCurrentClient();
if (client) { if (client) {
@ -194,6 +217,20 @@ export default defineComponent({
handleHold() { handleHold() {
show_advanced_menu.value = true; 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,
});
},
}; };
}, },
}); });

View File

@ -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 _initialize = async (options: _OptionsType) => {
const global_data = GlobalData.getInstance(); const global_data = GlobalData.getInstance();
let client = global_data.getCurrentClient(); let client = global_data.getCurrentClient();
@ -222,9 +237,10 @@ const _initialize = async (options: _OptionsType) => {
await _getApplicationConfig(options); await _getApplicationConfig(options);
/* await */ _initSignalSourceTree(options); _initSignalSourceTree(options);
/* await */ _initModeTree(options); _initModeTree(options);
/* await */ _initPlanTree(options); _initPlanTree(options);
_getCurrentRunningPlan(options);
_getWindows(options); _getWindows(options);
} }
}; };