feat: 阻止默认右键菜单

This commit is contained in:
2024-09-01 12:19:02 +08:00
parent b4ef6600c4
commit c2561d5498

View File

@@ -43,6 +43,10 @@ import {
useThemeVars,
} from 'naive-ui';
import {
onMounted, onBeforeUnmount,
} from 'vue';
import {
configProviderProps,
} from './assets/js/naive-ui';
@@ -57,6 +61,34 @@ const themeCommon = themeOverrides.common;
/** 默认主题变量 */
const themeVars = useThemeVars();
/**
* @description 阻止默认右键菜单
* @param {PointerEvent} event
*/
function handleContextMenu(event) {
let element = event.target;
// 排除输入框元素
if (
element instanceof HTMLInputElement &&
['password', 'text', 'textarea'].includes(element.type)
) {
return;
}
event.preventDefault();
}
onMounted(() => {
window.addEventListener('contextmenu', handleContextMenu);
});
onBeforeUnmount(() => {
window.removeEventListener('contextmenu', handleContextMenu);
});
</script>
<style lang="less">