slider.wxml 6.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156
  1. <wxs src="./slider.wxs" module="t" />
  2. <wxs src="../common/utils.wxs" module="_" />
  3. <view
  4. style="{{_._style([style, customStyle])}}"
  5. class="{{_.cls(classPrefix, [['top', label || scaleTextArray.length], ['disabled', disabled], ['range', range]])}} class {{prefix}}-class"
  6. >
  7. <block wx:if="{{!range}}">
  8. <text wx:if="{{showExtremeValue}}" class="{{classPrefix}}__value {{classPrefix}}__value--min">
  9. {{ label ? t.getValue(label, min) : min}}
  10. </text>
  11. <view
  12. id="sliderLine"
  13. class="{{_.cls(classPrefix + '__bar', [['disabled', disabled], theme, ['marks', isScale && theme == 'capsule']])}} {{prefix}}-class-bar"
  14. bind:tap="onSingleLineTap"
  15. >
  16. <block wx:if="{{isScale}}">
  17. <view
  18. class="{{_.cls(classPrefix + '__scale-item', [['active', _value >= item.val], ['disabled', disabled], theme, ['hidden', (index == 0 || index == scaleArray.length - 1) && theme == 'capsule' || value == item.val]])}}"
  19. wx:for="{{scaleArray}}"
  20. wx:key="index"
  21. style="left:{{item.left}}px; transform: translateX(-50%);"
  22. aria-hidden="{{true}}"
  23. >
  24. <view wx:if="{{scaleTextArray.length}}" class="{{_.cls(classPrefix + '__scale-desc', [theme])}}}}">
  25. {{scaleTextArray[index]}}
  26. </view>
  27. </view>
  28. </block>
  29. <view
  30. class="{{_.cls(classPrefix + '__line', [['disabled', disabled], theme, 'single'])}} {{prefix}}-class-bar-active"
  31. style="width: {{lineBarWidth}}"
  32. >
  33. <view
  34. id="singleDot"
  35. class="{{classPrefix}}__dot {{prefix}}-class-cursor"
  36. bind:touchmove="onSingleLineTap"
  37. bind:touchend="onTouchEnd"
  38. bind:touchcancel="onTouchEnd"
  39. >
  40. <view
  41. wx:if="{{label || isVisibleToScreenReader}}"
  42. class="{{_.cls(classPrefix+'__dot-value', [['sr-only', !label]])}}"
  43. aria-role="alert"
  44. aria-live="assertive"
  45. aria-hidden="{{!isVisibleToScreenReader}}"
  46. >
  47. {{t.getValue(label, _value) || _value}}
  48. </view>
  49. <view
  50. class="{{classPrefix}}__dot-slider"
  51. aria-role="slider"
  52. aria-disabled="{{disabled}}"
  53. aria-valuemax="{{max}}"
  54. aria-valuemin="{{min}}"
  55. aria-valuenow="{{_value}}"
  56. aria-valuetext="{{t.getValue(label, _value) || _value}}"
  57. ></view>
  58. </view>
  59. </view>
  60. </view>
  61. <!-- <view wx:if="{{label}}" class="{{classPrefix}}__value {{classPrefix}}__value--right">
  62. <text class="{{classPrefix}}__value--text"> {{t.getValue(label, _value)}}</text>
  63. </view> -->
  64. <text wx:if="{{showExtremeValue}}" class="{{classPrefix}}__value {{classPrefix}}__value--max">
  65. {{ label ? t.getValue(label, max) : max}}
  66. </text>
  67. </block>
  68. <!-- range选择器自定义 -->
  69. <block wx:if="{{range}}">
  70. <view wx:if="{{showExtremeValue}}" class="{{classPrefix}}__range-extreme {{classPrefix}}__range-extreme--min">
  71. {{min}}
  72. </view>
  73. <view
  74. id="sliderLine"
  75. bind:tap="onLineTap"
  76. class="{{_.cls(classPrefix + '__bar', [['disabled', disabled], theme, ['marks', isScale && theme == 'capsule']])}} {{prefix}}-class-bar"
  77. >
  78. <block wx:if="{{isScale}}">
  79. <view
  80. class="{{_.cls(classPrefix + '__scale-item', [['active', dotTopValue[1] >= item.val && item.val >= dotTopValue[0]], ['disabled', disabled], theme, ['hidden', (index == 0 || index == scaleArray.length - 1) && theme == 'capsule' || value == item.val]])}}"
  81. wx:for="{{scaleArray}}"
  82. wx:for-index="index"
  83. wx:key="index"
  84. style="left: {{item.left}}px; transform: translateX(-50%)"
  85. aria-hidden="{{true}}"
  86. >
  87. <view wx:if="{{scaleTextArray.length}}" class="{{_.cls(classPrefix + '__scale-desc', [theme])}}"
  88. >{{scaleTextArray[index]}}</view
  89. >
  90. </view>
  91. </block>
  92. <view
  93. class="{{_.cls(classPrefix + '__line', [['disabled', disabled], theme])}} {{prefix}}-class-bar-active"
  94. style="left: {{lineLeft}}px; right: {{lineRight}}px"
  95. >
  96. <view
  97. id="leftDot"
  98. bind:touchmove="onTouchMoveLeft"
  99. bind:touchend="onTouchEnd"
  100. bind:touchcancel="onTouchEnd"
  101. class="{{classPrefix}}__dot {{classPrefix}}__dot--left {{prefix}}-class-cursor"
  102. >
  103. <view
  104. wx:if="{{label || isVisibleToScreenReader}}"
  105. class="{{_.cls(classPrefix+'__dot-value', [['sr-only', !label]])}}"
  106. aria-role="alert"
  107. aria-live="assertive"
  108. aria-hidden="{{!isVisibleToScreenReader}}"
  109. >
  110. {{t.getValue(label, dotTopValue[0]) || dotTopValue[0]}}
  111. </view>
  112. <view
  113. class="{{classPrefix}}__dot-slider"
  114. aria-role="slider"
  115. aria-disabled="{{disabled}}"
  116. aria-valuemax="{{max}}"
  117. aria-valuemin="{{min}}"
  118. aria-valuenow="{{dotTopValue[0]}}"
  119. aria-valuetext="{{t.getValue(label, dotTopValue[0]) || dotTopValue[0]}}"
  120. ></view>
  121. </view>
  122. <view
  123. id="rightDot"
  124. bind:touchmove="onTouchMoveRight"
  125. bind:touchend="onTouchEnd"
  126. bind:touchcancel="onTouchEnd"
  127. class="{{classPrefix}}__dot {{classPrefix}}__dot--right {{prefix}}-class-cursor"
  128. >
  129. <view
  130. wx:if="{{label || isVisibleToScreenReader}}"
  131. class="{{_.cls(classPrefix+'__dot-value', [['sr-only', !label]])}}"
  132. aria-role="alert"
  133. aria-live="assertive"
  134. aria-hidden="{{!isVisibleToScreenReader}}"
  135. >
  136. {{t.getValue(label, dotTopValue[1]) || dotTopValue[1]}}
  137. </view>
  138. <view
  139. class="{{classPrefix}}__dot-slider"
  140. aria-role="slider"
  141. aria-disabled="{{disabled}}"
  142. aria-valuemax="{{max}}"
  143. aria-valuemin="{{min}}"
  144. aria-valuenow="{{dotTopValue[1]}}"
  145. aria-valuetext="{{t.getValue(label, dotTopValue[1]) || dotTopValue[1]}}"
  146. >
  147. </view>
  148. </view>
  149. </view>
  150. </view>
  151. <view wx:if="{{showExtremeValue}}" class="{{classPrefix}}__range-extreme {{classPrefix}}__range-extreme--max">
  152. {{max}}
  153. </view>
  154. </block>
  155. </view>