index.vue 12 KB

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