diff --git a/example/docs/zh-CN/components/slider.md b/example/docs/zh-CN/components/slider.md index 124c5a2d..73ac2603 100644 --- a/example/docs/zh-CN/components/slider.md +++ b/example/docs/zh-CN/components/slider.md @@ -13,7 +13,7 @@ ::: demo 使用 `lay-slider` 标签, 创建滑块 @@ -37,7 +37,7 @@ export default { ::: demo diff --git a/src/component/slider/StandardRange.vue b/src/component/slider/StandardRange.vue index 5ebb2a4e..ac85a61a 100644 --- a/src/component/slider/StandardRange.vue +++ b/src/component/slider/StandardRange.vue @@ -1,13 +1,14 @@ diff --git a/src/component/slider/Vertical.vue b/src/component/slider/Vertical.vue index ab279e4a..9fa8f871 100644 --- a/src/component/slider/Vertical.vue +++ b/src/component/slider/Vertical.vue @@ -9,6 +9,7 @@ interface Prop { step?: number; min?: number; max?: number; + showDots: boolean; } const props = withDefaults(defineProps(), { disabled: true, @@ -16,6 +17,7 @@ const props = withDefaults(defineProps(), { step: 0, min: 0, max: 100, + showDots: false, }); const moveAction = throttle(verticalMove); @@ -83,6 +85,22 @@ function calcWithStep( } } } +// 断点 +const makeDots = () => { + if (props.step === 0) return []; + let val = 0; + let dots = []; + let count = Math.floor(100 / props.step) - 1; + for (let i = 0; i < count; i++) { + val += props.step; + dots.push(val); + } + return dots; +}; +const dots = makeDots(); +const focusDot = (val: number) => { + emit("link-val-hook", val); +}; diff --git a/src/component/slider/VerticalRange.vue b/src/component/slider/VerticalRange.vue index c65ef86a..1c8c41bc 100644 --- a/src/component/slider/VerticalRange.vue +++ b/src/component/slider/VerticalRange.vue @@ -1,13 +1,14 @@ diff --git a/src/component/slider/index.less b/src/component/slider/index.less index ee353eac..cb756ec5 100644 --- a/src/component/slider/index.less +++ b/src/component/slider/index.less @@ -18,7 +18,8 @@ .layui-slider-btn-v { width: 12px; height: 12px; - background-color: @global-back-color; + // background-color: @global-back-color; + background-color: white; position: absolute; border: 2px solid @global-primary-color; border-radius: 50%; @@ -40,7 +41,7 @@ .layui-slider-line-v { width: 100%; height: 4px; - background-color: #eee; + background-color: #cccccc; position: absolute; top: 6px; } @@ -74,7 +75,8 @@ .layui-slider-vertical-btn { width: 12px; height: 12px; - background-color: @global-back-color; + // background-color: @global-back-color; + background-color: #ffffff; position: absolute; border: 2px solid @global-primary-color; border-radius: 50%; @@ -115,3 +117,23 @@ position: relative; cursor: pointer; } +.layui-slider-dots { + margin-top: 4px; + width: 8px; + height: 8px; + background-color: #ffffff; + border-radius: 5px; + position: absolute; + top:0; + z-index: 1; +} + +.layui-slider-vertical-dots { + width: 8px; + height: 8px; + background-color: #ffffff; + border-radius: 5px; + position: absolute; + z-index: 1; + margin-left: 5px; +} \ No newline at end of file diff --git a/src/component/slider/index.vue b/src/component/slider/index.vue index 74e85342..18cdc333 100644 --- a/src/component/slider/index.vue +++ b/src/component/slider/index.vue @@ -15,6 +15,7 @@ export interface LaySliderProps { disabled?: boolean; range?: boolean; rangeValue?: number[]; + showDots?: boolean } const emit = defineEmits(["update:modelValue"]); @@ -26,6 +27,7 @@ const props = withDefaults(defineProps(), { step: 0, min: 0, max: 100, + showDots: false }); let rangeValues: Ref | any = toRef(props, "rangeValue"); @@ -47,6 +49,7 @@ function valHook(val: any) { :rangeValue="rangeValues" :min="min" :max="max" + :showDots="showDots" />
@@ -58,6 +61,7 @@ function valHook(val: any) { :val="modelValue" :min="min" :max="max" + :showDots="showDots" />
@@ -71,6 +75,7 @@ function valHook(val: any) { :rangeValue="rangeValues" :min="min" :max="max" + :showDots="showDots" />
@@ -82,6 +87,7 @@ function valHook(val: any) { :step="step" :min="min" :max="max" + :showDots="showDots" >
diff --git a/src/component/slider/utils/index.ts b/src/component/slider/utils/index.ts index 400cd249..3495480b 100644 --- a/src/component/slider/utils/index.ts +++ b/src/component/slider/utils/index.ts @@ -13,3 +13,16 @@ export function throttle(func: Function) { export function handle_select(e: Event): void { e.preventDefault(); } + +export function makeDots(props: any) { + if (props.step === 0) return []; + let val = 0; + let dots = [0]; + let count = Math.floor(100 / props.step) - 1; + for (let i = 0; i < count; i++) { + val += props.step; + dots.push(val); + } + dots.push(100); + return dots; +}