register.vue 7.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230
  1. <template>
  2. <div class="backdrop" :style="{backgroundImage: 'url({'+(this.baseImg)+')'}">
  3. <el-container>
  4. <el-header style="display:block;position:relative;margin:auto;">
  5. <!-- logo -->
  6. <img :src="this.baseLogo" alt="" class="rightulliimg" />
  7. </el-header>
  8. <el-main>
  9. <!-- 中间部分 -->
  10. <div class="login">
  11. <el-form ref="loginForm" :model="loginForm" :rules="loginRules" class="login-form">
  12. <el-form-item prop="username">
  13. <el-input v-model="loginForm.username" type="text" auto-complete="off" placeholder="手机号">
  14. <svg-icon slot="prefix" icon-class="user" class="el-input__icon input-icon" />
  15. </el-input>
  16. </el-form-item>
  17. <el-form-item prop="code">
  18. <el-input v-model="loginForm.code" auto-complete="off" placeholder="验证码" style="width: 53%;" @keyup.enter.native="handleLogin">
  19. <svg-icon slot="prefix" icon-class="validCode" class="el-input__icon input-icon" />
  20. </el-input>
  21. <div class="login-code">
  22. <img :src="codeUrl" @click="getCode" class="login-code-img" />
  23. </div>
  24. </el-form-item>
  25. <el-form-item prop="cade">
  26. <el-input v-model="loginForm.shortMessageCode" type="text" maxlength="" auto-complete="off" placeholder="短信验证码" id="" onkeydown="enterHandler(event)" style=" width: 120px; ">
  27. <svg-icon slot="prefix" icon-class="validCode" class="el-input__icon input-icon" />
  28. </el-input>
  29. <el-button @click="sendMessage" :disabled="sendShortMessageBtn">{{codeBtnWord}}</el-button>
  30. </el-form-item>
  31. <el-button :loading="loading" size="medium" type="primary" @click.native.prevent="handleLogin" style="width: 190px;border-radius: 50px;margin-left:10%;margin-top:10%">
  32. <span v-if="!loading">注 册</span>
  33. <span v-else>注 册 中...</span>
  34. </el-button>
  35. </el-form>
  36. </div>
  37. </el-main>
  38. </el-container>
  39. </div>
  40. </template>
  41. <script>
  42. import { getCodeImg, sendShortMessage, chooseCompanyLogin} from "@/api/login";
  43. export default {
  44. name: "register",
  45. data() {
  46. return {
  47. loginForm: {
  48. shortMessageCode: '',
  49. username: "",
  50. code: "",
  51. uuid: "",
  52. unionId : ''
  53. },
  54. codeUrl : '',
  55. loading : false,
  56. sendShortMessageBtn : false,
  57. codeBtnWord : '获取验证码',
  58. loginRules: {
  59. username: [
  60. {
  61. required: true,
  62. trigger: "blur",
  63. message: "用户名不能为空",
  64. },
  65. ],
  66. code: [
  67. {
  68. required: true,
  69. trigger: "change",
  70. message: "验证码不能为空",
  71. },
  72. ]
  73. },
  74. baseLogo: require('../assets/images/lgo.png'),
  75. baseImg: require('../assets/images/logi_bg1.jpg'),
  76. };
  77. },
  78. created() {
  79. this.loginForm.unionId = this.getUrlKey("unionId");
  80. this.getCode();
  81. },
  82. methods:{
  83. getCode() {
  84. getCodeImg().then((res) => {
  85. this.codeUrl = "data:image/gif;base64," + res.img;
  86. this.loginForm.uuid = res.uuid;
  87. });
  88. },
  89. handleLogin() {
  90. this.$refs.loginForm.validate((valid) => {
  91. if (valid) {
  92. this.loading = true;
  93. this.loginForm.type = "2";
  94. // 密码不能为空
  95. if (this.loginForm.shortMessageCode == null || this.loginForm.shortMessageCode == "") {
  96. this.msgError("请输入短信验证码!");
  97. this.loading = false;
  98. return;
  99. }
  100. this.$store
  101. .dispatch("Login", this.loginForm)
  102. .then((data) => {
  103. console.log("跳转认证!")
  104. this.loading = false;
  105. this.$router.push({ path: "/certification" });
  106. })
  107. .catch(() => {
  108. this.loading = false;
  109. this.getCode();
  110. });
  111. }
  112. });
  113. },
  114. sendMessage(){
  115. this.$refs.loginForm.validate((valid) => {
  116. if (valid) {
  117. // 调用获取短信验证码接口
  118. sendShortMessage(this.loginForm.username, this.loginForm.code, this.loginForm.uuid).then(response => {
  119. this.sendShortMessageBtn = true;
  120. this.msgSuccess("发送成功!");
  121. // 因为下面用到了定时器,需要保存this指向
  122. let that = this
  123. that.waitTime = 60;
  124. this.codeBtnWord = `${this.waitTime}s 后重新获取`
  125. let timer = setInterval(function(){
  126. if(that.waitTime>1){
  127. that.waitTime--
  128. that.codeBtnWord = `${that.waitTime}s 后重新获取`
  129. }else{
  130. clearInterval(timer)
  131. that.codeBtnWord = '获取验证码'
  132. that.waitTime = 60
  133. that.getCode();
  134. that.sendShortMessageBtn = false;
  135. }
  136. },1000)
  137. }).catch((response)=>{
  138. this.getCode();
  139. });
  140. }
  141. })
  142. },
  143. getUrlKey(name) {
  144. return decodeURIComponent((new RegExp('[?|&]' + name + '=' + '([^&;]+?)(&|#|;|$)').exec(location.href) || [, ""])[1].replace(/\+/g, '%20')) || null
  145. },
  146. }
  147. };
  148. </script>
  149. <style rel="stylesheet/scss" lang="scss">
  150. .login {
  151. display: flex;
  152. justify-content: center;
  153. align-items: center;
  154. height: 100%;
  155. background-size: cover;
  156. }
  157. // 中间背景图
  158. .login-form {
  159. border-radius: 6px;
  160. width: 935px;
  161. height: 434px;
  162. padding: 73px 138px 103px 597px;
  163. background-image: url("../assets/images/login_bg2.png");
  164. background-size: 935px 434px;
  165. background-repeat: no-repeat;
  166. margin-top: 40px;
  167. // 输入框大小
  168. .el-input {
  169. height: 40px;
  170. width: 100%;
  171. input {
  172. height: 40px;
  173. width: 100%;
  174. }
  175. }
  176. .input-icon {
  177. height: 39px;
  178. width: 14px;
  179. margin-left: 2px;
  180. }
  181. }
  182. .login-tip {
  183. font-size: 13px;
  184. text-align: center;
  185. }
  186. // 验证码
  187. .login-code {
  188. width: 33%;
  189. height: 38px;
  190. float: right;
  191. margin-right: 6%;
  192. img {
  193. cursor: pointer;
  194. vertical-align: middle;
  195. }
  196. }
  197. .login-code-img {
  198. height: 38px;
  199. }
  200. // 大背景图
  201. .backdrop {
  202. background-repeat: no-repeat;
  203. background-size: 1536px 752px;
  204. background-size: cover;
  205. width: 100%;
  206. height: 100%;
  207. display: flex;
  208. justify-content: center;
  209. align-items: center;
  210. background-position: right top;
  211. background-attachment: fixed;
  212. }
  213. .rightulliimg{
  214. width: 860px;
  215. }
  216. .divider_left{
  217. margin-left: -40px;
  218. }.el-button.disabled-style {
  219. background-color: #EEEEEE;
  220. color: #CCCCCC;
  221. }
  222. </style>