login.vue 3.0 KB

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