Newer
Older

Дмитрий Малюгин
committed
<script setup lang="ts">
import { useInterfaceStore } from '@/app/stores/interface';
import { useDataStore } from '@/app/stores/data';
import { useAuthorizationStore } from '@/app/stores/authorization';
import { useWebsocketStore } from '@/app/stores/websocket';
import type { IEntity } from '@/app/interfaces/environment';
import type { IImageMainInfo } from '@/app/interfaces';
import { createEntity, fetchForEntities } from '@/app/helpers';
import cookies from '@/app/plugins/Cookie';
import { setDefaultPageBackground } from '@/app/helpers/images';
const dataStore = useDataStore();
const interfaceStore = useInterfaceStore();
const authorizationStore = useAuthorizationStore();
const websocketStore = useWebsocketStore();
const currentPageUuid = computed(() => cookies.get('current_page_uuid'));
const entities = computed(() => dataStore.entities);
const backgroundUrl = computed<string>(() => interfaceStore.pageBackground);
const defaultBackgroundUrl = computed<string>(() => interfaceStore.defaultPageBackground);
const isFetchedForBackground = computed(() => interfaceStore.isFetchedForBackground);
const isDarkMode = computed(() => interfaceStore.isDarkMode);
// const pageTitle = computed(() => dataStore.currentPage.page_title);
const isMenuVisible = ref<boolean>(false);
const isEditMode = ref<boolean>(false);
const isModalUploadFile = ref<boolean>(false);
const backgroundImageInfo = ref<IImageMainInfo>({
imageUrl: backgroundUrl.value,
image_width: 0,
image_height: 0
});
onMounted(() => {
const onKeydown = (event) => {
if (event.key === 'Alt') isEditMode.value = !isEditMode.value;
if (event.key === 'Escape') isMenuVisible.value = !isMenuVisible.value;
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
};
document.addEventListener('keydown', onKeydown);
const getPageBackgroundData = {
event: 'getPageBackground',
body: {
page_uuid: ''
}
};
websocketStore.setInitialDataToSend(getPageBackgroundData);
});
const unwatchBackground = watch([isFetchedForBackground], () => {
if (isFetchedForBackground.value) {
fetchForEntities(currentPageUuid.value);
unwatchBackground();
}
});
const createNewEntity = (newEntity: IEntity) => {
createEntity(newEntity);
};
const uploadFile = ($event: Event) => {
const target = $event.target as HTMLInputElement;
if (target && target.files && target.files?.[0]) {
const image = new Image();
const file = target.files![0];
const url = URL.createObjectURL(file);
image.src = url;
image.onload = function () {
backgroundImageInfo.value.imageUrl = url;
backgroundImageInfo.value.image_width = image.width;
backgroundImageInfo.value.image_height = image.height;
isModalUploadFile.value = true;
};
}
};
const saveImage = (finalImageUrl: string) => {
interfaceStore.editPageBackground(finalImageUrl);
isModalUploadFile.value = false;
};
const openMenu = () => (isMenuVisible.value = true);

Дмитрий Малюгин
committed
</script>
<template>
<PageHeader v-model:isEditMode="isEditMode" :title="'Home page'" />
<Drawer v-model:isVisible="isMenuVisible" theme="black">
<template #header><SidebarMenuHeader /></template>
<SidebarMenuContent class="relative z-50" />
<TelegramSection />
<CropImageModal
v-model:isVisible="isModalUploadFile"
v-model:imageInfo="backgroundImageInfo"
@saveImage="saveImage"
/>
<main
id="pageContainer"
class="flex flex-col"
:style="`background-color: ${isDarkMode ? 'black' : 'light'}`"
>
<article style="min-height: 200px" class="backgroundContainer relative">
<img
:src="backgroundUrl"
alt="Background image"
class="w-full pointer-events-none select-none"
/>
<PageBackgroundMenu
:isBackgroundDefault="backgroundUrl !== defaultBackgroundUrl"
@uploadFile="uploadFile"
@setDefaultBackground="setDefaultPageBackground"
/>
</article>
<article class="flex items-start justify-center">
<Suspense>
<div ref="entitiesContainer" class="w-full pt-4">
<EntitiesList
:entities="entities"
:isEditMode="isEditMode"
@createEntity="createNewEntity"
/>
</div>
<template #fallback><BaseLoader /></template
></Suspense>
</article>
</main>

Дмитрий Малюгин
committed
</template>
<style lang="scss">
.backgroundContainer > .changeImageBlock,
.backgroundContainer > .returnDefaultImageBlock {
opacity: 0;
}
.backgroundContainer:hover > .changeImageBlock,
.backgroundContainer:hover > .returnDefaultImageBlock {
opacity: 100;
}
.telegramContainer > .telegramText {
opacity: 0;
right: 0;
top: 50%;
transform: translateY(-50%);
}
.telegramContainer:hover > .telegramText {
opacity: 100;
right: 104%;
}
.telegramContainer:hover > a {
filter: brightness(0.75);
}
</style>