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