login.vue 2.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105
  1. <template>
  2. <view style="height: 100%;">
  3. <image mode="widthFix" src="/static/login_bg.jpg" class="full_img"></image>
  4. <u-navbar title="登录" background="{ background: '#ffffff',opacity:0.4; }" title-color="#ffffff" back-icon-color="#ffffff"></u-navbar>
  5. <view style="padding: 0 40rpx;margin-top: 90%;"><u-button open-type="getPhoneNumber" @getphonenumber="getPhoneNumber">微信授权登录</u-button></view>
  6. </view>
  7. </template>
  8. <script>
  9. export default {
  10. data() {
  11. return {
  12. code: ''
  13. };
  14. },
  15. mounted() {},
  16. methods: {
  17. getPhoneNumber(e) {
  18. let that = this;
  19. if (e.detail.encryptedData) {
  20. //用户同意授权
  21. var datas = {
  22. iv: e.detail.iv,
  23. encryptedData: e.detail.encryptedData,
  24. code: that.code
  25. };
  26. that.$api.login(datas).then(
  27. res => {
  28. if (res.data.code == 200) {
  29. uni.setStorageSync('union_id', res.data.data.union_id);
  30. uni.setStorageSync('token', res.data.data.token);
  31. that.$api.getInfo().then(resdata => {
  32. if(resdata.data.code == 200){
  33. uni.navigateBack();
  34. that.$store.state.userInfo = resdata.data.data;
  35. }
  36. });
  37. } else {
  38. uni.showModal({
  39. title: '提示',
  40. content: res.data.msg,
  41. showCancel: false
  42. });
  43. }
  44. },
  45. err => {
  46. console.log(err);
  47. }
  48. );
  49. }
  50. }
  51. },
  52. onLoad(option) {
  53. let that = this;
  54. this.from = option.from;
  55. uni.login({
  56. provider: 'weixin',
  57. success: function(loginRes) {
  58. that.code = loginRes.code;
  59. }
  60. });
  61. }
  62. };
  63. </script>
  64. <style>
  65. .u-border-bottom:after,
  66. .u-border-left:after,
  67. .u-border-right:after,
  68. .u-border-top-bottom:after,
  69. .u-border-top:after,
  70. .u-border:after {
  71. border: none !important;
  72. }
  73. page {
  74. background-color: #bee0ff;
  75. height: 100%;
  76. width: 100%;
  77. }
  78. </style>
  79. <style scoped>
  80. .full_img {
  81. position: absolute;
  82. left: 0;
  83. display: block;
  84. width: 100%;
  85. z-index: -999;
  86. top: 0;
  87. }
  88. .head {
  89. height: 96rpx;
  90. width: 100%;
  91. line-height: 96rpx;
  92. margin-top: 40rpx;
  93. text-align: center;
  94. display: flex;
  95. position: relative;
  96. justify-content: center;
  97. }
  98. .icon {
  99. position: absolute;
  100. left: 30rpx;
  101. }
  102. </style>