login.vue 1.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192
  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.showToast({
  39. title: '授权成功',
  40. icon: 'success',
  41. mask: true
  42. })
  43. uni.$emit('changeFlag', {
  44. data: true
  45. })
  46. setTimeout(() => {
  47. uni.navigateBack(1)
  48. }, 1500)
  49. }
  50. }
  51. }
  52. }
  53. </script>
  54. <style lang="scss" scoped>
  55. .container {
  56. display: flex;
  57. flex-direction: column;
  58. align-items: center;
  59. height: 100vh;
  60. background-color: #fff;
  61. img {
  62. margin-top: 116rpx;
  63. width: 138rpx;
  64. height: 138rpx;
  65. }
  66. .msg {
  67. margin-top: 32rpx;
  68. font-size: 32rpx;
  69. font-weight: bold;
  70. }
  71. .btn {
  72. position: absolute;
  73. // left: 20rpx;
  74. bottom: 74rpx;
  75. display: flex;
  76. justify-content: center;
  77. align-items: center;
  78. width: 710rpx;
  79. height: 96rpx;
  80. color: #fff;
  81. font-size: 32rpx;
  82. border-radius: 64rpx;
  83. background-color: #096562;
  84. }
  85. }
  86. </style>