index.vue 1.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687
  1. <template>
  2. <u-slider class="jnpf-slider" :class="{'jnpf-slider-disabled':disabled}" v-model="innerValue" :step="step"
  3. :min="min" :max="max" :disabled="disabled" @end="end">
  4. <view class="slider-badge-button" :class="{'disabled':disabled}">{{innerValue}}</view>
  5. </u-slider>
  6. </template>
  7. <script>
  8. export default {
  9. name: 'jnpf-slider',
  10. props: {
  11. modelValue: {
  12. type: [Number, String],
  13. default: 0
  14. },
  15. min: {
  16. type: Number,
  17. default: 0
  18. },
  19. max: {
  20. type: Number,
  21. default: 100
  22. },
  23. step: {
  24. type: Number,
  25. default: 1
  26. },
  27. disabled: {
  28. type: Boolean,
  29. default: false
  30. },
  31. },
  32. data() {
  33. return {
  34. innerValue: 0
  35. }
  36. },
  37. watch: {
  38. modelValue: {
  39. handler(val) {
  40. this.innerValue = val
  41. },
  42. immediate: true,
  43. deep: true
  44. },
  45. innerValue: {
  46. handler(val) {
  47. this.$emit('update:modelValue', val)
  48. this.$emit('change', val)
  49. },
  50. immediate: true,
  51. deep: true
  52. }
  53. },
  54. methods: {
  55. end() {
  56. this.$emit('update:modelValue', this.innerValue)
  57. this.$emit('change', this.innerValue)
  58. }
  59. }
  60. }
  61. </script>
  62. <style lang="scss" scoped>
  63. .jnpf-slider {
  64. width: 100%;
  65. .slider-badge-button {
  66. padding: 4rpx 6rpx;
  67. background-color: $u-type-primary;
  68. color: #fff;
  69. border-radius: 10rpx;
  70. font-size: 22rpx;
  71. line-height: 1;
  72. &.disabled {
  73. background-color: #E6E6E6 !important;
  74. color: #9B9B9B !important;
  75. }
  76. }
  77. &.jnpf-slider-disabled {
  78. :deep(.u-slider__gap) {
  79. background-color: #E6E6E6 !important;
  80. border-color: #D9D9D9 !important;
  81. }
  82. }
  83. }
  84. </style>