point-selection-captcha.vue 5.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181
  1. <script lang="ts" setup>
  2. import type { CaptchaPoint } from '@vben/common-ui';
  3. import { reactive, ref } from 'vue';
  4. import { Page, PointSelectionCaptcha } from '@vben/common-ui';
  5. import { Card, Input, InputNumber, message, Switch } from 'antdv-next';
  6. import { $t } from '#/locales';
  7. const DEFAULT_CAPTCHA_IMAGE =
  8. 'https://unpkg.com/@vbenjs/static-source@0.1.7/source/default-captcha-image.jpeg';
  9. const DEFAULT_HINT_IMAGE =
  10. 'https://unpkg.com/@vbenjs/static-source@0.1.7/source/default-hint-image.png';
  11. const selectedPoints = ref<CaptchaPoint[]>([]);
  12. const params = reactive({
  13. captchaImage: '',
  14. captchaImageUrl: DEFAULT_CAPTCHA_IMAGE,
  15. height: undefined,
  16. hintImage: '',
  17. hintImageUrl: DEFAULT_HINT_IMAGE,
  18. hintText: '唇,燕,碴,找',
  19. paddingX: undefined,
  20. paddingY: undefined,
  21. showConfirm: true,
  22. showHintImage: false,
  23. title: '',
  24. width: undefined,
  25. });
  26. const handleConfirm = (points: CaptchaPoint[], clear: () => void) => {
  27. message.success({
  28. content: `captcha points: ${JSON.stringify(points)}`,
  29. });
  30. clear();
  31. selectedPoints.value = [];
  32. };
  33. const handleRefresh = () => {
  34. selectedPoints.value = [];
  35. };
  36. const handleClick = (point: CaptchaPoint) => {
  37. selectedPoints.value.push(point);
  38. };
  39. </script>
  40. <template>
  41. <Page
  42. :description="$t('examples.captcha.pageDescription')"
  43. :title="$t('examples.captcha.pageTitle')"
  44. >
  45. <Card :title="$t('examples.captcha.basic')" class="mb-4 overflow-x-auto">
  46. <div class="mb-3 flex items-center justify-start">
  47. <Input
  48. v-model:value="params.title"
  49. :placeholder="$t('examples.captcha.titlePlaceholder')"
  50. class="w-64"
  51. />
  52. <Input
  53. v-model:value="params.captchaImageUrl"
  54. :placeholder="$t('examples.captcha.captchaImageUrlPlaceholder')"
  55. class="ml-8 w-64"
  56. />
  57. <div class="ml-8 flex w-96 items-center">
  58. <Switch
  59. v-model="params.showHintImage"
  60. :checked-children="$t('examples.captcha.hintImage')"
  61. :un-checked-children="$t('examples.captcha.hintText')"
  62. class="mr-4 w-40"
  63. />
  64. <Input
  65. v-show="params.showHintImage"
  66. v-model:value="params.hintImageUrl"
  67. :placeholder="$t('examples.captcha.hintImagePlaceholder')"
  68. />
  69. <Input
  70. v-show="!params.showHintImage"
  71. v-model:value="params.hintText"
  72. :placeholder="$t('examples.captcha.hintTextPlaceholder')"
  73. />
  74. </div>
  75. <Switch
  76. v-model="params.showConfirm"
  77. :checked-children="$t('examples.captcha.showConfirm')"
  78. :un-checked-children="$t('examples.captcha.hideConfirm')"
  79. class="ml-8 w-28"
  80. />
  81. </div>
  82. <div class="mb-3 flex items-center justify-start">
  83. <div>
  84. <InputNumber
  85. v-model:value="params.width"
  86. :min="1"
  87. :placeholder="$t('examples.captcha.widthPlaceholder')"
  88. :precision="0"
  89. :step="1"
  90. class="w-64"
  91. >
  92. <template #addonAfter>px</template>
  93. </InputNumber>
  94. </div>
  95. <div class="ml-8">
  96. <InputNumber
  97. v-model:value="params.height"
  98. :min="1"
  99. :placeholder="$t('examples.captcha.heightPlaceholder')"
  100. :precision="0"
  101. :step="1"
  102. class="w-64"
  103. >
  104. <template #addonAfter>px</template>
  105. </InputNumber>
  106. </div>
  107. <div class="ml-8">
  108. <InputNumber
  109. v-model:value="params.paddingX"
  110. :min="1"
  111. :placeholder="$t('examples.captcha.paddingXPlaceholder')"
  112. :precision="0"
  113. :step="1"
  114. class="w-64"
  115. >
  116. <template #addonAfter>px</template>
  117. </InputNumber>
  118. </div>
  119. <div class="ml-8">
  120. <InputNumber
  121. v-model:value="params.paddingY"
  122. :min="1"
  123. :placeholder="$t('examples.captcha.paddingYPlaceholder')"
  124. :precision="0"
  125. :step="1"
  126. class="w-64"
  127. >
  128. <template #addonAfter>px</template>
  129. </InputNumber>
  130. </div>
  131. </div>
  132. <PointSelectionCaptcha
  133. :captcha-image="params.captchaImageUrl || params.captchaImage"
  134. :height="params.height || 220"
  135. :hint-image="
  136. params.showHintImage ? params.hintImageUrl || params.hintImage : ''
  137. "
  138. :hint-text="params.hintText"
  139. :padding-x="params.paddingX"
  140. :padding-y="params.paddingY"
  141. :show-confirm="params.showConfirm"
  142. :width="params.width || 300"
  143. class="float-left"
  144. @click="handleClick"
  145. @confirm="handleConfirm"
  146. @refresh="handleRefresh"
  147. >
  148. <template #title>
  149. {{ params.title || $t('examples.captcha.captchaCardTitle') }}
  150. </template>
  151. </PointSelectionCaptcha>
  152. <ol class="float-left p-5">
  153. <li v-for="point in selectedPoints" :key="point.i" class="flex">
  154. <span class="mr-3 w-16">{{
  155. $t('examples.captcha.index') + point.i
  156. }}</span>
  157. <span class="mr-3 w-52">{{
  158. $t('examples.captcha.timestamp') + point.t
  159. }}</span>
  160. <span class="mr-3 w-16">{{
  161. $t('examples.captcha.x') + point.x
  162. }}</span>
  163. <span class="mr-3 w-16">{{
  164. $t('examples.captcha.y') + point.y
  165. }}</span>
  166. </li>
  167. </ol>
  168. </Card>
  169. </Page>
  170. </template>