index.vue 3.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127
  1. <template>
  2. <view class="u-demo">
  3. <view class="u-demo-wrap">
  4. <view class="u-demo-title">演示效果</view>
  5. <view class="u-demo-area">
  6. <u-toast ref="uToast"></u-toast>
  7. <u-slider :step="step" :height="height" :block-width="blockWidth"
  8. :active-color="activeColor" :value="30"
  9. :use-slot="useSlot" v-model="value"
  10. :min="min" :max="max"
  11. @end="end"
  12. @moving="moving"
  13. >
  14. <!-- #ifndef MP-WEIXIN || MP-TOUTIAO -->
  15. <view class="" v-if="useSlot">
  16. <view class="badge-button">
  17. {{value}}
  18. </view>
  19. </view>
  20. <!-- #endif -->
  21. </u-slider>
  22. <view class="u-demo-result-line">
  23. 滑块值:{{value}}
  24. </view>
  25. </view>
  26. </view>
  27. <view class="u-config-wrap">
  28. <view class="u-config-title u-border-bottom">参数配置</view>
  29. <view class="u-config-item">
  30. <view class="u-item-title">自定义颜色</view>
  31. <u-subsection :list="['primary', 'warning', 'error', 'success']" @change="typeChange"></u-subsection>
  32. </view>
  33. <!-- #ifndef MP-WEIXIN -->
  34. <view class="u-config-item">
  35. <view class="u-item-title">自定义传入内容</view>
  36. <u-subsection current="1" :list="['是', '否']" @change="slotChange"></u-subsection>
  37. </view>
  38. <!-- #endif -->
  39. <view class="u-config-item">
  40. <view class="u-item-title">自定义尺寸</view>
  41. <u-subsection current="1" :list="['是', '否']" @change="sizeChange"></u-subsection>
  42. </view>
  43. <view class="u-config-item">
  44. <view class="u-item-title">步进值</view>
  45. <u-subsection :list="['1', '10', '20']" @change="stepChange"></u-subsection>
  46. </view>
  47. <view class="u-config-item">
  48. <view class="u-item-title">最大最小值</view>
  49. <u-subsection :list="['0-100', '40-80']" @change="minMaxchange"></u-subsection>
  50. </view>
  51. </view>
  52. </view>
  53. </template>
  54. <script>
  55. export default {
  56. data() {
  57. return {
  58. value: 30,
  59. useSlot: false,
  60. setp: 1,
  61. activeColor: '#2979ff',
  62. height: 6,
  63. blockWidth: 30,
  64. step: 1,
  65. min: 0,
  66. max: 100
  67. };
  68. },
  69. onLoad() {
  70. },
  71. computed: {
  72. current() {
  73. return this.show ? 0 : 1;
  74. }
  75. },
  76. methods: {
  77. typeChange(index) {
  78. let type = ['primary', 'warning', 'error', 'success'];
  79. this.activeColor = this.$u.color[type[index]];
  80. },
  81. sizeChange(index) {
  82. if(index == 0) {
  83. this.height = 4;
  84. this.blockWidth = 30;
  85. } else {
  86. this.height = 6;
  87. this.blockWidth = 20;
  88. }
  89. },
  90. stepChange(index) {
  91. let arr = ['1', '10', '20'];
  92. this.step = arr[index];
  93. },
  94. slotChange(index) {
  95. this.useSlot = !index;
  96. },
  97. minMaxchange(index) {
  98. if(index == 0) {
  99. this.min = 0;
  100. this.max = 100;
  101. } else {
  102. this.min = 40;
  103. this.max = 80;
  104. }
  105. },
  106. end() {
  107. // console.log('end');
  108. },
  109. moving() {
  110. // console.log('moving');
  111. }
  112. }
  113. };
  114. </script>
  115. <style scoped lang="scss">
  116. .badge-button {
  117. padding: 4rpx 6rpx;
  118. background-color: $u-type-error;
  119. color: #fff;
  120. border-radius: 10rpx;
  121. font-size: 22rpx;
  122. line-height: 1;
  123. }
  124. </style>