login.vue 1.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293
  1. <template>
  2. <view class="container">
  3. <img src="../../static/index/logo.png" />
  4. <view class="msg">靖安乡村民宿</view>
  5. <view class="btn" @click="handleLogin">授权登录</view>
  6. </view>
  7. </template>
  8. <script>
  9. export default {
  10. data() {
  11. return {}
  12. },
  13. methods: {
  14. // 授权登录按钮回调
  15. handleLogin() {
  16. // 获取code
  17. uni.login({
  18. //使用微信登录
  19. provider: 'weixin',
  20. success: (res) => {
  21. console.log(res)
  22. this.loginReq(res.code)
  23. }
  24. })
  25. },
  26. // 解密用户信息请求
  27. async loginReq(code) {
  28. const res = await this.$myRequest({
  29. url: '/mhotel/ampauthorizationUser.action',
  30. data: {
  31. code
  32. }
  33. })
  34. // console.log(res)
  35. if (res.code === 200) {
  36. uni.setStorageSync('openid', res.data.openid)
  37. uni.setStorageSync('userInfo', res.data)
  38. uni.setStorageSync('userId', res.data.id)
  39. uni.showToast({
  40. title: '授权成功',
  41. icon: 'success',
  42. mask: true
  43. })
  44. uni.$emit('changeFlag', {
  45. data: true
  46. })
  47. setTimeout(() => {
  48. uni.navigateBack(1)
  49. }, 1500)
  50. }
  51. }
  52. }
  53. }
  54. </script>
  55. <style lang="scss" scoped>
  56. .container {
  57. display: flex;
  58. flex-direction: column;
  59. align-items: center;
  60. height: 100vh;
  61. background-color: #fff;
  62. img {
  63. margin-top: 116rpx;
  64. width: 138rpx;
  65. height: 138rpx;
  66. }
  67. .msg {
  68. margin-top: 32rpx;
  69. font-size: 32rpx;
  70. font-weight: bold;
  71. }
  72. .btn {
  73. position: absolute;
  74. // left: 20rpx;
  75. bottom: 74rpx;
  76. display: flex;
  77. justify-content: center;
  78. align-items: center;
  79. width: 710rpx;
  80. height: 96rpx;
  81. color: #fff;
  82. font-size: 32rpx;
  83. border-radius: 64rpx;
  84. background-color: #096562;
  85. }
  86. }
  87. </style>