index.vue 9.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319
  1. <template>
  2. <view class="page-box login-box">
  3. <view class="login-form sys-radius-50 " >
  4. <view class="from-title">
  5. <view class="title-list">
  6. <view class="title-text sys-size-28 text-center sys-weight-600" :class="{'default-text':type===1}" @click="setType(1)">验证码登录</view>
  7. <view class="title-text sys-size-28 text-center sys-weight-600" :class="{'default-text':type===2}" @click="setType(2)">密码登录</view>
  8. </view>
  9. <view class="title-bg one-background-color" :class="{'title-bg-two':type===2}">
  10. <view class="bg-icon dominant-background-color "></view>
  11. </view>
  12. </view>
  13. <view class="from-box one-background-color " :class="{'one-from':type===1,'two-from':type===2}">
  14. <view class="from-animation animate__animated animate__fadeIn" v-if="type===1" >
  15. <view class="input-item sys-from-background-color sys-radius-30 " :class="{'apply-shake':phoneShake}">
  16. <input type="number" class="login-input" placeholder="请输入手机号" maxlength="11" v-model="loginData.phone"></input>
  17. </view>
  18. <view class="input-item input-send sys-from-background-color sys-radius-30" :class="{'apply-shake':codedShake}">
  19. <input type="number" class="login-input" placeholder="请输入验证码" v-model="loginData.code"></input>
  20. <view class="login-send dominant-text-color sys-size-28 sys-weight-400" @click="getVerifiedCode" v-if="timeNum<=0">发送验证码</view>
  21. <view class="login-send dominant-text-color sys-size-28 sys-weight-400" v-else>{{ timeNum }} s</view>
  22. </view>
  23. </view>
  24. <view class="from-animation animate__animated animate__fadeIn" v-else>
  25. <view class="input-item sys-from-background-color sys-radius-30 " :class="{'apply-shake':phoneShake}">
  26. <input type="number" class="login-input" placeholder="请输入手机号" v-model="loginData.phone" maxlength="11"></input>
  27. </view>
  28. <view class="input-item sys-from-background-color sys-radius-30" :class="{'apply-shake':passwordShake}">
  29. <input type="password" class="login-input" placeholder="请输入密码" v-model="loginData.password"></input>
  30. </view>
  31. </view>
  32. <view class="input-agreement" @click="setIsConsent" :class="{'apply-shake':consentShake}">
  33. <image class="agreement-agree" v-if="isConsent" src="/static/img/login/Checked1@3x.png" mode="aspectFill"></image>
  34. <image class="agreement-agree" v-else src="/static/img/login/Checked2@3x.png" mode="aspectFill"></image>
  35. <view class="agreement-text three-text-color sys-size-24">已阅读并同意</view>
  36. <view class="agreement-text dominant-text-color sys-size-24">《隐私政策》</view>
  37. </view>
  38. <view
  39. class="input-but dominant-background-color one-text-color sys-size-30 sys-radius-100 sys-weight-600"
  40. :class="{'sys-selected-but':isLogin,'sys-unselected-but':!isLogin}"
  41. @click="login"
  42. >登陆</view>
  43. </view>
  44. </view>
  45. </view>
  46. </template>
  47. <script>
  48. import {commonSend} from "@/api/common";
  49. import tools from "@/service/tools";
  50. import {login} from "@/api/login";
  51. export default {
  52. components: {
  53. },
  54. data() {
  55. return {
  56. type:1,
  57. loginData: {
  58. phone: '',
  59. password: '',
  60. code: '',
  61. },
  62. phoneShake:false,
  63. passwordShake:false,
  64. codedShake:false,
  65. consentShake:false,
  66. isConsent:false,
  67. isLogin:false,
  68. timeNum: 0,
  69. timer: null,
  70. }
  71. },
  72. watch:{
  73. 'loginData': {
  74. handler() {
  75. this.verifyData()
  76. },
  77. deep: true
  78. }
  79. },
  80. mounted() {
  81. },
  82. methods: {
  83. setShake(type){
  84. if(type===1){
  85. this.phoneShake=true
  86. }else if(type===2){
  87. this.passwordShake=true
  88. }else if(type===3){
  89. this.codedShake=true
  90. }else if(type===4){
  91. this.consentShake=true
  92. }
  93. setTimeout(()=>{
  94. this.phoneShake=false
  95. this.passwordShake=false
  96. },500)
  97. },
  98. login() {
  99. if (this.loginData.phone === '') {
  100. tools.error('请输入手机号码');
  101. this.setShake(1)
  102. return;
  103. }
  104. if (this.type !== 1) {
  105. if (this.loginData.password === '') {
  106. this.setShake(2)
  107. tools.error('请输入登陆密码');
  108. return;
  109. }
  110. } else {
  111. if (this.loginData.code === '') {
  112. this.setShake(3)
  113. tools.error('请输入验证码');
  114. return;
  115. }
  116. }
  117. if (!this.isConsent) {
  118. this.setShake(4)
  119. tools.error('请阅读并同意协议');
  120. return;
  121. }
  122. login(this.loginData).then((res) => {
  123. if (res.code === 1) {
  124. tools.setLoginData(res.data, true)
  125. } else {
  126. tools.error(res.msg)
  127. }
  128. })
  129. },
  130. verifyData(){
  131. if(this.type===1){
  132. this.isLogin=this.loginData.phone!=='' && this.loginData.code!=='' && this.isConsent
  133. }else {
  134. this.isLogin=this.loginData.phone!=='' && this.loginData.password!=='' && this.isConsent
  135. }
  136. },
  137. getVerifiedCode() {
  138. if (this.timeNum > 0) {
  139. return;
  140. }
  141. if (this.loginData.phone === '') {
  142. tools.error("请输入手机号码")
  143. return;
  144. }
  145. let regPhone = /^(?:(?:\+|00)86)?1\d{10}$/;
  146. if (!regPhone.test(this.loginData.phone)) {
  147. tools.error("手机号码格式错误")
  148. return;
  149. }
  150. commonSend({
  151. 'phone': this.loginData.phone,
  152. 'send_type': 'retrieve'
  153. }).then((res) => {
  154. if (res.code === 1) {
  155. tools.success(res.msg);
  156. this.timeNum = 60;
  157. this.timer = setInterval(() => {
  158. this.timeNum--;
  159. if (this.timeNum <= 0) {
  160. clearInterval(this.timer);
  161. }
  162. }, 1000);
  163. } else {
  164. tools.error(res.msg);
  165. }
  166. })
  167. },
  168. setIsConsent(){
  169. this.isConsent=!this.isConsent
  170. },
  171. setType(type){
  172. if(type!==this.type){
  173. this.type=type
  174. }
  175. },
  176. },
  177. }
  178. </script>
  179. <style lang="scss" scoped>
  180. @import "/static/css/login.css";
  181. .page-box{
  182. padding-top: 370rpx;
  183. .login-form{
  184. margin: 0 30rpx;
  185. height: 630rpx;
  186. border-radius: 50rpx;
  187. background-color: rgba(255,255,255,0.5);
  188. .from-title{
  189. border-radius: 50rpx 50rpx 0 0;
  190. height: 110rpx;
  191. position: relative;
  192. .title-bg{
  193. position: absolute;
  194. border-radius: 50rpx 50rpx 0 0;
  195. top: 0;
  196. left: 0;
  197. height:110rpx;
  198. width: 50%;
  199. transition: .5s ease;
  200. z-index: 0;
  201. .bg-icon{
  202. margin: 86rpx auto 0 auto;
  203. width: 36rpx;
  204. height: 6rpx;
  205. border-radius: 99rpx;
  206. }
  207. }
  208. .title-bg-two{
  209. left: 50%;
  210. transition: .5s ease;
  211. }
  212. //.title-bg::after {
  213. // content: '';
  214. // position: absolute;
  215. // right: -50rpx;
  216. // bottom: 0;
  217. // width: 50rpx;
  218. // height:50rpx;
  219. // background-color: #fff;
  220. // border-radius: 50rpx 50rpx 50rpx 0;
  221. //}
  222. .title-list{
  223. display: flex;
  224. justify-content: space-between;
  225. z-index: 1;
  226. position: relative;
  227. .title-text{
  228. width: 50%;
  229. height: 110rpx;
  230. line-height: 102rpx;
  231. color: #333333;
  232. }
  233. .default-text{
  234. color: #10B261;
  235. }
  236. .title-text:first-child{
  237. background-image: url("/static/img/login/right.png");
  238. background-repeat: no-repeat;
  239. background-position: right bottom;
  240. }
  241. .title-text:last-child{
  242. background-image: url("/static/img/login/left.png");
  243. background-repeat: no-repeat;
  244. background-position: left bottom;
  245. }
  246. }
  247. }
  248. .from-box{
  249. height:520rpx;
  250. box-shadow: 0rpx 4rpx 36rpx 0rpx rgba(196,196,196,0.25);
  251. border-radius: 0 0 50rpx 50rpx;
  252. padding: 50rpx 45rpx;
  253. .input-item{
  254. height: 96rpx;
  255. padding: 28rpx 40rpx;
  256. box-sizing: border-box;
  257. .login-input{
  258. width: 100%;
  259. }
  260. }
  261. .input-item:last-child{
  262. margin-top: 30rpx;
  263. }
  264. .input-send{
  265. display: flex;
  266. justify-content: flex-start;
  267. align-items: center;
  268. .login-input{
  269. width:calc(100% - 140rpx) ;
  270. }
  271. .login-send{
  272. width: 140rpx;
  273. text-align: center;
  274. }
  275. }
  276. .input-agreement{
  277. margin-top: 25rpx;
  278. display: flex;
  279. justify-content: flex-start;
  280. align-items: center;
  281. .agreement-agree{
  282. width: 32rpx;
  283. height: 32rpx;
  284. transition: .5s ease;
  285. }
  286. .agreement-text{
  287. margin-left: 18rpx;
  288. }
  289. }
  290. .input-but{
  291. margin-top: 40rpx;
  292. width: 100%;
  293. height: 96rpx;
  294. line-height: 96rpx;
  295. text-align: center;
  296. }
  297. }
  298. .one-from{
  299. border-radius: 0 50rpx 50rpx 50rpx;
  300. }
  301. .two-from{
  302. border-radius: 50rpx 0 50rpx 50rpx;
  303. }
  304. }
  305. }
  306. </style>