checkbox.uvue 3.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147
  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. }"
  76. >
  77. {{ item.label }}
  78. </cl-checkbox>
  79. </view>
  80. <cl-list border>
  81. <cl-list-item :label="t('换个图标')">
  82. <cl-switch v-model="isIcon"></cl-switch>
  83. </cl-list-item>
  84. <cl-list-item :label="t('不显示图标')">
  85. <cl-switch v-model="isHideIcon"></cl-switch>
  86. </cl-list-item>
  87. <cl-list-item :label="t('禁用')">
  88. <cl-switch v-model="isDisabled"></cl-switch>
  89. </cl-list-item>
  90. <cl-list-item :label="t('其他样式')">
  91. <cl-switch v-model="isCustom"></cl-switch>
  92. </cl-list-item>
  93. </cl-list>
  94. </demo-item>
  95. </view>
  96. </cl-page>
  97. </template>
  98. <script lang="ts" setup>
  99. import { ref } from "vue";
  100. import DemoItem from "../components/item.uvue";
  101. import { useUi, type ClCheckboxOption } from "@/uni_modules/cool-ui";
  102. import { isDark, parseClass } from "@/cool";
  103. import { t } from "@/locale";
  104. const ui = useUi();
  105. const isIcon = ref(false);
  106. const isCustom = ref(false);
  107. const isDisabled = ref(false);
  108. const isHideIcon = ref(false);
  109. const isVerticalCustom = ref(false);
  110. const checked = ref<string[]>([]);
  111. const checked2 = ref<string[]>(["2"]);
  112. const checked3 = ref<string[]>(["2", "3"]);
  113. const checked4 = ref(false);
  114. const options = ref<ClCheckboxOption[]>([
  115. {
  116. label: "Vue",
  117. value: "1"
  118. },
  119. {
  120. label: "React",
  121. value: "2"
  122. },
  123. {
  124. label: "Angular",
  125. value: "3"
  126. },
  127. {
  128. label: "Svelte",
  129. value: "4"
  130. }
  131. ]);
  132. </script>