增加修改轮询功能,修复添加轮询不更新轮询列表的BUG

This commit is contained in:
fangxiang 2022-02-26 13:39:39 +08:00
parent e65352d757
commit 2511d6ff9b
8 changed files with 255 additions and 60 deletions

View File

@ -1,3 +1,4 @@
import { PollingEntity } from "./../entities/PollingEntity";
import ReconnectingWebSocket from "reconnecting-websocket";
import NormalWindowRequestEntity from "src/entities/NormalWindowRequestEntity";
import { PlanEntity } from "src/entities/PlanEntity";
@ -375,6 +376,30 @@ export default class ClientConnection {
}
}
public async addPolling(
group_uuid: string,
name: string,
datas: StringKeyValueEntity[]
) {
try {
return await this.doRpc<Protocol.AddPollingResponseEntity>(
new Protocol.AddPollingRequestEntity(0, group_uuid, name, datas, "")
);
} catch (e) {
console.error(e);
}
}
public async editPolling(entity: PollingEntity) {
try {
return await this.doRpc<Protocol.EditPollingResponseEntity>(
new Protocol.EditPollingRequestEntity(0, entity)
);
} catch (e) {
console.error(e);
}
}
public async deletePolling(uuid: string) {
try {
return await this.doRpc<Protocol.DeletePollingResponseEntity>(
@ -745,10 +770,11 @@ export default class ClientConnection {
public async setPollingData(
window_id: number,
name: string,
datas?: StringKeyValueEntity[]
) {
return await this.doRpc<Protocol.SetPollingDataResponseEntity>(
new Protocol.SetPollingDataRequestEntity(window_id, datas)
new Protocol.SetPollingDataRequestEntity(window_id, name, datas)
);
}

View File

@ -288,7 +288,7 @@ export default class RemoteDataExangeProcesser {
}
break;
case Protocol.Commands.kRpcAddPollingGroup:
case Protocol.Commands.kRpcAddPolling:
{
const temp = JSON.parse(
notify.data

View File

@ -40,6 +40,23 @@
<q-card-section style="max-height: 70vh; width: 50vw" class="scroll">
<q-list>
<q-item>
<q-item-section avatar>
<div class="text-h6 q-pb-md">
{{ $t("polling name") }}:
</div></q-item-section
>
<q-item-section
><q-input
v-model="polling_name"
lazy-rules
:placeholder="$t('please input polling name')"
:rules="[
(val) =>
(val && val.length > 0) || $t('Please type something'),
]"
/></q-item-section>
</q-item>
<q-item>
<q-item-section>
<q-table
@ -194,6 +211,7 @@ export default defineComponent({
let loading = ref(false);
let datas: Ref<StringKeyValueEntity[]> = ref([]);
let signals = ref(GlobalData.getInstance().signal_source);
let polling_name = ref("");
const columns = [
{
@ -228,10 +246,11 @@ export default defineComponent({
show_context_menu,
target_dom,
signals,
polling_name,
loga(a: any) {
console.log(a);
},
showDialog(options: StringKeyValueEntity[] | null) {
showDialog(name: string, options: StringKeyValueEntity[] | null) {
show_dialog.value = true;
if (options) {
datas.value = [];
@ -239,8 +258,9 @@ export default defineComponent({
datas.value.push(item);
}
}
polling_name.value = name ?? $t.t("new polling");
},
showDialogAsync(options: StringKeyValueEntity[] | null) {
showDialogAsync(name: string, options: StringKeyValueEntity[] | null) {
return new Promise((resolve) => {
if (_resolve) {
_resolve();
@ -255,6 +275,7 @@ export default defineComponent({
}
signals.value = GlobalData.getInstance().signal_source;
}
polling_name.value = name ?? $t.t("new polling");
});
},
resetData() {
@ -302,7 +323,10 @@ export default defineComponent({
loading.value = true;
try {
if (_resolve) {
_resolve(datas.value);
_resolve({
name: polling_name.value,
datas: datas.value,
});
_resolve = null;
}
show_dialog.value = false;

View File

@ -44,31 +44,21 @@
clickable
v-close-popup
v-ripple
@click="
$refs.polling_dialog.showDialog({
type: 1,
data: { uuid: prop.node.uuid },
})
"
@click="addPolling($event, prop.node.item_data)"
>
<q-item-section avatar><q-icon name="add" /></q-item-section>
<q-item-section>{{ $t("add polling item") }}</q-item-section>
<q-item-section>{{ $t("add polling") }}</q-item-section>
</q-item>
<q-item
clickable
v-close-popup
v-if="
prop.node.name == $t('root') ||
(prop.node.is_group && prop.node.item_data)
false &&
(prop.node.name == $t('root') ||
(prop.node.is_group && prop.node.item_data))
"
v-ripple
@click="
() =>
$refs.group_dialog.showDialog({
type: 1,
data: prop.node,
})
"
@click="addPollingGroup($event, prop.node.item_data)"
>
<q-item-section avatar
><q-icon name="create_new_folder"
@ -80,17 +70,8 @@
clickable
v-ripple
v-close-popup
v-if="prop.node.item_data && false"
@click="
() =>
(prop.node.is_group
? $refs.group_dialog
: $refs.polling_dialog
).showDialog({
type: 2,
data: prop.node,
})
"
v-if="!prop.node.is_group && prop.node.item_data"
@click="editPolling($event, prop.node.item_data)"
>
<q-item-section avatar><q-icon name="edit" /></q-item-section>
<q-item-section>{{ $t("edit") }}</q-item-section>
@ -117,10 +98,11 @@
</q-tree>
</q-scroll-area>
</div>
<polling-setting-dialog ref="polling_setting_dialog" />
</template>
<script lang="ts">
import { defineComponent, computed, onMounted, ref, nextTick } from "vue";
import { defineComponent, computed, onMounted, ref, Ref, nextTick } from "vue";
import { useStore } from "src/store";
import { Common } from "src/common/Common";
import GlobalData from "src/common/GlobalData";
@ -129,10 +111,17 @@ import { useI18n } from "vue-i18n";
import EventBus, { EventNamesDefine } from "src/common/EventBus";
import { Protocol } from "src/entities/WSProtocol";
import { NotifyMessage } from "src/common/ClientConnection";
import { PollingTreeItemEntity } from "src/entities/PollingEntity";
import {
PollingEntity,
PollingTreeItemEntity,
} from "src/entities/PollingEntity";
import PollingSettingDialog from "src/components/PollingSettingDialog.vue";
export default defineComponent({
name: "ComponentPollingTree",
components: {
PollingSettingDialog,
},
setup() {
const $store = useStore();
@ -156,6 +145,7 @@ export default defineComponent({
});
const tree: any | null = ref(null);
const polling_setting_dialog: Ref<any> = ref(null);
onMounted(async () => {
while (!tree.value.nodes.length) {
@ -166,6 +156,7 @@ export default defineComponent({
return {
tree,
polling_setting_dialog,
tree_nodes,
content_height,
loga(a: any) {
@ -209,6 +200,91 @@ export default defineComponent({
e.dataTransfer.dropEffect = "move";
}
},
async editPolling(event: MouseEvent, data: PollingEntity) {
if (polling_setting_dialog.value) {
const result = await polling_setting_dialog.value.showDialogAsync(
data.name,
data.polling_signal_sources
);
if (result) {
const { name, datas } = result;
if (name && datas) {
try {
const new_data = new PollingEntity();
PollingEntity.copy(new_data, data);
new_data.name = name;
new_data.polling_signal_sources = datas;
const resposne = await GlobalData.getInstance()
.getCurrentClient()
?.editPolling(new_data);
if (resposne) {
if (resposne.success) {
$q.notify({
color: "positive",
icon: "done",
message: $t.t("edit polling") + $t.t("success") + "!",
position: "top",
timeout: 1500,
});
} else {
$q.notify({
color: "negative",
icon: "warning",
message: $t.t("edit polling") + $t.t("failed") + "!",
position: "top",
timeout: 1500,
});
}
}
} catch (e) {
console.log(e);
}
}
}
}
},
async addPolling(event: MouseEvent, data: any) {
if (polling_setting_dialog.value) {
const result = await polling_setting_dialog.value.showDialogAsync(
null,
[]
);
if (result) {
const { name, datas } = result;
if (name && datas) {
try {
const resposne = await GlobalData.getInstance()
.getCurrentClient()
?.addPolling(/* data.uuid */ "", name, datas);
if (resposne) {
if (resposne.success) {
$q.notify({
color: "positive",
icon: "done",
message: $t.t("add polling") + $t.t("success") + "!",
position: "top",
timeout: 1500,
});
} else {
$q.notify({
color: "negative",
icon: "warning",
message: $t.t("add polling") + $t.t("failed") + "!",
position: "top",
timeout: 1500,
});
}
}
} catch (e) {
console.log(e);
}
}
}
}
},
addPollingGroup(event: MouseEvent, data: any) {
console.log(data);
},
};
},
});

View File

@ -1166,6 +1166,60 @@ export namespace Protocol {
}
}
export class AddPollingRequestEntity extends Protocol.PacketEntity {
name: string;
group_uuid: string;
polling_signal_sources: StringKeyValueEntity[];
note: string;
constructor(
rcp_id?: number,
group_uuid?: string,
name?: string,
polling_signal_sources?: StringKeyValueEntity[],
note?: string
) {
super();
this.rpc_id = rcp_id ?? 0;
this.command = Protocol.Commands.kRpcAddPolling;
this.name = name ?? "new pollong";
this.group_uuid = group_uuid ?? "";
this.polling_signal_sources = Array.isArray(polling_signal_sources)
? polling_signal_sources
: [];
this.note = note ?? "";
}
}
export class AddPollingResponseEntity extends Protocol.PacketEntity {
success = false;
constructor() {
super();
this.command = Protocol.Commands.kRpcAddPolling;
}
}
export class EditPollingRequestEntity extends Protocol.PacketEntity {
entity: PollingEntity = new PollingEntity();
constructor(rcp_id?: number, entity?: PollingEntity) {
super();
this.rpc_id = rcp_id ?? 0;
this.command = Protocol.Commands.kRpcEditPolling;
if (entity) {
this.entity = entity;
}
}
}
export class EditPollingResponseEntity extends Protocol.PacketEntity {
success = false;
constructor() {
super();
this.command = Protocol.Commands.kRpcEditPolling;
}
}
export class DeletePollingRequestEntity extends Protocol.PacketEntity {
uuid: string = "";
constructor(rcp_id?: number, uuid?: string) {
@ -1699,9 +1753,11 @@ export namespace Protocol {
export class SetPollingDataRequestEntity extends Protocol.PacketEntity {
datas: StringKeyValueEntity[] = [];
name: string;
window_id: number = 0;
constructor(
window_id: number,
name: string,
datas?: StringKeyValueEntity[],
rcp_id?: number
) {
@ -1715,6 +1771,7 @@ export namespace Protocol {
this.datas = datas;
}
this.window_id = window_id;
this.name = name;
}
}

View File

@ -340,4 +340,9 @@ export default {
usb7: "USB7",
usb8: "USB8",
polling: "轮询",
"polling name": "轮询名称",
"please input polling name": "请输入轮询名称",
"new polling": "新建轮询",
"add polling": "添加轮询",
"edit polling": "修改轮询",
};

View File

@ -886,35 +886,43 @@ export default defineComponent({
const polling = GlobalData.getInstance()._pollings.find(
(element) => element && element.uuid == window.polling_uuid
);
const datas = await polling_setting_dialog.value.showDialogAsync(
const signal_source = GlobalData.getInstance().signal_source.find(
(element) =>
element && element.uuid == window.signal_source_table_uuid
);
const result = await polling_setting_dialog.value.showDialogAsync(
polling ? polling.name : signal_source ? signal_source.name : null,
polling ? polling.polling_signal_sources : []
);
if (datas) {
try {
const resposne = await GlobalData.getInstance()
.getCurrentClient()
?.setPollingData(window_id, datas);
if (resposne) {
if (resposne.success) {
$q.notify({
color: "positive",
icon: "done",
message: $t.t("set polling data") + $t.t("success") + "!",
position: "top",
timeout: 1500,
});
} else {
$q.notify({
color: "negative",
icon: "warning",
message: $t.t("set polling data") + $t.t("failed") + "!",
position: "top",
timeout: 1500,
});
if (result) {
const { name, datas } = result;
if (name && datas) {
try {
const resposne = await GlobalData.getInstance()
.getCurrentClient()
?.setPollingData(window_id, name, datas);
if (resposne) {
if (resposne.success) {
$q.notify({
color: "positive",
icon: "done",
message: $t.t("set polling data") + $t.t("success") + "!",
position: "top",
timeout: 1500,
});
} else {
$q.notify({
color: "negative",
icon: "warning",
message: $t.t("set polling data") + $t.t("failed") + "!",
position: "top",
timeout: 1500,
});
}
}
} catch (e) {
console.log(e);
}
} catch (e) {
console.log(e);
}
}
}

View File

@ -791,7 +791,6 @@ export default store(function (/* { ssrContext } */) {
),
playload
);
console.log(state.polling_tree);
},
// polling tree end
setDeviceIpAddress(state: StateInterface, playload?: any) {