fix(login): remove profile check, always redirect to script page after login
This commit is contained in:
@@ -20,6 +20,22 @@
|
|||||||
<text class="subtitle">开启你的数字生命档案</text>
|
<text class="subtitle">开启你的数字生命档案</text>
|
||||||
</view>
|
</view>
|
||||||
|
|
||||||
|
<view
|
||||||
|
class="btn-primary wechat-login-btn"
|
||||||
|
:class="{ disabled: loading }"
|
||||||
|
@click="handleWechatLogin"
|
||||||
|
>
|
||||||
|
<text class="wechat-mark">微</text>
|
||||||
|
<text v-if="loading && activeMethod === 'wechat'">微信登录中...</text>
|
||||||
|
<text v-else>微信一键登录</text>
|
||||||
|
</view>
|
||||||
|
|
||||||
|
<view class="login-divider">
|
||||||
|
<view></view>
|
||||||
|
<text>或使用手机号登录</text>
|
||||||
|
<view></view>
|
||||||
|
</view>
|
||||||
|
|
||||||
<view class="form">
|
<view class="form">
|
||||||
<view class="input-group">
|
<view class="input-group">
|
||||||
<text class="input-label">手机号码</text>
|
<text class="input-label">手机号码</text>
|
||||||
@@ -94,6 +110,7 @@ onMounted(() => {
|
|||||||
const phone = ref('')
|
const phone = ref('')
|
||||||
const code = ref('')
|
const code = ref('')
|
||||||
const loading = ref(false)
|
const loading = ref(false)
|
||||||
|
const activeMethod = ref('')
|
||||||
const countdown = ref(60)
|
const countdown = ref(60)
|
||||||
const isCountingDown = ref(false)
|
const isCountingDown = ref(false)
|
||||||
|
|
||||||
@@ -132,20 +149,60 @@ const startCountdown = () => {
|
|||||||
}, 1000)
|
}, 1000)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
const routeAfterLogin = () => {
|
||||||
|
uni.redirectTo({ url: '/pages/main/index?tab=script' })
|
||||||
|
}
|
||||||
|
|
||||||
|
const getWechatLoginCode = () => {
|
||||||
|
return new Promise((resolve, reject) => {
|
||||||
|
uni.login({
|
||||||
|
provider: 'weixin',
|
||||||
|
success: (res) => {
|
||||||
|
if (res.code) {
|
||||||
|
resolve(res.code)
|
||||||
|
} else {
|
||||||
|
reject(new Error('未获取到微信登录凭证'))
|
||||||
|
}
|
||||||
|
},
|
||||||
|
fail: reject
|
||||||
|
})
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
|
const handleWechatLogin = async () => {
|
||||||
|
if (loading.value) return
|
||||||
|
|
||||||
|
loading.value = true
|
||||||
|
activeMethod.value = 'wechat'
|
||||||
|
|
||||||
|
try {
|
||||||
|
const loginCode = await getWechatLoginCode()
|
||||||
|
const result = await store.loginWithWechat({ code: loginCode })
|
||||||
|
|
||||||
|
if (result.success) {
|
||||||
|
routeAfterLogin()
|
||||||
|
} else {
|
||||||
|
uni.showToast({ title: result.error || '微信登录失败', icon: 'none' })
|
||||||
|
}
|
||||||
|
} catch (error) {
|
||||||
|
uni.showToast({ title: error.message || '微信登录失败', icon: 'none' })
|
||||||
|
} finally {
|
||||||
|
loading.value = false
|
||||||
|
activeMethod.value = ''
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
const handleLogin = async () => {
|
const handleLogin = async () => {
|
||||||
if (!canSubmit.value || loading.value) return
|
if (!canSubmit.value || loading.value) return
|
||||||
|
|
||||||
loading.value = true
|
loading.value = true
|
||||||
|
activeMethod.value = 'phone'
|
||||||
|
|
||||||
try {
|
try {
|
||||||
const result = await store.login(phone.value, code.value)
|
const result = await store.login(phone.value, code.value)
|
||||||
|
|
||||||
if (result.success) {
|
if (result.success) {
|
||||||
if (result.hasProfile) {
|
routeAfterLogin()
|
||||||
uni.redirectTo({ url: '/pages/main/index?tab=script' })
|
|
||||||
} else {
|
|
||||||
uni.redirectTo({ url: '/pages/onboarding/index' })
|
|
||||||
}
|
|
||||||
} else {
|
} else {
|
||||||
uni.showToast({ title: result.error || '登录失败', icon: 'none' })
|
uni.showToast({ title: result.error || '登录失败', icon: 'none' })
|
||||||
}
|
}
|
||||||
@@ -153,6 +210,7 @@ const handleLogin = async () => {
|
|||||||
uni.showToast({ title: '登录失败', icon: 'none' })
|
uni.showToast({ title: '登录失败', icon: 'none' })
|
||||||
} finally {
|
} finally {
|
||||||
loading.value = false
|
loading.value = false
|
||||||
|
activeMethod.value = ''
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
</script>
|
</script>
|
||||||
@@ -299,6 +357,48 @@ const handleLogin = async () => {
|
|||||||
margin-bottom: 36rpx;
|
margin-bottom: 36rpx;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
.wechat-login-btn {
|
||||||
|
gap: 16rpx;
|
||||||
|
margin-bottom: 26rpx;
|
||||||
|
background: linear-gradient(135deg, #35c76f 0%, #159552 100%);
|
||||||
|
box-shadow:
|
||||||
|
0 14rpx 36rpx rgba(21, 149, 82, 0.26),
|
||||||
|
inset 0 1rpx 0 rgba(255, 255, 255, 0.22);
|
||||||
|
}
|
||||||
|
|
||||||
|
.wechat-mark {
|
||||||
|
width: 42rpx;
|
||||||
|
height: 42rpx;
|
||||||
|
border-radius: 50%;
|
||||||
|
display: flex;
|
||||||
|
align-items: center;
|
||||||
|
justify-content: center;
|
||||||
|
color: #159552;
|
||||||
|
font-size: 24rpx;
|
||||||
|
line-height: 42rpx;
|
||||||
|
font-weight: 900;
|
||||||
|
background: rgba(255, 255, 255, 0.94);
|
||||||
|
}
|
||||||
|
|
||||||
|
.login-divider {
|
||||||
|
display: flex;
|
||||||
|
align-items: center;
|
||||||
|
gap: 18rpx;
|
||||||
|
margin-bottom: 30rpx;
|
||||||
|
}
|
||||||
|
|
||||||
|
.login-divider view {
|
||||||
|
flex: 1;
|
||||||
|
height: 1rpx;
|
||||||
|
background: rgba(224, 205, 255, 0.16);
|
||||||
|
}
|
||||||
|
|
||||||
|
.login-divider text {
|
||||||
|
color: rgba(225, 209, 255, 0.48);
|
||||||
|
font-size: 22rpx;
|
||||||
|
line-height: 1;
|
||||||
|
}
|
||||||
|
|
||||||
.input-group {
|
.input-group {
|
||||||
margin-bottom: 24rpx;
|
margin-bottom: 24rpx;
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user