| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150 |
- <template>
- <view class="layout-container">
- <!-- 顶部填充区 -->
- <view class="top-fill" :style="{height: safeArea.statusBarHeight+'px'}"></view>
-
- <!-- 顶部胶囊区 -->
- <view class="capsule-container"
- :style="{
- height: safeArea.capsuleBarHeight+'px',
- width: safeArea.capsuleBarLeft+'px',
- 'padding-top': safeArea.capsuleBarMarginTop+'px',
- 'padding-bottom': safeArea.capsuleBarMarginBottom+'px'}">
- <view class="back-container" :style="{
- height: safeArea.capsuleBarContentHeight+'px',
- width: safeArea.capsuleBarContentHeight+'px',
- }">
- <navigator url="/pages/index/index">
- <uni-icons type="back" :size="safeArea.capsuleBarContentHeight" color="#FFFFFF"></uni-icons>
- </navigator>
- </view>
- </view>
-
- <!-- 内容区 -->
- <view class="content-container">
- <view class="login-container">
- <view class="avator-container">
- <uni-icons type="person" size="130" color="#FFFFFF"></uni-icons>
- </view>
- <view class="btn-container" @click="login">登录</view>
- </view>
- </view>
-
- <!-- 底部填充区 -->
- <view class="bottom-fill" :style="{height: safeArea.bottomHeight+'px'}"></view>
- </view>
- </template>
- <script setup>
- import { ref } from 'vue';
- import { onLoad } from "@dcloudio/uni-app";
- import { loginApi } from '@/service/apis.js';
- import { getSafeArea } from '@/utils/system.js';
-
- /**
- * 头像
- */
- const avatar = ref("");
-
- /**
- * 昵称
- */
- const nickname = ref("");
-
- /**
- * 安全区
- */
- const safeArea = ref({});
-
- onLoad(() => {
- safeArea.value = getSafeArea();
- });
-
- const login = async () => {
- // 获取供应商
- let providerResult = await uni.getProvider({
- service: 'oauth'
- });
- const provider = providerResult.provider[0];
-
- // 获取登录的code
- let loginResult = await uni.login({
- provider
- });
-
- // 获取用户的头像和昵称
- let userInfoResult = await uni.getUserInfo({
- provider
- });
-
- // 获取后端token
- let token = await loginApi.login({
- "code": loginResult.code,
- "avatar": userInfoResult.userInfo.avatarUrl,
- "nickname": userInfoResult.userInfo.nickName
- });
-
- // 保存token
- uni.setStorageSync('token', token);
-
- // 登录结束返回主页
- uni.navigateTo({
- url: "/pages/index/index"
- })
-
- }
- </script>
- <style lang="scss" scoped>
- .back-container {
- border-radius: 50%;
- background-color: rgba(0, 0, 0, 0.1);
-
- display: flex;
- justify-content: center;
- align-items: center;
- }
-
- .login-container {
- width: 100%;
- height: 100%;
- display: flex;
- justify-content: center;
- align-items: center;
- flex-direction: column;
-
- .avator-container {
- left: 222rpx;
- top: 254rpx;
- width: 307rpx;
- height: 307rpx;
- background: #D2EFF3;
- border-radius: 50%;
- box-shadow: 0px 2px 2px 0px #DBDBDB;
-
- display: flex;
- justify-content: center;
- align-items: center;
- }
-
- .btn-container {
- margin-top: 57rpx;
-
- width: 500rpx;
- height: 100rpx;
- border-radius: 20rpx;
- background: #2A82E4;
-
- font-size: 48rpx;
- font-weight: 700;
- letter-spacing: 0rpx;
- line-height: 69.5rpx;
- color: #FFFFFF;
-
- display: flex;
- justify-content: center;
- align-items: center;
- }
- }
- </style>
|