feat: 添加微信授权成功通知功能

This commit is contained in:
wangqiao
2025-10-14 08:58:36 +08:00
parent 5baae7652f
commit 58d3f2e890
2 changed files with 24 additions and 30 deletions

View File

@ -28,13 +28,17 @@ export const loginByMobile = (params: { mobile: string; code: string; socialCode
* 发送邮箱验证码 * 发送邮箱验证码
*/ */
export const sendEmailCode = (data: { email: string }) => { export const sendEmailCode = (data: { email: string }) => {
return useDollarFetchRequest.post<IResponse<any>>('/prod-api/app-api/member/auth/send-email-code?email=' + data.email, {},{ return useDollarFetchRequest.post<IResponse<any>>(
'/prod-api/app-api/member/auth/send-email-code?email=' + data.email,
{},
{
headers: { headers: {
'Content-Type': 'application/x-www-form-urlencoded', 'Content-Type': 'application/x-www-form-urlencoded',
'Accept': 'application/json, text/plain, */*', Accept: 'application/json, text/plain, */*',
'Access-Control-Allow-Origin-Type': '*', 'Access-Control-Allow-Origin-Type': '*',
},
} }
}) )
} }
/** /**
@ -50,3 +54,10 @@ export const loginByEmail = (params: { email: string; code: string }) => {
export const resetPassword = (params: { password: string; code: string }) => { export const resetPassword = (params: { password: string; code: string }) => {
return useDollarFetchRequest.put<IResponse<boolean>>('/prod-api/app-api/member/user/update-password', params) return useDollarFetchRequest.put<IResponse<boolean>>('/prod-api/app-api/member/user/update-password', params)
} }
/**
* 授权成功通知后台
*/
export const notifyAuthSuccess = (params: { code: string; state: string }) => {
return useDollarFetchRequest.get<IResponse<any>>('/prod-api/app-api/member/auth/wx-login-url', { query: params })
}

View File

@ -30,36 +30,19 @@
</template> </template>
<script setup lang="ts"> <script setup lang="ts">
import { notifyAuthSuccess } from '~/api/login/index'
import { ref, onMounted } from 'vue'
import { useRoute } from 'vue-router'
const route = useRoute()
definePageMeta({ definePageMeta({
layout: 'success', layout: 'success',
}) })
import { ref, onMounted } from 'vue'
// 倒计时秒数
const countdown = ref(5)
onMounted(() => { onMounted(() => {
// 启动倒计时 notifyAuthSuccess({ code: route.query.code as string, state: route.query.state as string }).then(() => {
const timer = setInterval(() => { console.log('Notified backend of auth success')
countdown.value-- })
if (countdown.value <= 0) {
clearInterval(timer)
// 倒计时结束后尝试关闭页面(微信环境可能限制,仅作尝试)
closePage()
}
}, 1000)
}) })
// 关闭页面方法(微信环境中可能无法直接关闭,仅作提示)
const closePage = () => {
// 尝试关闭当前页面(部分浏览器支持)
if (window.close) {
window.close()
} else {
// 微信环境中提示用户手动关闭
alert('请手动关闭此页面,返回电脑端继续操作')
}
}
</script> </script>
<style scoped> <style scoped>