evui 3.3.36 → 3.3.39
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +21 -21
- package/README.md +40 -40
- package/dist/evui.common.js +1907 -1832
- package/dist/evui.common.js.map +1 -1
- package/dist/evui.umd.js +1907 -1832
- package/dist/evui.umd.js.map +1 -1
- package/dist/evui.umd.min.js +1 -1
- package/dist/evui.umd.min.js.map +1 -1
- package/dist/img/{EVUI.7f3588fb.svg → EVUI.b82ee81a.svg} +292 -292
- package/dist/img/{icon_mysql.7ea26d5d.svg → icon_mysql.1085fdc9.svg} +78 -78
- package/dist/img/{icon_oracle.9009b108.svg → icon_oracle.0572d3ee.svg} +13 -13
- package/dist/img/{icon_postgresql.f8fffba9.svg → icon_postgresql.ee12bde8.svg} +58 -58
- package/package.json +61 -61
- package/src/common/emitter.js +20 -20
- package/src/common/utils.debounce.js +223 -223
- package/src/common/utils.js +134 -134
- package/src/common/utils.table.js +78 -78
- package/src/common/utils.throttle.js +83 -83
- package/src/common/utils.tree.js +18 -18
- package/src/components/button/Button.vue +198 -198
- package/src/components/button/index.js +7 -7
- package/src/components/buttonGroup/ButtonGroup.vue +11 -11
- package/src/components/buttonGroup/index.js +7 -7
- package/src/components/calendar/Calendar.vue +661 -661
- package/src/components/calendar/index.js +7 -7
- package/src/components/calendar/uses.js +1272 -1272
- package/src/components/chart/Chart.vue +189 -192
- package/src/components/chart/chart.core.js +870 -870
- package/src/components/chart/element/element.bar.js +524 -524
- package/src/components/chart/element/element.bar.time.js +156 -156
- package/src/components/chart/element/element.heatmap.js +533 -533
- package/src/components/chart/element/element.line.js +339 -339
- package/src/components/chart/element/element.pie.js +197 -197
- package/src/components/chart/element/element.scatter.js +184 -184
- package/src/components/chart/element/element.tip.js +550 -542
- package/src/components/chart/helpers/helpers.canvas.js +265 -265
- package/src/components/chart/helpers/helpers.constant.js +206 -206
- package/src/components/chart/helpers/helpers.util.js +346 -338
- package/src/components/chart/index.js +9 -9
- package/src/components/chart/model/index.js +4 -4
- package/src/components/chart/model/model.series.js +93 -93
- package/src/components/chart/model/model.store.js +977 -967
- package/src/components/chart/plugins/plugins.interaction.js +769 -769
- package/src/components/chart/plugins/plugins.legend.gradient.js +602 -602
- package/src/components/chart/plugins/plugins.legend.js +1155 -1151
- package/src/components/chart/plugins/plugins.pie.js +254 -254
- package/src/components/chart/plugins/plugins.title.js +56 -56
- package/src/components/chart/plugins/plugins.tooltip.js +692 -692
- package/src/components/chart/scale/scale.js +848 -848
- package/src/components/chart/scale/scale.linear.js +38 -38
- package/src/components/chart/scale/scale.logarithmic.js +128 -128
- package/src/components/chart/scale/scale.step.js +336 -336
- package/src/components/chart/scale/scale.time.category.js +277 -277
- package/src/components/chart/scale/scale.time.js +48 -48
- package/src/components/chart/style/chart.scss +312 -312
- package/src/components/chart/uses.js +264 -252
- package/src/components/checkbox/Checkbox.vue +200 -200
- package/src/components/checkbox/index.js +7 -7
- package/src/components/checkboxGroup/CheckboxGroup.vue +44 -44
- package/src/components/checkboxGroup/index.js +7 -7
- package/src/components/contextMenu/ContextMenu.vue +80 -80
- package/src/components/contextMenu/MenuList.vue +149 -149
- package/src/components/contextMenu/index.js +7 -7
- package/src/components/contextMenu/uses.js +203 -203
- package/src/components/datePicker/DatePicker.vue +437 -437
- package/src/components/datePicker/index.js +7 -7
- package/src/components/datePicker/uses.js +419 -419
- package/src/components/grid/Grid.vue +827 -827
- package/src/components/grid/grid.filter.window.vue +493 -493
- package/src/components/grid/grid.pagination.vue +75 -75
- package/src/components/grid/grid.summary.vue +265 -265
- package/src/components/grid/grid.toolbar.vue +26 -26
- package/src/components/grid/index.js +11 -11
- package/src/components/grid/style/grid.scss +263 -263
- package/src/components/grid/uses.js +1002 -1007
- package/src/components/icon/Icon.vue +49 -49
- package/src/components/icon/index.js +8 -8
- package/src/components/inputNumber/InputNumber.vue +212 -212
- package/src/components/inputNumber/index.js +7 -7
- package/src/components/inputNumber/uses.js +217 -217
- package/src/components/loading/Loading.vue +125 -125
- package/src/components/loading/index.js +7 -7
- package/src/components/menu/Menu.vue +68 -68
- package/src/components/menu/MenuItem.vue +187 -187
- package/src/components/menu/index.js +7 -7
- package/src/components/message/Message.vue +223 -223
- package/src/components/message/index.js +31 -31
- package/src/components/messageBox/MessageBox.vue +358 -358
- package/src/components/messageBox/index.js +22 -22
- package/src/components/notification/Notification.vue +316 -316
- package/src/components/notification/index.js +49 -49
- package/src/components/pagination/Pagination.vue +271 -271
- package/src/components/pagination/index.js +7 -7
- package/src/components/pagination/pageButton.vue +30 -30
- package/src/components/progress/Progress.vue +139 -139
- package/src/components/progress/index.js +7 -7
- package/src/components/radio/Radio.vue +159 -159
- package/src/components/radio/index.js +7 -7
- package/src/components/radioGroup/RadioGroup.vue +41 -41
- package/src/components/radioGroup/index.js +7 -7
- package/src/components/scheduler/Scheduler.vue +149 -149
- package/src/components/scheduler/index.js +7 -7
- package/src/components/scheduler/uses.js +183 -183
- package/src/components/select/Select.vue +440 -440
- package/src/components/select/index.js +7 -7
- package/src/components/select/uses.js +270 -270
- package/src/components/slider/Slider.vue +505 -505
- package/src/components/slider/index.js +7 -7
- package/src/components/slider/uses.js +390 -390
- package/src/components/tabPanel/TabPanel.vue +74 -74
- package/src/components/tabPanel/index.js +7 -7
- package/src/components/tabs/Tabs.vue +517 -517
- package/src/components/tabs/index.js +7 -7
- package/src/components/textField/TextField.vue +375 -375
- package/src/components/textField/index.js +7 -7
- package/src/components/timePicker/TimePicker.vue +352 -352
- package/src/components/timePicker/index.js +7 -7
- package/src/components/toggle/Toggle.vue +115 -115
- package/src/components/toggle/index.js +7 -7
- package/src/components/tree/Tree.vue +313 -313
- package/src/components/tree/TreeNode.vue +293 -293
- package/src/components/tree/index.js +7 -7
- package/src/components/treeGrid/TreeGrid.vue +758 -758
- package/src/components/treeGrid/TreeGridNode.vue +275 -275
- package/src/components/treeGrid/index.js +9 -9
- package/src/components/treeGrid/style/treeGrid.scss +261 -261
- package/src/components/treeGrid/treeGrid.toolbar.vue +26 -26
- package/src/components/treeGrid/uses.js +867 -867
- package/src/components/window/Window.vue +329 -329
- package/src/components/window/index.js +7 -7
- package/src/components/window/uses.js +899 -899
- package/src/directives/clickoutside.js +90 -90
- package/src/main.js +116 -116
- package/src/style/components/input.scss +108 -108
- package/src/style/functions.scss +3 -3
- package/src/style/index.scss +6 -6
- package/src/style/lib/fonts/EVUI.svg +292 -292
- package/src/style/lib/icon.css +888 -888
- package/src/style/mixins.scss +94 -94
- package/src/style/themes.scss +67 -67
- package/src/style/variables.scss +22 -22
|
@@ -1,390 +1,390 @@
|
|
|
1
|
-
import { ref, reactive, watch, computed, onMounted, getCurrentInstance } from 'vue';
|
|
2
|
-
import { isEqual } from 'lodash-es';
|
|
3
|
-
import { convertToPercent } from '@/common/utils';
|
|
4
|
-
import { getValueCloseToStep } from '@/components/inputNumber/uses';
|
|
5
|
-
|
|
6
|
-
export const useModel = () => {
|
|
7
|
-
const { props, emit } = getCurrentInstance();
|
|
8
|
-
const currentValue = ref(props.modelValue);
|
|
9
|
-
|
|
10
|
-
const setStepList = () => {
|
|
11
|
-
if (!props.showStep) {
|
|
12
|
-
return [];
|
|
13
|
-
}
|
|
14
|
-
// step은 이동 단위 기준으로, 입력값에 따라 클릭 및 드레그 시 이동 단위를 나타냄
|
|
15
|
-
const sliderRange = props.max - props.min;
|
|
16
|
-
const stepCount = sliderRange / props.step;
|
|
17
|
-
const stepWidth = convertToPercent(props.step, sliderRange);
|
|
18
|
-
const result = [];
|
|
19
|
-
for (let ix = 1; ix < stepCount; ix++) {
|
|
20
|
-
result.push(ix * stepWidth);
|
|
21
|
-
}
|
|
22
|
-
return result;
|
|
23
|
-
};
|
|
24
|
-
|
|
25
|
-
const setMarkList = () => {
|
|
26
|
-
if (!props.mark || !Object.keys(props.mark).length) {
|
|
27
|
-
return [];
|
|
28
|
-
}
|
|
29
|
-
const getResultList = (obj, type = 'value') => {
|
|
30
|
-
if (!obj) {
|
|
31
|
-
return [];
|
|
32
|
-
}
|
|
33
|
-
const style = props.mark.style && (typeof props.mark.style === 'object') ? props.mark.style : {};
|
|
34
|
-
const keyList = Object.keys(obj);
|
|
35
|
-
const resultList = [];
|
|
36
|
-
let markVal;
|
|
37
|
-
for (let ix = 0; ix < keyList.length; ix++) {
|
|
38
|
-
markVal = +keyList[ix];
|
|
39
|
-
if (!isNaN(markVal)) {
|
|
40
|
-
resultList.push({
|
|
41
|
-
posX: type === 'value' ? convertToPercent(markVal, props.max - props.min) : markVal,
|
|
42
|
-
label: obj[markVal],
|
|
43
|
-
style,
|
|
44
|
-
});
|
|
45
|
-
}
|
|
46
|
-
}
|
|
47
|
-
return resultList;
|
|
48
|
-
};
|
|
49
|
-
|
|
50
|
-
const hasDetailOption = props.mark.value || props.mark.percent;
|
|
51
|
-
if (!hasDetailOption) {
|
|
52
|
-
return [...getResultList(props.mark)];
|
|
53
|
-
}
|
|
54
|
-
return [
|
|
55
|
-
...getResultList(props.mark.value),
|
|
56
|
-
...getResultList(props.mark.percent, 'percent'),
|
|
57
|
-
];
|
|
58
|
-
};
|
|
59
|
-
|
|
60
|
-
const state = reactive({
|
|
61
|
-
isInit: false,
|
|
62
|
-
dragging: false,
|
|
63
|
-
handleType: null, // 'left', 'right', null
|
|
64
|
-
leftValue: null,
|
|
65
|
-
rightValue: null,
|
|
66
|
-
});
|
|
67
|
-
const slider = reactive({
|
|
68
|
-
valueRange: 0,
|
|
69
|
-
stepList: computed(setStepList),
|
|
70
|
-
markList: computed(setMarkList),
|
|
71
|
-
offset: {
|
|
72
|
-
left: 0,
|
|
73
|
-
width: 0,
|
|
74
|
-
},
|
|
75
|
-
});
|
|
76
|
-
const sliderLine = ref();
|
|
77
|
-
|
|
78
|
-
// tooltip format
|
|
79
|
-
const formatValue = computed(() => {
|
|
80
|
-
const tooltipFormat = props.tooltipFormat;
|
|
81
|
-
const useFormat = tooltipFormat instanceof Function;
|
|
82
|
-
return {
|
|
83
|
-
left: useFormat ? tooltipFormat(state.leftValue) : state.leftValue,
|
|
84
|
-
right: useFormat ? tooltipFormat(state.rightValue) : state.rightValue,
|
|
85
|
-
};
|
|
86
|
-
});
|
|
87
|
-
|
|
88
|
-
const setHandleValue = (val) => {
|
|
89
|
-
const optionObj = {
|
|
90
|
-
min: props.min,
|
|
91
|
-
max: props.max,
|
|
92
|
-
step: props.step,
|
|
93
|
-
};
|
|
94
|
-
|
|
95
|
-
let leftVal;
|
|
96
|
-
let rightVal;
|
|
97
|
-
if (props.range && Array.isArray(val)) {
|
|
98
|
-
leftVal = typeof val[0] === 'number' && !isNaN(val[0]) ? val[0] : props.min;
|
|
99
|
-
rightVal = typeof val[1] === 'number' && !isNaN(val[1]) ? val[1] : props.min;
|
|
100
|
-
|
|
101
|
-
state.leftValue = getValueCloseToStep(leftVal, optionObj);
|
|
102
|
-
state.rightValue = getValueCloseToStep(rightVal, optionObj);
|
|
103
|
-
} else {
|
|
104
|
-
leftVal = props.min;
|
|
105
|
-
rightVal = typeof val === 'number' && !isNaN(val) ? val : props.min;
|
|
106
|
-
|
|
107
|
-
state.leftValue = getValueCloseToStep(leftVal, optionObj);
|
|
108
|
-
state.rightValue = getValueCloseToStep(rightVal, optionObj);
|
|
109
|
-
}
|
|
110
|
-
};
|
|
111
|
-
|
|
112
|
-
const setSliderValue = (val) => {
|
|
113
|
-
if (slider.valueRange <= 0) {
|
|
114
|
-
return;
|
|
115
|
-
}
|
|
116
|
-
|
|
117
|
-
setHandleValue(val);
|
|
118
|
-
|
|
119
|
-
let result;
|
|
120
|
-
if (props.range && Array.isArray(val)) {
|
|
121
|
-
const minVal = Math.min(state.leftValue, state.rightValue);
|
|
122
|
-
const maxVal = Math.max(state.leftValue, state.rightValue);
|
|
123
|
-
result = [minVal, maxVal];
|
|
124
|
-
} else {
|
|
125
|
-
result = state.rightValue;
|
|
126
|
-
}
|
|
127
|
-
|
|
128
|
-
currentValue.value = result;
|
|
129
|
-
emit('update:modelValue', result);
|
|
130
|
-
emit('change', result);
|
|
131
|
-
};
|
|
132
|
-
|
|
133
|
-
const updateSliderInfo = () => {
|
|
134
|
-
const sliderRect = sliderLine.value.getBoundingClientRect();
|
|
135
|
-
slider.offset.left = sliderRect.left;
|
|
136
|
-
slider.offset.width = sliderRect.width;
|
|
137
|
-
slider.valueRange = props.max - props.min;
|
|
138
|
-
};
|
|
139
|
-
|
|
140
|
-
watch(() => props.modelValue, (curr, prev) => {
|
|
141
|
-
if (curr
|
|
142
|
-
&& !isEqual(curr, prev)
|
|
143
|
-
&& !state.dragging
|
|
144
|
-
) {
|
|
145
|
-
setHandleValue(curr);
|
|
146
|
-
currentValue.value = curr;
|
|
147
|
-
}
|
|
148
|
-
});
|
|
149
|
-
watch(() => props.step, () => {
|
|
150
|
-
setSliderValue(currentValue.value);
|
|
151
|
-
});
|
|
152
|
-
|
|
153
|
-
return {
|
|
154
|
-
currentValue,
|
|
155
|
-
state,
|
|
156
|
-
slider,
|
|
157
|
-
formatValue,
|
|
158
|
-
sliderLine,
|
|
159
|
-
updateSliderInfo,
|
|
160
|
-
setSliderValue,
|
|
161
|
-
};
|
|
162
|
-
};
|
|
163
|
-
|
|
164
|
-
export const useStyle = (params) => {
|
|
165
|
-
const { props } = getCurrentInstance();
|
|
166
|
-
const { state, slider } = params;
|
|
167
|
-
const colorDefault = 'transparent';
|
|
168
|
-
|
|
169
|
-
const leftHandleStyle = computed(() => ({
|
|
170
|
-
left: slider.valueRange > 0 ? `${convertToPercent(state.leftValue - props.min, slider.valueRange)}%` : 0,
|
|
171
|
-
}));
|
|
172
|
-
const rightHandleStyle = computed(() => ({
|
|
173
|
-
left: slider.valueRange > 0 ? `${convertToPercent(state.rightValue - props.min, slider.valueRange)}%` : 0,
|
|
174
|
-
}));
|
|
175
|
-
const handleBtnStyle = computed(() => {
|
|
176
|
-
if (!props.color
|
|
177
|
-
|| (Array.isArray(props.color) && props.color.length !== 1)
|
|
178
|
-
) {
|
|
179
|
-
return {};
|
|
180
|
-
}
|
|
181
|
-
return {
|
|
182
|
-
borderColor: (typeof props.color === 'string' ? props.color : props.color[0]) || colorDefault,
|
|
183
|
-
};
|
|
184
|
-
});
|
|
185
|
-
|
|
186
|
-
/**
|
|
187
|
-
* Slider 색 칠하기 : props.color 갖고 있을 때
|
|
188
|
-
* color 로 받은 값에 따라 왼쪽 부터 채워짐. 없을 경우 기본 색 = transparent
|
|
189
|
-
* */
|
|
190
|
-
const isColorArray = computed(() => props.color && Array.isArray(props.color));
|
|
191
|
-
|
|
192
|
-
const rangeThumbStyle = computed(() => {
|
|
193
|
-
const minVal = Math.min(state.leftValue, state.rightValue);
|
|
194
|
-
const maxVal = Math.max(state.leftValue, state.rightValue);
|
|
195
|
-
const mvRange = +(maxVal - minVal).toFixed(2);
|
|
196
|
-
const leftPosX = (slider.valueRange > 0 && props.range)
|
|
197
|
-
? convertToPercent(+(minVal - props.min).toFixed(2), slider.valueRange) : 0;
|
|
198
|
-
const thumbWidth = (mvRange > 0) ? convertToPercent(mvRange, slider.valueRange) : 0;
|
|
199
|
-
|
|
200
|
-
const thumbColor = {};
|
|
201
|
-
if (props.color) {
|
|
202
|
-
if (typeof props.color === 'string'
|
|
203
|
-
|| (Array.isArray(props.color) && props.color.length === 1)
|
|
204
|
-
) {
|
|
205
|
-
thumbColor.backgroundColor = (typeof props.color === 'string' ? props.color : props.color[0]) || colorDefault;
|
|
206
|
-
} else if (Array.isArray(props.color) && props.color.length > 1) {
|
|
207
|
-
thumbColor.backgroundColor = (props.range ? props.color[1] : props.color[0])
|
|
208
|
-
|| colorDefault;
|
|
209
|
-
}
|
|
210
|
-
}
|
|
211
|
-
return {
|
|
212
|
-
left: `${leftPosX}%`,
|
|
213
|
-
width: `${thumbWidth}%`,
|
|
214
|
-
...thumbColor,
|
|
215
|
-
};
|
|
216
|
-
});
|
|
217
|
-
|
|
218
|
-
const leftThumbStyle = computed(() => {
|
|
219
|
-
if (
|
|
220
|
-
!isColorArray.value
|
|
221
|
-
|| props.color.length < 2
|
|
222
|
-
|| !props.range
|
|
223
|
-
) {
|
|
224
|
-
return {};
|
|
225
|
-
}
|
|
226
|
-
const minVal = Math.min(state.leftValue, state.rightValue);
|
|
227
|
-
const thumbWidth = convertToPercent(Math.abs(minVal - props.min), slider.valueRange);
|
|
228
|
-
return {
|
|
229
|
-
width: `${thumbWidth}%`,
|
|
230
|
-
backgroundColor: props.color[0] || colorDefault,
|
|
231
|
-
};
|
|
232
|
-
});
|
|
233
|
-
|
|
234
|
-
const rightThumbStyle = computed(() => {
|
|
235
|
-
if (!isColorArray.value || props.color.length < 2) {
|
|
236
|
-
return {};
|
|
237
|
-
}
|
|
238
|
-
const maxVal = Math.max(state.leftValue, state.rightValue);
|
|
239
|
-
const leftPosX = convertToPercent(+(maxVal - props.min).toFixed(2), slider.valueRange);
|
|
240
|
-
const thumbWidth = convertToPercent(+(props.max - maxVal).toFixed(2), slider.valueRange);
|
|
241
|
-
|
|
242
|
-
const lastIdx = !props.range ? props.color.length - 1 : 2;
|
|
243
|
-
return {
|
|
244
|
-
left: `${leftPosX}%`,
|
|
245
|
-
width: `${thumbWidth}%`,
|
|
246
|
-
backgroundColor: props.color[lastIdx] || colorDefault,
|
|
247
|
-
};
|
|
248
|
-
});
|
|
249
|
-
|
|
250
|
-
return {
|
|
251
|
-
isColorArray,
|
|
252
|
-
leftHandleStyle,
|
|
253
|
-
rightHandleStyle,
|
|
254
|
-
handleBtnStyle,
|
|
255
|
-
rangeThumbStyle,
|
|
256
|
-
leftThumbStyle,
|
|
257
|
-
rightThumbStyle,
|
|
258
|
-
};
|
|
259
|
-
};
|
|
260
|
-
|
|
261
|
-
export const useEvent = (params) => {
|
|
262
|
-
const { props } = getCurrentInstance();
|
|
263
|
-
const { currentValue, state, slider, updateSliderInfo, setSliderValue } = params;
|
|
264
|
-
|
|
265
|
-
const getSelectedValue = (e) => {
|
|
266
|
-
if (!state.dragging) {
|
|
267
|
-
updateSliderInfo();
|
|
268
|
-
}
|
|
269
|
-
|
|
270
|
-
const currentOffsetX = e.type.indexOf('touch') !== -1 ? e.touches[0].clientX : e.clientX;
|
|
271
|
-
const { valueRange, offset } = slider;
|
|
272
|
-
let clickedValue = props.min + ((currentOffsetX - offset.left) * valueRange) / offset.width;
|
|
273
|
-
|
|
274
|
-
if (clickedValue < props.min) {
|
|
275
|
-
clickedValue = props.min;
|
|
276
|
-
} else if (clickedValue > props.max) {
|
|
277
|
-
clickedValue = props.max;
|
|
278
|
-
}
|
|
279
|
-
|
|
280
|
-
return clickedValue;
|
|
281
|
-
};
|
|
282
|
-
|
|
283
|
-
const clickSlider = (e) => {
|
|
284
|
-
if (props.readonly || props.disabled || state.dragging) {
|
|
285
|
-
return;
|
|
286
|
-
}
|
|
287
|
-
|
|
288
|
-
const selectedValue = getSelectedValue(e);
|
|
289
|
-
let convertValue;
|
|
290
|
-
if (props.range) {
|
|
291
|
-
const minValue = Math.min(state.leftValue, state.rightValue);
|
|
292
|
-
const rangeHalfValue = minValue + Math.abs((state.rightValue - state.leftValue) / 2);
|
|
293
|
-
const isReverse = state.leftValue > state.rightValue;
|
|
294
|
-
|
|
295
|
-
if (selectedValue < rangeHalfValue) {
|
|
296
|
-
state.handleType = isReverse ? 'right' : 'left';
|
|
297
|
-
} else {
|
|
298
|
-
state.handleType = isReverse ? 'left' : 'right';
|
|
299
|
-
}
|
|
300
|
-
convertValue = state.handleType === 'left' ? [selectedValue, state.rightValue] : [state.leftValue, selectedValue];
|
|
301
|
-
} else {
|
|
302
|
-
state.handleType = 'right';
|
|
303
|
-
convertValue = selectedValue;
|
|
304
|
-
}
|
|
305
|
-
|
|
306
|
-
setSliderValue(convertValue);
|
|
307
|
-
};
|
|
308
|
-
|
|
309
|
-
const onDrag = (e) => {
|
|
310
|
-
const selectedValue = getSelectedValue(e);
|
|
311
|
-
state.dragging = true;
|
|
312
|
-
|
|
313
|
-
let convertValue;
|
|
314
|
-
if (props.range) {
|
|
315
|
-
convertValue = state.handleType === 'left' ? [selectedValue, state.rightValue] : [state.leftValue, selectedValue];
|
|
316
|
-
} else {
|
|
317
|
-
convertValue = selectedValue;
|
|
318
|
-
}
|
|
319
|
-
|
|
320
|
-
setSliderValue(convertValue);
|
|
321
|
-
};
|
|
322
|
-
const endDrag = () => {
|
|
323
|
-
state.handleType = null;
|
|
324
|
-
state.dragging = false;
|
|
325
|
-
document.body.style.cursor = '';
|
|
326
|
-
|
|
327
|
-
window.removeEventListener('mousemove', onDrag);
|
|
328
|
-
window.removeEventListener('touchmove', onDrag);
|
|
329
|
-
window.removeEventListener('mouseup', endDrag);
|
|
330
|
-
window.removeEventListener('touchend', endDrag);
|
|
331
|
-
};
|
|
332
|
-
const startDrag = (handleType) => {
|
|
333
|
-
if (props.readonly || props.disabled) {
|
|
334
|
-
return;
|
|
335
|
-
}
|
|
336
|
-
state.handleType = handleType;
|
|
337
|
-
document.body.style.cursor = 'grabbing';
|
|
338
|
-
|
|
339
|
-
window.addEventListener('mousemove', onDrag);
|
|
340
|
-
window.addEventListener('touchmove', onDrag);
|
|
341
|
-
window.addEventListener('mouseup', endDrag);
|
|
342
|
-
window.addEventListener('touchend', endDrag);
|
|
343
|
-
};
|
|
344
|
-
|
|
345
|
-
const changeInput = (val, type) => {
|
|
346
|
-
if (props.showInput && !state.dragging && state.isInit) {
|
|
347
|
-
if (props.range && Array.isArray(currentValue.value)) {
|
|
348
|
-
const result = type === 'left' ? [val, currentValue.value[1]] : [currentValue.value[0], val];
|
|
349
|
-
setSliderValue(result);
|
|
350
|
-
} else if (!props.range) {
|
|
351
|
-
setSliderValue(val);
|
|
352
|
-
}
|
|
353
|
-
}
|
|
354
|
-
};
|
|
355
|
-
return {
|
|
356
|
-
startDrag,
|
|
357
|
-
clickSlider,
|
|
358
|
-
changeInput,
|
|
359
|
-
};
|
|
360
|
-
};
|
|
361
|
-
|
|
362
|
-
export const useInit = (params) => {
|
|
363
|
-
const { props, emit } = getCurrentInstance();
|
|
364
|
-
const { currentValue, state, slider, updateSliderInfo, setSliderValue } = params;
|
|
365
|
-
|
|
366
|
-
const validateProps = () => {
|
|
367
|
-
const hasMaxProps = props.max || props.max === 0;
|
|
368
|
-
const hasMinProps = props.min || props.min === 0;
|
|
369
|
-
if (hasMaxProps && hasMinProps) {
|
|
370
|
-
if (props.max <= props.min) {
|
|
371
|
-
console.warn('[EVUI][Slider] Max value must be greater than min value.');
|
|
372
|
-
}
|
|
373
|
-
}
|
|
374
|
-
};
|
|
375
|
-
const initValue = () => {
|
|
376
|
-
updateSliderInfo();
|
|
377
|
-
|
|
378
|
-
if (slider.valueRange <= 0) {
|
|
379
|
-
currentValue.value = props.range ? [props.min, props.min] : props.min;
|
|
380
|
-
emit('update:modelValue', currentValue.value);
|
|
381
|
-
}
|
|
382
|
-
setSliderValue(currentValue.value);
|
|
383
|
-
state.isInit = true;
|
|
384
|
-
};
|
|
385
|
-
|
|
386
|
-
onMounted(() => {
|
|
387
|
-
validateProps();
|
|
388
|
-
initValue();
|
|
389
|
-
});
|
|
390
|
-
};
|
|
1
|
+
import { ref, reactive, watch, computed, onMounted, getCurrentInstance } from 'vue';
|
|
2
|
+
import { isEqual } from 'lodash-es';
|
|
3
|
+
import { convertToPercent } from '@/common/utils';
|
|
4
|
+
import { getValueCloseToStep } from '@/components/inputNumber/uses';
|
|
5
|
+
|
|
6
|
+
export const useModel = () => {
|
|
7
|
+
const { props, emit } = getCurrentInstance();
|
|
8
|
+
const currentValue = ref(props.modelValue);
|
|
9
|
+
|
|
10
|
+
const setStepList = () => {
|
|
11
|
+
if (!props.showStep) {
|
|
12
|
+
return [];
|
|
13
|
+
}
|
|
14
|
+
// step은 이동 단위 기준으로, 입력값에 따라 클릭 및 드레그 시 이동 단위를 나타냄
|
|
15
|
+
const sliderRange = props.max - props.min;
|
|
16
|
+
const stepCount = sliderRange / props.step;
|
|
17
|
+
const stepWidth = convertToPercent(props.step, sliderRange);
|
|
18
|
+
const result = [];
|
|
19
|
+
for (let ix = 1; ix < stepCount; ix++) {
|
|
20
|
+
result.push(ix * stepWidth);
|
|
21
|
+
}
|
|
22
|
+
return result;
|
|
23
|
+
};
|
|
24
|
+
|
|
25
|
+
const setMarkList = () => {
|
|
26
|
+
if (!props.mark || !Object.keys(props.mark).length) {
|
|
27
|
+
return [];
|
|
28
|
+
}
|
|
29
|
+
const getResultList = (obj, type = 'value') => {
|
|
30
|
+
if (!obj) {
|
|
31
|
+
return [];
|
|
32
|
+
}
|
|
33
|
+
const style = props.mark.style && (typeof props.mark.style === 'object') ? props.mark.style : {};
|
|
34
|
+
const keyList = Object.keys(obj);
|
|
35
|
+
const resultList = [];
|
|
36
|
+
let markVal;
|
|
37
|
+
for (let ix = 0; ix < keyList.length; ix++) {
|
|
38
|
+
markVal = +keyList[ix];
|
|
39
|
+
if (!isNaN(markVal)) {
|
|
40
|
+
resultList.push({
|
|
41
|
+
posX: type === 'value' ? convertToPercent(markVal, props.max - props.min) : markVal,
|
|
42
|
+
label: obj[markVal],
|
|
43
|
+
style,
|
|
44
|
+
});
|
|
45
|
+
}
|
|
46
|
+
}
|
|
47
|
+
return resultList;
|
|
48
|
+
};
|
|
49
|
+
|
|
50
|
+
const hasDetailOption = props.mark.value || props.mark.percent;
|
|
51
|
+
if (!hasDetailOption) {
|
|
52
|
+
return [...getResultList(props.mark)];
|
|
53
|
+
}
|
|
54
|
+
return [
|
|
55
|
+
...getResultList(props.mark.value),
|
|
56
|
+
...getResultList(props.mark.percent, 'percent'),
|
|
57
|
+
];
|
|
58
|
+
};
|
|
59
|
+
|
|
60
|
+
const state = reactive({
|
|
61
|
+
isInit: false,
|
|
62
|
+
dragging: false,
|
|
63
|
+
handleType: null, // 'left', 'right', null
|
|
64
|
+
leftValue: null,
|
|
65
|
+
rightValue: null,
|
|
66
|
+
});
|
|
67
|
+
const slider = reactive({
|
|
68
|
+
valueRange: 0,
|
|
69
|
+
stepList: computed(setStepList),
|
|
70
|
+
markList: computed(setMarkList),
|
|
71
|
+
offset: {
|
|
72
|
+
left: 0,
|
|
73
|
+
width: 0,
|
|
74
|
+
},
|
|
75
|
+
});
|
|
76
|
+
const sliderLine = ref();
|
|
77
|
+
|
|
78
|
+
// tooltip format
|
|
79
|
+
const formatValue = computed(() => {
|
|
80
|
+
const tooltipFormat = props.tooltipFormat;
|
|
81
|
+
const useFormat = tooltipFormat instanceof Function;
|
|
82
|
+
return {
|
|
83
|
+
left: useFormat ? tooltipFormat(state.leftValue) : state.leftValue,
|
|
84
|
+
right: useFormat ? tooltipFormat(state.rightValue) : state.rightValue,
|
|
85
|
+
};
|
|
86
|
+
});
|
|
87
|
+
|
|
88
|
+
const setHandleValue = (val) => {
|
|
89
|
+
const optionObj = {
|
|
90
|
+
min: props.min,
|
|
91
|
+
max: props.max,
|
|
92
|
+
step: props.step,
|
|
93
|
+
};
|
|
94
|
+
|
|
95
|
+
let leftVal;
|
|
96
|
+
let rightVal;
|
|
97
|
+
if (props.range && Array.isArray(val)) {
|
|
98
|
+
leftVal = typeof val[0] === 'number' && !isNaN(val[0]) ? val[0] : props.min;
|
|
99
|
+
rightVal = typeof val[1] === 'number' && !isNaN(val[1]) ? val[1] : props.min;
|
|
100
|
+
|
|
101
|
+
state.leftValue = getValueCloseToStep(leftVal, optionObj);
|
|
102
|
+
state.rightValue = getValueCloseToStep(rightVal, optionObj);
|
|
103
|
+
} else {
|
|
104
|
+
leftVal = props.min;
|
|
105
|
+
rightVal = typeof val === 'number' && !isNaN(val) ? val : props.min;
|
|
106
|
+
|
|
107
|
+
state.leftValue = getValueCloseToStep(leftVal, optionObj);
|
|
108
|
+
state.rightValue = getValueCloseToStep(rightVal, optionObj);
|
|
109
|
+
}
|
|
110
|
+
};
|
|
111
|
+
|
|
112
|
+
const setSliderValue = (val) => {
|
|
113
|
+
if (slider.valueRange <= 0) {
|
|
114
|
+
return;
|
|
115
|
+
}
|
|
116
|
+
|
|
117
|
+
setHandleValue(val);
|
|
118
|
+
|
|
119
|
+
let result;
|
|
120
|
+
if (props.range && Array.isArray(val)) {
|
|
121
|
+
const minVal = Math.min(state.leftValue, state.rightValue);
|
|
122
|
+
const maxVal = Math.max(state.leftValue, state.rightValue);
|
|
123
|
+
result = [minVal, maxVal];
|
|
124
|
+
} else {
|
|
125
|
+
result = state.rightValue;
|
|
126
|
+
}
|
|
127
|
+
|
|
128
|
+
currentValue.value = result;
|
|
129
|
+
emit('update:modelValue', result);
|
|
130
|
+
emit('change', result);
|
|
131
|
+
};
|
|
132
|
+
|
|
133
|
+
const updateSliderInfo = () => {
|
|
134
|
+
const sliderRect = sliderLine.value.getBoundingClientRect();
|
|
135
|
+
slider.offset.left = sliderRect.left;
|
|
136
|
+
slider.offset.width = sliderRect.width;
|
|
137
|
+
slider.valueRange = props.max - props.min;
|
|
138
|
+
};
|
|
139
|
+
|
|
140
|
+
watch(() => props.modelValue, (curr, prev) => {
|
|
141
|
+
if (curr
|
|
142
|
+
&& !isEqual(curr, prev)
|
|
143
|
+
&& !state.dragging
|
|
144
|
+
) {
|
|
145
|
+
setHandleValue(curr);
|
|
146
|
+
currentValue.value = curr;
|
|
147
|
+
}
|
|
148
|
+
});
|
|
149
|
+
watch(() => props.step, () => {
|
|
150
|
+
setSliderValue(currentValue.value);
|
|
151
|
+
});
|
|
152
|
+
|
|
153
|
+
return {
|
|
154
|
+
currentValue,
|
|
155
|
+
state,
|
|
156
|
+
slider,
|
|
157
|
+
formatValue,
|
|
158
|
+
sliderLine,
|
|
159
|
+
updateSliderInfo,
|
|
160
|
+
setSliderValue,
|
|
161
|
+
};
|
|
162
|
+
};
|
|
163
|
+
|
|
164
|
+
export const useStyle = (params) => {
|
|
165
|
+
const { props } = getCurrentInstance();
|
|
166
|
+
const { state, slider } = params;
|
|
167
|
+
const colorDefault = 'transparent';
|
|
168
|
+
|
|
169
|
+
const leftHandleStyle = computed(() => ({
|
|
170
|
+
left: slider.valueRange > 0 ? `${convertToPercent(state.leftValue - props.min, slider.valueRange)}%` : 0,
|
|
171
|
+
}));
|
|
172
|
+
const rightHandleStyle = computed(() => ({
|
|
173
|
+
left: slider.valueRange > 0 ? `${convertToPercent(state.rightValue - props.min, slider.valueRange)}%` : 0,
|
|
174
|
+
}));
|
|
175
|
+
const handleBtnStyle = computed(() => {
|
|
176
|
+
if (!props.color
|
|
177
|
+
|| (Array.isArray(props.color) && props.color.length !== 1)
|
|
178
|
+
) {
|
|
179
|
+
return {};
|
|
180
|
+
}
|
|
181
|
+
return {
|
|
182
|
+
borderColor: (typeof props.color === 'string' ? props.color : props.color[0]) || colorDefault,
|
|
183
|
+
};
|
|
184
|
+
});
|
|
185
|
+
|
|
186
|
+
/**
|
|
187
|
+
* Slider 색 칠하기 : props.color 갖고 있을 때
|
|
188
|
+
* color 로 받은 값에 따라 왼쪽 부터 채워짐. 없을 경우 기본 색 = transparent
|
|
189
|
+
* */
|
|
190
|
+
const isColorArray = computed(() => props.color && Array.isArray(props.color));
|
|
191
|
+
|
|
192
|
+
const rangeThumbStyle = computed(() => {
|
|
193
|
+
const minVal = Math.min(state.leftValue, state.rightValue);
|
|
194
|
+
const maxVal = Math.max(state.leftValue, state.rightValue);
|
|
195
|
+
const mvRange = +(maxVal - minVal).toFixed(2);
|
|
196
|
+
const leftPosX = (slider.valueRange > 0 && props.range)
|
|
197
|
+
? convertToPercent(+(minVal - props.min).toFixed(2), slider.valueRange) : 0;
|
|
198
|
+
const thumbWidth = (mvRange > 0) ? convertToPercent(mvRange, slider.valueRange) : 0;
|
|
199
|
+
|
|
200
|
+
const thumbColor = {};
|
|
201
|
+
if (props.color) {
|
|
202
|
+
if (typeof props.color === 'string'
|
|
203
|
+
|| (Array.isArray(props.color) && props.color.length === 1)
|
|
204
|
+
) {
|
|
205
|
+
thumbColor.backgroundColor = (typeof props.color === 'string' ? props.color : props.color[0]) || colorDefault;
|
|
206
|
+
} else if (Array.isArray(props.color) && props.color.length > 1) {
|
|
207
|
+
thumbColor.backgroundColor = (props.range ? props.color[1] : props.color[0])
|
|
208
|
+
|| colorDefault;
|
|
209
|
+
}
|
|
210
|
+
}
|
|
211
|
+
return {
|
|
212
|
+
left: `${leftPosX}%`,
|
|
213
|
+
width: `${thumbWidth}%`,
|
|
214
|
+
...thumbColor,
|
|
215
|
+
};
|
|
216
|
+
});
|
|
217
|
+
|
|
218
|
+
const leftThumbStyle = computed(() => {
|
|
219
|
+
if (
|
|
220
|
+
!isColorArray.value
|
|
221
|
+
|| props.color.length < 2
|
|
222
|
+
|| !props.range
|
|
223
|
+
) {
|
|
224
|
+
return {};
|
|
225
|
+
}
|
|
226
|
+
const minVal = Math.min(state.leftValue, state.rightValue);
|
|
227
|
+
const thumbWidth = convertToPercent(Math.abs(minVal - props.min), slider.valueRange);
|
|
228
|
+
return {
|
|
229
|
+
width: `${thumbWidth}%`,
|
|
230
|
+
backgroundColor: props.color[0] || colorDefault,
|
|
231
|
+
};
|
|
232
|
+
});
|
|
233
|
+
|
|
234
|
+
const rightThumbStyle = computed(() => {
|
|
235
|
+
if (!isColorArray.value || props.color.length < 2) {
|
|
236
|
+
return {};
|
|
237
|
+
}
|
|
238
|
+
const maxVal = Math.max(state.leftValue, state.rightValue);
|
|
239
|
+
const leftPosX = convertToPercent(+(maxVal - props.min).toFixed(2), slider.valueRange);
|
|
240
|
+
const thumbWidth = convertToPercent(+(props.max - maxVal).toFixed(2), slider.valueRange);
|
|
241
|
+
|
|
242
|
+
const lastIdx = !props.range ? props.color.length - 1 : 2;
|
|
243
|
+
return {
|
|
244
|
+
left: `${leftPosX}%`,
|
|
245
|
+
width: `${thumbWidth}%`,
|
|
246
|
+
backgroundColor: props.color[lastIdx] || colorDefault,
|
|
247
|
+
};
|
|
248
|
+
});
|
|
249
|
+
|
|
250
|
+
return {
|
|
251
|
+
isColorArray,
|
|
252
|
+
leftHandleStyle,
|
|
253
|
+
rightHandleStyle,
|
|
254
|
+
handleBtnStyle,
|
|
255
|
+
rangeThumbStyle,
|
|
256
|
+
leftThumbStyle,
|
|
257
|
+
rightThumbStyle,
|
|
258
|
+
};
|
|
259
|
+
};
|
|
260
|
+
|
|
261
|
+
export const useEvent = (params) => {
|
|
262
|
+
const { props } = getCurrentInstance();
|
|
263
|
+
const { currentValue, state, slider, updateSliderInfo, setSliderValue } = params;
|
|
264
|
+
|
|
265
|
+
const getSelectedValue = (e) => {
|
|
266
|
+
if (!state.dragging) {
|
|
267
|
+
updateSliderInfo();
|
|
268
|
+
}
|
|
269
|
+
|
|
270
|
+
const currentOffsetX = e.type.indexOf('touch') !== -1 ? e.touches[0].clientX : e.clientX;
|
|
271
|
+
const { valueRange, offset } = slider;
|
|
272
|
+
let clickedValue = props.min + ((currentOffsetX - offset.left) * valueRange) / offset.width;
|
|
273
|
+
|
|
274
|
+
if (clickedValue < props.min) {
|
|
275
|
+
clickedValue = props.min;
|
|
276
|
+
} else if (clickedValue > props.max) {
|
|
277
|
+
clickedValue = props.max;
|
|
278
|
+
}
|
|
279
|
+
|
|
280
|
+
return clickedValue;
|
|
281
|
+
};
|
|
282
|
+
|
|
283
|
+
const clickSlider = (e) => {
|
|
284
|
+
if (props.readonly || props.disabled || state.dragging) {
|
|
285
|
+
return;
|
|
286
|
+
}
|
|
287
|
+
|
|
288
|
+
const selectedValue = getSelectedValue(e);
|
|
289
|
+
let convertValue;
|
|
290
|
+
if (props.range) {
|
|
291
|
+
const minValue = Math.min(state.leftValue, state.rightValue);
|
|
292
|
+
const rangeHalfValue = minValue + Math.abs((state.rightValue - state.leftValue) / 2);
|
|
293
|
+
const isReverse = state.leftValue > state.rightValue;
|
|
294
|
+
|
|
295
|
+
if (selectedValue < rangeHalfValue) {
|
|
296
|
+
state.handleType = isReverse ? 'right' : 'left';
|
|
297
|
+
} else {
|
|
298
|
+
state.handleType = isReverse ? 'left' : 'right';
|
|
299
|
+
}
|
|
300
|
+
convertValue = state.handleType === 'left' ? [selectedValue, state.rightValue] : [state.leftValue, selectedValue];
|
|
301
|
+
} else {
|
|
302
|
+
state.handleType = 'right';
|
|
303
|
+
convertValue = selectedValue;
|
|
304
|
+
}
|
|
305
|
+
|
|
306
|
+
setSliderValue(convertValue);
|
|
307
|
+
};
|
|
308
|
+
|
|
309
|
+
const onDrag = (e) => {
|
|
310
|
+
const selectedValue = getSelectedValue(e);
|
|
311
|
+
state.dragging = true;
|
|
312
|
+
|
|
313
|
+
let convertValue;
|
|
314
|
+
if (props.range) {
|
|
315
|
+
convertValue = state.handleType === 'left' ? [selectedValue, state.rightValue] : [state.leftValue, selectedValue];
|
|
316
|
+
} else {
|
|
317
|
+
convertValue = selectedValue;
|
|
318
|
+
}
|
|
319
|
+
|
|
320
|
+
setSliderValue(convertValue);
|
|
321
|
+
};
|
|
322
|
+
const endDrag = () => {
|
|
323
|
+
state.handleType = null;
|
|
324
|
+
state.dragging = false;
|
|
325
|
+
document.body.style.cursor = '';
|
|
326
|
+
|
|
327
|
+
window.removeEventListener('mousemove', onDrag);
|
|
328
|
+
window.removeEventListener('touchmove', onDrag);
|
|
329
|
+
window.removeEventListener('mouseup', endDrag);
|
|
330
|
+
window.removeEventListener('touchend', endDrag);
|
|
331
|
+
};
|
|
332
|
+
const startDrag = (handleType) => {
|
|
333
|
+
if (props.readonly || props.disabled) {
|
|
334
|
+
return;
|
|
335
|
+
}
|
|
336
|
+
state.handleType = handleType;
|
|
337
|
+
document.body.style.cursor = 'grabbing';
|
|
338
|
+
|
|
339
|
+
window.addEventListener('mousemove', onDrag);
|
|
340
|
+
window.addEventListener('touchmove', onDrag);
|
|
341
|
+
window.addEventListener('mouseup', endDrag);
|
|
342
|
+
window.addEventListener('touchend', endDrag);
|
|
343
|
+
};
|
|
344
|
+
|
|
345
|
+
const changeInput = (val, type) => {
|
|
346
|
+
if (props.showInput && !state.dragging && state.isInit) {
|
|
347
|
+
if (props.range && Array.isArray(currentValue.value)) {
|
|
348
|
+
const result = type === 'left' ? [val, currentValue.value[1]] : [currentValue.value[0], val];
|
|
349
|
+
setSliderValue(result);
|
|
350
|
+
} else if (!props.range) {
|
|
351
|
+
setSliderValue(val);
|
|
352
|
+
}
|
|
353
|
+
}
|
|
354
|
+
};
|
|
355
|
+
return {
|
|
356
|
+
startDrag,
|
|
357
|
+
clickSlider,
|
|
358
|
+
changeInput,
|
|
359
|
+
};
|
|
360
|
+
};
|
|
361
|
+
|
|
362
|
+
export const useInit = (params) => {
|
|
363
|
+
const { props, emit } = getCurrentInstance();
|
|
364
|
+
const { currentValue, state, slider, updateSliderInfo, setSliderValue } = params;
|
|
365
|
+
|
|
366
|
+
const validateProps = () => {
|
|
367
|
+
const hasMaxProps = props.max || props.max === 0;
|
|
368
|
+
const hasMinProps = props.min || props.min === 0;
|
|
369
|
+
if (hasMaxProps && hasMinProps) {
|
|
370
|
+
if (props.max <= props.min) {
|
|
371
|
+
console.warn('[EVUI][Slider] Max value must be greater than min value.');
|
|
372
|
+
}
|
|
373
|
+
}
|
|
374
|
+
};
|
|
375
|
+
const initValue = () => {
|
|
376
|
+
updateSliderInfo();
|
|
377
|
+
|
|
378
|
+
if (slider.valueRange <= 0) {
|
|
379
|
+
currentValue.value = props.range ? [props.min, props.min] : props.min;
|
|
380
|
+
emit('update:modelValue', currentValue.value);
|
|
381
|
+
}
|
|
382
|
+
setSliderValue(currentValue.value);
|
|
383
|
+
state.isInit = true;
|
|
384
|
+
};
|
|
385
|
+
|
|
386
|
+
onMounted(() => {
|
|
387
|
+
validateProps();
|
|
388
|
+
initValue();
|
|
389
|
+
});
|
|
390
|
+
};
|