captcha.vue 8.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238
  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. const container = document.querySelector("body")
  55. container.style.background = 'transparent'
  56. container.addEventListener('DOMSubtreeModified', function () {
  57. const element = document.querySelector('#tcaptcha_transform')
  58. const tcaptcha_iframe = document.querySelector('#tcaptcha_iframe')
  59. const t_verify = document.querySelector('#t_verify')
  60. const mask = document.querySelector('.t-mask')
  61. if (tcaptcha_iframe) {
  62. tcaptcha_iframe.style.background = 'transparent'
  63. }
  64. if (mask) {
  65. mask.style.display = 'none'
  66. }
  67. if (t_verify) {
  68. t_verify.style.border = 'transparent'
  69. t_verify.style.background = 'transparent'
  70. }
  71. if (element) {
  72. t_verify.style.display = 'none'
  73. element.style.border = 'transparent'
  74. element.style.background = 'transparent'
  75. }
  76. }, false);
  77. this.isAndroid = /(Android)/i.test(navigator.userAgent)
  78. this.isiOS = /(iPhone|iPad|iPod|iOS)/i.test(navigator.userAgent)
  79. const that = this;
  80. this.phone = location.href.split('?')[1].split('&')[0].split('=')[1];
  81. this.number = this.phone.substring(0, 3) + ' ' + this.phone.substring(3, 7) + ' ' + this.phone.substring(7, 11);
  82. this.TencentCaptcha = new window.TencentCaptcha(
  83. getAppId(),
  84. function (res) {/* callback */
  85. if (res.ret === 0) {
  86. postAction(getCaptchaCode, {
  87. ticket: res.ticket,
  88. randstr: res.randstr,
  89. phone: that.phone
  90. }).then(() => {
  91. if (that.isiOS) {
  92. window.webkit.messageHandlers.returnVerificationCode.postMessage(res.ret.toString());
  93. }
  94. if (that.isAndroid) {
  95. window.hap.verificationCode(res.ret.toString());
  96. }
  97. }).catch(data => {
  98. that.$toast.fail({icon: 'close', message: data.errmsg})
  99. setTimeout(function () {
  100. if (that.isiOS) {
  101. window.webkit.messageHandlers.returnVerificationCode.postMessage('2');
  102. }
  103. if (that.isAndroid) {
  104. window.hap.verificationCode('2');
  105. }
  106. }, 1200)
  107. })
  108. } else {
  109. if (that.isiOS) {
  110. window.webkit.messageHandlers.returnVerificationCode.postMessage(res.ret.toString());
  111. }
  112. if (that.isAndroid) {
  113. window.hap.verificationCode(res.ret.toString());
  114. }
  115. }
  116. },
  117. {
  118. enableDarkMode: true,
  119. sdkOpts: {
  120. width: 0,
  121. height: 0
  122. },
  123. }
  124. );
  125. this.getCaptcha();
  126. },
  127. methods: {
  128. // next(index) {
  129. // const input = document.querySelectorAll('input');
  130. // if (this.captcha[index]) {
  131. // if (this.captcha.length === index + 1) {
  132. // if (this.can_jump) {
  133. // if (this.isiOS) {
  134. // window.webkit.messageHandlers.returnVerificationCode.postMessage('发送成功');
  135. // }
  136. // if (this.isAndroid) {
  137. // // window.webkit.messageHandlers.returnVerificationCode.postMessage(this.captcha.join(''));
  138. // }
  139. // }
  140. // } else {
  141. // input[index + 1].focus();
  142. // }
  143. // } else {
  144. // if (index > 0) {
  145. // input[index - 1].focus();
  146. // }
  147. // }
  148. // },
  149. getCaptcha() {
  150. this.can_jump = false;
  151. this.TencentCaptcha.show();
  152. },
  153. // countDown() {
  154. // if (this.time === 60) {
  155. // this.time = --this.time;
  156. // this.time_tips = `${this.time}s 后重新获取验证码`
  157. // const setint = setInterval(() => {
  158. // if (this.time > 0) {
  159. // this.time = --this.time;
  160. // this.time_tips = `${this.time}s 后重新获取验证码`
  161. // } else {
  162. // clearInterval(setint);
  163. // this.time = 60;
  164. // this.time_tips = `重新获取验证码`
  165. // }
  166. // }, 1000)
  167. // } else {
  168. // this.$toast({message: '请勿重复点击'})
  169. // }
  170. // }
  171. }
  172. }
  173. </script>
  174. <style lang="less" scoped>
  175. .image {
  176. height: 180px;
  177. position: fixed;
  178. right: 0;
  179. top: 24px;
  180. }
  181. .title {
  182. padding: 0 45px;
  183. }
  184. .tips {
  185. margin-top: 113px;
  186. font-size: 27px;
  187. color: #000000;
  188. font-family: PingFangSC-Semibold, PingFang SC;
  189. }
  190. .number {
  191. font-size: 14px;
  192. font-family: PingFangSC-Regular, PingFang SC;
  193. margin-top: 17px;
  194. }
  195. .captcha {
  196. margin-top: 38px;
  197. }
  198. .input {
  199. padding: 0 45px;
  200. display: flex;
  201. align-items: center;
  202. justify-content: space-between;
  203. }
  204. input {
  205. border: none;
  206. font-size: 32px;
  207. text-align: center;
  208. padding-bottom: 10px;
  209. width: 10%;
  210. border-bottom: 1px solid #eee;
  211. }
  212. .border {
  213. border-bottom: 1px solid #ccc;
  214. }
  215. .time {
  216. font-size: 14px;
  217. text-align: right;
  218. padding: 0 45px;
  219. margin-top: 15px;
  220. }
  221. /deep/ #t_mask {
  222. background: transparent !important;
  223. }
  224. </style>