右键菜单
代码事例
vue
<template>
<fk-space>
<div class="contextmenu-wrap" @contextmenu="handleContextmenu">右键点击区域</div>
<div class="hover-wrap" @mouseenter="handleMouseEnter">Hover区域</div>
</fk-space>
<p>数据模型</p>
<fk-row>
<JsonViewer :data="selected" />
</fk-row>
</template>
<script lang="ts" setup>
import { reactive } from 'vue';
import { createContextMenu, pop } from '@erp/biz';
import { IconClose, IconCloseCircle, IconPushpin, IconRefresh, IconSync, IconToLeft, IconToRight } from '@erp/common';
const selected = reactive({
contextmenu: '',
hovermenu: '',
});
const menus = [
{
label: '固定标签',
value: 'collect',
icon: IconPushpin,
},
{
label: '取消固定',
value: 'cancel-collect',
icon: IconPushpin,
},
{
label: '刷新页面',
value: 'refresh',
icon: IconRefresh,
},
{
label: '刷新应用',
value: 'reset',
icon: IconSync,
},
{
label: '关闭标签',
value: 'close',
icon: IconCloseCircle,
},
{
label: '关闭右侧',
value: 'close-right',
icon: IconToRight,
},
{
label: '关闭左侧',
value: 'close-left',
icon: IconToLeft,
},
{
label: '关闭其他',
value: 'close-other',
icon: IconClose,
},
];
const handleContextmenu = (evt: MouseEvent) => {
createContextMenu(evt, menus).then((item: any) => {
pop.info(`【${item.label}】菜单点击了`);
item.command && item.command();
selected.contextmenu = item.label;
});
};
const handleMouseEnter = (evt: MouseEvent) => {
createContextMenu(evt, menus).then((item: any) => {
pop.info(`【${item.label}】菜单点击了`);
item.click && item.click();
selected.hovermenu = item.label;
});
};
</script>
<style lang="less">
.contextmenu-wrap {
width: 300px;
height: 300px;
background: #f5f6f7;
display: flex;
justify-content: center;
align-items: center;
}
.hover-wrap {
width: 300px;
height: 300px;
background: #f5f6f7;
display: flex;
justify-content: center;
align-items: center;
}
</style>1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100