enum-data.vue 1.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465
  1. <script lang="uts">
  2. import { ItemType } from './enum-data-types'
  3. import { state } from '@/store/index.uts'
  4. export default {
  5. emits: ['change'],
  6. props: {
  7. title: {
  8. type: String,
  9. default: ''
  10. },
  11. items: {
  12. type: Array as PropType<Array<ItemType>>,
  13. required: true
  14. }
  15. },
  16. computed: {
  17. isDarkMode() : boolean {
  18. return state.isDarkMode
  19. }
  20. },
  21. data() {
  22. return {
  23. current: 0
  24. }
  25. },
  26. methods: {
  27. // @ts-ignore
  28. _change(e : RadioGroupChangeEvent) {
  29. const selected = this.items.find((item : ItemType) : boolean => {
  30. return item.value.toString() == e.detail.value
  31. })
  32. if (selected != null) {
  33. this.$emit('change', selected.value)
  34. uni.showToast({
  35. icon: 'none',
  36. title: '当前选中:' + selected.name,
  37. })
  38. }
  39. }
  40. }
  41. }
  42. </script>
  43. <template>
  44. <view class="uni-padding-wrap" :class="isDarkMode ? 'theme-dark' : 'theme-light'">
  45. <view class="uni-title uni-common-mt">
  46. <text class="uni-title-text"> {{title}} </text>
  47. </view>
  48. </view>
  49. <view class="uni-list uni-common-pl" :class="isDarkMode ? 'theme-dark' : 'theme-light'">
  50. <radio-group @change="_change">
  51. <radio class="uni-list-cell uni-list-cell-pd" v-for="(item, index) in items" :key="item.name"
  52. :class="index < items.length - 1 ? 'uni-list-cell-line' : ''"
  53. :value="item.value + ''" :color="isDarkMode ? '#a8a8b7' : '#007AFF'">
  54. <text class="radio-text">{{ item.name }}</text>
  55. </radio>
  56. </radio-group>
  57. </view>
  58. </template>
  59. <style>
  60. .uni-list .radio-text {
  61. color: var(--text-color, #333333);
  62. }
  63. </style>