loginBox.vue 19 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627
  1. <template>
  2. <div class="main">
  3. <ul class="tab-container">
  4. <li @click="changeTab(item.id)" v-for="item,index in tabList" :key="index" :class="{'active':item.id===selectedTab||item.default}">{{item.label}}</li>
  5. </ul>
  6. <div class="tab-item-container">
  7. <div class="account-container">
  8. <el-input v-if="type.account==='phone'" @change="phoneAccountChanged" placeholder="请输入内容" v-model="loginInfo.account" class="input-with-select special-input">
  9. <el-select v-model="loginInfo.selectArea" slot="prepend" placeholder="请选择">
  10. <el-option
  11. v-for='item,index in areaOptions'
  12. :key="index"
  13. :label="item.ch_name"
  14. :value="item.code">
  15. </el-option>
  16. </el-select>
  17. </el-input>
  18. <el-input v-if="type.account==='email'" @change="emailAccountChanged" class="special-input" placeholder="请输入您的邮箱号码" v-model="loginInfo.account">
  19. <template slot="prepend"><i class="prepend-icon iconfont">&#xe600;</i> </template>
  20. </el-input>
  21. </div>
  22. <div v-if="checkBoxState('','login','code',2)||checkBoxState('phone','find','','')||checkBoxState('','set','','')" class="code-container">
  23. <div class="code-input-inner">
  24. <el-input class="special-input" placeholder="请输入验证码" v-model="loginInfo.code"></el-input>
  25. <button class="send-code-button" @click="sendMessage" :class="{'disabled':disableSend}">{{sendButtonText}}</button>
  26. </div>
  27. <p class="no-code-notice" v-if="showNoCodeNotice&&checkBoxState('','set','','')">收不到短信?试试 <a class="notice-link" href="#">语音验证码</a></p>
  28. </div>
  29. <div v-if="checkBoxState('','login','pwd',2)||checkBoxState('phone','find','','')||checkBoxState('','set','','')" class="password-container">
  30. <el-input class="special-input" type="password" placeholder="请输入内容" @change="disableAction=!loginInfo.password" v-model="loginInfo.password">
  31. <template slot="prepend"><i class="prepend-icon iconfont">&#xe6c5;</i> </template>
  32. <i slot="suffix" class="el-input__icon iconfont">&#xe653;</i>
  33. </el-input>
  34. </div>
  35. <div class="action-container">
  36. <div class="login-action" v-if="checkBoxState('','login','',2)">
  37. <div class="login-action__phone" v-if="checkBoxState('phone','login','code',2)">
  38. <el-checkbox label="我已了解风险提示!" @change="disableAction=!loginInfo.checkItem" v-model="loginInfo.checkItem"></el-checkbox>
  39. </div>
  40. <div class="login-action__pwd" v-if="checkBoxState('','login','pwd',2)">
  41. <el-checkbox label="记住密码" v-model="loginInfo.rememberPwd"></el-checkbox>
  42. <p class="forget-pwd" @click="handleForgetPwd">忘记密码?</p>
  43. </div>
  44. </div>
  45. <div class="set-action" v-if="checkBoxState('','set','',2)">
  46. <p class="go-back" @click="handleGoBack">返回</p>
  47. </div>
  48. <div class="find-action" v-if="checkBoxState('','find','','')">
  49. <p class="go-back" @click="handleGoBack">返回</p>
  50. </div>
  51. <div class="register-action" v-if="checkBoxState('','login','',1)">
  52. <a class="register" @click="handleRegister">立即注册</a>
  53. </div>
  54. </div>
  55. <div class="button-container">
  56. <p class="top-notice no-code-notice" v-if="showNoCodeNotice&&checkBoxState('','login','','')">收不到短信?试试 <a class="notice-link" href="#">语音验证</a></p>
  57. <button class="action-button" :class="{'disabled':disableAction}" @click="handleActionClick">{{buttonText}}</button>
  58. <p class="switch-notice" @click="handleSwitch">{{switchNoticeText}}</p>
  59. </div>
  60. </div>
  61. </div>
  62. </template>
  63. <script>
  64. export default {
  65. name: "loginBox",
  66. data(){
  67. return{
  68. selectedTab:'phone',
  69. tabList: {
  70. 'phone': {
  71. id: 'phone',
  72. label: '手机'
  73. },
  74. 'email': {
  75. id: 'email',
  76. label: '邮箱'
  77. },
  78. },
  79. tabListGroup:{
  80. 'login': {
  81. 'phone': {
  82. id: 'phone',
  83. label: '手机'
  84. },
  85. 'email': {
  86. id: 'email',
  87. label: '邮箱'
  88. },
  89. },
  90. 'phone-find':{
  91. 'phone': {
  92. id: 'phone',
  93. label: '手机找回密码',
  94. default:true,
  95. },
  96. },
  97. 'email-find':{
  98. 'email': {
  99. id: 'phone',
  100. label: '邮箱找回密码',
  101. default:true,
  102. },
  103. },
  104. 'email-set':{
  105. 'phone': {
  106. id: 'phone',
  107. label: '邮箱设置密码',
  108. default:true,
  109. },
  110. },
  111. 'phone-set':{
  112. 'phone': {
  113. id: 'phone',
  114. label: '手机设置密码',
  115. default:true,
  116. },
  117. },
  118. },
  119. areaOptions:[
  120. ],
  121. buttonText:'',
  122. switchNoticeText:'',
  123. loginInfo:{
  124. selectArea:'86',
  125. account:'',
  126. code:'',
  127. password:'',
  128. checkItem:false,
  129. rememberPwd:false,
  130. },
  131. showNoCodeNotice:false,
  132. disableAction:true,
  133. disableSend:false,
  134. sendButtonText:'发送验证码',
  135. nextSendCountDown:0,
  136. countDownTimerId:"",
  137. type:{
  138. account:'phone',//email phone
  139. action:'login',//login find set
  140. password:'code',//code pwd
  141. step:1,//0 1 2
  142. },
  143. typeList:{
  144. account:['email','phone'],
  145. action:['login','find','set'],
  146. password:['code','pwd'],
  147. step:[0,1,2],
  148. },
  149. }
  150. }
  151. ,
  152. computed:{
  153. },
  154. mounted(){
  155. this.buttonText=this.buttonTextChange();
  156. this.switchNoticeText=this.switchNoticeTextChange();
  157. this.$http.get(this._ajaxAdress.getCountryList).then((response)=>{
  158. this.areaOptions=response.data.data;
  159. })
  160. // this.type.password='psw';
  161. },
  162. methods:{
  163. changeTab(id){
  164. if(this.tabList.length<2){
  165. return;
  166. }
  167. this.disableAction=true;
  168. this.selectedTab=id;
  169. this.type.step=1;
  170. this.type.account=id;
  171. this.type.action='login';
  172. this.type.password='code';
  173. this.buttonText=this.buttonTextChange();
  174. this.switchNoticeText=this.switchNoticeTextChange();
  175. this.loginInfo.account='';
  176. },
  177. checkBoxState(account,action,password,step){//根据条件设置各个输入框的状态
  178. let type=this.type;
  179. if(
  180. account&&//如果account是空的
  181. !(typeof account!=='object'?account===type.account://如果account不是数组,那么直接比较
  182. !!(~account.indexOf(type.account)))//如果是数组,利用indexOf查找是否在数组中
  183. ){//注意是反着来的 如果判断为真说明不符合条件 那么函数返回假 下方同理
  184. return false;
  185. }
  186. if(
  187. action&&
  188. !(typeof action!=='object'?action===type.action:
  189. !!(~action.indexOf(type.action)))
  190. ){
  191. return false;
  192. }
  193. if(
  194. password&&
  195. !(typeof password!=='object'?password===type.password:
  196. !!(~password.indexOf(type.password)))
  197. ){
  198. return false;
  199. }
  200. if(
  201. step&&
  202. !(typeof step!=='object'?step===type.step:
  203. !!(~step.indexOf(type.step)))
  204. ){
  205. return false;
  206. }
  207. return true;
  208. },
  209. tabItemChange(){
  210. if(this.checkBoxState('email','find','','')){
  211. this.tabList=this.tabListGroup["email-find"];
  212. return;
  213. }
  214. if(this.checkBoxState('phone','find','','')){
  215. this.tabList=this.tabListGroup["phone-find"];
  216. return;
  217. }
  218. if(this.checkBoxState('','login','','')){
  219. this.tabList=this.tabListGroup.login;
  220. return;
  221. }
  222. if(this.checkBoxState('email','set','','')){
  223. this.tabList=this.tabListGroup["email-set"];
  224. return;
  225. }
  226. if(this.checkBoxState('phone','set','','')){
  227. this.tabList=this.tabListGroup["phone-set"];
  228. return;
  229. }
  230. },
  231. textChange(){
  232. this.buttonText=this.buttonTextChange();
  233. this.switchNoticeText=this.switchNoticeTextChange();
  234. this.tabItemChange();
  235. this.showNoCodeNotice=false;
  236. } ,
  237. handleForgetPwd(){
  238. this.type.action='find';
  239. this.textChange();
  240. },
  241. handleRegister(){
  242. this.type.action='set';
  243. this.type.step=2;
  244. this.textChange();
  245. },
  246. handleGoBack(){
  247. this.type.action='login';
  248. this.textChange();
  249. },
  250. buttonTextChange(){
  251. let text='';
  252. // console.log(this.checkBoxState('','','',1))
  253. if(this.checkBoxState('','','',1)){return '下一步';}
  254. if(this.checkBoxState('email','find','','')){return '下一步'}
  255. switch(this.type.action){
  256. case'find':
  257. return '确定找回';
  258. break;
  259. case'set':
  260. return '确定';
  261. break;
  262. case'login':
  263. return '注册/登录';
  264. break;
  265. }
  266. },
  267. phoneAccountChanged(val){
  268. this.disableAction=!/^(1)[0-9]{10}$/.test(val);
  269. },
  270. emailAccountChanged(val){
  271. this.disableAction=!/^\w+([-+.]\w+)*@\w+([-.]\w+)*\.\w+([-.]\w+)*$/.test(val);
  272. },
  273. switchNoticeTextChange() {
  274. if(this.checkBoxState('','login','code',2)){
  275. return '切换密码登录'
  276. }
  277. if(this.checkBoxState('','login','pwd',2)){
  278. return '切换验证码登录'
  279. }
  280. if(this.checkBoxState('email','find','','')){
  281. return '手机找回密码'
  282. }
  283. if(this.checkBoxState('phone','find','','')){
  284. return '邮箱找回密码'
  285. }
  286. return ''
  287. },
  288. setUrlParams(obj){
  289. let param = new URLSearchParams();
  290. for(let item in obj){
  291. param.append(item,obj[item]);
  292. }
  293. return param
  294. },
  295. handleActionClick(){
  296. if(this.disableAction)return;
  297. this.disableAction=true;
  298. if(this.checkBoxState('','login','',2)){//登录
  299. let params={
  300. 'email':'',
  301. 'password':'',
  302. 'redirect_uri':'https://dev407.33.cn',
  303. 'os':'web',
  304. 'type':'',
  305. 'area':'',
  306. 'logintype':'',
  307. 'code':'',
  308. 'mobile':'',
  309. 'platform':'fx66',
  310. 'broker_code':'04031632e48cd96e',
  311. }
  312. if(this.checkBoxState('','login','pwd',2)){
  313. params.password=this.loginInfo.password
  314. params.logintype='password'
  315. }else{
  316. params.code=this.loginInfo.code
  317. params.logintype='code'
  318. }
  319. if(this.checkBoxState('email','login','pwd',2)){
  320. params.email=this.loginInfo.account;
  321. params.type='email';
  322. }else{
  323. params.mobile=this.loginInfo.account;
  324. params.type='sms';
  325. params.area=this.loginInfo.selectArea;
  326. }
  327. if(this.checkBoxState('email','login','code',2)){
  328. params.email=this.loginInfo.account;
  329. params.type='email';
  330. }else{
  331. params.mobile=this.loginInfo.account;
  332. params.type='sms';
  333. params.area=this.loginInfo.selectArea;
  334. }
  335. this.$http.post(this._ajaxAdress.postLogin,this.setUrlParams(params)).then((response)=>{//todo 将get改为post
  336. if(response.data.code==200){
  337. this.$emit('loginSuccess');
  338. localStorage.setItem('token',response.data.data.access_token);
  339. localStorage.setItem('username',(this.checkBoxState('phone','','','')?this.loginInfo.selectArea:'')+this.loginInfo.account)
  340. }else{
  341. this.$notify({
  342. title: '提示',
  343. message: response.data.message,
  344. type: 'warning'
  345. });
  346. }
  347. this.disableAction=false;
  348. })
  349. }
  350. if(this.checkBoxState('','find','','')){//密码找回
  351. let params={
  352. 'email':'',
  353. 'os':'web',
  354. 'type':'',
  355. 'area':'',
  356. 'mobile':'',
  357. 'platform':'fx66',
  358. }
  359. if(this.checkBoxState('email','find','','')){
  360. params.email=this.loginInfo.account;
  361. }else{
  362. params.mobile=this.loginInfo.account;
  363. params.area=this.loginInfo.selectArea;
  364. }
  365. this.$http.post(this._ajaxAdress.findPwd,this.setUrlParams(params)).then((response)=>{
  366. if(response.data.code==200){
  367. if(this.checkBoxState('email','find','','')){
  368. this.$notify({
  369. title: '成功',
  370. message: '你的邮箱验证码已经发送到你的邮箱\n请前往修改密码!',
  371. type: 'success'
  372. })
  373. }
  374. }else{
  375. this.$notify({
  376. title: '提示',
  377. message: response.data.message,
  378. type: 'warning'
  379. });
  380. }
  381. this.disableAction=false;
  382. })
  383. }
  384. if(this.checkBoxState('','set','','')){
  385. let params={
  386. 'email':'',
  387. 'password':'',
  388. 'type':'',
  389. 'area':'',
  390. 'code':'',
  391. 'mobile':'',
  392. }
  393. params.code=this.loginInfo.code;
  394. params.password=this.loginInfo.password;
  395. if(this.checkBoxState('email','set','','')){
  396. params.email=this.loginInfo.account;
  397. params.type='email';
  398. }else{
  399. params.mobile=this.loginInfo.account;
  400. params.type='sms';
  401. params.area=this.loginInfo.selectArea;
  402. }
  403. this.$http.post(this._ajaxAdress.postRegister,this.setUrlParams(params)).then((response)=>{//todo 将get改为post
  404. if(response.data.code==200){
  405. this.$notify({
  406. title: '成功',
  407. message:'注册成功',
  408. type: 'success'
  409. });
  410. }else{
  411. this.$notify({
  412. title: '提示',
  413. message: response.data.message,
  414. type: 'warning'
  415. });
  416. }
  417. this.disableAction=false;
  418. })
  419. }
  420. if(this.checkBoxState('','','',1)&&!this.checkBoxState('email','find','','')){
  421. this.type.step+=1;
  422. }
  423. //must bottom
  424. this.textChange();
  425. },
  426. handleSwitch(){
  427. // console.log(this.checkBoxState('','login','code',2))
  428. if(this.checkBoxState('','login','','')){
  429. this.type.password=this.checkBoxState('','login','code',2)?'pwd':'code';
  430. }
  431. if(this.checkBoxState('','find','','')){
  432. this.type.account=this.checkBoxState('email','find','','')?'phone':'email';
  433. }
  434. this.textChange();
  435. },
  436. sendMessage(){
  437. if(this.disableSend)return;
  438. this.disableSend=true;
  439. this.nextSendCountDown=2;//todo
  440. this.countDownTimerId=setInterval(()=>{
  441. if(this.nextSendCountDown===0){
  442. clearInterval(this.countDownTimerId);
  443. this.sendButtonText="发送验证码";
  444. this.showNoCodeNotice=true;
  445. this.disableSend=false;
  446. }else{
  447. this.sendButtonText=`${this.nextSendCountDown}s重新发送`;
  448. this.nextSendCountDown--;
  449. }
  450. },1000)
  451. }
  452. }
  453. }
  454. </script>
  455. <style scoped lang="less">
  456. @import "../assets/less/_variable.less";
  457. .el-input__icon{
  458. font-size: 26px;
  459. padding-right: 14px;
  460. }
  461. .main{
  462. width: 100%;
  463. height: 100%;
  464. padding: 25px;
  465. & .tab-container{
  466. box-sizing: border-box;
  467. border-bottom: solid 2px #e5e5e5;
  468. display:inline-flex;
  469. justify-content: space-around;
  470. width: 100%;
  471. &>li{
  472. transition: border-bottom-color 0.25s ease;
  473. cursor: pointer;
  474. margin-bottom: -2px;
  475. box-sizing: border-box;
  476. &.active{
  477. border-bottom: 2px solid @primaryBlue;
  478. }
  479. padding: 0 30px 20px;
  480. font-size: 20px;
  481. color: @lightBlack;
  482. }
  483. }
  484. .no-code-notice{
  485. font-size: 14px;
  486. color: @lighterBlack;
  487. margin: 20px 0 0 15px;
  488. & .notice-link{
  489. color:@primaryBlue;
  490. }
  491. }
  492. & .tab-item-container{
  493. margin-top: 15px;
  494. & .special-input{
  495. margin-top: 20px;
  496. }
  497. & .code-container{
  498. & .code-input-inner{
  499. display:flex ;
  500. align-items: flex-end;
  501. & .send-code-button{
  502. border: 0;
  503. margin-left: 10px;
  504. width: 134px;
  505. height: 50px;
  506. background-color: #ffe366;
  507. cursor: pointer;
  508. }
  509. }
  510. }
  511. & .button-container{
  512. width: 310px;
  513. position: absolute;
  514. bottom:30px;
  515. left: 25px;
  516. & .action-button{
  517. cursor: pointer;
  518. border: 0;
  519. font-size: 18px;
  520. color: #fffcfc;
  521. width: 100%;
  522. height: 50px;
  523. background-color: @primaryBlue;
  524. }
  525. & .switch-notice{
  526. font-size: 14px;
  527. color: #666666;
  528. margin-top: 20px;
  529. cursor: pointer;
  530. }
  531. & .top-notice{
  532. margin-top: 0;
  533. margin-bottom: 20px;
  534. }
  535. }
  536. & .action-container{
  537. margin-top: 12px;
  538. font-size: 14px;
  539. color:@lighterBlack;
  540. & .login-action{
  541. & .login-action__phone{
  542. text-align: left;
  543. }
  544. & .login-action__pwd{
  545. & .forget-pwd{
  546. cursor: pointer;
  547. }
  548. display: flex;
  549. justify-content: space-between;
  550. }
  551. }
  552. & .find-action{
  553. & .go-back{
  554. float: right;
  555. }
  556. text-align: right;
  557. cursor: pointer;
  558. }
  559. & .set-action{
  560. & .go-back{
  561. float: right;
  562. }
  563. text-align: right;
  564. cursor: pointer;
  565. }
  566. }
  567. }
  568. }
  569. .register{
  570. float: left;
  571. cursor: pointer;
  572. color:@primaryBlue;
  573. }
  574. .disabled{
  575. background-color: #dcdcdc!important;
  576. cursor: default!important;
  577. }
  578. .prepend-icon{
  579. display: inline-block;
  580. font-size: 21px;
  581. /*padding: 0 1px;*/
  582. }
  583. </style>
  584. <!--全局样式覆写-->