添加、修改预案功能

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 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<Protocol.AddPlanResponseEntity>(
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<Protocol.EditPlanResponseEntity>(
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<Protocol.GetPlansResponseEntity>(

View File

@ -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,

View File

@ -134,14 +134,41 @@
<div v-if="props.col.name == 'value'">
<div v-if="props.pageIndex % 2">
{{ 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 v-else>
<!-- <q-select></q-select> -->
{{ props.value }}
<q-popup-edit v-model="props.row.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 v-else>
{{ props.value }}
{{ $t(props.value) }}
</div>
</q-td>
</template>
@ -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<StringKeyValueEntity[]> = 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(

View File

@ -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();
}

View File

@ -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": "已经自动删除未知模式",
};

View File

@ -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,
});
}
}

View File

@ -67,6 +67,16 @@
@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-btn-dropdown
stretch
@ -129,12 +139,23 @@ export default defineComponent({
let $t = useI18n();
let show_advanced_menu = ref(false);
let show_stop_plan = ref(false);
EventBus.getInstance().on(
EventNamesDefine.NotifyMessage,
(notify: NotifyMessage) => {
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,
});
},
};
},
});

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 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);
}
};