slider.uvue 6.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186
  1. <script>
  2. export default {
  3. data() {
  4. return {
  5. sliderValue: 50,
  6. sliderBlockSize: 20,
  7. sliderBackgroundColor: "#000000",
  8. sliderActiveColor: "#FFCC33",
  9. sliderBlockColor: "#8A6DE9",
  10. // 组件属性 autotest
  11. show_value_boolean: false,
  12. disabled_boolean: false,
  13. min_input: 0,
  14. max_input: 100,
  15. step_input: 1,
  16. value_input: 0,
  17. activeColor_input: "#007aff",
  18. backgroundColor_input: "#e9e9e9",
  19. block_size_input: 28,
  20. block_color_input: "#ffffff",
  21. valueColor: "#888888",
  22. };
  23. },
  24. methods: {
  25. sliderChange(e : UniSliderChangeEvent) {
  26. console.log("value 发生变化:" + e.detail.value);
  27. },
  28. slider_click() {
  29. console.log("组件被点击时触发");
  30. },
  31. slider_touchstart() {
  32. console.log("手指触摸动作开始");
  33. },
  34. slider_touchmove() {
  35. console.log("手指触摸后移动");
  36. },
  37. slider_touchcancel() {
  38. console.log("手指触摸动作被打断,如来电提醒,弹窗");
  39. },
  40. slider_touchend() {
  41. console.log("手指触摸动作结束");
  42. },
  43. slider_tap() {
  44. console.log("手指触摸后马上离开");
  45. },
  46. slider_longpress() {
  47. console.log(
  48. "如果一个组件被绑定了 longpress 事件,那么当用户长按这个组件时,该事件将会被触发。"
  49. );
  50. },
  51. slider_change() {
  52. console.log("完成一次拖动后触发的事件,event.detail = {value: value}");
  53. },
  54. slider_changing() {
  55. console.log("拖动过程中触发的事件,event.detail = {value: value}");
  56. },
  57. change_show_value_boolean(checked : boolean) {
  58. this.show_value_boolean = checked;
  59. },
  60. change_disabled_boolean(checked : boolean) {
  61. this.disabled_boolean = checked;
  62. },
  63. confirm_min_input(value : number) {
  64. this.min_input = value;
  65. },
  66. confirm_max_input(value : number) {
  67. this.max_input = value;
  68. },
  69. confirm_step_input(value : number) {
  70. this.step_input = value;
  71. },
  72. confirm_value_input(value : number) {
  73. this.value_input = value;
  74. },
  75. confirm_activeColor_input(value : string) {
  76. this.activeColor_input = value;
  77. },
  78. confirm_backgroundColor_input(value : string) {
  79. this.backgroundColor_input = value;
  80. },
  81. confirm_block_size_input(value : number) {
  82. this.block_size_input = value;
  83. },
  84. confirm_block_color_input(value : string) {
  85. this.block_color_input = value;
  86. },
  87. confirm_value_color_input(value : string) {
  88. this.valueColor = value;
  89. },
  90. },
  91. };
  92. </script>
  93. <template>
  94. <view class="main">
  95. <slider :disabled="disabled_boolean" :min="min_input" :max="max_input" :step="step_input" :value="value_input"
  96. :activeColor="activeColor_input" :backgroundColor="backgroundColor_input" :block-size="block_size_input"
  97. :block-color="block_color_input" :show-value="show_value_boolean" :valueColor="valueColor" @click="slider_click"
  98. @touchstart="slider_touchstart" @touchmove="slider_touchmove" @touchcancel="slider_touchcancel"
  99. @touchend="slider_touchend" @tap="slider_tap" @longpress="slider_longpress" @change="slider_change"
  100. @changing="slider_changing" style="width: 90%"></slider>
  101. </view>
  102. <scroll-view style="flex: 1">
  103. <view class="content">
  104. <page-head title="组件属性"></page-head>
  105. <boolean-data :defaultValue="false" title="是否显示当前 value" @change="change_show_value_boolean"></boolean-data>
  106. <boolean-data :defaultValue="false" title="是否禁用" @change="change_disabled_boolean"></boolean-data>
  107. <input-data defaultValue="0" title="最小值(min)" type="number" @confirm="confirm_min_input"></input-data>
  108. <input-data defaultValue="100" title="最大值(max)" type="number" @confirm="confirm_max_input"></input-data>
  109. <input-data defaultValue="1" title="步长(step),取值必须大于 0,并且可被(max - min)整除" type="number"
  110. @confirm="confirm_step_input"></input-data>
  111. <input-data defaultValue="0" title="当前取值(value)" type="number" @confirm="confirm_value_input"></input-data>
  112. <input-data defaultValue="#007aff" title="滑块左侧已选择部分的线条颜色(active-color)" type="text"
  113. @confirm="confirm_activeColor_input"></input-data>
  114. <input-data defaultValue="#e9e9e9" title="背景条的颜色(background-color)" type="text"
  115. @confirm="confirm_backgroundColor_input"></input-data>
  116. <input-data defaultValue="28" title="滑块的大小(block-size),取值范围为 12 - 28" type="number"
  117. @confirm="confirm_block_size_input"></input-data>
  118. <input-data defaultValue="#ffffff" title="滑块颜色(block-color)" type="text"
  119. @confirm="confirm_block_color_input"></input-data>
  120. <input-data defaultValue="#888888" title="Value颜色(value-color)" type="text"
  121. @confirm="confirm_value_color_input"></input-data>
  122. </view>
  123. <view class="uni-padding-wrap">
  124. <page-head title="默认及使用"></page-head>
  125. <view class="uni-title">显示当前value</view>
  126. <view>
  127. <slider @change="sliderChange" :value="50" :show-value="true" />
  128. </view>
  129. <view class="uni-title">设置步进:step=10跳动</view>
  130. <view>
  131. <view class="uni-row">
  132. <text>0</text>
  133. <text class="m-l-a">100</text>
  134. </view>
  135. <slider @change="sliderChange" :value="60" :step="10" />
  136. </view>
  137. <view class="uni-title">浮点步进:step=0.01跳动</view>
  138. <view>
  139. <slider :value="0.5" :min="0" :max="1" :step="0.01" :show-value="true" />
  140. </view>
  141. <view class="uni-title">设置最小/最大值</view>
  142. <view>
  143. <slider @change="sliderChange" :value="100" :min="50" :max="200" :show-value="true" />
  144. </view>
  145. <view class="uni-title">不同颜色和大小的滑块</view>
  146. <view>
  147. <slider id="slider-custom-color-and-size" @change="sliderChange" :value="sliderValue"
  148. :backgroundColor="sliderBackgroundColor" :activeColor="sliderActiveColor"
  149. :activeBackgroundColor="sliderActiveColor" :blockColor="sliderBlockColor" :foreColor="sliderBlockColor"
  150. :block-size="sliderBlockSize" />
  151. </view>
  152. <view class="uni-title">暗黑模式</view>
  153. <view>
  154. <slider :show-value="true" backgroundColor="rgba(32,32,32,0.5)" valueColor="#555" />
  155. </view>
  156. <navigator class="uni-common-mb" url="./slider-in-swiper">
  157. <button>slider in swiper</button>
  158. </navigator>
  159. <navigator class="uni-common-mb" url="./slider-maxValue">
  160. <button>slider maxValue</button>
  161. </navigator>
  162. </view>
  163. </scroll-view>
  164. </template>
  165. <style>
  166. .main {
  167. padding: 5px 0;
  168. border-bottom: 1px solid rgba(0, 0, 0, 0.06);
  169. flex-direction: row;
  170. justify-content: center;
  171. }
  172. .m-l-a {
  173. margin-left: auto;
  174. }
  175. </style>