forked from FoundKeyGang/FoundKey
client: refactor classic.header.vue to composition api
This commit is contained in:
parent
20f45e0179
commit
9a22905e85
1 changed files with 43 additions and 74 deletions
|
@ -7,13 +7,13 @@
|
||||||
</MkA>
|
</MkA>
|
||||||
<template v-for="item in menu">
|
<template v-for="item in menu">
|
||||||
<div v-if="item === '-'" class="divider"></div>
|
<div v-if="item === '-'" class="divider"></div>
|
||||||
<component :is="menuDef[item].to ? 'MkA' : 'button'" v-else-if="menuDef[item] && (menuDef[item].show !== false)" v-click-anime v-tooltip="$ts[menuDef[item].title]" class="item _button" :class="item" active-class="active" :to="menuDef[item].to" v-on="menuDef[item].action ? { click: menuDef[item].action } : {}">
|
<component :is="menuDef[item].to ? 'MkA' : 'button'" v-else-if="menuDef[item] && (menuDef[item].show !== false)" v-click-anime v-tooltip="i18n.ts[menuDef[item].title]" class="item _button" :class="item" active-class="active" :to="menuDef[item].to" v-on="menuDef[item].action ? { click: menuDef[item].action } : {}">
|
||||||
<i class="fa-fw" :class="menuDef[item].icon"></i>
|
<i class="fa-fw" :class="menuDef[item].icon"></i>
|
||||||
<span v-if="menuDef[item].indicated" class="indicator"><i class="fas fa-circle"></i></span>
|
<span v-if="menuDef[item].indicated" class="indicator"><i class="fas fa-circle"></i></span>
|
||||||
</component>
|
</component>
|
||||||
</template>
|
</template>
|
||||||
<div class="divider"></div>
|
<div class="divider"></div>
|
||||||
<MkA v-if="$i.isAdmin || $i.isModerator" v-click-anime v-tooltip="$ts.controlPanel" class="item" active-class="active" to="/admin" :behavior="settingsWindowed ? 'modalWindow' : null">
|
<MkA v-if="iAmModerator" v-click-anime v-tooltip="i18n.ts.controlPanel" class="item" active-class="active" to="/admin" :behavior="settingsWindowed ? 'modalWindow' : null">
|
||||||
<i class="fas fa-door-open fa-fw"></i>
|
<i class="fas fa-door-open fa-fw"></i>
|
||||||
</MkA>
|
</MkA>
|
||||||
<button v-click-anime class="item _button" @click="more">
|
<button v-click-anime class="item _button" @click="more">
|
||||||
|
@ -25,7 +25,7 @@
|
||||||
<MkA v-click-anime v-tooltip="$ts.settings" class="item" active-class="active" to="/settings" :behavior="settingsWindowed ? 'modalWindow' : null">
|
<MkA v-click-anime v-tooltip="$ts.settings" class="item" active-class="active" to="/settings" :behavior="settingsWindowed ? 'modalWindow' : null">
|
||||||
<i class="fas fa-cog fa-fw"></i>
|
<i class="fas fa-cog fa-fw"></i>
|
||||||
</MkA>
|
</MkA>
|
||||||
<button v-click-anime class="item _button account" @click="openAccountMenu">
|
<button v-click-anime class="item _button account" @click="openAccountMenuWrapper">
|
||||||
<MkAvatar :user="$i" class="avatar"/><MkAcct class="acct" :user="$i"/>
|
<MkAvatar :user="$i" class="avatar"/><MkAcct class="acct" :user="$i"/>
|
||||||
</button>
|
</button>
|
||||||
<div class="post" @click="post">
|
<div class="post" @click="post">
|
||||||
|
@ -38,83 +38,52 @@
|
||||||
</div>
|
</div>
|
||||||
</template>
|
</template>
|
||||||
|
|
||||||
<script lang="ts">
|
<script lang="ts" setup>
|
||||||
import { defineAsyncComponent, defineComponent } from 'vue';
|
import { defineAsyncComponent, watch } from 'vue';
|
||||||
import { host } from '@/config';
|
|
||||||
import { search } from '@/scripts/search';
|
|
||||||
import * as os from '@/os';
|
import * as os from '@/os';
|
||||||
import { menuDef } from '@/menu';
|
import { menuDef } from '@/menu';
|
||||||
import { openAccountMenu } from '@/account';
|
import { openAccountMenu, $i, iAmModerator } from '@/account';
|
||||||
import MkButton from '@/components/ui/button.vue';
|
import MkButton from '@/components/ui/button.vue';
|
||||||
|
import { defaultStore } from '@/store';
|
||||||
|
import { i18n } from '@/i18n';
|
||||||
|
|
||||||
export default defineComponent({
|
let settingsWindowed = $ref(false);
|
||||||
components: {
|
|
||||||
MkButton,
|
|
||||||
},
|
|
||||||
|
|
||||||
data() {
|
const menu = $computed(() => defaultStore.state.menu);
|
||||||
return {
|
const otherNavItemIndicated = $computed((): boolean => {
|
||||||
host,
|
for (const def in menuDef) {
|
||||||
accounts: [],
|
if (menu.includes(def)) continue;
|
||||||
connection: null,
|
if (menuDef[def].indicated) return true;
|
||||||
menuDef,
|
}
|
||||||
settingsWindowed: false,
|
return false;
|
||||||
};
|
|
||||||
},
|
|
||||||
|
|
||||||
computed: {
|
|
||||||
menu(): string[] {
|
|
||||||
return this.$store.state.menu;
|
|
||||||
},
|
|
||||||
|
|
||||||
otherNavItemIndicated(): boolean {
|
|
||||||
for (const def in this.menuDef) {
|
|
||||||
if (this.menu.includes(def)) continue;
|
|
||||||
if (this.menuDef[def].indicated) return true;
|
|
||||||
}
|
|
||||||
return false;
|
|
||||||
},
|
|
||||||
},
|
|
||||||
|
|
||||||
watch: {
|
|
||||||
'$store.reactiveState.menuDisplay.value'() {
|
|
||||||
this.calcViewState();
|
|
||||||
},
|
|
||||||
},
|
|
||||||
|
|
||||||
created() {
|
|
||||||
window.addEventListener('resize', this.calcViewState);
|
|
||||||
this.calcViewState();
|
|
||||||
},
|
|
||||||
|
|
||||||
methods: {
|
|
||||||
calcViewState() {
|
|
||||||
this.settingsWindowed = (window.innerWidth > 1400);
|
|
||||||
},
|
|
||||||
|
|
||||||
post() {
|
|
||||||
os.post();
|
|
||||||
},
|
|
||||||
|
|
||||||
search() {
|
|
||||||
search();
|
|
||||||
},
|
|
||||||
|
|
||||||
more(ev) {
|
|
||||||
os.popup(defineAsyncComponent(() => import('@/components/launch-pad.vue')), {
|
|
||||||
src: ev.currentTarget ?? ev.target,
|
|
||||||
anchor: { x: 'center', y: 'bottom' },
|
|
||||||
}, {
|
|
||||||
}, 'closed');
|
|
||||||
},
|
|
||||||
|
|
||||||
openAccountMenu: (ev) => {
|
|
||||||
openAccountMenu({
|
|
||||||
withExtraOperation: true,
|
|
||||||
}, ev);
|
|
||||||
},
|
|
||||||
},
|
|
||||||
});
|
});
|
||||||
|
|
||||||
|
function calcViewState(): void {
|
||||||
|
settingsWindowed = (window.innerWidth > 1400);
|
||||||
|
}
|
||||||
|
|
||||||
|
watch(defaultStore.reactiveState.menuDisplay, calcViewState);
|
||||||
|
|
||||||
|
window.addEventListener('resize', calcViewState);
|
||||||
|
calcViewState();
|
||||||
|
|
||||||
|
function post(): void {
|
||||||
|
os.post();
|
||||||
|
}
|
||||||
|
|
||||||
|
function more(ev: MouseEvent | TouchEvent): void {
|
||||||
|
os.popup(defineAsyncComponent(() => import('@/components/launch-pad.vue')), {
|
||||||
|
src: ev.currentTarget ?? ev.target,
|
||||||
|
anchor: { x: 'center', y: 'bottom' },
|
||||||
|
}, {
|
||||||
|
}, 'closed');
|
||||||
|
}
|
||||||
|
|
||||||
|
function openAccountMenuWrapper(ev: MouseEvent): void {
|
||||||
|
openAccountMenu({
|
||||||
|
withExtraOperation: true,
|
||||||
|
}, ev);
|
||||||
|
}
|
||||||
</script>
|
</script>
|
||||||
|
|
||||||
<style lang="scss" scoped>
|
<style lang="scss" scoped>
|
||||||
|
|
Loading…
Reference in a new issue