index.vue 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374
  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 text-color-dominant sys-size-28 sys-weight-400" @click="getVerifiedCode" v-if="timeNum<=0">发送验证码</view>
  21. <view class="login-send text-color-dominant 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 text-color-666 sys-size-24">已阅读并同意</view>
  36. <view class="agreement-text text-color-dominant sys-size-24">《隐私政策》</view>
  37. </view>
  38. <view
  39. class="input-but dominant-background-color text-color-fff 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 class="register-box">
  46. <view class="register-text sys-weight-400 sys-size-24 text-color-666">还没有账号?</view>
  47. <view class="register-text text-color-dominant sys-size-24 sys-weight-400">立即注册</view>
  48. </view>
  49. <view class="wx-box">
  50. <view class="wx-title">
  51. <view class="wx-wire"></view>
  52. <view class="wx-text sys-size-24 text-color-7c sys-weight-400">第三方登录</view>
  53. <view class="wx-wire"></view>
  54. </view>
  55. <image class="wx-logo" src="/static/img/login/wx-img.png" mode="aspectFill"></image>
  56. </view>
  57. </view>
  58. </template>
  59. <script>
  60. import {commonSend} from "@/api/common";
  61. import tools from "@/service/tools";
  62. import {login} from "@/api/login";
  63. export default {
  64. components: {
  65. },
  66. data() {
  67. return {
  68. type:1,
  69. loginData: {
  70. phone: '',
  71. password: '',
  72. code: '',
  73. },
  74. phoneShake:false,
  75. passwordShake:false,
  76. codedShake:false,
  77. consentShake:false,
  78. isConsent:false,
  79. isLogin:false,
  80. timeNum: 0,
  81. timer: null,
  82. }
  83. },
  84. watch:{
  85. 'loginData': {
  86. handler() {
  87. this.verifyData()
  88. },
  89. deep: true
  90. },
  91. 'isConsent':function () {
  92. this.verifyData()
  93. }
  94. },
  95. mounted() {
  96. },
  97. methods: {
  98. setShake(type){
  99. if(type===1){
  100. this.phoneShake=true
  101. }else if(type===2){
  102. this.passwordShake=true
  103. }else if(type===3){
  104. this.codedShake=true
  105. }else if(type===4){
  106. this.consentShake=true
  107. }
  108. setTimeout(()=>{
  109. this.phoneShake=false
  110. this.passwordShake=false
  111. },500)
  112. },
  113. login() {
  114. if (this.loginData.phone === '') {
  115. tools.error('请输入手机号码');
  116. this.setShake(1)
  117. return;
  118. }
  119. if (this.type !== 1) {
  120. if (this.loginData.password === '') {
  121. this.setShake(2)
  122. tools.error('请输入登陆密码');
  123. return;
  124. }
  125. } else {
  126. if (this.loginData.code === '') {
  127. this.setShake(3)
  128. tools.error('请输入验证码');
  129. return;
  130. }
  131. }
  132. if (!this.isConsent) {
  133. this.setShake(4)
  134. tools.error('请阅读并同意协议');
  135. return;
  136. }
  137. login(this.loginData).then((res) => {
  138. if (res.code === 1) {
  139. tools.setLoginData(res.data, true)
  140. } else {
  141. tools.error(res.msg)
  142. }
  143. })
  144. },
  145. verifyData(){
  146. if(this.type===1){
  147. this.isLogin=this.loginData.phone!=='' && this.loginData.code!=='' && this.isConsent
  148. }else {
  149. this.isLogin=this.loginData.phone!=='' && this.loginData.password!=='' && this.isConsent
  150. }
  151. },
  152. getVerifiedCode() {
  153. if (this.timeNum > 0) {
  154. return;
  155. }
  156. if (this.loginData.phone === '') {
  157. tools.error("请输入手机号码")
  158. return;
  159. }
  160. let regPhone = /^(?:(?:\+|00)86)?1\d{10}$/;
  161. if (!regPhone.test(this.loginData.phone)) {
  162. tools.error("手机号码格式错误")
  163. return;
  164. }
  165. commonSend({
  166. 'phone': this.loginData.phone,
  167. 'send_type': 'retrieve'
  168. }).then((res) => {
  169. if (res.code === 1) {
  170. tools.success(res.msg);
  171. this.timeNum = 60;
  172. this.timer = setInterval(() => {
  173. this.timeNum--;
  174. if (this.timeNum <= 0) {
  175. clearInterval(this.timer);
  176. }
  177. }, 1000);
  178. } else {
  179. tools.error(res.msg);
  180. }
  181. })
  182. },
  183. setIsConsent(){
  184. this.isConsent=!this.isConsent
  185. },
  186. setType(type){
  187. if(type!==this.type){
  188. this.type=type
  189. }
  190. },
  191. },
  192. }
  193. </script>
  194. <style lang="scss" scoped>
  195. @import "/static/css/login.css";
  196. .page-box{
  197. position: relative;
  198. padding-top: 370rpx;
  199. .login-form{
  200. margin: 0 30rpx;
  201. border-radius: 50rpx;
  202. background-color: rgba(255,255,255,0.5);
  203. .from-title{
  204. border-radius: 50rpx 50rpx 0 0;
  205. height: 110rpx;
  206. position: relative;
  207. .title-bg{
  208. position: absolute;
  209. border-radius: 50rpx 50rpx 0 0;
  210. top: 0;
  211. left: 0;
  212. height:110rpx;
  213. width: 50%;
  214. transition: .5s ease;
  215. z-index: 0;
  216. .bg-icon{
  217. margin: 86rpx auto 0 auto;
  218. width: 36rpx;
  219. height: 6rpx;
  220. border-radius: 99rpx;
  221. }
  222. }
  223. .title-bg-two{
  224. left: 50%;
  225. transition: .5s ease;
  226. }
  227. //.title-bg::after {
  228. // content: '';
  229. // position: absolute;
  230. // right: -50rpx;
  231. // bottom: 0;
  232. // width: 50rpx;
  233. // height:50rpx;
  234. // background-color: #fff;
  235. // border-radius: 50rpx 50rpx 50rpx 0;
  236. //}
  237. .title-list{
  238. display: flex;
  239. justify-content: space-between;
  240. z-index: 1;
  241. position: relative;
  242. .title-text{
  243. width: 50%;
  244. height: 110rpx;
  245. line-height: 102rpx;
  246. color: #333333;
  247. }
  248. .default-text{
  249. color: #10B261;
  250. }
  251. .title-text:first-child{
  252. background-image: url("/static/img/login/right.png");
  253. background-repeat: no-repeat;
  254. background-position: right bottom;
  255. }
  256. .title-text:last-child{
  257. background-image: url("/static/img/login/left.png");
  258. background-repeat: no-repeat;
  259. background-position: left bottom;
  260. }
  261. }
  262. }
  263. .from-box{
  264. box-shadow: 0rpx 4rpx 36rpx 0rpx rgba(196,196,196,0.25);
  265. border-radius: 0 0 50rpx 50rpx;
  266. padding: 50rpx 45rpx;
  267. .input-item{
  268. height: 96rpx;
  269. padding: 28rpx 40rpx;
  270. box-sizing: border-box;
  271. .login-input{
  272. width: 100%;
  273. }
  274. }
  275. .input-item:last-child{
  276. margin-top: 30rpx;
  277. }
  278. .input-send{
  279. display: flex;
  280. justify-content: flex-start;
  281. align-items: center;
  282. .login-input{
  283. width:calc(100% - 140rpx) ;
  284. }
  285. .login-send{
  286. width: 140rpx;
  287. text-align: center;
  288. }
  289. }
  290. .input-agreement{
  291. margin-top: 25rpx;
  292. display: flex;
  293. justify-content: flex-start;
  294. align-items: center;
  295. .agreement-agree{
  296. width: 32rpx;
  297. height: 32rpx;
  298. transition: .5s ease;
  299. }
  300. .agreement-text{
  301. margin-left: 18rpx;
  302. }
  303. }
  304. .input-but{
  305. margin-top: 40rpx;
  306. width: 100%;
  307. height: 96rpx;
  308. line-height: 96rpx;
  309. text-align: center;
  310. }
  311. }
  312. .one-from{
  313. border-radius: 0 50rpx 50rpx 50rpx;
  314. }
  315. .two-from{
  316. border-radius: 50rpx 0 50rpx 50rpx;
  317. }
  318. }
  319. .register-box{
  320. display: flex;
  321. justify-content: center;
  322. align-items: center;
  323. margin-top: 60rpx;
  324. .register-text{
  325. height: 34rpx;
  326. line-height: 34rpx;
  327. }
  328. .register-text:last-child{
  329. margin-right: 5rpx;
  330. }
  331. }
  332. .wx-box{
  333. position: absolute;
  334. bottom: calc(60rpx + env(safe-area-inset-bottom));
  335. left: 0;
  336. width: 100%;
  337. display: flex;
  338. flex-direction: column;
  339. justify-content: center;
  340. .wx-title{
  341. display: flex;
  342. justify-content: center;
  343. align-items: center;
  344. .wx-wire{
  345. background: linear-gradient( 90deg, #D9D9D9 0%, rgba(115,115,115,0) 100%);
  346. width: 174rpx;
  347. height: 2rpx;
  348. border-radius: 50%;
  349. }
  350. .wx-text{
  351. margin: 0 15rpx;
  352. height: 34rpx;
  353. line-height: 34rpx;
  354. }
  355. }
  356. .wx-logo{
  357. margin: 25rpx auto 0 auto;
  358. width: 80rpx;
  359. height: 80rpx;
  360. }
  361. }
  362. }
  363. </style>