radio.uvue 3.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146
  1. <template>
  2. <cl-page>
  3. <view class="p-3">
  4. <demo-item :label="t('基础用法')">
  5. <view class="flex flex-row flex-wrap">
  6. <cl-radio
  7. v-model="checked2"
  8. v-for="(item, index) in options"
  9. :key="index"
  10. :value="item.value"
  11. :pt="{
  12. className: 'mr-5'
  13. }"
  14. >
  15. {{ item.label }}
  16. </cl-radio>
  17. </view>
  18. </demo-item>
  19. <demo-item :label="t('纵向排列')">
  20. <cl-radio
  21. v-model="checked"
  22. v-for="(item, index) in options"
  23. :key="index"
  24. :value="item.value"
  25. :pt="{
  26. className: parseClass([
  27. 'my-2',
  28. [
  29. isVerticalCustom,
  30. 'justify-between border border-solid border-surface-200 rounded-lg p-2 !my-1'
  31. ]
  32. ])
  33. }"
  34. >
  35. {{ item.label }}
  36. </cl-radio>
  37. <cl-list
  38. border
  39. :pt="{
  40. className: 'mt-2'
  41. }"
  42. >
  43. <cl-list-item :label="t('换个样式')">
  44. <cl-switch v-model="isVerticalCustom"></cl-switch>
  45. </cl-list-item>
  46. </cl-list>
  47. </demo-item>
  48. <demo-item :label="t('自定义')">
  49. <view class="mb-3 flex flex-row flex-wrap">
  50. <cl-radio
  51. v-model="checked3"
  52. v-for="(item, index) in options"
  53. :key="index"
  54. :value="item.value"
  55. :disabled="isDisabled"
  56. :show-icon="!isHideIcon"
  57. :active-icon="isIcon ? 'heart-fill' : 'checkbox-circle-line'"
  58. :inactive-icon="isIcon ? 'heart-line' : 'checkbox-blank-circle-line'"
  59. :pt="{
  60. className: parseClass([
  61. 'mr-5',
  62. [isCustom, 'bg-surface-100 py-2 px-3 rounded-lg !mr-2 !mb-2'],
  63. {
  64. '!bg-surface-700': isDark && isCustom
  65. }
  66. ]),
  67. icon: {
  68. className: parseClass([
  69. [isCustom && item.value == checked3, 'text-red-500']
  70. ])
  71. },
  72. label: {
  73. className: parseClass([
  74. [isCustom && item.value == checked3, 'text-red-500']
  75. ])
  76. }
  77. }"
  78. >
  79. {{ item.label }}
  80. </cl-radio>
  81. </view>
  82. <cl-list border>
  83. <cl-list-item :label="t('换个图标')">
  84. <cl-switch v-model="isIcon"></cl-switch>
  85. </cl-list-item>
  86. <cl-list-item :label="t('不显示图标')">
  87. <cl-switch v-model="isHideIcon"></cl-switch>
  88. </cl-list-item>
  89. <cl-list-item :label="t('禁用')">
  90. <cl-switch v-model="isDisabled"></cl-switch>
  91. </cl-list-item>
  92. <cl-list-item :label="t('其他样式')">
  93. <cl-switch v-model="isCustom"></cl-switch>
  94. </cl-list-item>
  95. </cl-list>
  96. </demo-item>
  97. </view>
  98. </cl-page>
  99. </template>
  100. <script lang="ts" setup>
  101. import { ref } from "vue";
  102. import DemoItem from "../components/item.uvue";
  103. import { parseClass } from "@/cool";
  104. import { useUi, type ClRadioOption } from "@/uni_modules/cool-ui";
  105. import { isDark } from "@/cool";
  106. import { t } from "@/locale";
  107. const ui = useUi();
  108. const isIcon = ref(false);
  109. const isCustom = ref(false);
  110. const isDisabled = ref(false);
  111. const isHideIcon = ref(false);
  112. const isVerticalCustom = ref(false);
  113. const checked = ref("1");
  114. const checked2 = ref("2");
  115. const checked3 = ref("3");
  116. const options = ref<ClRadioOption[]>([
  117. {
  118. label: "Vue",
  119. value: "1"
  120. },
  121. {
  122. label: "React",
  123. value: "2"
  124. },
  125. {
  126. label: "Angular",
  127. value: "3"
  128. },
  129. {
  130. label: "Svelte",
  131. value: "4"
  132. }
  133. ]);
  134. </script>