slider.wxml 4.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115
  1. <wxs src="./slider.wxs" module="utils" />
  2. <view
  3. class="{{classPrefix}}__container {{isScale && scaleTextArray.length ? classPrefix + '--bottom' : ''}} {{prefix}}-class {{disabled ? prefix + '-is-disabled ' + prefix + '-class-bar-disabled' : ''}}"
  4. >
  5. <block wx:if="{{!range}}">
  6. <view class="{{classPrefix}}__wrapper">
  7. <text wx:if="{{showExtremeValue}}" class="{{classPrefix}}__value {{classPrefix}}__value--min">
  8. {{ label ? utils.getValue(label, min) : min}}
  9. </text>
  10. <view
  11. id="sliderLine"
  12. class="{{classPrefix}}__main {{prefix}}-class-bar"
  13. style="background-color: {{disabled ? disabledColor[1] : colors[1]}};"
  14. bind:tap="onSingleLineTap"
  15. >
  16. <block wx:if="{{isScale}}">
  17. <view
  18. class="{{classPrefix}}__scale-item"
  19. wx:for="{{scaleArray}}"
  20. wx:for-index="index"
  21. wx:key="index"
  22. style="background:{{_value < item ? (disabled ? disabledColor[1] : colors[1]) : ( disabled ? disabledColor[0] : colors[0])}}; left:{{item}}%; transform:translateX({{- item}}%);"
  23. >
  24. <view wx:if="{{scaleTextArray.length}}" class="{{classPrefix}}__scale-desc">
  25. {{scaleTextArray[index]}}
  26. </view>
  27. </view>
  28. </block>
  29. <view
  30. class="{{classPrefix}}__line {{prefix}}-class-bar-active"
  31. style="background-color: {{disabled ? disabledColor[0] : colors[0]}}; left: {{lineLeft}}px; width: {{lineBarWidth}};"
  32. >
  33. <view
  34. id="singleDot"
  35. class="{{classPrefix}}__dot {{prefix}}-class-cursor"
  36. style="left: {{activeLeft}}px; border-color: {{disabled ? disabledColor[0] : ''}}"
  37. bind:touchmove="onSingleLineTap"
  38. bind:touchend="onTouchEnd"
  39. bind:touchcancel="onTouchEnd"
  40. />
  41. </view>
  42. </view>
  43. <view wx:if="{{label}}" class="{{classPrefix}}__value {{classPrefix}}__value--right">
  44. <text class="{{classPrefix}}__value--text"> {{utils.getValue(label, _value)}}</text>
  45. </view>
  46. <text wx:if="{{showExtremeValue}}" class="{{classPrefix}}__value {{classPrefix}}__value--max">
  47. {{ label ? utils.getValue(label, max) : max}}
  48. </text>
  49. </view>
  50. </block>
  51. <!-- range选择器自定义 -->
  52. <block wx:if="{{range}}">
  53. <view class="{{classPrefix}}__range-container">
  54. <view
  55. wx:if="{{showExtremeValue}}"
  56. class="{{classPrefix}}__range-extreme {{classPrefix}}__range-extreme--min"
  57. >
  58. {{min}}
  59. </view>
  60. <view
  61. id="sliderLine"
  62. bind:tap="onLineTap"
  63. class="{{classPrefix}}__bar {{prefix}}-class-bar"
  64. style="background-color: {{disabled ? disabledColor[1] : colors[1]}};"
  65. >
  66. <block wx:if="{{isScale}}">
  67. <view
  68. class="{{classPrefix}}__scale-item"
  69. wx:for="{{scaleArray}}"
  70. wx:for-index="index"
  71. wx:key="index"
  72. style="background:{{dotTopValue[1] < item || item < dotTopValue[0] ? (disabled ? disabledColor[1] : colors[1]) : ( disabled ? disabledColor[0] : colors[0])}};left: {{item}}%;transform:translateX({{- item}}%);"
  73. >
  74. <view wx:if="{{scaleTextArray.length}}">{{scaleTextArray[index]}}</view>
  75. </view>
  76. </block>
  77. <view
  78. class="{{classPrefix}}__line {{prefix}}-class-bar-active"
  79. style="background-color: {{disabled ? disabledColor[0] : colors[0]}}; left: {{lineLeft}}px; right: {{lineRight}}px;"
  80. />
  81. <view
  82. id="leftDot"
  83. bind:touchmove="onTouchMoveLeft"
  84. bind:touchend="onTouchEnd"
  85. bind:touchcancel="onTouchEnd"
  86. class="{{classPrefix}}__dot {{classPrefix}}__dot--left {{prefix}}-class-cursor"
  87. style="left: {{activeLeft}}px; border-color: {{disabled ? disabledColor[0] : ''}}"
  88. >
  89. <view wx:if="{{label}}" class="{{classPrefix}}__dot-value">
  90. {{utils.getValue(label, dotTopValue[0])}}
  91. </view>
  92. </view>
  93. <view
  94. id="rightDot"
  95. bind:touchmove="onTouchMoveRight"
  96. bind:touchend="onTouchEnd"
  97. bind:touchcancel="onTouchEnd"
  98. class="{{classPrefix}}__dot {{classPrefix}}__dot--right {{prefix}}-class-cursor"
  99. style="right: {{activeRight}}px; border-color: {{disabled ? disabledColor[0] : ''}}"
  100. >
  101. <view wx:if="{{label}}" class="{{classPrefix}}__dot-value">
  102. {{utils.getValue(label, dotTopValue[1])}}
  103. </view>
  104. </view>
  105. </view>
  106. <view
  107. wx:if="{{showExtremeValue}}"
  108. class="{{classPrefix}}__range-extreme {{classPrefix}}__range-extreme--max"
  109. >
  110. {{max}}
  111. </view>
  112. </view>
  113. </block>
  114. </view>