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