input-otp.uvue 1.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475
  1. <template>
  2. <cl-page>
  3. <view class="p-3">
  4. <demo-item :label="t('基础用法')">
  5. <cl-input-otp></cl-input-otp>
  6. </demo-item>
  7. <demo-item :label="t('自动聚焦')">
  8. <cl-input-otp autofocus></cl-input-otp>
  9. </demo-item>
  10. <demo-item :label="t('自定义')">
  11. <view class="mb-3">
  12. <cl-input-otp
  13. :length="isLength ? 6 : 4"
  14. :disabled="isDisabled"
  15. :pt="{
  16. item: {
  17. className: parseClass({
  18. '!bg-sky-100': isCustom,
  19. '!border-white': isCustom
  20. })
  21. },
  22. value: {
  23. className: parseClass({
  24. '!text-sky-700': isCustom
  25. })
  26. },
  27. cursor: {
  28. className: parseClass({
  29. '!bg-sky-700': isCustom
  30. })
  31. }
  32. }"
  33. @done="toDone"
  34. ></cl-input-otp>
  35. </view>
  36. <cl-list border>
  37. <cl-list-item :label="t('长度为6')">
  38. <cl-switch v-model="isLength"></cl-switch>
  39. </cl-list-item>
  40. <cl-list-item :label="t('禁用')">
  41. <cl-switch v-model="isDisabled"></cl-switch>
  42. </cl-list-item>
  43. <cl-list-item :label="t('其他样式')">
  44. <cl-switch v-model="isCustom"></cl-switch>
  45. </cl-list-item>
  46. </cl-list>
  47. </demo-item>
  48. </view>
  49. </cl-page>
  50. </template>
  51. <script lang="ts" setup>
  52. import { ref } from "vue";
  53. import DemoItem from "../components/item.uvue";
  54. import { useUi } from "@/uni_modules/cool-ui";
  55. import { parseClass } from "@/cool";
  56. import { t } from "@/locale";
  57. const ui = useUi();
  58. const isLength = ref(true);
  59. const isDisabled = ref(false);
  60. const isCustom = ref(false);
  61. function toDone() {
  62. ui.showToast({
  63. message: "Done"
  64. });
  65. }
  66. </script>