primevue-mirror/layouts/AppWrapper.vue

67 lines
2.2 KiB
Vue
Raw Normal View History

2022-02-23 11:42:11 +00:00
<template>
2022-02-23 19:01:47 +00:00
<router-view></router-view>
2022-02-23 19:52:21 +00:00
</template>
<script>
2022-09-06 11:52:18 +00:00
import EventBus from './AppEventBus';
2022-04-07 12:57:53 +00:00
import NewsService from '@/service/NewsService';
2022-02-23 19:52:21 +00:00
export default {
themeChangeListener: null,
2022-04-07 12:57:53 +00:00
newsActivate: null,
newsService: null,
data() {
return {
storageKey: 'primevue'
}
},
created() {
this.newsService = new NewsService();
},
2022-02-23 19:52:21 +00:00
mounted() {
2022-04-07 12:57:53 +00:00
this.newsActivate = () => {
this.newsService.fetchNews().then(data => {
this.$appState.announcement = data;
const itemString = localStorage.getItem(this.storageKey);
if (itemString) {
const item = JSON.parse(itemString);
if (item.hiddenNews && item.hiddenNews !== data.id) {
this.$appState.newsActive = true;
}
else this.$appState.newsActive = false;
}
else {
this.$appState.newsActive = true;
}
});
};
2022-02-23 19:52:21 +00:00
this.themeChangeListener = (event) => {
const elementId = 'theme-link';
const linkElement = document.getElementById(elementId);
const cloneLinkElement = linkElement.cloneNode(true);
const newThemeUrl = linkElement.getAttribute('href').replace(this.$appState.theme, event.theme);
cloneLinkElement.setAttribute('id', elementId + '-clone');
cloneLinkElement.setAttribute('href', newThemeUrl);
cloneLinkElement.addEventListener('load', () => {
linkElement.remove();
cloneLinkElement.setAttribute('id', elementId);
});
linkElement.parentNode.insertBefore(cloneLinkElement, linkElement.nextSibling);
this.$appState.theme = event.theme;
this.$appState.darkTheme = event.dark;
};
2022-04-07 13:25:08 +00:00
EventBus.on('theme-change', this.themeChangeListener);
2022-04-07 12:57:53 +00:00
EventBus.on('news-activate', this.newsActivate);
2022-02-23 19:52:21 +00:00
},
beforeUnmount() {
EventBus.off('theme-change', this.themeChangeListener);
2022-04-07 12:57:53 +00:00
EventBus.off('news-activate', this.newsActivate);
2022-02-23 19:52:21 +00:00
}
}
</script>