captcha.vue 6.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203
  1. <template>
  2. <div>
  3. <!-- <img-->
  4. <!-- src="https://happyjob.oss-cn-shanghai.aliyuncs.com/uploadfiles/mina/images/happyjob/login_xiaobai.png"-->
  5. <!-- alt=""-->
  6. <!-- class="image">-->
  7. <!-- <div class="title">-->
  8. <!-- <div class="tips">-->
  9. <!-- 请输入验证码-->
  10. <!-- </div>-->
  11. <!-- <div class="number">-->
  12. <!-- 验证码已发送至 {{number}}-->
  13. <!-- </div>-->
  14. <!-- </div>-->
  15. <!-- <div class="captcha">-->
  16. <!-- <div class="input">-->
  17. <!-- <input-->
  18. <!-- v-for="(val,ind) in captcha"-->
  19. <!-- :key="ind"-->
  20. <!-- maxlength="1"-->
  21. <!-- type="text"-->
  22. <!-- :autofocus="!Boolean(ind)"-->
  23. <!-- placeholder=""-->
  24. <!-- :class="val&&'border'"-->
  25. <!-- v-model="captcha[ind]"-->
  26. <!-- @input="next(ind)"-->
  27. <!-- >-->
  28. <!-- </div>-->
  29. <!-- </div>-->
  30. <!-- <div class="time" @click="getCaptcha">-->
  31. <!-- {{time_tips}}-->
  32. <!-- </div>-->
  33. </div>
  34. </template>
  35. <script>
  36. import {getCaptchaCode} from '@/api/index'
  37. import {postAction} from '@/api/manage'
  38. import {getAppId} from '@/utils/util'
  39. export default {
  40. name: "captcha",
  41. data() {
  42. return {
  43. captcha: ['', '', '', '', '', ''],
  44. number: '',
  45. time_tips: '发送验证码',
  46. time: 60,
  47. TencentCaptcha: '',
  48. isAndroid: false,
  49. isiOS: false,
  50. can_jump: false,
  51. }
  52. },
  53. mounted() {
  54. document.querySelector('iframe').onload = function () {
  55. document.querySelector('.t-mask').style.display = 'none'
  56. }
  57. this.isAndroid = /(Android)/i.test(navigator.userAgent)
  58. this.isiOS = /(iPhone|iPad|iPod|iOS)/i.test(navigator.userAgent)
  59. const that = this;
  60. this.phone = location.href.split('?')[1].split('&')[0].split('=')[1];
  61. this.number = this.phone.substring(0, 3) + ' ' + this.phone.substring(3, 7) + ' ' + this.phone.substring(7, 11);
  62. this.TencentCaptcha = new window.TencentCaptcha(
  63. getAppId(process.env.NODE_ENV),
  64. function (res) {/* callback */
  65. if (that.isiOS) {
  66. window.webkit.messageHandlers.returnVerificationCode.postMessage(res.ret.toString());
  67. }
  68. if (that.isAndroid) {
  69. window.hap.verificationCode(res.ret.toString());
  70. }
  71. if (res.ret === 0) {
  72. postAction(getCaptchaCode, {
  73. ticket: res.ticket,
  74. randstr: res.randstr,
  75. phone: that.phone
  76. })
  77. }
  78. },
  79. {
  80. enableDarkMode: true,
  81. sdkOpts: {
  82. width: 0,
  83. height: 0
  84. },
  85. }
  86. );
  87. this.getCaptcha();
  88. },
  89. methods: {
  90. // next(index) {
  91. // const input = document.querySelectorAll('input');
  92. // if (this.captcha[index]) {
  93. // if (this.captcha.length === index + 1) {
  94. // if (this.can_jump) {
  95. // if (this.isiOS) {
  96. // window.webkit.messageHandlers.returnVerificationCode.postMessage('发送成功');
  97. // }
  98. // if (this.isAndroid) {
  99. // // window.webkit.messageHandlers.returnVerificationCode.postMessage(this.captcha.join(''));
  100. // }
  101. // }
  102. // } else {
  103. // input[index + 1].focus();
  104. // }
  105. // } else {
  106. // if (index > 0) {
  107. // input[index - 1].focus();
  108. // }
  109. // }
  110. // },
  111. getCaptcha() {
  112. this.can_jump = false;
  113. this.TencentCaptcha.show();
  114. },
  115. // countDown() {
  116. // if (this.time === 60) {
  117. // this.time = --this.time;
  118. // this.time_tips = `${this.time}s 后重新获取验证码`
  119. // const setint = setInterval(() => {
  120. // if (this.time > 0) {
  121. // this.time = --this.time;
  122. // this.time_tips = `${this.time}s 后重新获取验证码`
  123. // } else {
  124. // clearInterval(setint);
  125. // this.time = 60;
  126. // this.time_tips = `重新获取验证码`
  127. // }
  128. // }, 1000)
  129. // } else {
  130. // this.$toast({message: '请勿重复点击'})
  131. // }
  132. // }
  133. }
  134. }
  135. </script>
  136. <style lang="less" scoped>
  137. body {
  138. background: transparent;
  139. }
  140. .image {
  141. height: 180px;
  142. position: fixed;
  143. right: 0;
  144. top: 24px;
  145. }
  146. .title {
  147. padding: 0 45px;
  148. }
  149. .tips {
  150. margin-top: 113px;
  151. font-size: 27px;
  152. color: #000000;
  153. font-family: PingFangSC-Semibold, PingFang SC;
  154. }
  155. .number {
  156. font-size: 14px;
  157. font-family: PingFangSC-Regular, PingFang SC;
  158. margin-top: 17px;
  159. }
  160. .captcha {
  161. margin-top: 38px;
  162. }
  163. .input {
  164. padding: 0 45px;
  165. display: flex;
  166. align-items: center;
  167. justify-content: space-between;
  168. }
  169. input {
  170. border: none;
  171. font-size: 32px;
  172. text-align: center;
  173. padding-bottom: 10px;
  174. width: 10%;
  175. border-bottom: 1px solid #eee;
  176. }
  177. .border {
  178. border-bottom: 1px solid #ccc;
  179. }
  180. .time {
  181. font-size: 14px;
  182. text-align: right;
  183. padding: 0 45px;
  184. margin-top: 15px;
  185. }
  186. /deep/ #t_mask {
  187. background: transparent !important;
  188. }
  189. </style>