zhangxiaoxu123456
2021-12-17 4d4a844ef624dde8667b314d353599297f6cb8d9
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
<template>
    <view class="u-demo">
        <view class="u-demo-wrap">
            <view class="u-demo-title">演示效果</view>
            <view class="u-demo-area">
                <u-toast ref="uToast"></u-toast>
                <u-slider :step="step" :height="height" :block-width="blockWidth" 
                    :active-color="activeColor" :value="30" 
                    :use-slot="useSlot" v-model="value"
                    :min="min" :max="max" 
                    @end="end"
                    @moving="moving"
                >
                    <!-- #ifndef MP-WEIXIN || MP-TOUTIAO -->
                    <view class="" v-if="useSlot">
                        <view class="badge-button">
                            {{value}}
                        </view>
                    </view>
                    <!-- #endif -->
                </u-slider>
                <view class="u-demo-result-line">
                    滑块值:{{value}}
                </view>
            </view>
        </view>
        <view class="u-config-wrap">
            <view class="u-config-title u-border-bottom">参数配置</view>
            <view class="u-config-item">
                <view class="u-item-title">自定义颜色</view>
                <u-subsection :list="['primary', 'warning', 'error', 'success']" @change="typeChange"></u-subsection>
            </view>
            <!-- #ifndef MP-WEIXIN -->
            <view class="u-config-item">
                <view class="u-item-title">自定义传入内容</view>
                <u-subsection current="1" :list="['是', '否']" @change="slotChange"></u-subsection>
            </view>
            <!-- #endif -->
            <view class="u-config-item">
                <view class="u-item-title">自定义尺寸</view>
                <u-subsection current="1" :list="['是', '否']" @change="sizeChange"></u-subsection>
            </view>
            <view class="u-config-item">
                <view class="u-item-title">步进值</view>
                <u-subsection :list="['1', '10', '20']" @change="stepChange"></u-subsection>
            </view>
            <view class="u-config-item">
                <view class="u-item-title">最大最小值</view>
                <u-subsection :list="['0-100', '40-80']" @change="minMaxchange"></u-subsection>
            </view>
        </view>
    </view>
</template>
 
<script>
    export default {
        data() {
            return {
                value: 30,
                useSlot: false,
                setp: 1,
                activeColor: '#2979ff',
                height: 6,
                blockWidth: 30,
                step: 1,
                min: 0,
                max: 100
            };
        },
        onLoad() {
            
        },
        computed: {
            current() {
                return this.show ? 0 : 1;
            }
        },
        methods: {
            typeChange(index) {
                let type = ['primary', 'warning', 'error', 'success'];
                this.activeColor = this.$u.color[type[index]];
            },
            sizeChange(index) {
                if(index == 0) {
                    this.height = 4;
                    this.blockWidth = 30;
                } else {
                    this.height = 6;
                    this.blockWidth = 20;
                }
            },
            stepChange(index) {
                let arr = ['1', '10', '20'];
                this.step = arr[index];
            },
            slotChange(index) {
                this.useSlot = !index;
            },
            minMaxchange(index) {
                if(index == 0) {
                    this.min = 0;
                    this.max = 100;
                } else {
                    this.min = 40;
                    this.max = 80;
                }
            },
            end() {
                // console.log('end');
            },
            moving() {
                // console.log('moving');
            }
        }
    };
</script>
 
<style scoped lang="scss">
    .badge-button {
        padding: 4rpx 6rpx;
        background-color: $u-type-error;
        color: #fff;
        border-radius: 10rpx;
        font-size: 22rpx;
        line-height: 1;
    }
</style>