Control.vue
3.19 KB
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
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
<template>
<div class="control-container">
<!-- 功能按钮 -->
<ul>
<li
v-for="(item, key) in titleLists"
:key="key"
:title="item.text"
@mouseenter.prevent="onEnter(key)"
@mouseleave.prevent="focusIndex = -1"
>
<a-button
:disabled="item.disabled"
:style="{ cursor: item.disabled === false ? 'pointer' : 'not-allowed' }"
@click="onControl(item, key)"
>
<span :class="'iconfont ' + item.icon"></span>
<p>{{ item.text }}</p>
</a-button>
</li>
</ul>
</div>
</template>
<script lang="ts">
import { defineComponent, ref, unref, onMounted } from 'vue';
export default defineComponent({
name: 'Control',
props: {
lf: Object || String,
catTurboData: Boolean,
},
emits: ['catData'],
setup(props, { emit }) {
let focusIndex = ref(-1);
let titleLists = ref([
{
icon: 'icon-zoom-out-hs',
text: '缩小',
disabled: false,
},
{
icon: 'icon-enlarge-hs',
text: '放大',
disabled: false,
},
{
icon: 'icon-full-screen-hs',
text: '适应',
disabled: false,
},
{
icon: 'icon-previous-hs',
text: '上一步',
disabled: true,
},
{
icon: 'icon-next-step-hs',
text: '下一步',
disabled: true,
},
{
icon: 'icon-download-hs',
text: '下载图片',
disabled: false,
},
{
icon: 'icon-watch-hs',
text: '查看数据',
disabled: false,
},
]);
const onControl = (item, key) => {
['zoom', 'zoom', 'resetZoom', 'undo', 'redo', 'getSnapshot'].forEach((v, i) => {
let domControl = props.lf;
if (key === 1) {
domControl.zoom(true);
}
if (key === 6) {
emit('catData');
}
if (key === i) {
domControl[v]();
}
});
};
const onEnter = (key) => {
focusIndex.value = key;
};
onMounted(() => {
props.lf.on('history:change', ({ data: { undoAble, redoAble } }) => {
unref(titleLists)[3].disabled = !undoAble;
unref(titleLists)[4].disabled = !redoAble;
});
});
return {
focusIndex,
titleLists,
onControl,
onEnter,
};
},
});
</script>
<style scoped>
@import './assets/iconfont/iconfont.css';
.control-container {
position: absolute;
right: 20px;
background: hsla(0, 0%, 100%, 0.8);
box-shadow: 0 1px 4px rgb(0 0 0 / 30%);
}
.iconfont {
font-size: 25px;
}
.control-container p {
margin: 0;
font-size: 12px;
}
.control-container ul {
display: flex;
justify-content: space-around;
align-items: center;
margin: 2px;
}
.control-container ul li {
width: 60px;
text-align: center;
}
.control-container ul li button {
width: 100%;
height: 60px;
padding: 0;
background-color: transparent;
border: none;
outline: none;
}
</style>