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