login.vue 2.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103
  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. that.$api.getInfo().then(resdata => {
  30. that.$store.state.userInfo = resdata.data.data;
  31. });
  32. uni.setStorageSync('union_id', res.data.data.union_id);
  33. uni.setStorageSync('token', res.data.data.token);
  34. uni.navigateBack();
  35. } else {
  36. uni.showModal({
  37. title: '提示',
  38. content: res.data.msg,
  39. showCancel: false
  40. });
  41. }
  42. },
  43. err => {
  44. console.log(err);
  45. }
  46. );
  47. }
  48. }
  49. },
  50. onLoad(option) {
  51. let that = this;
  52. this.from = option.from;
  53. uni.login({
  54. provider: 'weixin',
  55. success: function(loginRes) {
  56. that.code = loginRes.code;
  57. }
  58. });
  59. }
  60. };
  61. </script>
  62. <style>
  63. .u-border-bottom:after,
  64. .u-border-left:after,
  65. .u-border-right:after,
  66. .u-border-top-bottom:after,
  67. .u-border-top:after,
  68. .u-border:after {
  69. border: none !important;
  70. }
  71. page {
  72. background-color: #bee0ff;
  73. height: 100%;
  74. width: 100%;
  75. }
  76. </style>
  77. <style scoped>
  78. .full_img {
  79. position: absolute;
  80. left: 0;
  81. display: block;
  82. width: 100%;
  83. z-index: -999;
  84. top: 0;
  85. }
  86. .head {
  87. height: 96rpx;
  88. width: 100%;
  89. line-height: 96rpx;
  90. margin-top: 40rpx;
  91. text-align: center;
  92. display: flex;
  93. position: relative;
  94. justify-content: center;
  95. }
  96. .icon {
  97. position: absolute;
  98. left: 30rpx;
  99. }
  100. </style>