login.vue 3.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150
  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 { onLoad } from "@dcloudio/uni-app";
  37. import { loginApi } from '@/service/apis.js';
  38. import { getSafeArea } from '@/utils/system.js';
  39. /**
  40. * 头像
  41. */
  42. const avatar = ref("");
  43. /**
  44. * 昵称
  45. */
  46. const nickname = ref("");
  47. /**
  48. * 安全区
  49. */
  50. const safeArea = ref({});
  51. onLoad(() => {
  52. safeArea.value = getSafeArea();
  53. });
  54. const login = async () => {
  55. // 获取供应商
  56. let providerResult = await uni.getProvider({
  57. service: 'oauth'
  58. });
  59. const provider = providerResult.provider[0];
  60. // 获取登录的code
  61. let loginResult = await uni.login({
  62. provider
  63. });
  64. // 获取用户的头像和昵称
  65. let userInfoResult = await uni.getUserInfo({
  66. provider
  67. });
  68. // 获取后端token
  69. let token = await loginApi.login({
  70. "code": loginResult.code,
  71. "avatar": userInfoResult.userInfo.avatarUrl,
  72. "nickname": userInfoResult.userInfo.nickName
  73. });
  74. // 保存token
  75. uni.setStorageSync('token', token);
  76. // 登录结束返回主页
  77. uni.navigateTo({
  78. url: "/pages/index/index"
  79. })
  80. }
  81. </script>
  82. <style lang="scss" scoped>
  83. .back-container {
  84. border-radius: 50%;
  85. background-color: rgba(0, 0, 0, 0.1);
  86. display: flex;
  87. justify-content: center;
  88. align-items: center;
  89. }
  90. .login-container {
  91. width: 100%;
  92. height: 100%;
  93. display: flex;
  94. justify-content: center;
  95. align-items: center;
  96. flex-direction: column;
  97. .avator-container {
  98. left: 222rpx;
  99. top: 254rpx;
  100. width: 307rpx;
  101. height: 307rpx;
  102. background: #D2EFF3;
  103. border-radius: 50%;
  104. box-shadow: 0px 2px 2px 0px #DBDBDB;
  105. display: flex;
  106. justify-content: center;
  107. align-items: center;
  108. }
  109. .btn-container {
  110. margin-top: 57rpx;
  111. width: 500rpx;
  112. height: 100rpx;
  113. border-radius: 20rpx;
  114. background: #2A82E4;
  115. font-size: 48rpx;
  116. font-weight: 700;
  117. letter-spacing: 0rpx;
  118. line-height: 69.5rpx;
  119. color: #FFFFFF;
  120. display: flex;
  121. justify-content: center;
  122. align-items: center;
  123. }
  124. }
  125. </style>