phoneForget.vue 6.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224
  1. <template>
  2. <div>
  3. <div class="login-con">
  4. <div class="input-con" :class="{inputActive:inputActive==='phone'}">
  5. <div class="phone-select" ref="quhaoMenu">
  6. <div class="phone-select-div" @click="showSelect=!showSelect">
  7. <span>{{codeActive[1]}}</span>
  8. <!-- (<span>{{codeActive[0]}}</span>) -->
  9. <div class="sanjiao"></div>
  10. </div>
  11. <phoneSelect v-show="showSelect" @selectItem="selectItem" />
  12. </div>
  13. <input
  14. class="guding"
  15. v-model="phone"
  16. oninput="value=value.replace(/[^\d]/g,'')"
  17. maxlength="11"
  18. @focus="inputActive='phone'"
  19. @blur="inputActive=''"
  20. type="text"
  21. :placeholder="langLogin.phone.placeholder"
  22. />
  23. </div>
  24. <div class="code-con">
  25. <div class="input-con" :class="{inputActive:inputActive==='code'}">
  26. <input
  27. v-model="authCode"
  28. @focus="inputActive='code'"
  29. @blur="inputActive=''"
  30. style="padding-left:6px;"
  31. type="text"
  32. oninput="value=value.replace(/[^\d]/g,'')"
  33. maxlength="6"
  34. :placeholder="langLogin.code.placeholder"
  35. />
  36. <div class="send-btn" v-if="!jishi" @click="getAuthCode">{{langLogin.code.txt}}</div>
  37. <span
  38. class="send-btn"
  39. v-else
  40. >{{language==='en'?`Resend after ${interTime}s`:`${interTime}s后重新发送`}}</span>
  41. </div>
  42. </div>
  43. <div class="input-con" :class="{inputActive:inputActive==='password'}">
  44. <input
  45. v-model="password"
  46. @focus="inputActive='password'"
  47. @blur="inputActive=''"
  48. maxlength="16"
  49. type="password"
  50. :placeholder="langLogin.newpass.placeholder"
  51. />
  52. </div>
  53. <div class="input-con" :class="{inputActive:inputActive==='confirm'}">
  54. <input
  55. v-model="confirmpass"
  56. @focus="inputActive='confirm'"
  57. @blur="inputActive=''"
  58. maxlength="16"
  59. type="password"
  60. :placeholder="langLogin.comfirmpass.placeholder"
  61. />
  62. </div>
  63. <div class="btns" @click="submit">{{langLogin.submit}}</div>
  64. <div class="to-login">
  65. <div class="lo-con">
  66. {{langLogin.resigter1}}
  67. <router-link :to="{path:'/login'}">{{langLogin.resigter2}}</router-link>
  68. </div>
  69. </div>
  70. </div>
  71. </div>
  72. </template>
  73. <script>
  74. import {mapState} from 'vuex'
  75. import phoneSelect from '@/components/common/phoneSelect'
  76. import { encodeStr } from '@/util'
  77. import { Base64 } from 'js-base64'
  78. export default {
  79. computed: {
  80. ...mapState({
  81. language: state => state.language.current,
  82. langToast: state => state.language.home.toast,
  83. langLogin: state => state.language.home.home.loginAside,
  84. token: state => state.user.token
  85. })
  86. },
  87. data () {
  88. return {
  89. showSelect: false,
  90. codeActive: ['中国', '+86', 'China'],
  91. phone: '',
  92. authCode: '',
  93. interTime: 60,
  94. jishi: false,
  95. password: '',
  96. confirmpass: '',
  97. inputActive: ''
  98. }
  99. },
  100. components: {
  101. phoneSelect
  102. },
  103. mounted () {
  104. document.addEventListener('click', (e) => {
  105. if (this.$refs.quhaoMenu) {
  106. if (!this.$refs.quhaoMenu.contains(e.target)) {
  107. this.showSelect = false
  108. }
  109. }
  110. })
  111. },
  112. methods: {
  113. selectItem (item) {
  114. this.showSelect = false
  115. this.codeActive = item
  116. },
  117. async getAuthCode () {
  118. let check = value => {
  119. for (let i = 0, len = value.length; i < len; i++) {
  120. if (!value[i].val) {
  121. return this.$toast.show('warn', (this.language === 'en' ? value[i].En : value[i].name) + this.langToast['7'])
  122. }
  123. }
  124. return true
  125. }
  126. let checkStr = [
  127. {
  128. name: '手机号码',
  129. En: 'Phone number',
  130. val: this.phone
  131. }
  132. ]
  133. if (!check(checkStr)) {
  134. return
  135. }
  136. let res = await this.$store.dispatch('getAuthCode', {
  137. phone: this.phone,
  138. code: Number(this.codeActive[1].substr(1))
  139. })
  140. if (res) {
  141. this.interl && clearInterval(this.interl)
  142. this.interl = null
  143. this.jishi = true
  144. this.interl = setInterval(() => {
  145. this.interTime--
  146. if (this.interTime <= 0) {
  147. this.jishi = false
  148. this.interTime = 60
  149. clearInterval(this.interl)
  150. this.interl = null
  151. }
  152. }, 1000)
  153. }
  154. },
  155. async submit () {
  156. let check = value => {
  157. for (let i = 0, len = value.length; i < len; i++) {
  158. if (!value[i].val) {
  159. return this.$toast.show('warn', (this.language === 'en' ? value[i].En : value[i].name) + this.langToast['7'])
  160. }
  161. }
  162. return true
  163. }
  164. let checkStr = [
  165. {
  166. name: '手机号码',
  167. En: 'Phone number',
  168. val: this.phone
  169. },
  170. {
  171. name: '验证码',
  172. En: 'Verification code',
  173. val: this.authCode
  174. },
  175. {
  176. name: '密码',
  177. En: 'Password',
  178. val: this.password
  179. },
  180. {
  181. name: '确认密码',
  182. En: 'Password',
  183. val: this.confirmpass
  184. }
  185. ]
  186. if (!check(checkStr)) {
  187. return
  188. }
  189. if (this.password.length < 8 || this.confirmpass.length < 8) {
  190. return this.$toast.show('warn', this.langToast['31'])
  191. }
  192. let temp = encodeStr(Base64.encode(this.password), Base64.encode(this.confirmpass))
  193. let params = {
  194. password: temp[0],
  195. phoneNum: this.phone,
  196. confirmPwd: temp[1],
  197. msgAuthCode: this.authCode
  198. }
  199. let res = await this.$http({
  200. method: 'post',
  201. headers: {
  202. token: this.token
  203. },
  204. data: params,
  205. url: 'sso/user/changePassword'
  206. })
  207. let response = res.data
  208. if (response.code !== 0) {
  209. return this.$toast.show('warn', this.langToast[response.code])
  210. }
  211. this.$toast.show('success', this.langToast['32'], () => {
  212. this.$router.push({path: '/login'})
  213. })
  214. }
  215. }
  216. }
  217. </script>
  218. <style lang="scss" scoped>
  219. @import './style.scss';
  220. </style>