app-slider.vue 2.8 KB
Newer Older
1
<template>
2 3 4 5 6 7 8 9 10 11 12 13 14 15
    <div class="app-slider">
        <el-slider
            v-model="currentVal"
            :disabled="disabled || readonly"
            :step="step"
            :min="min"
            :max="max"
            :show-stops="showStops"
            :range="range"
            :show-input="showInput"
            @change="change"
        >
        </el-slider>
    </div>
16 17 18 19 20 21 22 23
</template>

<script lang='ts'>
import { Component, Vue, Prop, Model, Watch } from "vue-property-decorator";

@Component({})
export default class AppSlider extends Vue {
    /**
24 25 26 27 28
     * 传入值
     * @type {any}
     * @memberof AppSlider
     */
    @Prop() public value?: any;
29 30

    /**
31 32 33 34
     * 是否禁用
     * @type {boolean}
     * @memberof AppSlider
     */
35 36 37
    @Prop() public disabled?: boolean;

    /**
38 39 40 41 42
     * 属性项名称
     *
     * @type {string}
     * @memberof AppPicker
     */
43 44 45
    @Prop() public name!: string;

    /**
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
     * 步长
     * @type {number}
     * @memberof AppSlider
     */
    @Prop({ default: 1 }) public step!: number;

    /**
     * 最小值
     * @type {number}
     * @memberof AppSlider
     */
    @Prop({ default: 0 }) public min!: number;

    /**
     * 最大值
     * @type {number}
     * @memberof AppSlider
     */
    @Prop({ default: 100 }) public max!: number;

    /**
     * 只读模式
     *
     * @type {boolean}
     */
    @Prop({ default: false }) public readonly?: boolean;
72 73

    /**
74 75 76 77 78
     * 显示间隔点
     * @type {boolean}
     * @memberof AppSlider
     */
    @Prop({ default: false }) public showStops!: boolean;
79 80

    /**
81 82 83 84 85
     * 显示范围
     * @type {number}
     * @memberof AppSlider
     */
    @Prop({ default: false }) public range!: boolean;
86 87

    /**
88 89 90 91 92 93 94 95 96 97 98 99
     * 显示输入框
     * @type {number}
     * @memberof AppSlider
     */
    @Prop({ default: false }) public showInput!: boolean;

    /**
     * 当前值
     *
     * @memberof AppSlider
     */
    currentVal: number | Array<any> = 0;
100 101 102 103 104 105 106 107

    /**
     * 值变化
     *
     * @param {*} newVal
     * @param {*} oldVal
     * @memberof AppPicker
     */
108
    @Watch("value",{immediate:true,deep:true})
109
    public onValueChange(newVal: any, oldVal: any) {
110 111 112 113 114 115 116 117 118 119 120 121 122 123
        if(this.range){
            if(newVal && Array.isArray(newVal) &&  newVal.length > 0){
                //范围滑动条
                this.currentVal = newVal.map((item:any)=>{
                    return parseInt(item);
                })
            }else{
                this.currentVal = [this.min,this.max];
            }

        }else{
            newVal = newVal === null ? 0 : newVal;
            this.currentVal = parseInt(newVal);
        } 
124 125 126 127 128 129 130 131 132
    }

    /**
     * change事件
     *
     * @param {*} val
     * @memberof AppPicker
     */
    public change(val: any) {
133
        this.$emit("change", { name: this.name, value: val });
134 135 136
    }
}
</script>