login.vue 14 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432
  1. <template>
  2. <div class="login">
  3. <div class="login-left">
  4. <img src="../assets/login-logo.png" />
  5. </div>
  6. <div class="login-container">
  7. <div class="login-container-inner">
  8. <h2 class="title-big">登录</h2>
  9. <p class="title-name">欢迎来到二十一世纪英语智慧阅读平台</p>
  10. <div class="tabs-box">
  11. <a :class="[tabsIndex===1?'active':'']" @click="handleChangeTabs(1)">验证码登录</a>
  12. <a :class="[tabsIndex===0?'active':'']" @click="handleChangeTabs(0)">账号密码登录</a>
  13. </div>
  14. <el-form label-position="top" label-width="80px" ref="loginPwdForm" :model="loginPwdForm" class="form" :hide-required-asterisk="true" :rules="rulesPassword" v-show="tabsIndex===0">
  15. <el-form-item label="用户名/邮箱" prop="userName">
  16. <el-input v-model="loginPwdForm.userName" autocomplete="off" placeholder="用户名/邮箱" @blur="handleTrim('loginPwdForm','userName')" maxlength="100">
  17. </el-input>
  18. </el-form-item>
  19. <el-form-item label="密码" prop="password">
  20. <el-input v-model="loginPwdForm.password" :type="passwordFlag?'text':'password'" autocomplete="off" placeholder="请输入密码" @blur="handleTrim('loginPwdForm','password')" maxlength="20">
  21. <i slot="suffix" class="el-icon-view show-icon" @click="changeIcon('passwordFlag')" v-if="passwordFlag"></i>
  22. <i slot="suffix" class="show-icon" @click="changeIcon('passwordFlag')" v-else>
  23. <svg-icon icon-class="eye-invisible"></svg-icon>
  24. </i>
  25. </el-input>
  26. </el-form-item>
  27. <el-form-item prop="userAgreeCheck" class="userAgree-box">
  28. <el-checkbox-group v-model="loginPwdForm.userAgreeCheck">
  29. <el-checkbox label="1" name="userAgreeCheck"><a @click.prevent="lookUserAgreement">阅读并同意《用户协议》</a></el-checkbox>
  30. </el-checkbox-group>
  31. <a class="forgotPwd">忘记密码?</a>
  32. </el-form-item>
  33. <el-form-item class="btn-box">
  34. <el-button type="primary" @click="onSubmitPassword('loginPwdForm')" size="small" :loading="loading">登录</el-button>
  35. <el-button @click="onCancel('loginPwdForm')" size="small">取消</el-button>
  36. </el-form-item>
  37. </el-form>
  38. <el-form label-position="top" label-width="80px" ref="loginCodeForm" :model="loginCodeForm" class="form" :hide-required-asterisk="true" :rules="rulesCode" v-show="tabsIndex===1">
  39. <el-form-item label="手机号" prop="phone">
  40. <el-input v-model="loginCodeForm.phone" autocomplete="off" placeholder="请输入完整手机号" @blur="handleTrim('loginCodeForm','phone')" maxlength="20">
  41. <template slot="prepend">+86</template>
  42. </el-input>
  43. </el-form-item>
  44. <el-form-item label="验证码" prop="code" class="code-box">
  45. <el-input v-model="loginCodeForm.code" autocomplete="off" placeholder="请输入验证码" class="code-input" @blur="handleTrim('loginCodeForm','code')" maxlength="20">
  46. </el-input>
  47. <el-button type="primary" @click="sendCode('time','phone','verificationCodeShow')" size="small" class="sendCode">
  48. {{ verificationCodeShow ? time+'s' : '发送验证码' }}
  49. </el-button>
  50. </el-form-item>
  51. <el-form-item prop="userAgreeCheck" class="userAgree-box">
  52. <el-checkbox-group v-model="loginCodeForm.userAgreeCheck">
  53. <el-checkbox label="1" name="userAgreeCheck"><a @click.prevent="lookUserAgreement">阅读并同意《用户协议》</a></el-checkbox>
  54. </el-checkbox-group>
  55. <a class="forgotPwd">忘记密码?</a>
  56. </el-form-item>
  57. <el-form-item class="btn-box">
  58. <el-button type="primary" @click="onSubmitPassword('loginCodeForm')" size="small" :loading="loading">登录</el-button>
  59. <el-button @click="onCancel('loginCodeForm')" size="small">取消</el-button>
  60. </el-form-item>
  61. </el-form>
  62. </div>
  63. </div>
  64. </div>
  65. </template>
  66. <script>
  67. import { getLogin } from "@/api/ajax";
  68. import { setToken } from "@/utils/auth";
  69. export default {
  70. name: "Login",
  71. props: [],
  72. data() {
  73. const validatePhone = (rule, value, callback) => {
  74. if(this.tabsIndex===1){
  75. if (value === '') {
  76. callback(new Error('请输入手机号'));
  77. } else {
  78. let reg = /^1[3-9]\d{9}$/;
  79. let result = reg.test(value);
  80. if (result) {
  81. callback();
  82. } else {
  83. callback(new Error('请输入正确的手机号'));
  84. }
  85. }
  86. }
  87. };
  88. return {
  89. tabsIndex:1,
  90. loginPwdForm:{
  91. userName:'',
  92. password:'',
  93. type:'ADMIN',
  94. userAgreeCheck: []
  95. },
  96. passwordFlag:false,
  97. rulesPassword:{
  98. userName:[
  99. { required: true, message: '请输入账号', trigger: 'blur' }
  100. ],
  101. password:[
  102. { required: true, message: '请输入密码', trigger: 'blur' }
  103. ],
  104. userAgreeCheck:[
  105. { type: 'array', required: true, message: '请阅读并同意《用户协议》', trigger: 'change' }
  106. ]
  107. },
  108. loginCodeForm:{
  109. phone:'',
  110. code:'',
  111. type:'ADMIN',
  112. userAgreeCheck: []
  113. },
  114. rulesCode:{
  115. phone:[
  116. { required: true, validator: validatePhone, trigger: 'blur' }
  117. ],
  118. code:[
  119. { required: true, message: '请输入验证码', trigger: 'blur' }
  120. ],
  121. userAgreeCheck:[
  122. { type: 'array', required: true, message: '请阅读并同意《用户协议》', trigger: 'change' }
  123. ]
  124. },
  125. time: 60, //获取验证码的时间
  126. verificationCodeShow: false, //是否已经获取了验证码
  127. loading: false,
  128. timer: null
  129. };
  130. },
  131. watch: {
  132. },
  133. methods: {
  134. // 切换tabs
  135. handleChangeTabs(value){
  136. this.tabsIndex = value
  137. },
  138. changeIcon(flag){
  139. this[flag] = !this[flag]
  140. },
  141. // 查看用户协议
  142. lookUserAgreement(){
  143. },
  144. // 密码登录提交表单
  145. onSubmitPassword(formName){
  146. this.$refs[formName].validate((valid) => {
  147. if (valid) {
  148. this.loading = true
  149. let MethodName = "/OrgServer/LoginControl/Login";
  150. let data = null
  151. if(this.tabsIndex===0){
  152. data = {
  153. user_type:this.loginPwdForm.type,
  154. user_name:this.loginPwdForm.userName,
  155. password:this.loginPwdForm.password
  156. }
  157. }else{
  158. data = {
  159. user_type:this.loginCodeForm.type,
  160. user_name:this.loginCodeForm.phone,
  161. password:this.loginCodeForm.code,
  162. is_dynamic_verification_code_login:"true",
  163. dynamic_verification_code_send_type:"SMS"
  164. }
  165. }
  166. getLogin(MethodName, data)
  167. .then((res) => {
  168. this.loading = false
  169. setToken(res);
  170. this.$router.push({ path: "/EnterSys" });
  171. window.location.reload()
  172. })
  173. .catch(() => {
  174. this.loading = false
  175. this.verificationCodeShow = false;
  176. clearInterval(this.timer);
  177. this.time = 60;
  178. });
  179. } else {
  180. return false;
  181. }
  182. });
  183. },
  184. // 取消 恢复到修改前状态
  185. onCancel(formName){
  186. this.$refs[formName].resetFields();
  187. },
  188. // 发送验证码
  189. sendCode(time,phone,flag,obj){
  190. let this_ = this;
  191. if(this_[time] != 60){
  192. return
  193. }
  194. this_.timer = null;
  195. if (this_.loginCodeForm[phone]) {
  196. let reg = /^1[3-9]\d{9}$/;
  197. let result = reg.test(this_.loginCodeForm[phone]);
  198. if (!result) {
  199. this_.$message.warning('请输入正确的手机号');
  200. return
  201. }
  202. this_[flag] = true;
  203. this_.timer = setInterval(() => {
  204. this_[time]--;
  205. if (this_[time] == 0) {
  206. this_[flag] = false;
  207. clearInterval(this_.timer);
  208. this_.timer = null;
  209. this_[time] = 60;
  210. }
  211. }, 1000);
  212. let MethodName = "/OrgServer/LoginControl/SendVerificationCode";
  213. let data = {
  214. send_type: 'SMS',
  215. phone_or_email: this_.loginCodeForm.phone,
  216. };
  217. getLogin(MethodName, data).then((res) => {
  218. }).catch(()=>{
  219. this_[flag] = false;
  220. clearInterval(this_.timer);
  221. this_.timer = null;
  222. this_[time] = 60;
  223. });
  224. } else {
  225. this_.$message.warning('请先输入手机号');
  226. }
  227. },
  228. // 去掉前后空格
  229. handleTrim(form,fild){
  230. this[form][fild] = this[form][fild].trim()
  231. }
  232. },
  233. mounted() {
  234. },
  235. };
  236. </script>
  237. <style lang="scss" scoped>
  238. .login{
  239. height: 100vh;
  240. display: flex;
  241. width: 100%;
  242. &-left{
  243. width: 655px;
  244. background: url('../assets/login-bg.png') left center no-repeat;
  245. background-size: 655px 100%;
  246. display: flex;
  247. align-items: center;
  248. justify-content: center;
  249. img{
  250. width: 208px;
  251. padding-top: 32px;
  252. }
  253. }
  254. }
  255. .login-container{
  256. background: #FFFFFF;
  257. padding: 64px 72px;
  258. min-height: 100vh;
  259. flex: 1;
  260. display: flex;
  261. align-items: center;
  262. justify-content: center;
  263. &-inner{
  264. width: 360px;
  265. }
  266. .title-big{
  267. font-weight: 400;
  268. font-size: 32px;
  269. line-height: 40px;
  270. margin: 0;
  271. color: #1D2129;
  272. }
  273. .title-name{
  274. font-size: 14px;
  275. line-height: 22px;
  276. color: #86909C;
  277. margin: 0 0 40px 0;
  278. }
  279. .tabs-box{
  280. display: flex;
  281. a{
  282. font-size: 14px;
  283. line-height: 22px;
  284. color: #4E5969;
  285. border-radius: 100px;
  286. padding: 5px 16px;
  287. margin-right: 16px;
  288. &:hover{
  289. background: #F2F3F5;
  290. }
  291. &.active{
  292. background: #F2F3F5;
  293. font-weight: 500;
  294. color: #165DFF;
  295. }
  296. }
  297. }
  298. .form{
  299. margin-top: 40px;
  300. .show-icon{
  301. cursor: pointer;
  302. color: #4E5969;
  303. }
  304. .forgotPwd{
  305. font-size: 14px;
  306. line-height: 22px;
  307. color: #165DFF;
  308. }
  309. }
  310. }
  311. </style>
  312. <style lang="scss">
  313. .login-container{
  314. .form{
  315. .el-form-item__label{
  316. font-weight: 400;
  317. font-size: 14px;
  318. line-height: 22px;
  319. color: #4E5969;
  320. padding-bottom: 8px;
  321. }
  322. .userAgree-box{
  323. .el-form-item__content{
  324. display: flex;
  325. justify-content: space-between;
  326. line-height: 22px;
  327. }
  328. .el-checkbox-group{
  329. flex: 1;
  330. .el-checkbox{
  331. color: rgba(0, 0, 0, 0.88);
  332. font-weight: 400;
  333. }
  334. }
  335. }
  336. .btn-box{
  337. .el-button{
  338. width: 100%;
  339. }
  340. .el-button+.el-button{
  341. margin-left: 0;
  342. margin-top: 8px;
  343. }
  344. }
  345. // .el-button--primary{
  346. // background: #165DFF;
  347. // border-color: #165DFF;
  348. // border-radius: 2px;
  349. // &:hover{
  350. // background: #4080FF;
  351. // border-color: #4080FF;
  352. // }
  353. // &:focus{
  354. // background: #0E42D2;
  355. // border-color: #0E42D2;
  356. // }
  357. // }
  358. // .el-button--default{
  359. // background: #F2F3F5;
  360. // border-radius: 2px;
  361. // border: none;
  362. // color: #4E5969;
  363. // &:hover{
  364. // background: #E5E6EB;
  365. // }
  366. // &:focus{
  367. // background: #C9CDD4;
  368. // }
  369. // }
  370. .code-box{
  371. .el-form-item__content{
  372. display: flex;
  373. }
  374. }
  375. .code-input{
  376. height: 32px;
  377. .el-input__inner{
  378. border-radius: 4px 0 0 4px;
  379. }
  380. }
  381. .sendCode{
  382. border-radius: 0 4px 4px 0;
  383. margin-top: 1px;
  384. width: 92px;
  385. flex-shrink: 0;
  386. }
  387. .el-form-item__content,.el-input__icon{
  388. line-height: 32px;
  389. }
  390. .el-input__inner{
  391. height: 32px;
  392. color: #1D2129;
  393. background: #F2F3F5;
  394. border: none;
  395. }
  396. .el-textarea__inner,.el-input-group__prepend{
  397. color: #1D2129;
  398. }
  399. .el-checkbox__input.is-checked+.el-checkbox__label{
  400. color: #165DFF;
  401. }
  402. .el-checkbox__input.is-checked .el-checkbox__inner, .el-checkbox__input.is-indeterminate .el-checkbox__inner{
  403. background: #165DFF;
  404. border-color: #165DFF;
  405. }
  406. .el-input-group__prepend{
  407. width: 54px;
  408. height: 32px;
  409. border: none;
  410. background: #F2F3F5;
  411. border-radius: 2px 0px 0px 2px;
  412. line-height: 32px;
  413. text-align: center;
  414. padding: 0;
  415. }
  416. .el-input-group--prepend{
  417. display: flex;
  418. .el-input__inner{
  419. margin-left: 8px;
  420. flex: 1;
  421. }
  422. }
  423. }
  424. }
  425. </style>