Step2.vue 5.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183
  1. <template>
  2. <div>
  3. <a-form-model ref="form" :model="model" :rules="validatorRules" class="password-retrieval-form" @keyup.enter.native="nextStep">
  4. <a-form-model-item label="手机" required prop="phone" :labelCol="{span: 5}" :wrapperCol="{span: 19}">
  5. <a-input v-model="model.phone" type="text" autocomplete="false" placeholder="请输入手机号">
  6. <a-icon slot="prefix" type="phone" :style="{ color: 'rgba(0,0,0,.25)'}"/>
  7. </a-input>
  8. </a-form-model-item>
  9. <a-form-model-item v-if="show" required prop="captcha" label="验证码" :labelCol="{span: 5}" :wrapperCol="{span: 19}">
  10. <a-row :gutter="16">
  11. <a-col class="gutter-row" :span="12">
  12. <a-input @change="captchaChange" v-model="model.captcha" type="text" placeholder="手机短信验证码">
  13. <a-icon slot="prefix" type="code" :style="{ color: 'rgba(0,0,0,.25)'}"/>
  14. </a-input>
  15. </a-col>
  16. <a-col class="gutter-row" :span="8">
  17. <a-button
  18. tabindex="-1"
  19. size="default"
  20. :disabled="state.smsSendBtn"
  21. @click.stop.prevent="getCaptcha"
  22. v-text="!state.smsSendBtn && '获取验证码' || (state.time+' s')"></a-button>
  23. </a-col>
  24. </a-row>
  25. </a-form-model-item>
  26. <a-form-model-item :wrapperCol="{span: 19, offset: 5}">
  27. <router-link style="float: left;line-height: 40px;" :to="{ name: 'login' }">使用已有账户登录</router-link>
  28. <a-button type="primary" @click="nextStep" style="margin-left: 20px">下一步</a-button>
  29. </a-form-model-item>
  30. </a-form-model>
  31. </div>
  32. </template>
  33. <script>
  34. import {postAction} from '@/api/manage'
  35. export default {
  36. name: "Step2",
  37. props: ['userList'],
  38. data() {
  39. return {
  40. model: {},
  41. loading: false,
  42. // accountName: this.userList.username,
  43. dropList: "0",
  44. captcha: "",
  45. show: true,
  46. state: {
  47. time: 60,
  48. smsSendBtn: false,
  49. },
  50. formLogin: {
  51. captcha: "",
  52. mobile: "",
  53. },
  54. validatorRules: {
  55. phone: [
  56. { required: true, message: '请输入手机号码!' },
  57. { validator: this.validatePhone }
  58. ],
  59. captcha: [
  60. { required: true, message: '请输入短信验证码!' }
  61. ]
  62. },
  63. }
  64. },
  65. computed: {
  66. },
  67. methods: {
  68. nextStep() {
  69. let that = this
  70. that.loading = true
  71. this.$refs['form'].validate((success) => {
  72. if(success==true){
  73. let params = {
  74. phone: this.model.phone,
  75. smscode: this.model.captcha
  76. }
  77. postAction("/sys/user/phoneVerification", params).then((res) => {
  78. if (res.success) {
  79. console.log(res);
  80. let userList = {
  81. username: res.result.username,
  82. phone: params.phone,
  83. smscode: res.result.smscode
  84. };
  85. setTimeout(function () {
  86. that.$emit('nextStep', userList)
  87. }, 0)
  88. } else {
  89. this.cmsFailed(res.message);
  90. }
  91. });
  92. }
  93. })
  94. },
  95. getCaptcha(e) {
  96. e.preventDefault();
  97. const that = this
  98. that.$refs['form'].validateField('phone', err=>{
  99. if(!err){
  100. that.state.smsSendBtn = true;
  101. let interval = window.setInterval(() => {
  102. if (that.state.time-- <= 0) {
  103. that.state.time = 60;
  104. that.state.smsSendBtn = false;
  105. window.clearInterval(interval);
  106. }
  107. }, 1000);
  108. const hide = that.$message.loading('验证码发送中..', 0);
  109. let smsParams = {
  110. mobile: that.model.phone,
  111. smsmode: "2"
  112. };
  113. postAction("/sys/sms", smsParams).then(res => {
  114. if (!res.success) {
  115. setTimeout(hide, 1);
  116. that.cmsFailed(res.message);
  117. }
  118. setTimeout(hide, 500);
  119. })
  120. }else{
  121. that.cmsFailed(err);
  122. }
  123. })
  124. },
  125. cmsFailed(err) {
  126. this.$notification['error']({
  127. message: "验证错误",
  128. description: err,
  129. duration: 4,
  130. });
  131. },
  132. handleChangeSelect(value) {
  133. var that = this;
  134. console.log(value);
  135. if (value == 0) {
  136. that.dropList = "0";
  137. that.show = true;
  138. } else {
  139. that.dropList = "1";
  140. that.show = false;
  141. }
  142. },
  143. validatePhone(rule,value,callback){
  144. if(value){
  145. var myreg=/^[1][3,4,5,7,8][0-9]{9}$/;
  146. if(!myreg.test(value)){
  147. callback("请输入正确的手机号")
  148. }else{
  149. callback();
  150. }
  151. }else{
  152. callback()
  153. }
  154. },
  155. //手机号改变事件
  156. captchaChange(val){
  157. this.$refs['form'].validateField("captcha")
  158. }
  159. }
  160. }
  161. </script>
  162. <style lang="less" scoped>
  163. .stepFormText {
  164. margin-bottom: 24px;
  165. }
  166. .ant-form-item-label,
  167. .ant-form-item-control {
  168. line-height: 22px;
  169. }
  170. .getCaptcha {
  171. display: block;
  172. width: 100%;
  173. height: 40px;
  174. }
  175. </style>