db-radio-group.vue 1.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263
  1. <template>
  2. <view class="db-radio-group">
  3. <view
  4. v-for="opt in options"
  5. :key="opt.value"
  6. class="db-radio"
  7. :class="{ 'db-radio--active': modelValue === opt.value, 'db-radio--disabled': disabled }"
  8. @click="onPick(opt.value)"
  9. >
  10. <view class="db-radio__dot" />
  11. <text>{{ opt.label }}</text>
  12. </view>
  13. </view>
  14. </template>
  15. <script setup>
  16. const props = defineProps({
  17. modelValue: String,
  18. disabled: Boolean,
  19. options: {
  20. type: Array,
  21. default: () => [
  22. { label: '入库', value: '入库' },
  23. { label: '出库', value: '出库' }
  24. ]
  25. }
  26. })
  27. const emit = defineEmits(['update:modelValue', 'change'])
  28. function onPick(v) {
  29. if (props.disabled) return
  30. emit('update:modelValue', v)
  31. emit('change', v)
  32. }
  33. </script>
  34. <style scoped>
  35. .db-radio-group {
  36. display: flex;
  37. gap: 16px;
  38. }
  39. .db-radio {
  40. display: flex;
  41. align-items: center;
  42. gap: 6px;
  43. font-size: 14px;
  44. color: #323233;
  45. }
  46. .db-radio__dot {
  47. width: 16px;
  48. height: 16px;
  49. border-radius: 50%;
  50. border: 1px solid #c8c9cc;
  51. box-sizing: border-box;
  52. }
  53. .db-radio--active .db-radio__dot {
  54. border-color: #52b788;
  55. background: radial-gradient(circle, #52b788 0 45%, transparent 50%);
  56. }
  57. .db-radio--disabled {
  58. opacity: 0.5;
  59. }
  60. </style>