fs-checkbox-cell.vue 1.4 KB

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