slider.uvue 6.5 KB
Newer Older
1
<script>
H
hdx 已提交
2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23
  export default {
    data() {
      return {
        sliderValue: 50,
        sliderBlockSize: 20,
        sliderBackgroundColor: "#000000",
        sliderActiveColor: "#FFCC33",
        sliderBlockColor: "#8A6DE9",
        // 组件属性 autotest
        show_value_boolean: false,
        disabled_boolean: false,
        min_input: 0,
        max_input: 100,
        step_input: 1,
        value_input: 0,
        activeColor_input: "#007aff",
        backgroundColor_input: "#e9e9e9",
        block_size_input: 28,
        block_color_input: "#ffffff",
      };
    },
    methods: {
H
hdx 已提交
24
      sliderChange(e : UniSliderChangeEvent) {
H
hdx 已提交
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
        console.log("value 发生变化:" + e.detail.value);
      },
      slider_click() {
        console.log("组件被点击时触发");
      },
      slider_touchstart() {
        console.log("手指触摸动作开始");
      },
      slider_touchmove() {
        console.log("手指触摸后移动");
      },
      slider_touchcancel() {
        console.log("手指触摸动作被打断,如来电提醒,弹窗");
      },
      slider_touchend() {
        console.log("手指触摸动作结束");
      },
      slider_tap() {
        console.log("手指触摸后马上离开");
      },
      slider_longpress() {
        console.log(
          "如果一个组件被绑定了 longpress 事件,那么当用户长按这个组件时,该事件将会被触发。"
        );
      },
      slider_change() {
        console.log("完成一次拖动后触发的事件,event.detail = {value: value}");
      },
      slider_changing() {
        console.log("拖动过程中触发的事件,event.detail = {value: value}");
      },
      change_show_value_boolean(checked : boolean) {
        this.show_value_boolean = checked;
      },
      change_disabled_boolean(checked : boolean) {
        this.disabled_boolean = checked;
      },
      confirm_min_input(value : number) {
        this.min_input = value;
      },
      confirm_max_input(value : number) {
        this.max_input = value;
      },
      confirm_step_input(value : number) {
        this.step_input = value;
      },
      confirm_value_input(value : number) {
        this.value_input = value;
      },
      confirm_activeColor_input(value : string) {
        this.activeColor_input = value;
      },
      confirm_backgroundColor_input(value : string) {
        this.backgroundColor_input = value;
      },
      confirm_block_size_input(value : number) {
        this.block_size_input = value;
      },
      confirm_block_color_input(value : string) {
        this.block_color_input = value;
      },
    },
  };
H
hdx 已提交
88 89
</script>

90
<template>
91
  <view class="main">
H
hdx 已提交
92 93 94 95 96 97
    <slider :disabled="disabled_boolean" :min="min_input" :max="max_input" :step="step_input" :value="value_input"
      :activeColor="activeColor_input" :backgroundColor="backgroundColor_input" :block-size="block_size_input"
      :block-color="block_color_input" :show-value="show_value_boolean" @click="slider_click"
      @touchstart="slider_touchstart" @touchmove="slider_touchmove" @touchcancel="slider_touchcancel"
      @touchend="slider_touchend" @tap="slider_tap" @longpress="slider_longpress" @change="slider_change"
      @changing="slider_changing" style="width: 90%"><text>uni-app-x</text></slider>
98 99
  </view>

雪洛's avatar
雪洛 已提交
100
  <scroll-view style="flex: 1">
A
Anne_LXM 已提交
101
    <view class="content">
H
hdx 已提交
102
      <page-head title="组件属性"></page-head>
H
hdx 已提交
103 104
      <boolean-data :defaultValue="false" title="是否显示当前 value" @change="change_show_value_boolean"></boolean-data>
      <boolean-data :defaultValue="false" title="是否禁用" @change="change_disabled_boolean"></boolean-data>
H
hdx 已提交
105 106 107
      <input-data defaultValue="0" title="最小值(min)" type="number" @confirm="confirm_min_input"></input-data>
      <input-data defaultValue="100" title="最大值(max)" type="number" @confirm="confirm_max_input"></input-data>
      <input-data defaultValue="1" title="步长(step),取值必须大于 0,并且可被(max - min)整除" type="number"
H
hdx 已提交
108
        @confirm="confirm_step_input"></input-data>
H
hdx 已提交
109 110
      <input-data defaultValue="0" title="当前取值(value)" type="number" @confirm="confirm_value_input"></input-data>
      <input-data defaultValue="#007aff" title="滑块左侧已选择部分的线条颜色(active-color)" type="text"
H
hdx 已提交
111
        @confirm="confirm_activeColor_input"></input-data>
H
hdx 已提交
112
      <input-data defaultValue="#e9e9e9" title="背景条的颜色(background-color)" type="text"
H
hdx 已提交
113
        @confirm="confirm_backgroundColor_input"></input-data>
H
hdx 已提交
114
      <input-data defaultValue="28" title="滑块的大小(block-size),取值范围为 12 - 28" type="number"
H
hdx 已提交
115
        @confirm="confirm_block_size_input"></input-data>
H
hdx 已提交
116 117
      <input-data defaultValue="#ffffff" title="滑块颜色(block-color)" type="text"
        @confirm="confirm_block_color_input"></input-data>
H
hdx 已提交
118
    </view>
119

H
hdx 已提交
120 121 122 123 124 125
    <view class="uni-padding-wrap">
      <page-head title="默认及使用"></page-head>
      <view class="uni-title">显示当前value</view>
      <view>
        <slider @change="sliderChange" :value="50" :show-value="true" />
      </view>
126

H
hdx 已提交
127
      <view class="uni-title">设置步进:step=10跳动</view>
H
hdx 已提交
128 129 130 131 132
      <view>
        <view class="uni-row">
          <text>0</text>
          <text class="m-l-a">100</text>
        </view>
H
hdx 已提交
133
        <slider @change="sliderChange" :value="60" :step="10" />
H
hdx 已提交
134
      </view>
135

H
hdx 已提交
136 137 138 139 140
      <view class="uni-title">浮点步进:step=0.01跳动</view>
      <view>
        <slider :value="0.5" :min="0" :max="1" :step="0.01" :show-value="true" />
      </view>

H
hdx 已提交
141 142
      <view class="uni-title">设置最小/最大值</view>
      <view>
H
hdx 已提交
143
        <slider @change="sliderChange" :value="100" :min="50" :max="200" :show-value="true" />
H
hdx 已提交
144
      </view>
145

H
hdx 已提交
146 147
      <view class="uni-title">不同颜色和大小的滑块</view>
      <view>
148
        <slider id="slider-custom-color-and-size" @change="sliderChange" :value="sliderValue"
H
hdx 已提交
149 150
          :backgroundColor="sliderBackgroundColor" :activeColor="sliderActiveColor" :blockColor="sliderBlockColor"
          :block-size="sliderBlockSize" />
H
hdx 已提交
151
      </view>
H
hdx 已提交
152 153 154 155 156
      <view class="uni-title">暗黑模式</view>
      <view>
        <slider :show-value="true"
         backgroundColor="rgba(32,32,32,0.5)" valueColor="#555" />
      </view>
H
hdx 已提交
157 158 159 160

      <navigator url="./slider-in-swiper">
        <button>slider in swiper</button>
      </navigator>
H
hdx 已提交
161 162
    </view>
  </scroll-view>
163 164
</template>

H
hdx 已提交
165
<style>
H
hdx 已提交
166
  .main {
H
hdx 已提交
167
    padding: 5px 0;
H
hdx 已提交
168 169 170 171
    border-bottom: 1px solid rgba(0, 0, 0, 0.06);
    flex-direction: row;
    justify-content: center;
  }
H
hdx 已提交
172

H
hdx 已提交
173 174
  .main .list-item {
    width: 100%;
H
hdx 已提交
175
    height: 100px;
H
hdx 已提交
176 177
    border: 1px solid #666;
  }
178

H
hdx 已提交
179 180 181
  .m-l-a {
    margin-left: auto;
  }
182
</style>