login.vue 1.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495
  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. code: '',
  13. encryptedData: '',
  14. iv: ''
  15. }
  16. },
  17. methods: {
  18. // 授权登录按钮回调
  19. handleLogin() {
  20. // 获取code
  21. uni.login({
  22. //使用微信登录
  23. provider: 'weixin',
  24. success: (loginRes) => {
  25. this.code = loginRes.code
  26. // 获取用户加密信息
  27. uni.getUserInfo({
  28. provider: 'weixin',
  29. lang: 'zh_CN',
  30. success: (res) => {
  31. console.log(res)
  32. this.encryptedData = res.encryptedData
  33. this.iv = res.iv
  34. // 发送请求到后端解密用户信息
  35. this.loginReq()
  36. }
  37. })
  38. }
  39. })
  40. },
  41. // 解密用户信息请求
  42. async loginReq() {
  43. const res = await this.$myRequest({
  44. url: '/mhotel2/appcode.action',
  45. method: 'post',
  46. data: {
  47. code: this.code,
  48. encryptedData: this.encryptedData,
  49. iv: this.iv
  50. }
  51. })
  52. console.log(res)
  53. }
  54. }
  55. }
  56. </script>
  57. <style lang="scss" scoped>
  58. .container {
  59. display: flex;
  60. flex-direction: column;
  61. align-items: center;
  62. height: 100vh;
  63. background-color: #fff;
  64. img {
  65. margin-top: 116rpx;
  66. width: 138rpx;
  67. height: 138rpx;
  68. }
  69. .msg {
  70. margin-top: 32rpx;
  71. font-size: 32rpx;
  72. font-weight: bold;
  73. }
  74. .btn {
  75. position: absolute;
  76. // left: 20rpx;
  77. bottom: 74rpx;
  78. display: flex;
  79. justify-content: center;
  80. align-items: center;
  81. width: 710rpx;
  82. height: 96rpx;
  83. color: #fff;
  84. font-size: 32rpx;
  85. border-radius: 64rpx;
  86. background-color: #096562;
  87. }
  88. }
  89. </style>