index.vue 1.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172
  1. <template>
  2. <view class="jnpf-switch">
  3. <u-switch v-model="innerValue" :active-value="activeValue" :inactive-value="inactiveValue" :disabled="disabled"
  4. :class="{'jnpf-switch-disabled':disabled}" @change="onChange" :size="size"></u-switch>
  5. </view>
  6. </template>
  7. <script>
  8. export default {
  9. name: 'jnpf-switch',
  10. props: {
  11. modelValue: {
  12. type: [String, Number, Boolean],
  13. },
  14. activeValue: {
  15. type: [String, Number, Boolean],
  16. default: 1
  17. },
  18. inactiveValue: {
  19. type: [String, Number, Boolean],
  20. default: 0
  21. },
  22. size: {
  23. default: 40
  24. },
  25. disabled: {
  26. type: Boolean,
  27. default: false
  28. },
  29. },
  30. data() {
  31. return {
  32. innerValue: ''
  33. }
  34. },
  35. watch: {
  36. modelValue: {
  37. handler(val) {
  38. this.innerValue = !!Number(val)
  39. },
  40. immediate: true,
  41. }
  42. },
  43. methods: {
  44. onChange(val) {
  45. this.$emit('update:modelValue', val)
  46. this.$emit('change', val)
  47. },
  48. }
  49. }
  50. </script>
  51. <style scoped lang="scss">
  52. .jnpf-switch {
  53. width: 100%;
  54. display: flex;
  55. justify-content: flex-end;
  56. align-items: center;
  57. :deep(.u-switch--disabled) {
  58. background-color: #E6E6E6 !important;
  59. border-color: #D9D9D9 !important;
  60. }
  61. .jnpf-switch-disabled {
  62. :deep(.u-switch__node) {
  63. background-color: #E6E6E6 !important;
  64. border-color: #D9D9D9 !important;
  65. }
  66. }
  67. }
  68. </style>