Commit 8bab1c35 authored by youjie's avatar youjie

line登录

parent ab11a246
...@@ -68,7 +68,7 @@ const router = createRouter({ ...@@ -68,7 +68,7 @@ const router = createRouter({
] ]
}, },
{ {
path: "/login/:type?", path: "/login/:reType?",
name: "login", name: "login",
component: () => import("../views/auth/Login.vue"), component: () => import("../views/auth/Login.vue"),
meta: { title: "page.login" }, meta: { title: "page.login" },
......
...@@ -153,7 +153,7 @@ const loginMsg = reactive({ ...@@ -153,7 +153,7 @@ const loginMsg = reactive({
parentId: null, parentId: null,
redirectUri: '', redirectUri: '',
}) })
if(params&&params.type) loginMsg.reType = Number(params.type) if(params&&params.reType) loginMsg.reType = Number(params.reType)
const loginMethods = ref([ const loginMethods = ref([
{ {
...@@ -238,7 +238,7 @@ const useLineLogin = async(code:string) => { ...@@ -238,7 +238,7 @@ const useLineLogin = async(code:string) => {
} }
// 微信授权登录 // 微信授权登录
const loginWechat = () => { const loginWechat = () => {
const redirect_url = openInfo.value.redirectUri || 'https://www.oytour.com/#/login/2' const redirect_url = openInfo.value.redirectUri || 'http://localhost:8002/login/2'
const url = `https://open.weixin.qq.com/connect/qrconnect?appid=${openInfo.value.appId}&redirect_uri=${encodeURIComponent(redirect_url)}&response_type=code&scope=snsapi_login&state=${1}&wechat_redirect=${redirect_url}`; const url = `https://open.weixin.qq.com/connect/qrconnect?appid=${openInfo.value.appId}&redirect_uri=${encodeURIComponent(redirect_url)}&response_type=code&scope=snsapi_login&state=${1}&wechat_redirect=${redirect_url}`;
window.location.href = url; window.location.href = url;
} }
...@@ -259,7 +259,7 @@ const getAppIdRedirectUri = async (providerType: string) => { ...@@ -259,7 +259,7 @@ const getAppIdRedirectUri = async (providerType: string) => {
if(providerType==providerTypeEnum.WECHAT.value){ if(providerType==providerTypeEnum.WECHAT.value){
loginWechat() loginWechat()
}else if(providerType==providerTypeEnum.GOOGLE.value){ }else if(providerType==providerTypeEnum.GOOGLE.value){
renderGoogleButton(openInfo.value.appId) renderGoogleButton()
}else if(providerType==providerTypeEnum.LINE.value){ }else if(providerType==providerTypeEnum.LINE.value){
loginWithLine() loginWithLine()
} }
...@@ -315,8 +315,8 @@ const loginHandler = async ({ values, errors }: any) => { ...@@ -315,8 +315,8 @@ const loginHandler = async ({ values, errors }: any) => {
const loginWithGoogle = () => { const loginWithGoogle = () => {
// 手动构建授权URL(适用于无第三方库的简单场景) // 手动构建授权URL(适用于无第三方库的简单场景)
const clientId = '532164762940-vk65sge5jab1eq8mgbv1srh672ehnkff.apps.googleusercontent.com'; const clientId = openInfo.value.appId //'532164762940-vk65sge5jab1eq8mgbv1srh672ehnkff.apps.googleusercontent.com';
const redirectUri = encodeURIComponent('https://www.oytour.com/#/login?reType=1'); // 必须与Google控制台配置的一致 const redirectUri = encodeURIComponent(openInfo.value.redirectUri || 'http://localhost:8002/login/1'); // 必须与Google控制台配置的一致
const scope = encodeURIComponent('profile email'); // 请求的权限范围 const scope = encodeURIComponent('profile email'); // 请求的权限范围
const authUrl = `https://accounts.google.com/o/oauth2/v2/auth?client_id=${clientId}&redirect_uri=${redirectUri}&response_type=code&scope=${scope}&access_type=offline`; const authUrl = `https://accounts.google.com/o/oauth2/v2/auth?client_id=${clientId}&redirect_uri=${redirectUri}&response_type=code&scope=${scope}&access_type=offline`;
window.location.href = authUrl; window.location.href = authUrl;
...@@ -327,7 +327,7 @@ const renderGoogleButton = () => { ...@@ -327,7 +327,7 @@ const renderGoogleButton = () => {
try { try {
// 渲染 Google 登录按钮 // 渲染 Google 登录按钮
window.google.accounts.id.initialize({ window.google.accounts.id.initialize({
client_id: '532164762940-vk65sge5jab1eq8mgbv1srh672ehnkff.apps.googleusercontent.com', client_id: openInfo.value.appId,// '532164762940-vk65sge5jab1eq8mgbv1srh672ehnkff.apps.googleusercontent.com'
callback: handleSignInSuccess, callback: handleSignInSuccess,
error_callback: handleSignInError, error_callback: handleSignInError,
ux_mode: 'popup' // 可选:popup/redirect ux_mode: 'popup' // 可选:popup/redirect
......
...@@ -292,7 +292,7 @@ const getAppIdRedirectUri = async (providerType: string) => { ...@@ -292,7 +292,7 @@ const getAppIdRedirectUri = async (providerType: string) => {
if(providerType==providerTypeEnum.WECHAT.value){ if(providerType==providerTypeEnum.WECHAT.value){
loginWechat() loginWechat()
}else if(providerType==providerTypeEnum.GOOGLE.value){ }else if(providerType==providerTypeEnum.GOOGLE.value){
renderGoogleButton(openInfo.value.appId) renderGoogleButton()
}else if(providerType==providerTypeEnum.LINE.value){ }else if(providerType==providerTypeEnum.LINE.value){
loginWithLine() loginWithLine()
} }
...@@ -322,11 +322,11 @@ const useWechatBind = async(code:string) => { ...@@ -322,11 +322,11 @@ const useWechatBind = async(code:string) => {
} }
// 渲染 Google 按钮 // 渲染 Google 按钮
const renderGoogleButton = (client_id:string) => { const renderGoogleButton = () => {
try { try {
// 渲染 Google 按钮 // 渲染 Google 按钮
window.google.accounts.id.initialize({ window.google.accounts.id.initialize({
client_id,// '532164762940-vk65sge5jab1eq8mgbv1srh672ehnkff.apps.googleusercontent.com' client_id: openInfo.value.appId,// '532164762940-vk65sge5jab1eq8mgbv1srh672ehnkff.apps.googleusercontent.com'
callback: handleSignInSuccess, callback: handleSignInSuccess,
error_callback: handleSignInError, error_callback: handleSignInError,
ux_mode: 'popup' // 可选:popup/redirect ux_mode: 'popup' // 可选:popup/redirect
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment