|
|
|
@ -21,7 +21,7 @@ export default { |
|
|
|
ip: '', |
|
|
|
sourceUrl: '', |
|
|
|
uniqueToken: '', |
|
|
|
kefuid: '' |
|
|
|
customerid: '' |
|
|
|
} |
|
|
|
} |
|
|
|
}, |
|
|
|
@ -60,7 +60,7 @@ export default { |
|
|
|
console.log("来源网址:", this.dataForm.sourceUrl); |
|
|
|
}, |
|
|
|
|
|
|
|
// 获取URL参数中的token和kefuid |
|
|
|
// 获取URL参数中的token和customerid |
|
|
|
getTokenFromUrl() { |
|
|
|
// #ifdef H5 |
|
|
|
const pages = getCurrentPages(); |
|
|
|
@ -71,20 +71,20 @@ export default { |
|
|
|
this.dataForm.uniqueToken = options.token; |
|
|
|
} |
|
|
|
|
|
|
|
if (options.kefuid) { |
|
|
|
this.dataForm.kefuid = options.kefuid; |
|
|
|
if (options.customerid) { |
|
|
|
this.dataForm.customerid = options.customerid; |
|
|
|
} |
|
|
|
|
|
|
|
const urlParams = new URLSearchParams(window.location.search); |
|
|
|
const token = urlParams.get('token'); |
|
|
|
const kefuid = urlParams.get('kefuid'); |
|
|
|
const customerid = urlParams.get('customerid'); |
|
|
|
|
|
|
|
if (token) { |
|
|
|
this.dataForm.uniqueToken = token; |
|
|
|
} |
|
|
|
|
|
|
|
if (kefuid) { |
|
|
|
this.dataForm.kefuid = kefuid; |
|
|
|
if (customerid) { |
|
|
|
this.dataForm.customerid = customerid; |
|
|
|
} |
|
|
|
// #endif |
|
|
|
|
|
|
|
@ -96,8 +96,8 @@ export default { |
|
|
|
if (options.token) { |
|
|
|
this.dataForm.uniqueToken = options.token; |
|
|
|
} |
|
|
|
if (options.kefuid) { |
|
|
|
this.dataForm.kefuid = options.kefuid; |
|
|
|
if (options.customerid) { |
|
|
|
this.dataForm.customerid = options.customerid; |
|
|
|
} |
|
|
|
// #endif |
|
|
|
|
|
|
|
@ -110,8 +110,8 @@ export default { |
|
|
|
this.dataForm.uniqueToken = options.token; |
|
|
|
} |
|
|
|
console.log(options); |
|
|
|
if (options.kefuid) { |
|
|
|
this.dataForm.kefuid = options.kefuid; |
|
|
|
if (options.customerid) { |
|
|
|
this.dataForm.customerid = options.customerid; |
|
|
|
} |
|
|
|
// #endif |
|
|
|
}, |
|
|
|
@ -127,7 +127,6 @@ export default { |
|
|
|
if (!this.dataForm.uniqueToken) { |
|
|
|
console.log("未携带token,跳转到404页面"); |
|
|
|
// #ifdef H5 |
|
|
|
// 考虑基础路径 /h5/ |
|
|
|
window.location.href = '/h5/#/pages/login/404'; |
|
|
|
// #endif |
|
|
|
|
|
|
|
@ -153,7 +152,7 @@ export default { |
|
|
|
ip: this.dataForm.ip, |
|
|
|
sourceUrl: this.dataForm.sourceUrl, |
|
|
|
uniqueToken: this.dataForm.uniqueToken, |
|
|
|
keFuId: this.dataForm.kefuid, // 添加kefuid参数 |
|
|
|
customerId: this.dataForm.customerid, |
|
|
|
}; |
|
|
|
|
|
|
|
this.$http({ |
|
|
|
@ -179,9 +178,10 @@ export default { |
|
|
|
} |
|
|
|
this.friendStore.addFriend(friend); |
|
|
|
|
|
|
|
// 清除 URL 中的 token 参数,跳转到聊天页面 |
|
|
|
this.clearUrlParams(); |
|
|
|
|
|
|
|
// #ifdef H5 |
|
|
|
const cleanUrl = window.location.origin + '/h5/' + '#/pages/chat/chat-box?targetId=' + loginInfo.customerServiceId + '&type=PRIVATE'; |
|
|
|
const cleanUrl = window.location.origin + '/h5/#/pages/chat/chat-box?targetId=' + loginInfo.customerServiceId + '&type=PRIVATE'; |
|
|
|
window.location.href = cleanUrl; |
|
|
|
// #endif |
|
|
|
|
|
|
|
@ -195,24 +195,28 @@ export default { |
|
|
|
}).catch(err => { |
|
|
|
console.log("自动登录失败", err); |
|
|
|
GLOBAL_AUTO_LOGIN_LOCK = false; |
|
|
|
this.clearUrlParams(); |
|
|
|
|
|
|
|
// 如果是认证失败(如token无效),也可以跳转404 |
|
|
|
if (err && (err.code === 401 || err.statusCode === 401)) { |
|
|
|
// #ifdef H5 |
|
|
|
window.location.href = '/h5/pages/login/404'; |
|
|
|
window.location.href = '/h5/#/pages/login/404'; |
|
|
|
// #endif |
|
|
|
|
|
|
|
// #ifndef H5 |
|
|
|
uni.redirectTo({ |
|
|
|
url: '/pages/login/404' |
|
|
|
}); |
|
|
|
uni.redirectTo({ url: '/pages/login/404' }); |
|
|
|
// #endif |
|
|
|
} |
|
|
|
}); |
|
|
|
}, |
|
|
|
|
|
|
|
clearUrlParams() { |
|
|
|
// #ifdef H5 |
|
|
|
const url = new URL(window.location.href); |
|
|
|
url.searchParams.delete('token'); |
|
|
|
url.searchParams.delete('customerid'); |
|
|
|
window.history.replaceState(null, '', url.pathname + url.search + url.hash); |
|
|
|
// #endif |
|
|
|
}, |
|
|
|
|
|
|
|
getIp() { |
|
|
|
// 获取本机ip |
|
|
|
return new Promise((resolve, reject) => { |
|
|
|
uni.request({ |
|
|
|
url: 'https://api.ipify.org?format=json', |
|
|
|
@ -235,16 +239,14 @@ export default { |
|
|
|
}, |
|
|
|
|
|
|
|
onLoad(options) { |
|
|
|
// 在onLoad中直接获取options中的token |
|
|
|
if (options.token) { |
|
|
|
this.dataForm.uniqueToken = options.token; |
|
|
|
console.log("onLoad获取到token:", this.dataForm.uniqueToken); |
|
|
|
} |
|
|
|
if (options.kefuid) { |
|
|
|
this.dataForm.kefuid = options.kefuid; |
|
|
|
console.log("onLoad获取到kefuid:", this.dataForm.kefuid); |
|
|
|
if (options.customerid) { |
|
|
|
this.dataForm.customerid = options.customerid; |
|
|
|
console.log("onLoad获取到customerid:", this.dataForm.customerid); |
|
|
|
} |
|
|
|
// 延迟执行,彻底避开双加载 |
|
|
|
setTimeout(() => { |
|
|
|
this.autoLogin(); |
|
|
|
}, 50); |
|
|
|
|