2022-04-21 18:20:39 +08:00
|
|
|
<script lang="ts" setup>
|
2023-05-22 13:35:04 +08:00
|
|
|
import { ref, watchEffect } from "vue"
|
2022-05-05 17:18:58 +08:00
|
|
|
import { ElMessage } from "element-plus"
|
2022-04-22 01:16:02 +08:00
|
|
|
import screenfull from "screenfull"
|
2022-04-21 18:20:39 +08:00
|
|
|
|
2022-11-12 10:17:05 +08:00
|
|
|
const props = defineProps({
|
2022-11-12 13:53:32 +08:00
|
|
|
/** 全屏的元素,默认是 html */
|
|
|
|
element: {
|
|
|
|
type: String,
|
|
|
|
default: "html"
|
|
|
|
},
|
|
|
|
/** 打开全屏提示语 */
|
|
|
|
openTips: {
|
|
|
|
type: String,
|
|
|
|
default: "全屏"
|
|
|
|
},
|
|
|
|
/** 关闭全屏提示语 */
|
|
|
|
exitTips: {
|
|
|
|
type: String,
|
|
|
|
default: "退出全屏"
|
2022-11-12 10:17:05 +08:00
|
|
|
}
|
|
|
|
})
|
|
|
|
|
2022-11-12 13:53:32 +08:00
|
|
|
const tips = ref<string>(props.openTips)
|
|
|
|
const isFullscreen = ref<boolean>(false)
|
2022-08-22 15:29:29 +08:00
|
|
|
|
2023-05-22 13:35:04 +08:00
|
|
|
const handleClick = () => {
|
|
|
|
const dom = document.querySelector(props.element) || undefined
|
2023-05-22 13:44:48 +08:00
|
|
|
screenfull.isEnabled ? screenfull.toggle(dom) : ElMessage.warning("您的浏览器无法工作")
|
2022-04-21 18:20:39 +08:00
|
|
|
}
|
2022-08-22 15:29:29 +08:00
|
|
|
|
2023-05-22 13:35:04 +08:00
|
|
|
const handleChange = () => {
|
2022-08-22 15:29:29 +08:00
|
|
|
isFullscreen.value = screenfull.isFullscreen
|
2022-11-12 13:53:32 +08:00
|
|
|
tips.value = screenfull.isFullscreen ? props.exitTips : props.openTips
|
2022-08-22 15:29:29 +08:00
|
|
|
}
|
|
|
|
|
2023-05-22 13:35:04 +08:00
|
|
|
watchEffect((onCleanup) => {
|
|
|
|
// 挂载组件时自动执行
|
|
|
|
screenfull.on("change", handleChange)
|
|
|
|
// 卸载组件时自动执行
|
|
|
|
onCleanup(() => {
|
2023-05-22 13:46:45 +08:00
|
|
|
screenfull.isEnabled && screenfull.off("change", handleChange)
|
2023-05-22 13:35:04 +08:00
|
|
|
})
|
2022-08-22 15:29:29 +08:00
|
|
|
})
|
2022-04-21 18:20:39 +08:00
|
|
|
</script>
|
2022-04-22 12:47:04 +08:00
|
|
|
|
|
|
|
<template>
|
2023-05-22 13:35:04 +08:00
|
|
|
<div @click="handleClick">
|
2022-11-12 13:53:32 +08:00
|
|
|
<el-tooltip effect="dark" :content="tips" placement="bottom">
|
2022-08-22 15:29:29 +08:00
|
|
|
<svg-icon :name="isFullscreen ? 'fullscreen-exit' : 'fullscreen'" />
|
2022-04-22 12:47:04 +08:00
|
|
|
</el-tooltip>
|
|
|
|
</div>
|
|
|
|
</template>
|
2022-08-22 15:29:29 +08:00
|
|
|
|
|
|
|
<style lang="scss" scoped>
|
|
|
|
.svg-icon {
|
|
|
|
font-size: 20px;
|
|
|
|
&:focus {
|
|
|
|
outline: none;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
</style>
|