zyejMAll-mobile/pages/index/login.vue

41 lines
1.0 KiB
Vue
Raw Normal View History

2024-08-07 10:31:42 +08:00
<!-- 微信公众号的登录回调页 -->
<template>
<!-- 空登陆页 -->
<view />
</template>
<script setup>
import sheep from '@/sheep';
import { onLoad } from '@dcloudio/uni-app';
onLoad(async (options) => {
// #ifdef H5
// 将 search 参数赋值到 options 中,方便下面解析
new URLSearchParams(location.search).forEach((value, key) => {
options[key] = value;
});
const event = options.event;
const code = options.code;
const state = options.state;
2024-08-07 21:40:27 +08:00
if (event === 'login') {
// 场景一:登录
2024-08-07 10:31:42 +08:00
const res = await sheep.$platform.useProvider().login(code, state);
2024-08-07 21:40:27 +08:00
} else if (event === 'bind') {
// 场景二:绑定
2024-08-07 10:31:42 +08:00
sheep.$platform.useProvider().bind(code, state);
}
// 检测 H5 登录回调
let returnUrl = uni.getStorageSync('returnUrl');
if (returnUrl) {
2024-08-07 21:40:27 +08:00
uni.removeStorage({ key: 'returnUrl' });
2024-08-07 10:31:42 +08:00
location.replace(returnUrl);
} else {
uni.switchTab({
url: '/',
});
}
// #endif
});
</script>