fs-radio-cell.vue 1.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152
  1. <template>
  2. <fs-cell
  3. border
  4. justify="right"
  5. @click="handleToggle">
  6. <template #title>
  7. <view :class="selected ? checkedColorType : ''" :style="{color: selected ? checkedColor : ''}">
  8. <slot>{{label}}</slot>
  9. </view>
  10. </template>
  11. <template #value>
  12. <fs-icon type="icon-right" :colorType="checkedColorType" :color="checkedColor" v-if="selected"></fs-icon>
  13. </template>
  14. </fs-cell>
  15. </template>
  16. <script setup>
  17. import { ref, watch, inject } from 'vue'
  18. const props = defineProps({
  19. label: String,
  20. value: {
  21. type: null,
  22. required: true
  23. },
  24. checkedColor: String,
  25. checkedColorType: String,
  26. checked: Boolean
  27. })
  28. let selected = ref(props.checked)
  29. watch(() => props.checked, val => {
  30. selected.value = val
  31. })
  32. const radioGroup = inject('radioGroup')
  33. const checkedColorType = props.checkedColorType || radioGroup.checkedColorType
  34. const checkedColor = props.checkedColor || radioGroup.checkedColor
  35. radioGroup.updateChildren({
  36. selected,
  37. value: props.value
  38. })
  39. const handleToggle = () => {
  40. radioGroup.updateValue(props.value)
  41. }
  42. </script>
  43. <style lang="scss" scoped>
  44. </style>