index.vue 12 KB

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