7fc28d3d016909819174aee6a2def00cdd22f39c.svn-base 5.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183
  1. <template>
  2. <div class="main">
  3. <a-form style="max-width: 500px; margin: 40px auto 0;" :form="form" @keyup.enter.native="nextStep">
  4. <a-form-item>
  5. <a-input
  6. v-decorator="['username',validatorRules.username]"
  7. size="large"
  8. type="text"
  9. autocomplete="false"
  10. placeholder="请输入用户账号或手机号">
  11. <a-icon slot="prefix" type="lock" :style="{ color: 'rgba(0,0,0,.25)' }"/>
  12. </a-input>
  13. </a-form-item>
  14. <a-row :gutter="0">
  15. <a-col :span="14">
  16. <a-form-item>
  17. <a-input
  18. v-decorator="['inputCode',validatorRules.inputCode]"
  19. size="large"
  20. type="text"
  21. @change="inputCodeChange"
  22. placeholder="请输入验证码">
  23. <a-icon slot="prefix" v-if=" inputCodeContent==verifiedCode " type="smile"
  24. :style="{ color: 'rgba(0,0,0,.25)' }"/>
  25. <a-icon slot="prefix" v-else type="frown" :style="{ color: 'rgba(0,0,0,.25)' }"/>
  26. </a-input>
  27. </a-form-item>
  28. </a-col>
  29. <a-col :span="10" style="text-align: right">
  30. <img v-if="requestCodeSuccess" style="margin-top: 2px;" :src="randCodeImage" @click="handleChangeCheckCode"/>
  31. <img v-else style="margin-top: 2px;" src="../../../assets/checkcode.png" @click="handleChangeCheckCode"/>
  32. </a-col>
  33. </a-row>
  34. <a-form-item :wrapperCol="{span: 19, offset: 5}">
  35. <router-link style="float: left;line-height: 40px;" :to="{ name: 'login' }">使用已有账户登录</router-link>
  36. <a-button type="primary" @click="nextStep">下一步</a-button>
  37. </a-form-item>
  38. </a-form>
  39. </div>
  40. </template>
  41. <script>
  42. import { getAction,postAction } from '@/api/manage'
  43. import { checkOnlyUser } from '@/api/api'
  44. export default {
  45. name: "Step1",
  46. data() {
  47. return {
  48. form: this.$form.createForm(this),
  49. inputCodeContent: "",
  50. inputCodeNull: true,
  51. verifiedCode: "",
  52. validatorRules: {
  53. username: {rules: [{required: false}, {validator: this.validateInputUsername}]},
  54. inputCode: {rules: [{required: true, message: '请输入验证码!'}]},
  55. },
  56. randCodeImage:'',
  57. requestCodeSuccess:true,
  58. currdatetime:''
  59. }
  60. },
  61. created(){
  62. this.handleChangeCheckCode();
  63. },
  64. methods: {
  65. handleChangeCheckCode(){
  66. this.currdatetime = new Date().getTime();
  67. getAction(`/sys/randomImage/${this.currdatetime}`).then(res=>{
  68. if(res.success){
  69. this.randCodeImage = res.result
  70. this.requestCodeSuccess=true
  71. }else{
  72. this.$message.error(res.message)
  73. this.requestCodeSuccess=false
  74. }
  75. }).catch(()=>{
  76. this.requestCodeSuccess=false
  77. })
  78. },
  79. nextStep() {
  80. let that = this
  81. this.form.validateFields((err, values) => {
  82. if (!err) {
  83. let isPhone = false;
  84. var params = {}
  85. var reg = /^[1-9]\d*$|^0$/;
  86. var username = values.username;
  87. if (reg.test(username) == true) {
  88. params.phone = username;
  89. isPhone = true
  90. } else {
  91. params.username = username;
  92. }
  93. that.validateInputCode().then(()=>{
  94. getAction("/sys/user/querySysUser", params).then((res) => {
  95. if (res.success) {
  96. var userList = {
  97. username: res.result.username,
  98. phone: res.result.phone,
  99. isPhone: isPhone
  100. };
  101. setTimeout(function () {
  102. that.$emit('nextStep', userList)
  103. })
  104. }
  105. });
  106. })
  107. }
  108. })
  109. },
  110. validateInputCode() {
  111. return new Promise((resolve,reject)=>{
  112. postAction("/sys/checkCaptcha",{
  113. captcha:this.inputCodeContent,
  114. checkKey:this.currdatetime
  115. }).then(res=>{
  116. if(res.success){
  117. resolve();
  118. }else{
  119. this.$message.error(res.message)
  120. reject();
  121. }
  122. });
  123. })
  124. },
  125. inputCodeChange(e) {
  126. this.inputCodeContent = e.target.value;
  127. console.log(this.inputCodeContent)
  128. if (!e.target.value || 0 == e.target.value) {
  129. this.inputCodeNull = true
  130. } else {
  131. this.inputCodeContent = this.inputCodeContent.toLowerCase()
  132. this.inputCodeNull = false
  133. }
  134. },
  135. generateCode(value) {
  136. this.verifiedCode = value.toLowerCase();
  137. console.log(this.verifiedCode);
  138. },
  139. validateInputUsername(rule, value, callback) {
  140. console.log(value);
  141. var reg = /^[0-9]+.?[0-9]*/;
  142. if (!value) {
  143. callback("请输入用户名和手机号!");
  144. }
  145. //判断用户输入账号还是手机号码
  146. if (reg.test(value)) {
  147. var params = {
  148. phone: value,
  149. };
  150. checkOnlyUser(params).then((res) => {
  151. if (res.success) {
  152. callback("用户名不存在!")
  153. } else {
  154. callback()
  155. }
  156. })
  157. } else {
  158. var params = {
  159. username: value,
  160. };
  161. checkOnlyUser(params).then((res) => {
  162. if (res.success) {
  163. callback("用户名不存在!")
  164. } else {
  165. callback()
  166. }
  167. })
  168. }
  169. },
  170. }
  171. }
  172. </script>
  173. <style scoped>
  174. </style>