media_player_client/src/components/ModeDialog.vue

533 lines
17 KiB
Vue
Raw Normal View History

<template>
2022-01-25 19:41:28 +08:00
<q-dialog
persistent
v-model="show_dialog"
@before-hide="resetData"
@keydown="
(evt) => {
if (!loading && evt.keyCode == 27) {
2022-01-25 19:41:28 +08:00
show_dialog = false;
}
}
"
>
<q-card class="overflow-hidden" style="overflow-y: scroll; max-width: 45vw">
<q-form @submit="onSubmit">
<q-card-section class="q-ma-none q-pa-sm">
<div class="row">
2021-08-17 17:17:51 +08:00
<div class="col-auto text-h6">
{{
type == 1
2021-08-24 15:20:01 +08:00
? $t("add mode")
: type == 2
2021-08-24 15:20:01 +08:00
? $t("edit mode")
2021-08-25 17:30:02 +08:00
: $t("add mode")
}}
</div>
2021-08-17 17:17:51 +08:00
<q-space />
<div>
<q-btn
:loading="loading"
flat
round
icon="close"
:disable="loading"
color="red"
v-close-popup
>
<q-tooltip>
{{ $t("close") }}
</q-tooltip>
</q-btn>
</div>
</div>
</q-card-section>
<q-separator />
<q-card-section style="max-height: 50vh; width: 45vw" class="scroll">
<q-list>
2021-08-24 15:20:01 +08:00
<q-item>
<q-item-label>{{ $t("parent group") }}:</q-item-label>
</q-item>
2021-08-24 15:20:01 +08:00
<q-item class="q-pa-none q-ma-none">
<q-item-section style="padding-right: 10px">
<q-tree
ref="tree"
class="scroll"
:class="loading ? 'disable_tree' : ''"
v-model:selected="selected"
:nodes="tree_nodes"
default-expand-all
node-key="uuid"
labelKey="name"
filter="group filter"
:filter-method="treeNodesFilter"
>
<template v-slot:default-header="prop">
<q-item
class="full-width"
:class="
prop.tree.selected == prop.key ? 'item-selected-bg' : ''
"
>
<q-item-section avatar>
<q-icon
:name="'img:source_icon/group.png'"
color="orange"
size="28px"
class="q-mr-sm"
/>
</q-item-section>
<q-item-section>
<div class="text-weight-bold text-primary">
{{ prop.node.name }}
</div>
</q-item-section>
</q-item>
</template>
</q-tree>
</q-item-section>
</q-item>
<q-item>
<q-item-section>
<q-input
autofocus
:loading="loading"
:disable="loading"
filled
v-model="name"
2021-08-24 15:20:01 +08:00
:label="$t('mode name')"
:hint="$t('please input mode name')"
lazy-rules
:rules="[
(val) =>
(val && val.length > 0) || $t('Please type something'),
]"
@keydown="
(evt) => {
if (evt.keyCode == 13) {
$refs?.accept?.click();
}
}
"
>
<template v-if="name" v-slot:append>
<q-icon
name="cancel"
@click.stop="name = null"
class="cursor-pointer"
/>
</template>
</q-input>
</q-item-section>
</q-item>
2021-09-07 18:03:50 +08:00
<q-item>
<q-item-section>
<q-input
autofocus
:loading="loading"
:disable="loading"
filled
type="number"
min="0"
max="65535"
v-model.number="index"
:label="$t('mode index')"
:hint="$t('please input mode index')"
lazy-rules
:rules="[checkIndex]"
@keydown="
(evt) => {
if (evt.keyCode == 13) {
$refs?.accept?.click();
}
}
"
>
</q-input>
</q-item-section>
</q-item>
2022-08-26 15:08:39 +08:00
<q-item>
<q-card class="full-width" style="height: 25vh">
<q-card-section
><span>{{ $t("joint action equipment") }}</span>
<q-btn
style="float: right; top: -10px"
round
flat
icon="add"
color="green"
@click="addEquipment"
>
<q-tooltip>{{ $t("add") }}</q-tooltip>
</q-btn>
</q-card-section>
<q-separator />
<q-scroll-area style="height: 19vh" class="full-width scroll">
<q-list class="fit">
<q-item v-for="(item, index) of equipments" :key="index">
<q-item-section avatar class="q-mr-md">
{{ $t("equipment") }}:
</q-item-section>
<q-item-section>
<q-select
:options="equipment_options"
emit-value
map-options
v-model="item.key"
option-value="key"
option-label="value"
lazy-rules
/>
<!-- {{ getEquipmentName(item.key) }} -->
</q-item-section>
<q-item-section avatar class="q-mr-md">
{{ $t("mode") }}:
</q-item-section>
<q-item-section>
<q-input v-model="item.value"></q-input>
</q-item-section>
<q-space />
<q-item-section avatar>
<q-btn
@click="deleteEquipment(index)"
round
flat
icon="delete"
color="red"
>
<q-tooltip>{{ $t("delete") }}</q-tooltip>
</q-btn>
</q-item-section>
</q-item>
</q-list>
</q-scroll-area>
</q-card>
</q-item>
</q-list>
</q-card-section>
<q-separator />
<q-card-actions align="right">
<q-btn
:loading="loading"
flat
:label="$t('Cancel')"
2022-07-04 14:20:00 +08:00
no-caps
color="primary"
v-close-popup
/>
<q-btn
ref="accept"
flat
:label="$t('Accept')"
2022-07-04 14:20:00 +08:00
no-caps
:loading="loading"
type="submit"
color="primary"
/>
</q-card-actions>
</q-form>
</q-card>
</q-dialog>
2022-08-26 15:08:39 +08:00
<list-joint-action-equipment-dialog
ref="list_joint_action_equipment_dialog"
/>
</template>
<style scoped>
.disable_tree {
background: #9e9e9e;
cursor: wait;
pointer-events: none;
}
</style>
<script lang="ts">
2022-08-26 15:08:39 +08:00
import { defineComponent, ref, watch, computed, Ref } from "vue";
import { useStore } from "src/store";
import GlobalData from "src/common/GlobalData";
import { useQuasar } from "quasar";
import { useI18n } from "vue-i18n";
2021-09-07 18:03:50 +08:00
import { api } from "boot/axios";
import { HttpProtocol } from "src/entities/HttpProtocol";
2022-08-26 15:08:39 +08:00
import { StringKeyValueEntity } from "src/entities/StringKeyValueEntity";
import ListJointActionEquipmentDialog from "src/components/ListJointActionEquipmentDialog.vue";
import JointActionEquipmentTableEntity from "src/entities/JointActionEquipmentTableEntity";
import EventBus, { EventNamesDefine } from "src/common/EventBus";
export default defineComponent({
2021-08-24 15:20:01 +08:00
name: "ComponentModeDialog",
2022-08-26 15:08:39 +08:00
components: { ListJointActionEquipmentDialog },
setup() {
let $store = useStore();
let $q = useQuasar();
let $t = useI18n();
let show_dialog = ref(false);
let type = ref(1);
let name = ref(null);
let backup_index = 0;
2021-09-07 18:03:50 +08:00
let index = ref(0);
2021-08-10 15:09:11 +08:00
let uuid = ref("");
const selected: any = ref(null);
let loading = ref(false);
2022-08-26 15:08:39 +08:00
const equipments: Ref<StringKeyValueEntity[]> = ref([]);
const list_joint_action_equipment_dialog: Ref<any> = ref(null);
const equipment_options: Ref<StringKeyValueEntity[]> = ref([]);
const tree_nodes = computed({
2021-08-24 15:20:01 +08:00
get: () => $store.state.mode_tree,
2021-08-10 15:09:11 +08:00
set: (val) => {},
});
watch(
() => selected.value,
(newValue, oldValue) => {
if (newValue == null) {
selected.value = "";
}
}
);
2021-08-24 15:20:01 +08:00
const requestAddMode = async () => {
2021-08-10 15:09:11 +08:00
let response = await GlobalData.getInstance()
.getCurrentClient()
2022-08-26 15:08:39 +08:00
?.addMode(
selected.value,
name.value ?? "",
index.value,
equipments.value
);
2021-08-10 15:09:11 +08:00
if (response) {
$q.notify({
color: response.success ? "positive" : "negative",
icon: response.success ? "done" : "warning",
message:
2021-08-24 15:20:01 +08:00
$t.t("add mode") +
2021-08-10 15:09:11 +08:00
(response.success ? $t.t("success") : $t.t("fail")) +
"!",
position: "top",
2021-12-22 11:25:04 +08:00
timeout: 1500,
2021-08-10 15:09:11 +08:00
});
}
};
2021-08-24 15:20:01 +08:00
const requestEditMode = async () => {
2021-08-10 15:09:11 +08:00
let response = await GlobalData.getInstance()
.getCurrentClient()
2022-08-26 15:08:39 +08:00
?.editMode(
uuid.value,
name.value ?? "",
index.value,
selected.value,
equipments.value
);
2021-08-10 15:09:11 +08:00
if (response) {
$q.notify({
color: response.success ? "positive" : "negative",
icon: response.success ? "done" : "warning",
message:
2021-08-24 15:20:01 +08:00
$t.t("edit mode") +
2021-08-10 15:09:11 +08:00
(response.success ? $t.t("success") : $t.t("fail")) +
"!",
position: "top",
2021-12-22 11:25:04 +08:00
timeout: 1500,
2021-08-10 15:09:11 +08:00
});
}
};
2022-08-26 15:08:39 +08:00
const updateEquipmentOptions = () => {
GlobalData.getInstance()
.getCurrentClient()
?.getJointActionEquipments()
.then((response) => {
if (response && Array.isArray(response.entities)) {
equipment_options.value = [];
for (const item of response.entities) {
if (item) {
equipment_options.value.push({
key: item.uuid,
value: item.name,
});
}
}
}
});
};
EventBus.getInstance().on(
EventNamesDefine.RefreshJointActionEquipmentList,
() => {
updateEquipmentOptions();
}
);
return {
show_dialog,
type,
name,
2021-09-07 18:03:50 +08:00
index,
2021-08-10 15:09:11 +08:00
uuid,
selected,
loading,
tree_nodes,
2022-08-26 15:08:39 +08:00
equipments,
equipment_options,
list_joint_action_equipment_dialog,
showDialog(options: any) {
if (options) {
type.value = options.type ?? 1;
2021-08-10 15:09:11 +08:00
if (type.value == 2) {
name.value = options.data?.name ?? null;
2021-08-24 15:20:01 +08:00
selected.value = options.data?.item_data?.group_uuid ?? null;
uuid.value = options.data?.item_data?.uuid ?? null;
2021-09-07 18:03:50 +08:00
index.value = options.data?.item_data?.number ?? 0;
backup_index = index.value;
2022-08-26 15:08:39 +08:00
equipments.value =
options.data?.item_data?.joint_action_equipments ?? [];
2021-08-24 15:20:01 +08:00
} else {
selected.value = options.data?.uuid ?? null;
uuid.value = options.data?.uuid ?? null;
index.value = 0;
2021-08-10 15:09:11 +08:00
}
2022-08-26 15:08:39 +08:00
updateEquipmentOptions();
equipments.value = [];
{
let obj = null;
if (
typeof options.data?.item_data?.joint_action_equipments ==
"string"
) {
try {
obj = JSON.parse(
options.data?.item_data?.joint_action_equipments
);
} catch (e) {
console.error(e);
}
}
if (Array.isArray(obj)) {
for (const item of obj) {
if (item && typeof item != "undefined") {
const temp_item = item as StringKeyValueEntity;
if (temp_item) {
const f = equipment_options.value.find(
(element) => element && element.key == temp_item.key
);
if (f) {
equipments.value.push(temp_item);
}
}
}
}
}
}
}
show_dialog.value = true;
},
resetData() {
loading.value = false;
2022-08-26 15:08:39 +08:00
equipments.value = [];
selected.value = null;
name.value = null;
type.value = 1;
backup_index = 0;
2021-08-10 15:09:11 +08:00
},
treeNodesFilter(node: any, filter: any) {
2021-08-24 15:20:01 +08:00
return node.is_group;
},
2021-09-07 18:03:50 +08:00
checkIndex(val: number) {
return new Promise(async (resolve, reject) => {
if (val < 0) {
resolve($t.t("Please type 0~65535"));
} else {
try {
let url = GlobalData.getInstance().createCurrentRequestUrl();
if (!url) {
url = new URL(window.location.hostname);
}
url.pathname = HttpProtocol.RequestCheckModeIndex;
url.searchParams.append("index", index.value.toString());
let response = (await api.get(url.toString())).data as boolean;
if (typeof response != "boolean") {
try {
response = JSON.parse(response);
} catch {
response = false;
}
}
if (index.value == backup_index) {
response = true;
}
2021-09-07 18:03:50 +08:00
if (!response) {
resolve($t.t("index exised") + "!");
2021-09-07 18:03:50 +08:00
} else {
resolve(true);
}
} catch (e) {
resolve($t.t("check error"));
}
}
});
},
async onSubmit() {
loading.value = true;
try {
2021-08-24 15:20:01 +08:00
await (type.value == 2 ? requestEditMode() : requestAddMode());
show_dialog.value = false;
} catch {}
loading.value = false;
},
2022-08-26 15:08:39 +08:00
async addEquipment() {
const response = await GlobalData.getInstance()
.getCurrentClient()
?.getJointActionEquipments();
if (response && Array.isArray(response.entities)) {
if (response.entities.length) {
const v = new StringKeyValueEntity();
v.key = response.entities[0].uuid;
v.value = "mode name";
equipments.value.push(v);
} else {
$q.notify({
color: "warning",
icon: "warning",
message: $t.t(
"joint action equipment is empty! please add equipment first!"
),
position: "top",
timeout: 1500,
});
if (list_joint_action_equipment_dialog.value) {
list_joint_action_equipment_dialog.value.showDialog();
}
}
} else {
$q.notify({
color: "negative",
icon: "warning",
message: "data error!",
position: "top",
timeout: 1500,
});
}
},
deleteEquipment(index: number) {
equipments.value.splice(index, 1);
},
};
},
});
</script>