useCaptcha.ts 663 B

1234567891011121314151617181920212223242526272829
  1. import { ref } from 'vue'
  2. import { getCaptcha } from '@/app/api/system'
  3. interface formData {
  4. captcha_code: string,
  5. captcha_key: string
  6. }
  7. export function useCaptcha(formData: formData) {
  8. const image = ref('')
  9. const refresh = async () => {
  10. try {
  11. await getCaptcha().then((res: any) => {
  12. if (res.code == 1) {
  13. formData.captcha_key = res.data.captcha_key
  14. formData.captcha_code = ''
  15. image.value = res.data.img.replace(/\r\n/g, '')
  16. }
  17. })
  18. } catch (e) {
  19. }
  20. }
  21. return {
  22. image,
  23. refresh
  24. }
  25. }