media_player_client/src/pages/WallPage.vue

553 lines
17 KiB
Vue
Raw Normal View History

2021-08-05 14:23:45 +08:00
<template>
<div
ref="wall"
class="fit items-center justify-evenly wall"
@dragenter="onDragEnter"
@dragleave="onDragLeave"
@dragover="onDragOver"
@drop="onDrop"
>
2021-08-05 17:26:27 +08:00
<div id="windows" style="position: absolute">
2021-08-06 10:54:03 +08:00
<window
@reset_geometry_offset="resetGeometryOffset"
@commit_geometry="commitGeometry"
@close_this_window="closeWindow"
@close_other_windows="closeOtherWindows"
@close_all_windows="closeAllWindows"
2021-08-09 10:59:16 +08:00
@window_fouse_in="windowFocusIn"
:ref="'window_' + item.window_id"
:id="'window_' + item.window_id"
2021-08-05 17:26:27 +08:00
v-for="(item, index) in windows"
2021-08-09 10:59:16 +08:00
:uuid="item.uuid"
2021-08-05 17:26:27 +08:00
:key="index"
class="window"
2021-08-06 10:54:03 +08:00
:signal_source_table_uuid="item.signal_source_table_uuid"
:window="item"
2021-08-05 17:26:27 +08:00
:style="{
top: item.y / wall_height_scaler + 'px',
left: item.x / wall_width_scaler + 'px',
width: item.width / wall_width_scaler + 'px',
height: item.height / wall_height_scaler + 'px',
}"
>
{{ wall_height_scaler }}
{{ wall_width_scaler }}
2021-08-06 10:54:03 +08:00
</window>
2021-08-05 17:26:27 +08:00
</div>
2021-08-06 10:54:03 +08:00
<div ref="wall_grids" @click="onWallGridsClick">
2021-08-05 17:26:27 +08:00
<div
v-for="row in wall_rows"
:key="row"
class="row"
2021-08-05 14:23:45 +08:00
:style="{
height: item_height + 'px',
}"
>
2021-08-05 17:26:27 +08:00
<div
:ref="'item' + (row - 1) * wall_cols * col"
v-for="col in wall_cols"
:key="col"
2021-08-09 10:59:16 +08:00
class="col wall_item wall_item_flag"
2021-08-05 17:26:27 +08:00
:style="{
width: item_witdh + 'px',
height: item_height + 'px',
}"
@resize="(evt) => loga(evt)"
>
<q-popup-proxy context-menu>
2021-08-05 17:26:27 +08:00
<q-popup-proxy context-menu />
<q-list>
<q-item clickable v-close-popup @click="closeAllWindows">
2021-08-05 17:26:27 +08:00
<q-item-section avatar>
<q-icon name="close" color="red" />
</q-item-section>
<q-item-section> {{ $t("close all windwos") }} </q-item-section>
</q-item>
</q-list>
</q-popup-proxy>
</div>
2021-08-05 14:23:45 +08:00
</div>
</div>
</div>
</template>
<style scoped>
.wall {
border: 1px solid black;
}
.wall_item {
2021-08-06 10:54:03 +08:00
border: 1px solid gray;
2021-08-05 14:23:45 +08:00
}
2021-08-05 17:26:27 +08:00
.window {
position: absolute;
}
2021-08-09 10:59:16 +08:00
.wall_item_flag {
}
2021-08-05 14:23:45 +08:00
</style>
<script lang="ts">
import GlobalData from "src/common/GlobalData";
2021-08-06 10:54:03 +08:00
import {
defineComponent,
ref,
Ref,
computed,
watch,
onMounted,
getCurrentInstance,
} from "vue";
2021-08-05 14:23:45 +08:00
import { Common } from "src/common/Common";
import { Protocol } from "src/entities/WSProtocol";
2021-08-06 10:54:03 +08:00
import Window from "src/components/Window.vue";
2021-08-05 14:23:45 +08:00
import { useI18n } from "vue-i18n";
import { useStore } from "src/store";
2021-08-06 10:54:03 +08:00
import EventBus, { EventNamesDefine } from "src/common/EventBus";
2021-08-09 10:59:16 +08:00
import {
WindowOpenNotifyEntity,
WindowStates,
} from "src/entities/MultimediaWindowEntity";
import WindowOtherStateChangeNotifyEntity from "src/entities/WindowOtherStateChangeNotifyEntity";
2021-08-05 14:23:45 +08:00
interface _OptionsType {
$t: any;
$store: ReturnType<typeof useStore> | undefined | null;
}
const _getSignalSources = async () => {
const global_data = GlobalData.getInstance();
return (await global_data
.getCurrentClient()
?.getSignalSources()) as Protocol.GetSignalSourcesResponse;
};
const _initSignalSourceTree = async (options: _OptionsType) => {
const $store = options?.$store;
if ($store) {
try {
let response = await _getSignalSources();
if (response) {
$store.commit("buildSignalSourceTree", { options, response });
GlobalData.getInstance().signal_source = response.signal_sources;
}
} catch (e) {
console.error(e);
}
}
};
const _getApplicationConfig = async (options: _OptionsType) => {
const global_data = GlobalData.getInstance();
global_data.applicationConfig = (
await global_data.getCurrentClient()?.getApplicationSettins()
)?.config;
let $store = options.$store;
if (global_data.applicationConfig && $store) {
$store.commit("setWallCol", global_data.applicationConfig.wall_col);
$store.commit("setWallRow", global_data.applicationConfig.wall_row);
$store.commit(
"setDeviceScreenWidth",
global_data.applicationConfig.screen_width
);
$store.commit(
"setDeviceScreenHeight",
global_data.applicationConfig.screen_height
);
}
};
2021-08-05 17:26:27 +08:00
const _getWindows = async (options: _OptionsType) => {
const global_data = GlobalData.getInstance();
let windows = (await global_data.getCurrentClient()?.getWindows())?.windows;
let $store = options.$store;
if (windows && $store) {
$store.commit("setWindows", windows);
}
};
2021-08-05 14:23:45 +08:00
const _initialize = async (options: _OptionsType) => {
const global_data = GlobalData.getInstance();
let client = global_data.getCurrentClient();
if (client) {
while (!client.is_login) {
await Common.waitFor(100);
}
2021-08-09 15:05:14 +08:00
await _getApplicationConfig(options);
await _initSignalSourceTree(options).then(() => {
2021-08-05 17:26:27 +08:00
_getWindows(options);
});
2021-08-05 14:23:45 +08:00
}
};
export default defineComponent({
name: "PageWall",
2021-08-06 10:54:03 +08:00
components: { Window },
2021-08-05 14:23:45 +08:00
setup() {
const $store = useStore();
const $t = useI18n();
2021-08-05 17:26:27 +08:00
const windows = computed({
get: () => $store.state.windows,
set: (val) => $store.commit("setWindows", val),
});
2021-08-05 14:23:45 +08:00
const wall_rows = computed({
get: () => $store.state.wall_row,
set: (val) => $store.commit("setWallRow", val),
});
const wall_cols = computed({
get: () => $store.state.wall_col,
set: (val) => $store.commit("setWallCol", val),
});
const wall: Ref<HTMLElement | null> = ref(null);
2021-08-09 15:05:14 +08:00
let item_witdh = ref(0);
const item_height = ref(0);
2021-08-05 14:23:45 +08:00
2021-08-05 17:26:27 +08:00
const wall_width_scaler = ref(0);
const wall_height_scaler = ref(0);
const calcWallVWScaler = () => {
if (wall.value && wall.value.parentElement) {
wall_height_scaler.value =
$store.state.device_screen_height /
(item_height.value * wall_rows.value);
wall_width_scaler.value =
$store.state.device_screen_width /
wall.value.parentElement.offsetWidth;
wall_height_scaler.value += 0.1;
wall_width_scaler.value += 0.05;
}
};
2021-08-09 15:05:14 +08:00
const calcWallItemWH = () => {
item_witdh.value =
wall?.value?.parentElement?.offsetWidth ?? 0 / wall_cols.value;
if (wall.value && wall.value.parentElement) {
const wv_scaler =
$store.state.device_screen_width / $store.state.device_screen_height;
item_height.value =
wall.value.parentElement.offsetWidth / wv_scaler / wall_rows.value;
} else {
item_height.value = 0;
}
};
2021-08-06 10:54:03 +08:00
EventBus.getInstance().on(EventNamesDefine.WindowResize, () => {
2021-08-05 17:26:27 +08:00
calcWallVWScaler();
2021-08-09 15:05:14 +08:00
calcWallItemWH();
2021-08-05 17:26:27 +08:00
});
interface _ResponseMessage {
packet: Protocol.PacketEntity;
data: string;
}
EventBus.getInstance().on(
EventNamesDefine.ResponseMessage,
(response: _ResponseMessage) => {
try {
if ((response.packet.flag = Protocol.PacketEntity.FLAG_NOTIFY)) {
switch (response.packet.command) {
case Protocol.Commands.kCloseWindow:
{
const temp = JSON.parse(response.data);
if (temp && temp.window_id) {
$store.commit("removeWindow", {
window_id: temp.window_id,
});
}
}
break;
case Protocol.Commands.kMoveWindow:
{
const temp = JSON.parse(response.data);
if (temp && temp.window_id) {
const window = $store.state.windows.find(
(item) => item.window_id == temp.window_id
);
if (window) {
$store.commit("setWindowPropertys", [
{
window,
property_name: "x",
value: temp.x ?? 0,
},
{
window,
property_name: "y",
value: temp.y ?? 0,
},
]);
}
}
}
break;
case Protocol.Commands.kResizeWindow:
{
const temp = JSON.parse(response.data);
if (temp && temp.window_id) {
const window = $store.state.windows.find(
(item) => item.window_id == temp.window_id
);
if (window) {
$store.commit("setWindowPropertys", [
{
window,
property_name: "width",
value: temp.width ?? 0,
},
{
window,
property_name: "height",
value: temp.height ?? 0,
},
]);
}
}
}
break;
case Protocol.Commands.kOpenWindow:
{
const temp = JSON.parse(
response.data
) as WindowOpenNotifyEntity;
if (temp) {
$store.commit("pushWindow", temp);
}
}
break;
2021-08-09 10:59:16 +08:00
case Protocol.Commands.kWindowOtherStateChanged:
{
const temp = JSON.parse(
response.data
) as WindowOtherStateChangeNotifyEntity;
if (temp && temp.window_id) {
const window = $store.state.windows.find(
(item) => item.window_id == temp.window_id
);
if (window) {
window.window_state; //
$store.commit("setWindowProperty", {
window,
property_name: "window_state",
value: new WindowStates(
temp.playing,
temp.focus,
temp.muted
),
});
}
}
}
break;
default:
console.log(response.packet);
break;
}
}
} catch {}
}
);
2021-08-09 15:05:14 +08:00
_initialize({
$t,
$store,
}).then(() => {
calcWallItemWH();
2021-08-05 17:26:27 +08:00
calcWallVWScaler();
});
2021-08-05 14:23:45 +08:00
return {
2021-08-05 17:26:27 +08:00
windows,
2021-08-05 14:23:45 +08:00
wall,
wall_rows,
wall_cols,
item_witdh,
item_height,
2021-08-05 17:26:27 +08:00
wall_width_scaler,
wall_height_scaler,
2021-08-05 14:23:45 +08:00
loga(a: any) {
console.log(a);
},
onDrop(e: DragEvent) {
e.preventDefault();
let target = e.target as any;
if (target) {
target.classList.remove("drag-enter");
}
let uuid = e.dataTransfer?.getData("uuid");
if (uuid) {
let signal_sources = GlobalData.getInstance().signal_source.filter(
(item) => (item as any)?.uuid == uuid
);
if (signal_sources.length) {
let signal_source = signal_sources[0];
2021-08-07 11:04:39 +08:00
if (signal_source) {
2021-08-09 10:59:16 +08:00
let dom: HTMLElement | null = e.target as HTMLElement;
2021-08-07 11:04:39 +08:00
if (dom) {
2021-08-09 10:59:16 +08:00
if (dom.classList.contains("wall_item_flag")) {
GlobalData.getInstance()
.getCurrentClient()
?.openWindow(
new Protocol.OpenWindowRequestEntity(
signal_source.uuid,
(dom.offsetLeft - (wall.value?.offsetLeft ?? 0)) *
wall_width_scaler.value,
(dom.offsetTop - (wall.value?.offsetTop ?? 0)) *
wall_height_scaler.value,
dom.offsetWidth * wall_width_scaler.value,
dom.offsetHeight * wall_height_scaler.value
)
);
} else if (dom.classList.contains("window_flag")) {
let uuid = dom.getAttribute("uuid");
if (uuid) {
let window = $store.state.windows.find(
(item) => item.uuid == uuid
);
if (window) {
let client = GlobalData.getInstance().getCurrentClient();
if (client) {
let x = window.x;
let y = window.y;
let width = window.width;
let height = window.height;
client.closeWindow(window.window_id);
setTimeout(() => {
client?.openWindow(
new Protocol.OpenWindowRequestEntity(
signal_source.uuid,
x,
y,
width,
height
)
);
}, 100);
}
}
}
}
2021-08-07 11:04:39 +08:00
}
}
2021-08-05 14:23:45 +08:00
}
}
},
onDragEnter(e: DragEvent) {
2021-08-09 10:59:16 +08:00
let target: HTMLElement | null = e.target as HTMLElement;
2021-08-05 14:23:45 +08:00
if (target && target.draggable !== true) {
2021-08-09 10:59:16 +08:00
while (
target &&
!target.classList.contains("window_flag") &&
!target.classList.contains("wall_item_flag")
) {
target = target.parentElement;
}
target?.classList.add("drag-enter");
2021-08-05 14:23:45 +08:00
}
},
onDragLeave(e: DragEvent) {
2021-08-09 10:59:16 +08:00
let target: HTMLElement = e.target as HTMLElement;
target?.classList.remove("drag-enter");
2021-08-05 14:23:45 +08:00
},
onDragOver(e: DragEvent) {
e.preventDefault();
},
2021-08-06 10:54:03 +08:00
onWallGridsClick(e: MouseEvent) {
EventBus.getInstance().emit(EventNamesDefine.UnSelectAllWindows);
},
resetGeometryOffset(
2021-08-06 10:54:03 +08:00
window: any,
offset_x: number,
offset_y: number,
offset_width: number,
offset_height: number
) {
2021-08-06 10:54:03 +08:00
$store.commit("setWindowPropertys", [
{
window,
property_name: "x",
value: window.x + offset_x * wall_width_scaler.value,
},
{
window,
property_name: "y",
value: window.y + offset_y * wall_height_scaler.value,
},
{
window,
property_name: "width",
value: Math.max(
window.width + offset_width * wall_height_scaler.value,
32
),
},
{
window,
property_name: "height",
value: Math.max(
window.height + offset_height * wall_height_scaler.value,
32
),
},
2021-08-06 10:54:03 +08:00
]);
},
commitGeometry(window: any) {
const win = window as WindowOpenNotifyEntity;
if (win) {
GlobalData.getInstance()
.getCurrentClient()
?.moveWindow(win.window_id, win.x, win.y);
GlobalData.getInstance()
.getCurrentClient()
?.resizeWindow(win.window_id, win.width, win.height);
}
},
closeAllWindows() {
for (const window of $store.state.windows) {
if (window) {
GlobalData.getInstance()
.getCurrentClient()
?.closeWindow(window.window_id);
}
}
},
2021-08-09 10:59:16 +08:00
windowFocusIn(window_id: number) {
GlobalData.getInstance().getCurrentClient()?.focusIn(window_id);
},
closeOtherWindows(window_id: number) {
console.log(window_id);
for (const window of $store.state.windows) {
if (window && window.window_id != window_id) {
GlobalData.getInstance()
.getCurrentClient()
?.closeWindow(window.window_id);
}
}
},
closeWindow(window_id: number) {
GlobalData.getInstance().getCurrentClient()?.closeWindow(window_id);
},
2021-08-05 14:23:45 +08:00
};
},
});
</script>