input-otp.uvue 1.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970
  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. }"
  28. @done="toDone"
  29. ></cl-input-otp>
  30. </view>
  31. <cl-list border>
  32. <cl-list-item :label="t('长度为6')">
  33. <cl-switch v-model="isLength"></cl-switch>
  34. </cl-list-item>
  35. <cl-list-item :label="t('禁用')">
  36. <cl-switch v-model="isDisabled"></cl-switch>
  37. </cl-list-item>
  38. <cl-list-item :label="t('其他样式')">
  39. <cl-switch v-model="isCustom"></cl-switch>
  40. </cl-list-item>
  41. </cl-list>
  42. </demo-item>
  43. </view>
  44. </cl-page>
  45. </template>
  46. <script lang="ts" setup>
  47. import { ref } from "vue";
  48. import DemoItem from "../components/item.uvue";
  49. import { useUi } from "@/uni_modules/cool-ui";
  50. import { parseClass } from "@/cool";
  51. import { t } from "@/locale";
  52. const ui = useUi();
  53. const isLength = ref(true);
  54. const isDisabled = ref(false);
  55. const isCustom = ref(false);
  56. function toDone() {
  57. ui.showToast({
  58. message: "Done"
  59. });
  60. }
  61. </script>