合同小程序前端代码仓库
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

69 lines
1.6 KiB

  1. <template>
  2. <view class="l-radio-group" :class="'l-radio-group--'+ direction">
  3. <slot />
  4. </view>
  5. </template>
  6. <script lang="ts">
  7. // @ts-nocheck
  8. import { defineComponent, provide, ref, computed } from '@/uni_modules/lime-shared/vue'
  9. import radioGroupProps from './props'
  10. const name = 'l-radio-group'
  11. export default defineComponent({
  12. name,
  13. props: radioGroupProps,
  14. emits: ['update:value', 'update:modelValue', 'change', 'input'],
  15. setup(props, { emit }) {
  16. const innerValue = ref<any|null>(null);
  17. const groupValue = computed({
  18. set(value: any|null) {
  19. innerValue.value = value;
  20. emit('update:modelValue', value)
  21. emit('change', value)
  22. // #ifdef VUE2
  23. emit('input', value)
  24. // #endif
  25. },
  26. get():any|null {
  27. return props.value || props.name || props.modelValue || props.defaultValue || innerValue.value
  28. }
  29. } as WritableComputedOptions<any|null>)
  30. const handleRadioChange = (val: any) => {
  31. if (props.allowUncheck && val == groupValue.value) {
  32. groupValue.value = ''
  33. } else {
  34. groupValue.value = val
  35. }
  36. }
  37. provide('limeRadioGroupProps', props)
  38. provide('limeRadioGroupValue', groupValue)
  39. provide('limeRadioGroupChange', handleRadioChange)
  40. }
  41. })
  42. </script>
  43. <style lang="scss">
  44. // .l-radio-group {
  45. // display: flex;
  46. // flex-direction: row;
  47. // }
  48. // .l-radio-group--vertical {
  49. // flex-direction: column;
  50. // }
  51. .l-radio-group {
  52. // background-color: antiquewhite;
  53. }
  54. .l-radio-group--vertical {
  55. :deep(.l-radio) {
  56. display: flex;
  57. // line-height: 64rpx;
  58. }
  59. :deep(l-radio) {
  60. display: flex;
  61. // line-height: 64rpx;
  62. }
  63. }
  64. </style>