login.vue 2.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126
  1. <template>
  2. <view class="page-bg container">
  3. <view class="back-container">
  4. <navigator url="/pages/index/index">
  5. <uni-icons type="back" size="40" color="#FFFFFF"></uni-icons>
  6. </navigator>
  7. </view>
  8. <view class="login-container">
  9. <view class="avator-container">
  10. <uni-icons type="person" size="130" color="#FFFFFF"></uni-icons>
  11. </view>
  12. <view class="btn-container" @click="login">登录</view>
  13. </view>
  14. </view>
  15. </template>
  16. <script setup>
  17. import { ref } from 'vue';
  18. import { loginApi } from '@/service/apis.js';
  19. /**
  20. * 头像
  21. */
  22. const avatar = ref("");
  23. /**
  24. * 昵称
  25. */
  26. const nickname = ref("");
  27. const login = async () => {
  28. // 获取供应商
  29. let providerResult = await uni.getProvider({
  30. service: 'oauth'
  31. });
  32. const provider = providerResult.provider[0];
  33. // 获取登录的code
  34. let loginResult = await uni.login({
  35. provider
  36. });
  37. // 获取用户的头像和昵称
  38. let userInfoResult = await uni.getUserInfo({
  39. provider
  40. });
  41. // 获取后端token
  42. let token = await loginApi.login({
  43. "code": loginResult.code,
  44. "avatar": userInfoResult.userInfo.avatarUrl,
  45. "nickname": userInfoResult.userInfo.nickName
  46. });
  47. // 保存token
  48. uni.setStorageSync('token', token);
  49. // 登录结束返回主页
  50. uni.navigateTo({
  51. url: "/pages/index/index"
  52. })
  53. }
  54. </script>
  55. <style lang="scss" scoped>
  56. .container {
  57. width: 100vw;
  58. height: 100vh;
  59. padding: 16rpx;
  60. .back-container {
  61. left: 16rpx;
  62. top: 39px;
  63. width: 90rpx;
  64. height: 90rpx;
  65. border-radius: 50%;
  66. background-color: rgba(0, 0, 0, 0.1);
  67. display: flex;
  68. justify-content: center;
  69. align-items: center;
  70. }
  71. .login-container {
  72. width: 100%;
  73. height: 100%;
  74. display: flex;
  75. justify-content: center;
  76. align-items: center;
  77. flex-direction: column;
  78. .avator-container {
  79. left: 222rpx;
  80. top: 254rpx;
  81. width: 307rpx;
  82. height: 307rpx;
  83. background: #D2EFF3;
  84. border-radius: 50%;
  85. box-shadow: 0px 2px 2px 0px #DBDBDB;
  86. display: flex;
  87. justify-content: center;
  88. align-items: center;
  89. }
  90. .btn-container {
  91. margin-top: 57rpx;
  92. width: 500rpx;
  93. height: 100rpx;
  94. border-radius: 20rpx;
  95. background: #2A82E4;
  96. font-size: 48rpx;
  97. font-weight: 700;
  98. letter-spacing: 0rpx;
  99. line-height: 69.5rpx;
  100. color: #FFFFFF;
  101. display: flex;
  102. justify-content: center;
  103. align-items: center;
  104. }
  105. }
  106. }
  107. </style>