fs-radio-cell.vue 1.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364
  1. <template>
  2. <fs-cell border justify="right" @click="handleToggle">
  3. <template #title>
  4. <view :class="selected ? checkedColorType : ''" :style="{ color: selected ? checkedColor : '' }">
  5. <slot>{{ label }}</slot>
  6. </view>
  7. </template>
  8. <template #value>
  9. <fs-icon type="icon-right" :colorType="checkedColorType" :color="checkedColor" v-if="selected"></fs-icon>
  10. </template>
  11. </fs-cell>
  12. </template>
  13. <script>
  14. /**
  15. * 单选框组件
  16. * @description 单选框组件
  17. * @property {String} label 文本
  18. * @property {null} value 标识符(必须传)
  19. * @property {String} checkedColor 选中颜色
  20. * @property {String} checkedColorType = [primary | danger | warning | info | success] 选中颜色类型
  21. */
  22. export default {
  23. name: 'fs-radio-cell'
  24. }
  25. </script>
  26. <script setup>
  27. import { ref, watch, inject } from 'vue'
  28. const props = defineProps({
  29. label: String,
  30. value: {
  31. type: null,
  32. required: true
  33. },
  34. checkedColor: String,
  35. checkedColorType: String,
  36. checked: Boolean
  37. })
  38. let selected = ref(props.checked)
  39. watch(
  40. () => props.checked,
  41. val => {
  42. selected.value = val
  43. }
  44. )
  45. const radioGroup = inject('radioGroup')
  46. const checkedColorType = props.checkedColorType || radioGroup.checkedColorType
  47. const checkedColor = props.checkedColor || radioGroup.checkedColor
  48. radioGroup.updateChildren({
  49. selected,
  50. value: props.value
  51. })
  52. const handleToggle = () => {
  53. radioGroup.updateValue(props.value)
  54. }
  55. </script>
  56. <style lang="scss" scoped></style>