checkbox.uvue 3.7 KB

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