index.vue
4.29 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
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
<template>
<div class="go-edit-bottom">
<n-space>
<!-- 历史记录 -->
<edit-history></edit-history>
<!-- CTRL按键触发展示 -->
<n-text id="keyboard-dress-show" depth="3"></n-text>
</n-space>
<n-space class="bottom-ri">
<!-- 快捷键提示 -->
<edit-shortcut-key />
<!-- 缩放比例 -->
<n-select
ref="selectInstRef"
class="scale-btn"
v-model:value="filterValue"
size="mini"
:disabled="lockScale"
:options="filterOptions"
@update:value="selectHandle"
></n-select>
<!-- 锁定缩放 -->
<n-tooltip trigger="hover">
<template #trigger>
<n-button @click="lockHandle" text>
<n-icon class="lock-icon" :class="{ color: lockScale }" size="18" :depth="2">
<lock-closed-outline-icon v-if="lockScale"></lock-closed-outline-icon>
<lock-open-outline-icon v-else></lock-open-outline-icon>
</n-icon>
</n-button>
</template>
<span>{{ lockScale ? '解锁' : '锁定' }}当前比例</span>
</n-tooltip>
<!-- 拖动 -->
<n-slider
class="scale-slider"
v-model:value="sliderValue"
:default-value="50"
:min="10"
:max="200"
:step="5"
:format-tooltip="sliderFormatTooltip"
:disabled="lockScale"
:marks="sliderMaks"
@update:value="sliderHandle"
></n-slider>
</n-space>
</div>
</template>
<script setup lang="ts">
import { SelectInst } from 'naive-ui'
import { reactive, ref, toRefs, watchEffect } from 'vue'
import { icon } from '@/plugins'
import { EditHistory } from '../EditHistory/index'
import EditShortcutKey from '../EditShortcutKey/index.vue'
import { useDesignStore } from '@/store/modules/designStore/designStore'
import { useChartEditStore } from '@/store/modules/chartEditStore/chartEditStore'
import { EditCanvasTypeEnum } from '@/store/modules/chartEditStore/chartEditStore.d'
import { useChartLayoutStore } from '@/store/modules/chartLayoutStore/chartLayoutStore'
import { ChartLayoutStoreEnum } from '@/store/modules/chartLayoutStore/chartLayoutStore.d'
const { LockClosedOutlineIcon, LockOpenOutlineIcon } = icon.ionicons5
// 全局颜色
const designStore = useDesignStore()
const themeColor = ref(designStore.getAppTheme)
const chartLayoutStore = useChartLayoutStore()
const chartEditStore = useChartEditStore()
const { lockScale, scale } = toRefs(chartEditStore.getEditCanvas)
const selectInstRef = ref<SelectInst | null>(null)
// 缩放选项
let filterOptions = [
{
label: '200%',
value: 200
},
{
label: '150%',
value: 150
},
{
label: '100%',
value: 100
},
{
label: '50%',
value: 50
},
{
label: '自适应',
value: 0
}
]
// 选择值
const filterValue = ref('')
// 用户自选择
const selectHandle = (v: number) => {
selectInstRef.value?.blur()
if (v === 0) {
chartLayoutStore.setItemUnHandle(ChartLayoutStoreEnum.RE_POSITION_CANVAS, true)
chartEditStore.computedScale()
return
}
chartEditStore.setScale(v / 100)
}
// 点击锁处理
const lockHandle = () => {
chartEditStore.setEditCanvas(EditCanvasTypeEnum.LOCK_SCALE, !lockScale.value)
}
// 拖动
const sliderValue = ref(100)
// 拖动格式化
const sliderFormatTooltip = (v: string) => `${v}%`
// 拖动处理
const sliderHandle = (v: number) => {
chartEditStore.setScale(v / 100)
}
const sliderMaks = reactive({
100: ''
})
// 监听 scale 变化
watchEffect(() => {
const value = (scale.value * 100).toFixed(0)
filterValue.value = `${value}%`
sliderValue.value = parseInt(value)
})
</script>
<style lang="scss" scoped>
$min-width: 500px;
$max-width: 670px;
@include go('edit-bottom') {
width: 100%;
min-width: $min-width;
min-width: $max-width;
padding: 0 10px;
display: flex;
align-items: center;
justify-content: space-between;
.bottom-ri {
position: relative;
top: 15px;
.lock-icon {
padding-top: 4px;
&.color {
color: v-bind('themeColor');
}
}
.scale-btn {
width: 90px;
font-size: 12px;
@include deep() {
.n-base-selection-label {
padding: 3px;
}
}
}
.scale-slider {
position: relative;
top: -4px;
width: 100px;
}
}
}
</style>