|
@@ -1,4 +1,4 @@
|
|
|
-import { hrefToTarget, isMobile, isWechat } from 'billd-utils';
|
|
|
|
|
|
|
+import { hrefToTarget, isMobile } from 'billd-utils';
|
|
|
import { createApp } from 'vue';
|
|
import { createApp } from 'vue';
|
|
|
|
|
|
|
|
import { fetchQQLogin } from '@/api/qqUser';
|
|
import { fetchQQLogin } from '@/api/qqUser';
|
|
@@ -15,7 +15,7 @@ import LoginModalCpt from '@/hooks/loginModal/index.vue';
|
|
|
import { PlatformEnum } from '@/interface';
|
|
import { PlatformEnum } from '@/interface';
|
|
|
import { useAppStore } from '@/store/app';
|
|
import { useAppStore } from '@/store/app';
|
|
|
import { useUserStore } from '@/store/user';
|
|
import { useUserStore } from '@/store/user';
|
|
|
-import { clearLoginInfo, setLoginInfo } from '@/utils/cookie';
|
|
|
|
|
|
|
+import { clearThirdLoginInfo, setThirdLoginInfo } from '@/utils/cookie';
|
|
|
import { getToken } from '@/utils/localStorage/user';
|
|
import { getToken } from '@/utils/localStorage/user';
|
|
|
|
|
|
|
|
const app = createApp(LoginModalCpt);
|
|
const app = createApp(LoginModalCpt);
|
|
@@ -38,14 +38,14 @@ export async function handleQQLogin(e) {
|
|
|
try {
|
|
try {
|
|
|
switch (type) {
|
|
switch (type) {
|
|
|
case PlatformEnum.qqLogin: {
|
|
case PlatformEnum.qqLogin: {
|
|
|
- const res = await fetchQQLogin(data);
|
|
|
|
|
|
|
+ const res = await fetchQQLogin({ code: data.code, exp: data.qqExp });
|
|
|
if (res.code === 200) {
|
|
if (res.code === 200) {
|
|
|
window.$message.success('登录成功!');
|
|
window.$message.success('登录成功!');
|
|
|
fullLoading({
|
|
fullLoading({
|
|
|
loading: false,
|
|
loading: false,
|
|
|
});
|
|
});
|
|
|
}
|
|
}
|
|
|
- userStore.setToken(res.data);
|
|
|
|
|
|
|
+ userStore.setToken(res.data, data.qqExp);
|
|
|
userStore.getUserInfo();
|
|
userStore.getUserInfo();
|
|
|
appStore.showLoginModal = false;
|
|
appStore.showLoginModal = false;
|
|
|
break;
|
|
break;
|
|
@@ -54,7 +54,7 @@ export async function handleQQLogin(e) {
|
|
|
} catch (error) {
|
|
} catch (error) {
|
|
|
console.log(error);
|
|
console.log(error);
|
|
|
} finally {
|
|
} finally {
|
|
|
- clearLoginInfo();
|
|
|
|
|
|
|
+ clearThirdLoginInfo();
|
|
|
}
|
|
}
|
|
|
}
|
|
}
|
|
|
|
|
|
|
@@ -75,52 +75,48 @@ export function loginMessage() {
|
|
|
window.addEventListener('message', handleQQLogin);
|
|
window.addEventListener('message', handleQQLogin);
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
-export function useQQLogin() {
|
|
|
|
|
|
|
+export function useQQLogin(data: { exp }) {
|
|
|
fullLoading({
|
|
fullLoading({
|
|
|
loading: true,
|
|
loading: true,
|
|
|
showMask: true,
|
|
showMask: true,
|
|
|
content: 'qq登录...',
|
|
content: 'qq登录...',
|
|
|
style: { color: 'white' },
|
|
style: { color: 'white' },
|
|
|
});
|
|
});
|
|
|
- const url = (state: string) =>
|
|
|
|
|
|
|
+ const handleUrl = (state: string) =>
|
|
|
`${QQ_OAUTH_URL}/authorize?response_type=code&client_id=${QQ_CLIENT_ID}&redirect_uri=${QQ_REDIRECT_URI}&scope=get_user_info,get_vip_info,get_vip_rich_info&state=${state}`;
|
|
`${QQ_OAUTH_URL}/authorize?response_type=code&client_id=${QQ_CLIENT_ID}&redirect_uri=${QQ_REDIRECT_URI}&scope=get_user_info,get_vip_info,get_vip_rich_info&state=${state}`;
|
|
|
let loginInfo = JSON.stringify({
|
|
let loginInfo = JSON.stringify({
|
|
|
isMobile: false,
|
|
isMobile: false,
|
|
|
createTime: +new Date(),
|
|
createTime: +new Date(),
|
|
|
env: 'qq',
|
|
env: 'qq',
|
|
|
dev: process.env.NODE_ENV === 'development',
|
|
dev: process.env.NODE_ENV === 'development',
|
|
|
|
|
+ qqExp: data.exp,
|
|
|
});
|
|
});
|
|
|
if (isMobile()) {
|
|
if (isMobile()) {
|
|
|
loginInfo = JSON.stringify({ ...JSON.parse(loginInfo), isMobile: true });
|
|
loginInfo = JSON.stringify({ ...JSON.parse(loginInfo), isMobile: true });
|
|
|
- setLoginInfo(loginInfo);
|
|
|
|
|
- hrefToTarget(url(window.btoa(loginInfo)));
|
|
|
|
|
|
|
+ setThirdLoginInfo(loginInfo);
|
|
|
|
|
+ hrefToTarget(handleUrl(window.btoa(loginInfo)));
|
|
|
} else {
|
|
} else {
|
|
|
- setLoginInfo(loginInfo);
|
|
|
|
|
|
|
+ setThirdLoginInfo(loginInfo);
|
|
|
window.open(
|
|
window.open(
|
|
|
- url(window.btoa(loginInfo)),
|
|
|
|
|
|
|
+ handleUrl(window.btoa(loginInfo)),
|
|
|
'qq_login_window',
|
|
'qq_login_window',
|
|
|
'toolbar=yes,location=no,directories=no,status=no,menubar=no,scrollbars=no,titlebar=no,toolbar=no,resizable=no,copyhistory=yes, width=918, height=609,top=250,left=400'
|
|
'toolbar=yes,location=no,directories=no,status=no,menubar=no,scrollbars=no,titlebar=no,toolbar=no,resizable=no,copyhistory=yes, width=918, height=609,top=250,left=400'
|
|
|
);
|
|
);
|
|
|
}
|
|
}
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
-export const useWechatLogin = (qrData: { platform; exp; login_id }) => {
|
|
|
|
|
|
|
+export const useWechatLogin = (qrData: { platform; exp; loginId }) => {
|
|
|
const redirectUri = encodeURIComponent(WECHAT_REDIRECT_URI);
|
|
const redirectUri = encodeURIComponent(WECHAT_REDIRECT_URI);
|
|
|
- const flag = isWechat();
|
|
|
|
|
- if (flag) {
|
|
|
|
|
- window.$message.error('请在微信打开!');
|
|
|
|
|
- return;
|
|
|
|
|
- }
|
|
|
|
|
const loginInfo = JSON.stringify({
|
|
const loginInfo = JSON.stringify({
|
|
|
isMobile: false,
|
|
isMobile: false,
|
|
|
createTime: +new Date(),
|
|
createTime: +new Date(),
|
|
|
env: 'wechat',
|
|
env: 'wechat',
|
|
|
dev: process.env.NODE_ENV === 'development',
|
|
dev: process.env.NODE_ENV === 'development',
|
|
|
- qr_platform: qrData.platform,
|
|
|
|
|
- qr_exp: qrData.exp,
|
|
|
|
|
- qr_login_id: qrData.login_id,
|
|
|
|
|
|
|
+ qrcodePlatform: qrData.platform,
|
|
|
|
|
+ qrcodeExp: qrData.exp,
|
|
|
|
|
+ qrcodeLoginId: qrData.loginId,
|
|
|
});
|
|
});
|
|
|
- setLoginInfo(loginInfo);
|
|
|
|
|
|
|
+ setThirdLoginInfo(loginInfo);
|
|
|
const stateRes = window.btoa(loginInfo);
|
|
const stateRes = window.btoa(loginInfo);
|
|
|
// https://developers.weixin.qq.com/doc/oplatform/Website_App/WeChat_Login/Wechat_Login.html
|
|
// https://developers.weixin.qq.com/doc/oplatform/Website_App/WeChat_Login/Wechat_Login.html
|
|
|
const url = `${WECHAT_GZH_OAUTH_URL}appid=${WECHAT_GZH_APPID}&redirect_uri=${redirectUri}&scope=snsapi_userinfo&response_type=code&state=${stateRes}`;
|
|
const url = `${WECHAT_GZH_OAUTH_URL}appid=${WECHAT_GZH_APPID}&redirect_uri=${redirectUri}&scope=snsapi_userinfo&response_type=code&state=${stateRes}`;
|