FindByEmail.vue 9.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358
  1. <template>
  2. <div>
  3. <p class="form-title">{{ $t('login_register.find_password') }}</p>
  4. <p
  5. v-show="tipMsgStatus"
  6. :class="`form-msg ${tipMsg.type}`">
  7. <i :class="`iconfont ${tipMsg.type == 'error' ? 'icon-Shapex' : 'icon-all_tips'}`"/>{{ tipMsg.msg }}
  8. </p>
  9. <div class="form-item">
  10. <input
  11. v-model="email"
  12. :placeholder="$t('login_register.placeholder_email')"
  13. readonly="readonly"
  14. onfocus="javascript:this.removeAttribute('readonly');"
  15. type="text"
  16. class="hl-input"
  17. @input="handleListenEmailInput"
  18. @focus="handleListenEmailInput"
  19. @blur="handleBlurEmailInput"
  20. @keyup.enter="handleEmailInputKey('enter')"
  21. @keyup.up="handleEmailInputKey('up')"
  22. @keyup.down="handleEmailInputKey('down')">
  23. <ul
  24. v-if="emailArr.length"
  25. class="email-tip-list">
  26. <li
  27. v-for="(item,index) in emailArr"
  28. :key="index"
  29. :class="{'email-item':true,'active':item.isActive}"
  30. @mousedown="handleSelectEmail(index)">{{ item.email }}</li>
  31. </ul>
  32. </div>
  33. <div class="form-item">
  34. <input
  35. v-model="smsCode"
  36. :placeholder="$t('login_register.placeholder_email_code')"
  37. readonly="readonly"
  38. onfocus="javascript:this.removeAttribute('readonly');"
  39. maxlength="6"
  40. type="text"
  41. class="hl-input">
  42. <span
  43. class="get-code"
  44. @click="getCode">
  45. {{ codeText }}
  46. </span>
  47. </div>
  48. <div class="form-item">
  49. <input
  50. v-model="password"
  51. :type="showPassword ? 'text' : 'password'"
  52. :placeholder="$t('login_register.pwd_rules')"
  53. readonly="readonly"
  54. onfocus="javascript:this.removeAttribute('readonly');"
  55. class="hl-input">
  56. <i
  57. :class="`pwd-eye iconfont ${showPassword ? 'icon-zhengyan' : 'icon-biyan'}`"
  58. @click="showPassword = !showPassword"/>
  59. </div>
  60. <div class="form-item">
  61. <button
  62. :loading="isLoading"
  63. class="form-button"
  64. @click="commit">{{ btnLoginText }}</button>
  65. </div>
  66. <div class="skip-item">
  67. <span
  68. class="skip-button"
  69. @click="$emit('handleSkipView', 'FindBySms')">{{ $t('login_register.find_pwd_by_mobile') }}</span>
  70. </div>
  71. </div>
  72. </template>
  73. <script>
  74. import {
  75. php_api_user_verification,
  76. php_api_user_find_pwd
  77. } from '~/common/apis.js'
  78. import { myValidator } from '~/common/utils.js'
  79. export default {
  80. data() {
  81. return {
  82. emailSuffixArr: [
  83. '@qq.com',
  84. '@gmail.com',
  85. '@163.com',
  86. '@yahoo.com',
  87. '@hotmail.com'
  88. ],
  89. emailArr: [],
  90. email: '',
  91. smsCode: '',
  92. password: '',
  93. showPassword: false,
  94. smsTimer: null,
  95. countTime: 60,
  96. codeText: this.$t('login_register.btn_get_code'),
  97. btnLoginText: this.$t('login_register.login_ok'),
  98. tipMsg: {
  99. type: 'error',
  100. msg: ''
  101. },
  102. tipMsgStatus: false,
  103. dxLoaded: false,
  104. dxStatus: false,
  105. security_code: '',
  106. isLoading: false
  107. }
  108. },
  109. watch: {
  110. dxStatus(val) {
  111. // 验证成功
  112. if (val) {
  113. this.getCode()
  114. }
  115. }
  116. },
  117. created() {},
  118. destroyed() {
  119. this.clearTimer()
  120. },
  121. methods: {
  122. showTip(data) {
  123. this.tipMsg = { ...this.tipMsg, ...data }
  124. this.tipMsgStatus = true
  125. },
  126. handleListenEmailInput() {
  127. if (this.email.trim().length === 0) {
  128. this.emailArr = []
  129. return false
  130. }
  131. if (this.email.indexOf('@') !== -1) {
  132. let emailA = this.email.split('@')[0]
  133. if (emailA.length > 0) {
  134. let emailArr = []
  135. this.emailSuffixArr.forEach((val, i, arr) => {
  136. let tmp = {}
  137. tmp.email = `${emailA}${val}`
  138. if (this.email === tmp.email) {
  139. tmp.isActive = true
  140. } else {
  141. tmp.isActive = false
  142. }
  143. emailArr.push(tmp)
  144. })
  145. this.emailArr = emailArr
  146. } else {
  147. this.emailArr = []
  148. }
  149. } else {
  150. let emailArr = []
  151. this.emailSuffixArr.forEach((val, i, arr) => {
  152. let tmp = {
  153. email: `${this.email}${val}`,
  154. isActive: false
  155. }
  156. emailArr.push(tmp)
  157. })
  158. this.emailArr = emailArr
  159. }
  160. },
  161. handleBlurEmailInput() {
  162. this.emailArr = []
  163. },
  164. handleEmailInputKey(which) {
  165. switch (which) {
  166. case 'enter':
  167. this.emailArr.some((val, i, arr) => {
  168. if (val.isActive) {
  169. this.email = val.email
  170. return true
  171. }
  172. })
  173. this.emailArr = []
  174. break
  175. case 'up':
  176. this.keySelectEmail(which)
  177. break
  178. case 'down':
  179. this.keySelectEmail(which)
  180. break
  181. default:
  182. break
  183. }
  184. },
  185. handleSelectEmail(index) {
  186. this.email = this.emailArr[index].email
  187. this.emailArr = []
  188. },
  189. keySelectEmail(which) {
  190. let count = this.emailArr.length
  191. if (count === 0) {
  192. return false
  193. }
  194. let last = count - 1
  195. let curIndex = -1
  196. this.emailArr.some((val, i, arr) => {
  197. if (val.isActive) {
  198. curIndex = i
  199. return true
  200. }
  201. })
  202. if (which === 'up') {
  203. if (curIndex === -1) {
  204. curIndex = 0
  205. } else if (curIndex === 0) {
  206. curIndex = last
  207. } else {
  208. --curIndex
  209. }
  210. } else if (which === 'down') {
  211. if (curIndex === -1) {
  212. curIndex = 0
  213. } else if (curIndex === last) {
  214. curIndex = 0
  215. } else {
  216. ++curIndex
  217. }
  218. }
  219. let emailArr = []
  220. this.emailArr.forEach((val, i, arr) => {
  221. if (curIndex === i) {
  222. val.isActive = true
  223. } else {
  224. val.isActive = false
  225. }
  226. emailArr.push({ ...val })
  227. })
  228. this.emailArr = emailArr
  229. },
  230. checkEmail() {
  231. if (!myValidator.checkEmail(this.email)) {
  232. this.showTip({ msg: this.$t('login_register.check_email') })
  233. return false
  234. }
  235. return true
  236. },
  237. checkCode() {
  238. if (!myValidator.checkCode(this.smsCode)) {
  239. this.showTip({ msg: this.$t('login_register.check_sms_code') })
  240. return false
  241. }
  242. return true
  243. },
  244. checkPwd() {
  245. if (!myValidator.checkPwd(this.password)) {
  246. this.showTip({ msg: this.$t('login_register.pwd_rules') })
  247. return false
  248. }
  249. return true
  250. },
  251. bindDxEvent() {
  252. _dx.hooliCaptcha.on('verifySuccess', security_code => {
  253. this.security_code = security_code
  254. this.dxStatus = true
  255. })
  256. },
  257. getDxCode() {
  258. if (_dx) {
  259. if (!this.dxLoaded) {
  260. this.dxLoaded = true
  261. this.bindDxEvent()
  262. }
  263. _dx.hooliCaptcha.reload()
  264. _dx.hooliCaptcha.show()
  265. } else {
  266. // dx加载失败 直接跳过验证
  267. this.dxStatus = true
  268. }
  269. },
  270. async getCode() {
  271. if (this.codeTimer) return
  272. if (!this.checkEmail()) return
  273. this.tipMsgStatus = false
  274. if (!this.dxStatus) {
  275. this.getDxCode()
  276. return
  277. }
  278. const params = {
  279. email: this.email,
  280. token: this.security_code,
  281. status: '2'
  282. }
  283. try {
  284. const { code, data, msg } = await this.$axios.$post(
  285. php_api_user_verification,
  286. params
  287. )
  288. if (code) {
  289. this.showTip({ msg: msg || this.$t('login_register.network_wrong') })
  290. } else {
  291. this.dealCountDown()
  292. }
  293. } catch (error) {
  294. this.showTip({ msg: msg || this.$t('login_register.network_wrong') })
  295. }
  296. },
  297. clearTimer() {
  298. if (this.codeTimer) {
  299. window.clearTimeout(this.codeTimer)
  300. this.codeTimer = null
  301. }
  302. },
  303. dealCountDown() {
  304. let times = 60
  305. let countTime = () => {
  306. if (times > 0) {
  307. this.codeText = `${times}s`
  308. times--
  309. this.codeTimer = setTimeout(countTime, 1000)
  310. } else {
  311. this.clearTimer()
  312. this.codeText = this.$t('login_register.get_code_again')
  313. this.codeBtnDisable = false
  314. this.dxStatus = false
  315. }
  316. }
  317. countTime()
  318. },
  319. async commit() {
  320. if (!this.checkEmail() || !this.checkCode() || !this.checkPwd()) return
  321. const params = {
  322. email: this.email,
  323. code: this.smsCode,
  324. pwd: this.password
  325. }
  326. this.isLoading = true
  327. try {
  328. const { code, data, msg } = await this.$axios.$post(
  329. php_api_user_find_pwd,
  330. params
  331. )
  332. if (!code) {
  333. this.btnLoginText = this.$t('login_register.find_success')
  334. this.$Utils.MyCookie.setCookie(
  335. 'loginUserInfo',
  336. encodeURIComponent(JSON.stringify(data)),
  337. 7,
  338. true
  339. )
  340. location.reload()
  341. } else {
  342. this.isLoading = false
  343. this.showTip({ msg: msg || this.$t('login_register.network_wrong') })
  344. }
  345. } catch (error) {
  346. this.isLoading = false
  347. this.showTip({ msg: this.$t('login_register.network_wrong') })
  348. }
  349. }
  350. }
  351. }
  352. </script>