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