2020-10-17 13:12:00 +02:00
|
|
|
<template>
|
2021-04-10 17:03:31 +02:00
|
|
|
<div class="fdidabkb" :class="{ center }" :style="`--height:${height};`" :key="key">
|
2020-12-19 02:55:52 +01:00
|
|
|
<transition :name="$store.state.animation ? 'header' : ''" mode="out-in" appear>
|
2021-04-10 07:37:29 +02:00
|
|
|
<button class="_button back" v-if="withBack && canBack" @click.stop="back()" v-tooltip="$ts.goBack"><Fa :icon="faChevronLeft"/></button>
|
2020-10-17 13:12:00 +02:00
|
|
|
</transition>
|
|
|
|
<template v-if="info">
|
|
|
|
<div class="titleContainer">
|
2020-12-29 03:33:21 +01:00
|
|
|
<div class="title">
|
|
|
|
<Fa v-if="info.icon" :icon="info.icon" :key="info.icon" class="icon"/>
|
|
|
|
<MkAvatar v-else-if="info.avatar" class="avatar" :user="info.avatar" :disable-preview="true"/>
|
|
|
|
<span v-if="info.title" class="text">{{ info.title }}</span>
|
|
|
|
<MkUserName v-else-if="info.userName" :user="info.userName" :nowrap="false" class="text"/>
|
|
|
|
</div>
|
2020-10-17 13:12:00 +02:00
|
|
|
</div>
|
2021-04-10 06:38:24 +02:00
|
|
|
<div class="buttons">
|
|
|
|
<template v-if="info.actions && showActions">
|
|
|
|
<button v-for="action in info.actions" class="_button button" @click.stop="action.handler" v-tooltip="action.text"><Fa :icon="action.icon"/></button>
|
|
|
|
</template>
|
|
|
|
<button v-if="showMenu" class="_button button" @click.stop="menu"><Fa :icon="faEllipsisH"/></button>
|
|
|
|
</div>
|
2020-10-17 13:12:00 +02:00
|
|
|
</template>
|
|
|
|
</div>
|
|
|
|
</template>
|
|
|
|
|
|
|
|
<script lang="ts">
|
|
|
|
import { defineComponent } from 'vue';
|
2021-04-10 05:40:50 +02:00
|
|
|
import { faChevronLeft, faCircle, faShareAlt, faEllipsisH } from '@fortawesome/free-solid-svg-icons';
|
|
|
|
import { modalMenu } from '@client/os';
|
2021-04-10 16:52:45 +02:00
|
|
|
import { url } from '@client/config';
|
2020-10-17 13:12:00 +02:00
|
|
|
|
|
|
|
export default defineComponent({
|
|
|
|
props: {
|
|
|
|
info: {
|
|
|
|
required: true
|
|
|
|
},
|
|
|
|
withBack: {
|
|
|
|
type: Boolean,
|
|
|
|
required: false,
|
|
|
|
default: true,
|
|
|
|
},
|
2021-02-14 14:26:07 +01:00
|
|
|
center: {
|
|
|
|
type: Boolean,
|
|
|
|
required: false,
|
|
|
|
default: true,
|
|
|
|
},
|
2020-10-17 13:12:00 +02:00
|
|
|
},
|
|
|
|
|
|
|
|
data() {
|
|
|
|
return {
|
|
|
|
canBack: false,
|
2021-04-10 06:38:24 +02:00
|
|
|
showActions: false,
|
2020-10-17 13:12:00 +02:00
|
|
|
height: 0,
|
2021-04-10 17:03:31 +02:00
|
|
|
key: 0,
|
2021-04-10 05:40:50 +02:00
|
|
|
faChevronLeft, faCircle, faShareAlt, faEllipsisH,
|
2020-10-17 13:12:00 +02:00
|
|
|
};
|
|
|
|
},
|
|
|
|
|
2021-04-10 06:38:24 +02:00
|
|
|
computed: {
|
|
|
|
showMenu() {
|
|
|
|
if (this.info.actions != null && !this.showActions) return true;
|
|
|
|
if (this.info.menu != null) return true;
|
|
|
|
if (this.info.share != null) return true;
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
},
|
|
|
|
|
2020-10-17 13:12:00 +02:00
|
|
|
watch: {
|
2021-04-10 17:03:31 +02:00
|
|
|
info() {
|
|
|
|
this.key++;
|
|
|
|
},
|
|
|
|
|
2020-11-03 12:28:38 +01:00
|
|
|
$route: {
|
|
|
|
handler(to, from) {
|
|
|
|
this.canBack = (window.history.length > 0 && !['index'].includes(to.name));
|
|
|
|
},
|
|
|
|
immediate: true
|
2020-10-17 13:12:00 +02:00
|
|
|
},
|
|
|
|
},
|
|
|
|
|
|
|
|
mounted() {
|
|
|
|
this.height = this.$el.parentElement.offsetHeight + 'px';
|
2021-04-10 06:38:24 +02:00
|
|
|
this.showActions = this.$el.parentElement.offsetWidth >= 500;
|
2020-10-17 13:12:00 +02:00
|
|
|
new ResizeObserver((entries, observer) => {
|
|
|
|
this.height = this.$el.parentElement.offsetHeight + 'px';
|
2021-04-10 06:38:24 +02:00
|
|
|
this.showActions = this.$el.parentElement.offsetWidth >= 500;
|
2020-10-17 13:12:00 +02:00
|
|
|
}).observe(this.$el);
|
|
|
|
},
|
|
|
|
|
|
|
|
methods: {
|
|
|
|
back() {
|
|
|
|
if (this.canBack) this.$router.back();
|
|
|
|
},
|
2021-04-10 05:40:50 +02:00
|
|
|
|
|
|
|
share() {
|
2021-04-10 16:52:45 +02:00
|
|
|
navigator.share({
|
|
|
|
url: url + this.info.path,
|
|
|
|
...this.info.share,
|
|
|
|
});
|
2021-04-10 05:40:50 +02:00
|
|
|
},
|
|
|
|
|
|
|
|
menu(ev) {
|
2021-04-11 05:31:24 +02:00
|
|
|
let menu = this.info.menu ? this.info.menu() : [];
|
|
|
|
if (!this.showActions && this.info.actions) {
|
|
|
|
menu = [...this.info.actions.map(x => ({
|
|
|
|
text: x.text,
|
|
|
|
icon: x.icon,
|
|
|
|
action: x.handler
|
|
|
|
})), menu.length > 0 ? null : undefined, ...menu];
|
|
|
|
}
|
2021-04-10 05:40:50 +02:00
|
|
|
if (this.info.share) {
|
|
|
|
if (menu.length > 0) menu.push(null);
|
|
|
|
menu.push({
|
|
|
|
text: this.$ts.share,
|
|
|
|
icon: faShareAlt,
|
|
|
|
action: this.share
|
|
|
|
});
|
|
|
|
}
|
|
|
|
modalMenu(menu, ev.currentTarget || ev.target);
|
|
|
|
}
|
2020-10-17 13:12:00 +02:00
|
|
|
}
|
|
|
|
});
|
|
|
|
</script>
|
|
|
|
|
2020-11-28 04:15:22 +01:00
|
|
|
<style lang="scss" scoped>
|
2020-10-17 13:12:00 +02:00
|
|
|
.fdidabkb {
|
2021-02-14 14:26:07 +01:00
|
|
|
&.center {
|
|
|
|
text-align: center;
|
2020-10-17 13:12:00 +02:00
|
|
|
|
2021-04-10 05:40:50 +02:00
|
|
|
> .titleContainer {
|
|
|
|
margin: 0 auto;
|
|
|
|
}
|
2020-10-17 13:12:00 +02:00
|
|
|
}
|
|
|
|
|
2021-04-10 06:38:24 +02:00
|
|
|
> .back {
|
2021-04-10 05:40:50 +02:00
|
|
|
position: absolute;
|
|
|
|
z-index: 1;
|
|
|
|
top: 0;
|
2021-04-10 06:38:24 +02:00
|
|
|
left: 0;
|
2020-11-28 04:19:57 +01:00
|
|
|
height: var(--height);
|
|
|
|
width: var(--height);
|
2020-10-17 13:12:00 +02:00
|
|
|
}
|
|
|
|
|
2021-04-10 06:38:24 +02:00
|
|
|
> .buttons {
|
|
|
|
position: absolute;
|
|
|
|
z-index: 1;
|
|
|
|
top: 0;
|
2020-10-17 13:12:00 +02:00
|
|
|
right: 0;
|
2021-04-10 06:38:24 +02:00
|
|
|
|
|
|
|
> .button {
|
|
|
|
height: var(--height);
|
|
|
|
width: var(--height);
|
|
|
|
}
|
2020-10-17 13:12:00 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
> .titleContainer {
|
|
|
|
overflow: auto;
|
|
|
|
white-space: nowrap;
|
2021-04-10 05:40:50 +02:00
|
|
|
width: calc(100% - (var(--height) * 2));
|
2020-10-17 13:12:00 +02:00
|
|
|
|
|
|
|
> .title {
|
|
|
|
display: inline-block;
|
|
|
|
vertical-align: bottom;
|
|
|
|
white-space: nowrap;
|
2021-03-02 14:57:16 +01:00
|
|
|
overflow: hidden;
|
2020-10-17 13:12:00 +02:00
|
|
|
text-overflow: ellipsis;
|
|
|
|
padding: 0 16px;
|
2020-11-07 04:31:23 +01:00
|
|
|
position: relative;
|
2021-04-10 05:40:50 +02:00
|
|
|
height: var(--height);
|
2020-10-17 13:12:00 +02:00
|
|
|
|
|
|
|
> .icon + .text {
|
|
|
|
margin-left: 8px;
|
|
|
|
}
|
|
|
|
|
|
|
|
> .avatar {
|
|
|
|
$size: 32px;
|
|
|
|
display: inline-block;
|
|
|
|
width: $size;
|
|
|
|
height: $size;
|
|
|
|
vertical-align: bottom;
|
2021-04-10 05:40:50 +02:00
|
|
|
margin: calc((var(--height) - #{$size}) / 2) 8px calc((var(--height) - #{$size}) / 2) 0;
|
|
|
|
pointer-events: none;
|
2020-10-17 13:12:00 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
</style>
|