slider.wxml 6.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147
  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. style="{{t.getColor(disabled, false, disabledColor, colors)}}"
  15. bind:tap="onSingleLineTap"
  16. >
  17. <block wx:if="{{isScale}}">
  18. <view
  19. class="{{_.cls(classPrefix + '__scale-item', [['active', _value >= item.val], ['disabled', disabled], theme, ['hidden', (index == 0 || index == scaleArray.length - 1) && theme == 'capsule' || value == item.val]])}}"
  20. wx:for="{{scaleArray}}"
  21. wx:key="index"
  22. style="left:{{item.left}}px; transform: translateX(-50%); {{t.getColor(disabled, _value >= item.val, disabledColor, colors)}}"
  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}}; {{t.getColor(disabled, true, disabledColor, colors)}}"
  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. class="{{_.cls(classPrefix+'__dot-value', [['sr-only', !label]])}}"
  42. aria-role="region"
  43. aria-live="assertive"
  44. >
  45. {{t.getValue(label, _value) || _value}}
  46. </view>
  47. <view
  48. class="{{classPrefix}}__dot-slider"
  49. aria-role="slider"
  50. aria-disabled="{{disabled}}"
  51. aria-valuemax="{{max}}"
  52. aria-valuemin="{{min}}"
  53. aria-valuenow="{{_value}}"
  54. ></view>
  55. </view>
  56. </view>
  57. </view>
  58. <!-- <view wx:if="{{label}}" class="{{classPrefix}}__value {{classPrefix}}__value--right">
  59. <text class="{{classPrefix}}__value--text"> {{t.getValue(label, _value)}}</text>
  60. </view> -->
  61. <text wx:if="{{showExtremeValue}}" class="{{classPrefix}}__value {{classPrefix}}__value--max">
  62. {{ label ? t.getValue(label, max) : max}}
  63. </text>
  64. </block>
  65. <!-- range选择器自定义 -->
  66. <block wx:if="{{range}}">
  67. <view wx:if="{{showExtremeValue}}" class="{{classPrefix}}__range-extreme {{classPrefix}}__range-extreme--min">
  68. {{min}}
  69. </view>
  70. <view
  71. id="sliderLine"
  72. bind:tap="onLineTap"
  73. class="{{_.cls(classPrefix + '__bar', [['disabled', disabled], theme, ['marks', isScale && theme == 'capsule']])}} {{prefix}}-class-bar"
  74. style="{{t.getColor(disabled, false, disabledColor, colors)}}"
  75. >
  76. <block wx:if="{{isScale}}">
  77. <view
  78. 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]])}}"
  79. wx:for="{{scaleArray}}"
  80. wx:for-index="index"
  81. wx:key="index"
  82. style="left: {{item.left}}px; transform: translateX(-50%); {{t.getColor(disabled, (dotTopValue[1] >= item.val && item.val >= dotTopValue[0]), disabledColor, colors)}}"
  83. >
  84. <view wx:if="{{scaleTextArray.length}}" class="{{_.cls(classPrefix + '__scale-desc', [theme])}}"
  85. >{{scaleTextArray[index]}}</view
  86. >
  87. </view>
  88. </block>
  89. <view
  90. class="{{_.cls(classPrefix + '__line', [['disabled', disabled], theme])}} {{prefix}}-class-bar-active"
  91. style="left: {{lineLeft}}px; right: {{lineRight}}px; {{t.getColor(disabled, true, disabledColor, colors)}}"
  92. >
  93. <view
  94. id="leftDot"
  95. bind:touchmove="onTouchMoveLeft"
  96. bind:touchend="onTouchEnd"
  97. bind:touchcancel="onTouchEnd"
  98. class="{{classPrefix}}__dot {{classPrefix}}__dot--left {{prefix}}-class-cursor"
  99. >
  100. <view
  101. class="{{_.cls(classPrefix+'__dot-value', [['sr-only', !label]])}}"
  102. aria-role="region"
  103. aria-live="assertive"
  104. >
  105. {{t.getValue(label, dotTopValue[0]) || dotTopValue[0]}}
  106. </view>
  107. <view
  108. class="{{classPrefix}}__dot-slider"
  109. aria-role="slider"
  110. aria-disabled="{{disabled}}"
  111. aria-valuemax="{{t.getValue(label, dotTopValue[1]) || dotTopValue[1]}}"
  112. aria-valuemin="{{min}}"
  113. aria-valuenow="{{t.getValue(label, dotTopValue[0]) || dotTopValue[0]}}"
  114. ></view>
  115. </view>
  116. <view
  117. id="rightDot"
  118. bind:touchmove="onTouchMoveRight"
  119. bind:touchend="onTouchEnd"
  120. bind:touchcancel="onTouchEnd"
  121. class="{{classPrefix}}__dot {{classPrefix}}__dot--right {{prefix}}-class-cursor"
  122. >
  123. <view
  124. class="{{_.cls(classPrefix+'__dot-value', [['sr-only', !label]])}}"
  125. aria-role="region"
  126. aria-live="assertive"
  127. >
  128. {{t.getValue(label, dotTopValue[1]) || dotTopValue[1]}}
  129. </view>
  130. <view
  131. class="{{classPrefix}}__dot-slider"
  132. aria-role="slider"
  133. aria-disabled="{{disabled}}"
  134. aria-valuemax="{{max}}"
  135. aria-valuemin="{{t.getValue(label, dotTopValue[0]) || dotTopValue[0]}}"
  136. aria-valuenow="{{t.getValue(label, dotTopValue[1]) || dotTopValue[1]}}"
  137. >
  138. </view>
  139. </view>
  140. </view>
  141. </view>
  142. <view wx:if="{{showExtremeValue}}" class="{{classPrefix}}__range-extreme {{classPrefix}}__range-extreme--max">
  143. {{max}}
  144. </view>
  145. </block>
  146. </view>