boolean-data.vue 1.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859
  1. <script lang="uts">
  2. import { state } from '@/store/index.uts'
  3. export default {
  4. emits: ['change'],
  5. props: {
  6. title: {
  7. type: String,
  8. default: ''
  9. },
  10. disabled: {
  11. type: Boolean,
  12. default: false
  13. },
  14. defaultValue: {
  15. type: Boolean,
  16. default: false
  17. }
  18. },
  19. computed: {
  20. isDarkMode() : boolean {
  21. return state.isDarkMode
  22. }
  23. },
  24. data() {
  25. return {
  26. _checked: false
  27. }
  28. },
  29. created() {
  30. this._checked = this.defaultValue
  31. },
  32. methods: {
  33. // @ts-ignore
  34. _change(e : UniSwitchChangeEvent) {
  35. this._checked = e.detail.value;
  36. this.$emit('change', this._checked)
  37. }
  38. }
  39. }
  40. </script>
  41. <template>
  42. <view class="button-data-main uni-flex" :class="isDarkMode ? 'theme-dark' : 'theme-light'">
  43. <text class="uni-title" style="width:80%">{{ title }}</text>
  44. <switch :checked="_checked" :disabled="disabled" :color="isDarkMode ? '#a8a8b7' : '#007AFF'" @change="_change" />
  45. </view>
  46. </template>
  47. <style>
  48. .button-data-main {
  49. justify-content: space-between;
  50. padding: 10px;
  51. border-bottom: 1px solid var(--border-color, rgba(0, 0, 0, .06));
  52. align-items: center;
  53. }
  54. .button-data-main .uni-title {
  55. color: var(--text-color, #333333);
  56. }
  57. </style>