index.vue 12 KB

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