125 lines
2.4 KiB
Vue
Raw Normal View History

2021-12-19 19:19:46 +08:00
<template>
<div class="go-apple-control-btn">
2021-12-20 13:36:54 +08:00
<template v-for="item in filterBtnList" :key="item.key">
2021-12-19 19:19:46 +08:00
<div
class="btn"
:class="[item.key, disabled && 'disabled']"
@click="handleClick(item.key)"
>
<n-icon size="10" class="icon-base" :class="{ hover: !disabled }">
<component :is="item.icon" />
</n-icon>
</div>
</template>
</div>
</template>
<script lang="ts" setup>
import { icon } from '@/plugins'
2021-12-20 13:36:54 +08:00
import { computed } from 'vue'
import { screenfullFn } from '@/utils'
2021-12-19 19:19:46 +08:00
2021-12-20 13:36:54 +08:00
const emit = defineEmits(['close', 'remove', 'resize', 'fullResize'])
2021-12-19 19:19:46 +08:00
const props = defineProps({
2021-12-20 13:36:54 +08:00
// 禁用所有按钮
2021-12-19 19:19:46 +08:00
disabled: {
2021-12-20 13:36:54 +08:00
request: false,
type: Boolean,
default: false
},
// 要隐藏的按钮
hidden: {
request: false,
type: Array,
default: []
},
// 使用全屏功能
narrow: {
request: false,
2021-12-19 19:19:46 +08:00
type: Boolean,
default: false
}
})
const { CloseIcon, RemoveIcon, ResizeIcon } = icon.ionicons5
2021-12-20 13:36:54 +08:00
const filterBtnList = computed(() => {
const res = btnList.filter(e => {
return props.hidden.findIndex(p => e.key == p) === -1
})
return res
})
const isFull = computed(() => {
return props.narrow && screenfullFn(true)
})
2021-12-19 19:19:46 +08:00
const btnList = [
{
title: '关闭',
key: 'close',
icon: CloseIcon
},
{
title: '缩小',
key: 'remove',
icon: RemoveIcon
},
{
2021-12-20 13:36:54 +08:00
title: isFull ? '缩小' : '放大',
key: props.narrow ? 'fullResize' : 'resize',
2021-12-19 19:19:46 +08:00
icon: ResizeIcon
}
]
2021-12-20 13:36:54 +08:00
const handleClick = (key: 'close' | 'remove' | 'resize' | 'fullResize') => {
if (key === 'fullResize') screenfullFn()
// 缩小并关闭全屏
if (key === 'remove') screenfullFn(true) && screenfullFn()
2021-12-19 19:19:46 +08:00
emit(key)
}
</script>
<style lang="scss" scoped>
@include go('apple-control-btn') {
display: flex;
&:hover {
.btn {
.hover {
cursor: pointer;
opacity: 1;
}
}
}
.btn {
display: flex;
align-items: center;
justify-content: center;
width: 14px;
height: 14px;
margin: 0 4px;
color: $--color-text;
font-weight: bold;
border-radius: 50%;
&.disabled {
2021-12-20 13:36:54 +08:00
pointer-events: none;
2021-12-19 19:19:46 +08:00
}
.icon-base {
opacity: 0;
}
.hover {
@extend .go-transition;
}
}
.close {
background-color: $--color-red;
}
.remove {
background-color: $--color-warn;
}
2021-12-20 13:36:54 +08:00
.resize,
.fullResize {
2021-12-19 19:19:46 +08:00
background-color: $--color-success;
}
}
</style>