input-otp.uvue 1.6 KB

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