login.vue 2.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111
  1. <template>
  2. <view class="page" :style="{'min-height':h+'px', 'padding-top':mt+'px'}">
  3. <image class="topbg" src="http://106.54.209.120:8188/static/login_top.png" mode="widthFix"></image>
  4. <div class="content adffcacjc">
  5. <button class="zt_btn" open-type="getPhoneNumber" @getphonenumber="decryptPhoneNumber">快速登录</button>
  6. <div class="agree adfacjc" @tap="changeAgree">
  7. <image src="http://106.54.209.120:8188/static/selected_not.png" v-if="!agree"></image>
  8. <image src="http://106.54.209.120:8188/static/selected.png" v-else></image>
  9. <div class="a_text">已阅读并同意 <span>《用户协议》</span><span>《隐私政策》</span></div>
  10. </div>
  11. </div>
  12. </view>
  13. </template>
  14. <script>
  15. export default {
  16. data(){
  17. return {
  18. agree:false
  19. }
  20. },
  21. onShow: () => {
  22. if(uni.getStorageSync('userInfo')){
  23. uni.reLaunch({
  24. url:'/pages/home'
  25. })
  26. }
  27. },
  28. methods:{
  29. changeAgree(){
  30. this.agree = !this.agree;
  31. },
  32. decryptPhoneNumber(e){
  33. if(!this.agree) return this.$showToast('请勾选协议和政策');
  34. if(e.detail.code) this.wxLogin(e.detail.code);
  35. },
  36. wxLogin(code){
  37. uni.showLoading({ title:'登录中' });
  38. let that = this;
  39. wx.login({
  40. success(res){
  41. that.$api.get('/sys/wx/login',{
  42. code:res.code,
  43. phoneCode:code
  44. },false).then(res=>{
  45. if(res.data.code===0){
  46. uni.setStorageSync('token',res.data.data.token);
  47. uni.setStorageSync('userInfo',JSON.stringify({
  48. id:res.data.data.id,
  49. mobile:res.data.data.mobile,
  50. username:res.data.data.username
  51. }));
  52. uni.hideLoading();
  53. that.$showToast('登录成功');
  54. setTimeout(()=>{
  55. uni.reLaunch({ url:'/pages/home' })
  56. },1500)
  57. }else that.$showToast(res.data.msg)
  58. })
  59. }
  60. })
  61. }
  62. }
  63. }
  64. </script>
  65. <style scoped lang="scss">
  66. .page{
  67. background: #FFFFFF;
  68. display: flex;
  69. flex-direction: column;
  70. box-sizing: border-box;
  71. .topbg{
  72. width: 100%;
  73. position: fixed;
  74. top: 0;
  75. left: 0;
  76. z-index: 0;
  77. }
  78. .content{
  79. position: relative;
  80. display: flex;
  81. flex: 1;
  82. width: calc(100% - 140rpx);
  83. margin: 307rpx 70rpx 0;
  84. .agree{
  85. margin-top: 50rpx;
  86. &>image{
  87. width: 32rpx;
  88. height: 32rpx;
  89. margin-right: 10rpx;
  90. }
  91. .a_text{
  92. font-family: PingFangSC, PingFang SC;
  93. font-weight: 400;
  94. font-size: 24rpx;
  95. color: #A6A6A6;
  96. line-height: 33rpx;
  97. span{
  98. color: #72832B;
  99. }
  100. }
  101. }
  102. }
  103. }
  104. </style>