|
|
|
|
@@ -66,9 +66,8 @@
|
|
|
|
|
|
|
|
|
|
<script setup>
|
|
|
|
|
import { ref, onMounted } from 'vue';
|
|
|
|
|
import { authApi } from '@/api/index.js';
|
|
|
|
|
import { authApi, wechatApi } from '@/api/index.js';
|
|
|
|
|
import { useUserStore } from '@/store/index.js';
|
|
|
|
|
import { APP_ID } from '@/utils/env.js';
|
|
|
|
|
import { initWxConfig, wxScan, isInWechat } from '@/utils/wxsdk.js';
|
|
|
|
|
|
|
|
|
|
const userStore = useUserStore();
|
|
|
|
|
@@ -99,6 +98,7 @@
|
|
|
|
|
const agreed = ref(true);
|
|
|
|
|
const inputFocus = ref(false);
|
|
|
|
|
const showError = ref(false);
|
|
|
|
|
const wechatAppId = ref('');
|
|
|
|
|
|
|
|
|
|
const getCode = () => {
|
|
|
|
|
const params = new URLSearchParams(window.location.search);
|
|
|
|
|
@@ -109,10 +109,26 @@
|
|
|
|
|
window.history.replaceState({}, '', window.location.pathname);
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
const redirectToWxAuth = (assetToken) => {
|
|
|
|
|
const getWechatAppId = async () => {
|
|
|
|
|
if (wechatAppId.value) {
|
|
|
|
|
return wechatAppId.value;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
const data = await wechatApi.getAppId();
|
|
|
|
|
if (!data || !data.app_id) {
|
|
|
|
|
uni.showToast({ title: '微信公众号配置缺失', icon: 'none' });
|
|
|
|
|
throw new Error('wechat app_id is empty');
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
wechatAppId.value = data.app_id;
|
|
|
|
|
return wechatAppId.value;
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
const redirectToWxAuth = async (assetToken) => {
|
|
|
|
|
sessionStorage.setItem('assetToken', assetToken);
|
|
|
|
|
const appId = await getWechatAppId();
|
|
|
|
|
const redirectUri = encodeURIComponent(window.location.origin + window.location.pathname);
|
|
|
|
|
const url = `https://open.weixin.qq.com/connect/oauth2/authorize?appid=${APP_ID}&redirect_uri=${redirectUri}&response_type=code&scope=snsapi_userinfo&state=wechat_auth#wechat_redirect`;
|
|
|
|
|
const url = `https://open.weixin.qq.com/connect/oauth2/authorize?appid=${appId}&redirect_uri=${redirectUri}&response_type=code&scope=snsapi_userinfo&state=wechat_auth#wechat_redirect`;
|
|
|
|
|
window.location.href = url;
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
@@ -194,7 +210,7 @@ const handleScanLogin = async () => {
|
|
|
|
|
userStore.setAssetToken(verifyData.asset_token);
|
|
|
|
|
userStore.setIdentifier(identifier.value);
|
|
|
|
|
|
|
|
|
|
redirectToWxAuth(verifyData.asset_token);
|
|
|
|
|
await redirectToWxAuth(verifyData.asset_token);
|
|
|
|
|
} catch (e) {
|
|
|
|
|
console.error('登录失败', e);
|
|
|
|
|
loading.value = false;
|
|
|
|
|
@@ -446,4 +462,4 @@ const handleScanLogin = async () => {
|
|
|
|
|
font-weight: 500;
|
|
|
|
|
white-space: nowrap;
|
|
|
|
|
}
|
|
|
|
|
</style>
|
|
|
|
|
</style>
|
|
|
|
|
|