login.vue 16 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602
  1. <template>
  2. <view class="container">
  3. <view class="container_box flex-center" v-if="!weixinB">
  4. <view class="logo"></view>
  5. </view>
  6. <view class="revert">
  7. <image src="../../static/img/img03.png"></image>
  8. </view>
  9. <view class="loginTitle" >
  10. <view class="loginTitle-1" :class="isactive ? '' : 'active'" :style="isactive ? 'margin-bottom: 25rpx;' : ''" @click="choice()">
  11. <view >登录</view>
  12. <view class="display" v-show ="!isactive" ></view>
  13. </view>
  14. <view class="loginTitle-1" :class="isactive ? 'active' : ''" :style="isactive ? '' : 'margin-bottom: 25rpx;'" @click="choice()" >
  15. <view >注册</view>
  16. <view class="display" v-show ="isactive"></view>
  17. </view>
  18. </view>
  19. <view class="login_text" v-if="!isactive">
  20. <view class="login_input flex-start">
  21. <view class="login_img"><image src="/static/img/img05.png"></image></view>
  22. <view class="login_name"><input class="uni-input" v-model="username" focus placeholder="请输入手机号" /></view>
  23. </view>
  24. <view class="login_input flex-start" style="margin-bottom: 30rpx;">
  25. <view class="login_img"><image src="/static/img/img06.png"></image></view>
  26. <view class="login_name"><input class="uni-input" type="password" v-model="passward" focus placeholder="请输入密码" /></view>
  27. </view>
  28. <view class="forget flex-end" @click="forget">
  29. <image src="../../static/img/img04.png"></image>
  30. <view>忘记密码?</view>
  31. </view>
  32. <view><button type="green" class="uni-button uni-button-red" @click="toLogin">登录</button></view>
  33. <!-- <view><button type="green" class="uni-button uni-button-green uni-button-green-plain" plain="true" hover-class="none" @click="register">注册</button></view> -->
  34. <!-- <view class="forget" @click="register">没有账号?立即创建一个。</view> -->
  35. <view class="flex other">
  36. <view class="fenge"></view>
  37. <view class="qita">其他方式登录</view>
  38. <view class="fenge"></view>
  39. </view>
  40. <!-- <view class="weixin" @click="wxLogin"><image src="../../static/spend/img05.png"></image></view>
  41. <view class="weixin_text" @click="wxLogin">微信登录</view> -->
  42. <!-- #ifndef APP-PLUS -->
  43. <view class="weixin" @click="wecahtLogin"><image src="/static/img/img05.png"></image></view>
  44. <view class="weixin_text" @click="wecahtLogin">微信登录</view>
  45. <!-- #endif -->
  46. <!-- #ifdef APP-PLUS -->
  47. <block v-if="!is_ios">
  48. <view class="weixin" @click="wecahtLogin"><image src="/static/img/img05.png" mode="scaleToFill"></image></view>
  49. <view class="weixin_text" @click="wecahtLogin('weixin')">微信登录</view>
  50. </block>
  51. <block v-else>
  52. <view class="ios_login flex" @click="wecahtLogin('weixin')">
  53. <text class="iconfont iconweixin"></text>
  54. <text class="weixin_text">微信登录</text>
  55. </view>
  56. <view v-if='is_apple_login' class="ios_login flex" @click="wecahtLogin('apple')">
  57. <image class="loginIcon" src="/static/static/icon/appleIcon.png" mode=" scaleToFill"></image>
  58. <text class="weixin_text">通过Apple登录</text>
  59. </view>
  60. </block>
  61. <!-- #endif -->
  62. </view>
  63. <view class="login_text" v-if="isactive">
  64. <view class="login_input flex-start">
  65. <view class="login_img"><image src="/static/img/img05.png"></image></view>
  66. <view class="login_name"><input class="uni-input" v-model="phone" focus placeholder="请输入手机号" /></view>
  67. </view>
  68. <view class="login_input flex-start">
  69. <view class="login_img"><image src="/static/img/img06.png"></image></view>
  70. <view class="login_name"><input class="uni-input" type="password" v-model="password" focus placeholder="请输入密码" /></view>
  71. </view>
  72. <view class="login_input flex-start">
  73. <view class="login_img"><image src="/static/img/img06.png"></image></view>
  74. <view class="login_name"><input class="uni-input" type="password" v-model="repassword" focus placeholder="请重复输入密码" /></view>
  75. </view>
  76. <!-- <view class="login_input flex-start">
  77. <view class="login_img"><image src="/static/img/img06.png"></image></view>
  78. <view class="login_name"><input class="uni-input" type="password" v-model="spread" focus placeholder="请重复邀请人的id" /></view>
  79. </view> -->
  80. <!-- <view class="login_input flex">
  81. <view class="login_img"><image src="/static/icon/img07.png"></image></view>
  82. <view class="login_name"><input class="uni-input" type="text" v-model="invitation" focus placeholder="请输入邀请码" /></view>
  83. </view> -->
  84. <view class="login_input flex">
  85. <view class="login_img"><image src="/static/img/img07.png"></image></view>
  86. <view class="login_name flex">
  87. <input class="uni-input width" v-model="code" focus placeholder="请输入验证码" />
  88. <view class="code" @click="verification">{{ countDown == 0 ? '获取验证码' : countDown }}</view>
  89. </view>
  90. </view>
  91. <view><button type="green" @click="register" class="uni-button uni-button-red">注册</button></view>
  92. <!-- <view><button class="uni-button uni-button-green uni-button-green-plain" type="green" plain="true" hover-class="none" @click="login">返回登录</button></view> -->
  93. </view>
  94. <!-- <view class="image" @click="wxLogin">
  95. <image src="../../static/spend/wxin.png"></image>
  96. </view> -->
  97. </view>
  98. </template>
  99. <script>
  100. import { mapMutations } from 'vuex';
  101. import { login,getUserInfo } from '@/api/login.js';
  102. import { register, verify } from '@/api/login.js';
  103. export default {
  104. data() {
  105. return {
  106. spread:'',//邀请人的id
  107. phone: '', //用户
  108. password: '', //密码
  109. repassword: '',
  110. invitation: '', //邀请码
  111. code: '', //验证码
  112. isactive:false,
  113. username: '',
  114. passward: '',
  115. countDown: 0, //倒计时
  116. // #ifdef APP-PLUS
  117. // 保存当前是否为微信浏览器
  118. weixinB:false,
  119. // #endif
  120. };
  121. },
  122. watch: {
  123. // 监听倒计时
  124. countDown(i) {
  125. if (i == 0) {
  126. clearInterval(this.time);
  127. }
  128. }
  129. },
  130. onLoad() {
  131. this.weixinB=uni.getStorageSync('weichatBrowser')
  132. },
  133. methods: {
  134. ...mapMutations(['setUserInfo','login']),
  135. //发送验证码
  136. verification() {
  137. let obj = this;
  138. if (this.phone == '') {
  139. this.$api.msg('请输入电话号码');
  140. return;
  141. }
  142. if (this.phone.length < 11) {
  143. this.$api.msg('请输入正确的手机号');
  144. return;
  145. }
  146. // 判断是否在倒计时
  147. if (obj.countDown > 0) {
  148. return false;
  149. } else {
  150. obj.countDown = 60;
  151. obj.time = setInterval(() => {
  152. obj.countDown--;
  153. }, 1000);
  154. //调用验证码接口
  155. verify({
  156. phone: obj.phone,
  157. type: 'VERIFICATION_CODE'
  158. })
  159. .then(({ data }) => {})
  160. .catch(err => {
  161. console.log(err);
  162. });
  163. }
  164. },
  165. //登录
  166. async toLogin() {
  167. let obj = this;
  168. obj.logining = true;
  169. if (obj.username == '') {
  170. obj.$api.msg('请输入手机号');
  171. return;
  172. }
  173. if (obj.passward == '') {
  174. obj.$api.msg('请输入密码');
  175. return;
  176. }
  177. login({
  178. account:obj.username,
  179. password:obj.passward
  180. })
  181. .then(function(e) {
  182. console.log(e,100)
  183. uni.setStorageSync('token',e.data.token);
  184. getUserInfo({}).then((e)=> {
  185. obj.login();
  186. // 保存返回用户数据
  187. obj.setUserInfo(e.data);
  188. })
  189. //调用注册接口,成功跳转首页
  190. uni.switchTab({
  191. url: '/pages/index/index'
  192. });
  193. })
  194. .catch(function(e) {
  195. console.log(e);
  196. });
  197. },
  198. // 注册
  199. register() {
  200. let obj = this;
  201. if (obj.phone == '') {
  202. obj.$api.msg('请输入电话号码');
  203. return;
  204. }
  205. if (obj.phone.length != 11) {
  206. obj.$api.msg('请输入正确的手机号');
  207. return;
  208. }
  209. if (obj.password == '') {
  210. obj.$api.msg('请输入密码');
  211. return;
  212. }
  213. if (obj.repassword == '') {
  214. obj.$api.msg('请再次输入密码');
  215. return;
  216. }
  217. if (obj.repassword != obj.password) {
  218. obj.$api.msg('两次密码不正确');
  219. return;
  220. }
  221. if ((obj.invitation = '')) {
  222. obj.$api.msg('请输入邀请码');
  223. return;
  224. }
  225. if (obj.code == '') {
  226. obj.$api.msg('请输入验证码');
  227. return;
  228. }
  229. register({
  230. account: obj.phone, //账号
  231. captcha: obj.code, //验证码
  232. password: obj.password ,//密码
  233. // spread: obj.spread,//邀请人id
  234. }).then(function(e) {
  235. uni.showToast({
  236. title:'注册成功',
  237. duration:2000,
  238. position:'top',
  239. icon:'none'
  240. });
  241. setTimeout(function () {
  242. uni.navigateTo({
  243. url: '/pages/public/login'
  244. });
  245. },1000)
  246. });
  247. //调用注册接口,成功跳转登录页
  248. },
  249. //微信登录
  250. wxLogins(){
  251. uni.navigateTo({
  252. url: '/pages/public/wxLogin'
  253. });
  254. },
  255. // 微信登录
  256. wxLogin(){
  257. let _self = this
  258. uni.login({
  259. provider:'weixin',
  260. success(r){
  261. //获取到用户 判断用户是否在系统中 不在则获取用户信息,并跳转到绑定手机号页面
  262. if(r.errMsg=='login:ok'){
  263. //登录成功 将用户的微信信息存入缓存中
  264. //获取用户信息
  265. uni.getUserInfo({
  266. provider: 'weixin',
  267. success(r){
  268. uni.setStorageSync("wxinfo",JSON.stringify(r))
  269. let data = {
  270. wx_info:JSON.stringify(r)
  271. }
  272. _self.request({url:"/Registered/bind",data})
  273. .then(r=>{
  274. //前往绑定页面
  275. if(r.code==201){
  276. uni.navigateTo({url:"/pages/public/bindTel"})
  277. }
  278. //存储token
  279. console.log("微信登录返回信息",r)
  280. if(r.code==200){
  281. uni.setStorageSync("token",r.data)
  282. _self.$store.commit("changeState",{
  283. name:"hasLogin",
  284. value:true
  285. })
  286. let tabbar = _self.$store.state.tabbar
  287. tabbar.index = 0
  288. _self.$store.commit("changeState",{
  289. name:"tabbar",
  290. value:tabbar
  291. })
  292. setTimeout(function(){
  293. uni.reLaunch({url:"/pages/home/index"})
  294. },100)
  295. }
  296. })
  297. .catch()
  298. },
  299. fail(r){
  300. uni.showModal({
  301. title:"获取微信信息异常",
  302. content:JSON.stringify(r)
  303. })
  304. }
  305. })
  306. }
  307. },
  308. fail(r){
  309. uni.showModal({
  310. title:"登录异常",
  311. content:JSON.stringify(r)
  312. })
  313. }
  314. })
  315. },
  316. // 微信登录
  317. wecahtLogin(type) {
  318. let obj = this;
  319. // #ifdef H5
  320. let weichatBrowser = uni.getStorageSync('weichatBrowser');
  321. if (weichatBrowser) {
  322. loginWinxin();
  323. }
  324. // #endif
  325. // #ifdef APP-PLUS
  326. uni.login({
  327. provider: type,
  328. success(e) {
  329. uni.getUserInfo({
  330. provider: type,
  331. success(es) {
  332. if(type==='weixin'){
  333. loginWx(es.userInfo)
  334. .then(e => {
  335. uni.setStorageSync('token', e.data.token);
  336. getUserInfo({}).then(e => {
  337. obj.login();
  338. // 保存返回用户数据
  339. obj.setUserInfo(e.data);
  340. //成功跳转首页
  341. uni.switchTab({
  342. url: '/pages/index/index'
  343. });
  344. });
  345. })
  346. .catch(e => {
  347. console.log(e);
  348. uni.showModal({
  349. content: JSON.stringify(e),
  350. success() {},
  351. fail() {}
  352. });
  353. });
  354. }
  355. if(type==='apple'){
  356. console.log(es.userInfo);
  357. applelogin({
  358. account: es.userInfo.openId,
  359. })
  360. .then(function(e) {
  361. console.log(e,'token')
  362. uni.setStorageSync('token', e.data.token);
  363. getUserInfo({}).then(e => {
  364. obj.login();
  365. // 保存返回用户数据
  366. obj.setUserInfo(e.data);
  367. //成功跳转首页
  368. uni.switchTab({
  369. url: '/pages/index/index'
  370. });
  371. });
  372. })
  373. .catch(function(e) {
  374. console.log(e);
  375. });
  376. }
  377. },
  378. fail(es) {
  379. uni.showModal({
  380. content: JSON.stringify(es),
  381. success() {
  382. // obj.login();
  383. // // 保存返回用户数据
  384. // obj.setUserInfo(e.data);
  385. // //成功跳转首页
  386. // uni.switchTab({
  387. // url: '/pages/index/index'
  388. // });
  389. }
  390. });
  391. }
  392. });
  393. },
  394. fail(e) {
  395. uni.showModal({
  396. title: '提示',
  397. content: JSON.stringify(e),
  398. showCancel: false
  399. });
  400. }
  401. });
  402. // #endif
  403. },
  404. choice(){
  405. if(this.isactive == true){
  406. this.isactive = false;
  407. }else{
  408. this.isactive = true;
  409. }
  410. },
  411. //跳转忘记密码
  412. forget() {
  413. uni.navigateTo({
  414. url: `/pages/public/forget`
  415. });
  416. },
  417. // 后退
  418. navBack() {
  419. uni.navigateBack();
  420. }
  421. }
  422. };
  423. </script>
  424. <style lang="scss">
  425. page {
  426. height: 100%;
  427. background-color: #FFFFFF;
  428. }
  429. .container {
  430. margin-left: -1rpx;
  431. background-size: 100%;
  432. .container_box {
  433. width: 100%;
  434. height: 600rpx;
  435. background: url(https://mmz.liuniu946.com/statics/img/img02.png) no-repeat center;
  436. background-size: 750rpx 600rpx;
  437. position: relative;
  438. .logo{
  439. width: 180rpx;
  440. height: 180rpx;
  441. border-radius: 50%;
  442. background: url(../../static/error/missing-face.png) no-repeat center;
  443. background-size: 180rpx;
  444. }
  445. }
  446. .revert{
  447. width: 20rpx;
  448. height: 35rpx;
  449. position: absolute;
  450. top:20rpx;
  451. left:30rpx;
  452. image{
  453. width: 20rpx;
  454. height: 35rpx;
  455. }
  456. }
  457. .loginTitle {
  458. position: absolute;
  459. top:500rpx;
  460. width: 100%;
  461. color: #333333;
  462. font-size: 56rpx;
  463. padding-left: 50rpx;
  464. font-weight: bold;
  465. display: flex;
  466. align-items: flex-end;
  467. .loginTitle-1{
  468. width: 150rpx;
  469. font-size:36rpx;
  470. font-weight:400;
  471. color:#ffffff;
  472. text-align: center;
  473. .display{
  474. margin: 0 auto;
  475. margin-top: 20rpx;
  476. width: 40rpx;
  477. height: 6rpx;
  478. border-radius: 5rpx;
  479. background-color: #FFFFFF;
  480. }
  481. .active{
  482. display: none;
  483. }
  484. }
  485. .active{
  486. font-size:48rpx;
  487. font-weight:600;
  488. }
  489. }
  490. .login_text {
  491. margin: 60rpx 50rpx;
  492. position: relative;
  493. margin-top:60rpx !important;
  494. .login_input {
  495. background:#f2f2f2;
  496. padding: 35rpx 25rpx;
  497. margin-bottom: 45rpx;
  498. border-radius: 15rpx;
  499. .login_img image {
  500. height: 37rpx;
  501. width: 31rpx;
  502. margin-right: 30rpx;
  503. }
  504. .login_name {
  505. color: #333333;
  506. .uni-input {
  507. text-align: left;
  508. width: 380rpx;
  509. font-size: 30rpx !important;
  510. color:#666666;
  511. }
  512. .code {
  513. color: #FC4141;
  514. font-size: 23rpx;
  515. border-left: 1px solid #666666;
  516. width: 180rpx;
  517. flex-shrink: 0;
  518. text-align: center;
  519. }
  520. }
  521. }
  522. .forget {
  523. font-size:28rpx;
  524. font-weight:400;
  525. color:#999999;
  526. margin-bottom: 50rpx;
  527. image{
  528. width: 30rpx;
  529. height: 30rpx;
  530. margin-right: 15rpx;
  531. }
  532. }
  533. .forget:hover{
  534. cursor: pointer;
  535. }
  536. }
  537. .image{
  538. image{
  539. width: 150rpx;
  540. height: 150rpx;
  541. }
  542. }
  543. }
  544. .fenge {
  545. width: 30%;
  546. height: 2rpx;
  547. background-color: #eeeeee;
  548. }
  549. .qita {
  550. font-size: 28rpx;
  551. color: #999999;
  552. }
  553. .other {
  554. margin-top: 60rpx;
  555. }
  556. .weixin {
  557. width: 75rpx;
  558. height: 75rpx;
  559. margin: 25rpx auto;
  560. }
  561. .weixin image {
  562. width: 100%;
  563. height: 100%;
  564. }
  565. .weixin_text {
  566. text-align: center;
  567. font-size: 28rpx;
  568. color: #999999;
  569. }
  570. .uni-button-red {
  571. width: 100%;
  572. color: #FFFFFF;
  573. background:linear-gradient(90deg,rgba(254,78,70,1) 0%,rgba(252,65,65,1) 100%);
  574. border-radius: 15rpx;
  575. }
  576. .uni-button-green-plain {
  577. border: 1px solid #5dbc7c;
  578. margin: 40rpx 10rpx;
  579. border-radius: 50rpx;
  580. color: #5dbc7c;
  581. background-color: #ffffff;
  582. }
  583. .uni-button {
  584. height: 100rpx;
  585. line-height: 100rpx;
  586. }
  587. </style>