This commit is contained in:
2026-01-05 12:47:14 +08:00
commit 1fc846fae3
1614 changed files with 162035 additions and 0 deletions

115
pages/login/index.vue Normal file
View File

@@ -0,0 +1,115 @@
<template>
<view class="content">
<view class="avatar">
<nut-avatar size="80">
<nut-icon size="30" name="my" />
</nut-avatar>
</view>
<view class="divider">
</view>
</view>
<view class="tip-infos">
<text>申请获取以下权限</text>
<text>获得你的公开信息昵称头像等</text>
</view>
<view class="authorize-btn-inner">
<nut-button type="success" size="large" open-type="getUserInfo" @getuserinfo="getUserInfo">授权登录</nut-button>
</view>
<view class="authorize-btn-inner">
<nut-button type="danger" size="large" @click="switchTab('/pages/index/index')">暂不登录</nut-button>
</view>
</template>
<script setup>
import {
onMounted,
ref
} from 'vue';
import {
login
} from '@/api/user';
import {
onLoad
} from '@dcloudio/uni-app'
import {
navigateTo,
switchTab
} from '@/utils/helper';
const code = ref('')
const redirect_url = ref('')
onLoad((options) => {
redirect_url.value = options.redirect_url
})
onMounted(() => {
uni.login({
provider: "weixin",
success(res) {
if (res.errMsg === 'login:ok') {
code.value = res.code
}
}
})
})
const getUserInfo = (res) => {
if (code.value === '') {
uni.showToast({
icon: 'none',
title: '请稍后再试'
})
return;
}
login(code.value, JSON.stringify(res.detail.userInfo)).then(res => {
console.log(res);
uni.setStorageSync('token', res.token)
uni.setStorageSync('uid', res.user_id)
if(res.is_bind_phone){
navigateTo('/pages/login/phoneAuthorization');
return
}
uni.showToast({
title: '授权成功',
icon: 'none'
})
if (redirect_url.value !== 'undefined') {
navigateTo(redirect_url.value)
} else {
uni.navigateBack()
}
})
}
</script>
<style scoped lang="scss">
.divider {
height: 1px;
background: #eee;
width: 100%;
}
.content {
display: flex;
justify-content: center;
flex-direction: column;
padding: 25px 15px;
align-items: center;
gap: 20px;
}
.tip-infos {
display: flex;
flex-direction: column;
justify-content: flex-start;
padding: 10px 25px;
gap: 10px;
text:nth-child(2) {
font-size: 15px;
color: #666;
}
}
.authorize-btn-inner {
padding: 15px;
}
</style>