You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

71 lines
1.6 KiB

5 months ago
  1. <template>
  2. <view
  3. class="u-slider"
  4. :style="[addStyle(customStyle)]"
  5. >
  6. <slider
  7. :min="min"
  8. :max="max"
  9. :step="step"
  10. :value="modelValue"
  11. :activeColor="activeColor"
  12. :backgroundColor="inactiveColor"
  13. :blockSize="getPx(blockSize)"
  14. :blockColor="blockColor"
  15. :showValue="showValue"
  16. :disabled="disabled"
  17. @changing="changingHandler"
  18. @change="changeHandler"
  19. ></slider>
  20. </view>
  21. </template>
  22. <script>
  23. import { props } from './props';
  24. import { mpMixin } from '../../libs/mixin/mpMixin';
  25. import { mixin } from '../../libs/mixin/mixin';
  26. import { addStyle, getPx } from '../../libs/function/index.js';
  27. export default {
  28. name: 'up-slider',
  29. mixins: [mpMixin, mixin, props],
  30. emits: ["changing", "change", "update:modelValue"],
  31. methods: {
  32. addStyle,
  33. getPx,
  34. // 拖动过程中触发
  35. changingHandler(e) {
  36. const {
  37. value
  38. } = e.detail
  39. // 更新v-model的值
  40. // #ifdef VUE3
  41. this.$emit("update:modelValue", value);
  42. // #endif
  43. // #ifdef VUE2
  44. this.$emit("input", value);
  45. // #endif
  46. // 触发事件
  47. this.$emit('changing', value)
  48. },
  49. // 滑动结束时触发
  50. changeHandler(e) {
  51. const {
  52. value
  53. } = e.detail
  54. // 更新v-model的值
  55. // #ifdef VUE3
  56. this.$emit("update:modelValue", value);
  57. // #endif
  58. // #ifdef VUE2
  59. this.$emit("input", value);
  60. // #endif
  61. // 触发事件
  62. this.$emit('change', value)
  63. }
  64. },
  65. }
  66. </script>
  67. <style lang="scss" scoped>
  68. @import "../../libs/css/components.scss";
  69. </style>