useLogin.js 1.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364
  1. import {ref} from 'vue'
  2. import { showToast } from 'vant';
  3. import {_apiLogin} from '@/api/user'
  4. export function useLogin(){
  5. //图形验证码src
  6. let picSrc = ref('')
  7. //图形验证码id
  8. let picId = ref('')
  9. //获取图形验证码
  10. async function getPicCode(){
  11. const res = await _apiLogin.apiGetPicCode()
  12. if(res.Ret!==200) return
  13. picId.value = res.Data.Id
  14. picSrc.value = res.Data.Base64Blob
  15. }
  16. async function getCode({mobile,email,picCode,areaCode},model,source){
  17. const res = await _apiLogin.apiGetVerifyCode({
  18. VerifyType:model==='mobile'?1:2,
  19. CaptchaId:picId.value,
  20. CaptchaCode:picCode,
  21. Mobile:mobile||'',
  22. Email:email||'',
  23. TelAreaCode:areaCode+''||'',
  24. Source:source
  25. })
  26. if(res.Ret!==200) {
  27. getPicCode()
  28. return
  29. }
  30. showToast('验证码已发送')
  31. //60秒倒计时
  32. codeCountDown.value = 60
  33. countDown()
  34. timer = setInterval(()=>{
  35. countDown()
  36. },1000)
  37. }
  38. let timer = 0
  39. let codeStr = ref('获取验证码')
  40. let codeCountDown = ref(60)
  41. function countDown(){
  42. codeCountDown.value--
  43. codeStr.value = `重新获取(${codeCountDown.value})秒`
  44. if(codeCountDown.value<=0){
  45. clearInterval(timer)
  46. codeStr.value = '重新获取'
  47. }
  48. }
  49. return {
  50. picId,
  51. picSrc,
  52. getPicCode,
  53. timer,codeStr,codeCountDown,
  54. countDown,
  55. getCode,
  56. }
  57. }