index.wxml 2.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657
  1. <view class="wux-class {{ classes.wrap }}" style="{{ extWrapStyle }}">
  2. <view class="{{ classes.min }}" wx:if="{{ common.getValue(showValue, 'min') }}">{{ min }}</view>
  3. <slot name="min" wx:else></slot>
  4. <view class="{{ classes.railWrap }}" bindtap="onRailClick">
  5. <view class="{{ classes.rail }}" style="{{ extRailStyle }}">
  6. <block wx:for="{{ marks }}" wx:key="index" wx:if="{{ showMark && marks.length > 0 }}">
  7. <view class="{{ classes.mark }}" style="left: {{ item + '%' }}; {{ common.getStyle(extMarkStyle, index) }}" />
  8. </block>
  9. <block wx:for="{{ inputValue }}" wx:key="index">
  10. <view
  11. class="{{ classes.track }}"
  12. style="{{ common.getTrackStyle(offsets, index, inputValue.length > 1) }}; {{ common.getStyle(extTrackStyle, index) }}"
  13. wx:if="{{ inputValue.length === 1 || index !== inputValue.length - 1 }}"
  14. />
  15. <view
  16. class="{{ classes.handle }} {{ last === index ? prefixCls + '__handle--last' : '' }} {{ last === index && isTouched ? prefixCls + '__handle--is-touched' : '' }}"
  17. data-index="{{ index }}"
  18. data-meta="{{ common.format(tipFormatter, item) }}"
  19. bindtouchstart="onTouchStart"
  20. catchtouchmove="{{ isMoved ? 'noop' : '' }}"
  21. capture-bind:touchmove="onTouchMove"
  22. bindtouchend="onTouchEnd"
  23. style="left: {{ offsets[index] + '%' }}; {{ common.getStyle(extHandleStyle, index) }}"
  24. />
  25. </block>
  26. </view>
  27. </view>
  28. <view class="{{ classes.max }}" wx:if="{{ common.getValue(showValue, 'max') }}">{{ max }}</view>
  29. <slot name="max" wx:else></slot>
  30. </view>
  31. <wxs module="common">
  32. var util = require("../helpers/wxs/util.wxs")
  33. module.exports = {
  34. format: function(source, value) {
  35. return source.replace(getRegExp('\{d\}', 'g'), value)
  36. },
  37. getTrackStyle: function(offsets, index, multiple) {
  38. if (!multiple) {
  39. return 'width: ' + offsets[index] + '%'
  40. }
  41. return 'left: ' + offsets[index] + '%; width: ' + (offsets[index + 1] - offsets[index]) + '%'
  42. },
  43. getStyle: function(style, index) {
  44. if (util.type(style) !== 'string') {
  45. return style[index]
  46. }
  47. return style
  48. },
  49. getValue: function(obj, name) {
  50. if (util.type(obj) === 'object') {
  51. return obj[name]
  52. }
  53. return obj
  54. }
  55. }
  56. </wxs>