slider-captcha.vue 3.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116
  1. <script lang="ts" setup>
  2. import type {
  3. CaptchaVerifyPassingData,
  4. SliderCaptchaActionType,
  5. } from '@vben/common-ui';
  6. import { ref } from 'vue';
  7. import { Page, SliderCaptcha } from '@vben/common-ui';
  8. import { Bell, Sun } from '@vben/icons';
  9. import { Button, Card, message } from 'ant-design-vue';
  10. function handleSuccess(data: CaptchaVerifyPassingData) {
  11. const { time } = data;
  12. message.success(`校验成功,耗时${time}秒`);
  13. }
  14. function handleBtnClick(elRef?: SliderCaptchaActionType) {
  15. if (!elRef) {
  16. return;
  17. }
  18. elRef.resume();
  19. }
  20. const el1 = ref<SliderCaptchaActionType>();
  21. const el2 = ref<SliderCaptchaActionType>();
  22. const el3 = ref<SliderCaptchaActionType>();
  23. const el4 = ref<SliderCaptchaActionType>();
  24. const el5 = ref<SliderCaptchaActionType>();
  25. </script>
  26. <template>
  27. <Page description="用于前端简单的拖动校验场景" title="滑块校验">
  28. <Card class="mb-5" title="基础示例">
  29. <div class="flex items-center justify-center p-4 px-[30%]">
  30. <SliderCaptcha ref="el1" @success="handleSuccess" />
  31. <Button class="ml-2" type="primary" @click="handleBtnClick(el1)">
  32. 还原
  33. </Button>
  34. </div>
  35. </Card>
  36. <Card class="mb-5" title="自定义圆角">
  37. <div class="flex items-center justify-center p-4 px-[30%]">
  38. <SliderCaptcha
  39. ref="el2"
  40. class="rounded-full"
  41. @success="handleSuccess"
  42. />
  43. <Button class="ml-2" type="primary" @click="handleBtnClick(el2)">
  44. 还原
  45. </Button>
  46. </div>
  47. </Card>
  48. <Card class="mb-5" title="自定义背景色">
  49. <div class="flex items-center justify-center p-4 px-[30%]">
  50. <SliderCaptcha
  51. ref="el3"
  52. :bar-style="{
  53. backgroundColor: '#018ffb',
  54. }"
  55. success-text="校验成功"
  56. text="拖动以进行校验"
  57. @success="handleSuccess"
  58. />
  59. <Button class="ml-2" type="primary" @click="handleBtnClick(el3)">
  60. 还原
  61. </Button>
  62. </div>
  63. </Card>
  64. <Card class="mb-5" title="自定义拖拽图标">
  65. <div class="flex items-center justify-center p-4 px-[30%]">
  66. <SliderCaptcha ref="el4" @success="handleSuccess">
  67. <template #actionIcon="{ isPassing }">
  68. <Bell v-if="isPassing" />
  69. <Sun v-else />
  70. </template>
  71. </SliderCaptcha>
  72. <Button class="ml-2" type="primary" @click="handleBtnClick(el4)">
  73. 还原
  74. </Button>
  75. </div>
  76. </Card>
  77. <Card class="mb-5" title="自定义文本">
  78. <div class="flex items-center justify-center p-4 px-[30%]">
  79. <SliderCaptcha
  80. ref="el5"
  81. success-text="成功"
  82. text="拖动"
  83. @success="handleSuccess"
  84. />
  85. <Button class="ml-2" type="primary" @click="handleBtnClick(el5)">
  86. 还原
  87. </Button>
  88. </div>
  89. </Card>
  90. <Card class="mb-5" title="自定义内容(slot)">
  91. <div class="flex items-center justify-center p-4 px-[30%]">
  92. <SliderCaptcha ref="el5" @success="handleSuccess">
  93. <template #text="{ isPassing }">
  94. <template v-if="isPassing">
  95. <Bell class="mr-2 size-4" />
  96. 成功
  97. </template>
  98. <template v-else>
  99. 拖动
  100. <Sun class="ml-2 size-4" />
  101. </template>
  102. </template>
  103. </SliderCaptcha>
  104. <Button class="ml-2" type="primary" @click="handleBtnClick(el5)">
  105. 还原
  106. </Button>
  107. </div>
  108. </Card>
  109. </Page>
  110. </template>