loginBox.vue 14 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477
  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.label"
  14. :value="item.value">
  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','','')" 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','','')" class="password-container">
  30. <el-input class="special-input" type="password" placeholder="请输入内容" 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="我已了解风险提示!" 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="buttonTextChange();switchNoticeTextChange();">返回</p>
  47. </div>
  48. <div class="find-action" v-if="checkBoxState('','find','','')">
  49. <p class="go-back" @click="handleGoBack">返回</p>
  50. </div>
  51. </div>
  52. <div class="button-container">
  53. <p class="top-notice no-code-notice" v-if="showNoCodeNotice&&checkBoxState('','login','','')">收不到短信?试试 <a class="notice-link" href="#">语音验证</a></p>
  54. <button class="action-button" :class="{'disabled':disableAction}" @click="handleActionClick">{{buttonText}}</button>
  55. <p class="switch-notice" @click="handleSwitch">{{switchNoticeText}}</p>
  56. </div>
  57. </div>
  58. </div>
  59. </template>
  60. <script>
  61. export default {
  62. name: "loginBox",
  63. data(){
  64. return{
  65. selectedTab:'phone',
  66. tabList: {
  67. 'phone': {
  68. id: 'phone',
  69. label: '手机'
  70. },
  71. 'email': {
  72. id: 'email',
  73. label: '邮箱'
  74. },
  75. },
  76. tabListGroup:{
  77. 'login': {
  78. 'phone': {
  79. id: 'phone',
  80. label: '手机'
  81. },
  82. 'email': {
  83. id: 'email',
  84. label: '邮箱'
  85. },
  86. },
  87. 'phone-find':{
  88. 'phone': {
  89. id: 'phone',
  90. label: '手机找回密码',
  91. default:true,
  92. },
  93. },
  94. 'email-find':{
  95. 'email': {
  96. id: 'phone',
  97. label: '邮箱找回密码',
  98. default:true,
  99. },
  100. },
  101. 'email-set':{
  102. 'phone': {
  103. id: 'phone',
  104. label: '邮箱设置密码',
  105. default:true,
  106. },
  107. },
  108. 'phone-set':{
  109. 'phone': {
  110. id: 'phone',
  111. label: '手机设置密码',
  112. default:true,
  113. },
  114. },
  115. },
  116. areaOptions:[
  117. {
  118. label:'中国',
  119. value:'+86'
  120. }
  121. ],
  122. buttonText:'',
  123. switchNoticeText:'',
  124. loginInfo:{
  125. selectArea:'+86',
  126. account:'',
  127. code:'',
  128. password:'',
  129. checkItem:false,
  130. rememberPwd:false,
  131. },
  132. showNoCodeNotice:false,
  133. disableAction:true,
  134. disableSend:false,
  135. sendButtonText:'发送验证码',
  136. nextSendCountDown:0,
  137. countDownTimerId:"",
  138. type:{
  139. account:'phone',//email phone
  140. action:'login',//login find set
  141. password:'code',//code pwd
  142. step:1,//0 1 2
  143. },
  144. typeList:{
  145. account:['email','phone'],
  146. action:['login','find','set'],
  147. password:['code','pwd'],
  148. step:[0,1,2],
  149. },
  150. }
  151. }
  152. ,
  153. computed:{
  154. },
  155. mounted(){
  156. this.buttonText=this.buttonTextChange();
  157. this.switchNoticeText=this.switchNoticeTextChange();
  158. // this.type.password='psw';
  159. },
  160. // watch:{
  161. // type:function () {
  162. // this.setTypeFullCode()
  163. // },
  164. // deep:true
  165. //
  166. // },
  167. methods:{
  168. changeTab(id){
  169. if(this.tabList.length<2){
  170. return;
  171. }
  172. this.disableAction=true;
  173. this.selectedTab=id;
  174. this.type.step=1;
  175. this.type.account=id;
  176. this.type.action='login';
  177. this.type.password='code';
  178. this.buttonText=this.buttonTextChange();
  179. this.switchNoticeText=this.switchNoticeTextChange();
  180. this.loginInfo.account='';
  181. },
  182. checkBoxState(account,action,password,step){//根据条件设置各个输入框的状态
  183. let type=this.type;
  184. if(
  185. account&&//如果account是空的
  186. !(typeof account!=='object'?account===type.account://如果account不是数组,那么直接比较
  187. !!(~account.indexOf(type.account)))//如果是数组,利用indexOf查找是否在数组中
  188. ){//注意是反着来的 如果判断为真说明不符合条件 那么函数返回假 下方同理
  189. return false;
  190. }
  191. if(
  192. action&&
  193. !(typeof action!=='object'?action===type.action:
  194. !!(~action.indexOf(type.action)))
  195. ){
  196. return false;
  197. }
  198. if(
  199. password&&
  200. !(typeof password!=='object'?password===type.password:
  201. !!(~password.indexOf(type.password)))
  202. ){
  203. return false;
  204. }
  205. if(
  206. step&&
  207. !(typeof step!=='object'?step===type.step:
  208. !!(~step.indexOf(type.step)))
  209. ){
  210. return false;
  211. }
  212. return true;
  213. },
  214. tabItemChange(){
  215. if(this.checkBoxState('email','find','','')){
  216. this.tabList=this.tabListGroup["email-find"];
  217. return;
  218. }
  219. if(this.checkBoxState('phone','find','','')){
  220. this.tabList=this.tabListGroup["phone-find"];
  221. return;
  222. }
  223. if(this.checkBoxState('','login','','')){
  224. this.tabList=this.tabListGroup.login;
  225. return;
  226. }
  227. if(this.checkBoxState('email','set','','')){
  228. this.tabList=this.tabListGroup["email-set"];
  229. return;
  230. }
  231. if(this.checkBoxState('phone','set','','')){
  232. this.tabList=this.tabListGroup["phone-set"];
  233. return;
  234. }
  235. },
  236. textChange(){
  237. this.buttonText=this.buttonTextChange();
  238. this.switchNoticeText=this.switchNoticeTextChange();
  239. this.tabItemChange();
  240. this.showNoCodeNotice=false;
  241. } ,
  242. handleForgetPwd(){
  243. this.type.action='find';
  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. handleActionClick(){
  289. if(this.disableAction)return;
  290. if(this.checkBoxState('email','find','','')){
  291. console.log(123)
  292. }
  293. if(this.checkBoxState('phone','login','',2)){
  294. console.log(this.loginInfo.selectArea+this.loginInfo.account);
  295. }
  296. if(this.checkBoxState('','','',1)&&!this.checkBoxState('email','find','','')){
  297. this.type.step+=1;
  298. }
  299. //must bottom
  300. this.textChange();
  301. },
  302. handleSwitch(){
  303. // console.log(this.checkBoxState('','login','code',2))
  304. if(this.checkBoxState('','login','','')){
  305. this.type.password=this.checkBoxState('','login','code',2)?'pwd':'code';
  306. }
  307. if(this.checkBoxState('','find','','')){
  308. this.type.account=this.checkBoxState('email','find','','')?'phone':'email';
  309. }
  310. this.textChange();
  311. },
  312. sendMessage(){
  313. if(this.disableSend)return;
  314. this.disableSend=true;
  315. this.nextSendCountDown=2;//todo
  316. this.countDownTimerId=setInterval(()=>{
  317. if(this.nextSendCountDown===0){
  318. clearInterval(this.countDownTimerId);
  319. this.sendButtonText="发送验证码";
  320. this.showNoCodeNotice=true;
  321. this.disableSend=false;
  322. }else{
  323. this.sendButtonText=`${this.nextSendCountDown}s重新发送`;
  324. this.nextSendCountDown--;
  325. }
  326. },1000)
  327. }
  328. }
  329. }
  330. </script>
  331. <style scoped lang="less">
  332. @import "../assets/less/_variable.less";
  333. .el-input__icon{
  334. font-size: 26px;
  335. padding-right: 14px;
  336. }
  337. .main{
  338. width: 100%;
  339. height: 100%;
  340. padding: 25px;
  341. & .tab-container{
  342. box-sizing: border-box;
  343. border-bottom: solid 2px #e5e5e5;
  344. display:inline-flex;
  345. justify-content: space-around;
  346. width: 100%;
  347. &>li{
  348. transition: border-bottom-color 0.25s ease;
  349. cursor: pointer;
  350. margin-bottom: -2px;
  351. box-sizing: border-box;
  352. &.active{
  353. border-bottom: 2px solid @primaryBlue;
  354. }
  355. padding: 0 30px 20px;
  356. font-size: 20px;
  357. color: @lightBlack;
  358. }
  359. }
  360. .no-code-notice{
  361. font-size: 14px;
  362. color: @lighterBlack;
  363. margin: 20px 0 0 15px;
  364. & .notice-link{
  365. color:@primaryBlue;
  366. }
  367. }
  368. & .tab-item-container{
  369. margin-top: 15px;
  370. & .special-input{
  371. margin-top: 20px;
  372. }
  373. & .code-container{
  374. & .code-input-inner{
  375. display:flex ;
  376. align-items: flex-end;
  377. & .send-code-button{
  378. border: 0;
  379. margin-left: 10px;
  380. width: 134px;
  381. height: 50px;
  382. background-color: #ffe366;
  383. cursor: pointer;
  384. }
  385. }
  386. }
  387. & .button-container{
  388. width: 310px;
  389. position: absolute;
  390. bottom:30px;
  391. left: 25px;
  392. & .action-button{
  393. cursor: pointer;
  394. border: 0;
  395. font-size: 18px;
  396. color: #fffcfc;
  397. width: 100%;
  398. height: 50px;
  399. background-color: @primaryBlue;
  400. }
  401. & .switch-notice{
  402. font-size: 14px;
  403. color: #666666;
  404. margin-top: 20px;
  405. cursor: pointer;
  406. }
  407. & .top-notice{
  408. margin-top: 0;
  409. margin-bottom: 20px;
  410. }
  411. }
  412. & .action-container{
  413. margin-top: 12px;
  414. font-size: 14px;
  415. color:@lighterBlack;
  416. & .login-action{
  417. & .login-action__phone{
  418. text-align: left;
  419. }
  420. & .login-action__pwd{
  421. & .forget-pwd{
  422. cursor: pointer;
  423. }
  424. display: flex;
  425. justify-content: space-between;
  426. }
  427. }
  428. & .find-action{
  429. text-align: right;
  430. cursor: pointer;
  431. }
  432. }
  433. }
  434. }
  435. .disabled{
  436. background-color: #dcdcdc!important;
  437. cursor: default!important;
  438. }
  439. .prepend-icon{
  440. display: inline-block;
  441. font-size: 21px;
  442. /*padding: 0 1px;*/
  443. }
  444. </style>
  445. <!--全局样式覆写-->