login.vue 1.9 KB

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