|
|
|
@ -19,7 +19,8 @@ export default { |
|
|
|
userName: '', |
|
|
|
password: '', |
|
|
|
ip: '', |
|
|
|
sourceUrl: '' |
|
|
|
sourceUrl: '', |
|
|
|
uniqueToken: '' // 添加token字段 |
|
|
|
} |
|
|
|
} |
|
|
|
}, |
|
|
|
@ -53,35 +54,79 @@ export default { |
|
|
|
|
|
|
|
console.log("来源网址:", this.dataForm.sourceUrl); |
|
|
|
}, |
|
|
|
|
|
|
|
// 获取URL参数中的token |
|
|
|
getTokenFromUrl() { |
|
|
|
// #ifdef H5 |
|
|
|
// 方法1:从当前页面的options获取 |
|
|
|
const pages = getCurrentPages(); |
|
|
|
const currentPage = pages[pages.length - 1]; |
|
|
|
const options = currentPage.options || {}; |
|
|
|
|
|
|
|
if (options.token) { |
|
|
|
this.dataForm.uniqueToken = options.token; |
|
|
|
console.log("从options获取到token:", this.dataForm.uniqueToken); |
|
|
|
return; |
|
|
|
} |
|
|
|
|
|
|
|
// 方法2:直接从URL解析 |
|
|
|
const urlParams = new URLSearchParams(window.location.search); |
|
|
|
const token = urlParams.get('token'); |
|
|
|
if (token) { |
|
|
|
this.dataForm.uniqueToken = token; |
|
|
|
console.log("从URL解析获取到token:", this.dataForm.uniqueToken); |
|
|
|
} |
|
|
|
// #endif |
|
|
|
|
|
|
|
// #ifdef APP-PLUS |
|
|
|
// App端获取参数 |
|
|
|
const pages = getCurrentPages(); |
|
|
|
const currentPage = pages[pages.length - 1]; |
|
|
|
const options = currentPage.options || {}; |
|
|
|
if (options.token) { |
|
|
|
this.dataForm.uniqueToken = options.token; |
|
|
|
console.log("App端获取到token:", this.dataForm.uniqueToken); |
|
|
|
} |
|
|
|
// #endif |
|
|
|
|
|
|
|
// #ifdef MP-WEIXIN |
|
|
|
// 小程序端获取参数 |
|
|
|
const pages = getCurrentPages(); |
|
|
|
const currentPage = pages[pages.length - 1]; |
|
|
|
const options = currentPage.options || {}; |
|
|
|
if (options.token) { |
|
|
|
this.dataForm.uniqueToken = options.token; |
|
|
|
console.log("小程序端获取到token:", this.dataForm.uniqueToken); |
|
|
|
} |
|
|
|
// #endif |
|
|
|
}, |
|
|
|
|
|
|
|
async autoLogin() { |
|
|
|
if (GLOBAL_AUTO_LOGIN_LOCK) return; |
|
|
|
GLOBAL_AUTO_LOGIN_LOCK = true; |
|
|
|
|
|
|
|
// // 读取缓存 |
|
|
|
// const loginInfo = uni.getStorageSync("loginInfo"); |
|
|
|
// 获取token(优先使用URL中的token) |
|
|
|
this.getTokenFromUrl(); |
|
|
|
|
|
|
|
// // 已登录 → 先初始化,再跳转(修复点!) |
|
|
|
// if (loginInfo) { |
|
|
|
// try { |
|
|
|
// // 必须执行全局IM初始化 |
|
|
|
// getApp().$vm.init(); |
|
|
|
// getApp().$vm.unloadStore(); |
|
|
|
|
|
|
|
// uni.reLaunch({ |
|
|
|
// url: "/pages/chat/chat-box?chatIdx=0" |
|
|
|
// }); |
|
|
|
// } catch (err) { |
|
|
|
// console.log("自动登录初始化失败", err); |
|
|
|
// } |
|
|
|
// return; |
|
|
|
// } |
|
|
|
// 获取来源网址 |
|
|
|
this.getSourceUrl(); |
|
|
|
await this.getIp(); |
|
|
|
|
|
|
|
// 准备登录数据 |
|
|
|
const loginData = { |
|
|
|
terminal: this.dataForm.terminal, |
|
|
|
userName: this.dataForm.userName, |
|
|
|
password: this.dataForm.password, |
|
|
|
ip: this.dataForm.ip, |
|
|
|
sourceUrl: this.dataForm.sourceUrl, |
|
|
|
uniqueToken: this.dataForm.uniqueToken, |
|
|
|
}; |
|
|
|
|
|
|
|
console.log("登录参数:", loginData); |
|
|
|
|
|
|
|
this.$http({ |
|
|
|
url: '/login', |
|
|
|
data: this.dataForm, |
|
|
|
data: loginData, |
|
|
|
method: 'POST' |
|
|
|
}).then(loginInfo => { |
|
|
|
uni.setStorageSync("isAgree", this.isAgree); |
|
|
|
@ -89,6 +134,7 @@ export default { |
|
|
|
|
|
|
|
getApp().$vm.init() |
|
|
|
getApp().$vm.unloadStore(); |
|
|
|
console.log(loginInfo.customerServiceId); |
|
|
|
this.$http({ |
|
|
|
url: "/friend/add?friendId=" + loginInfo.customerServiceId, |
|
|
|
method: "POST" |
|
|
|
@ -102,17 +148,25 @@ export default { |
|
|
|
} |
|
|
|
this.friendStore.addFriend(friend); |
|
|
|
|
|
|
|
// ✅ 修改:传递客服ID和类型 |
|
|
|
// 清除 URL 中的 token 参数 |
|
|
|
// #ifdef H5 |
|
|
|
// 直接使用 window.location 跳转,清除所有参数 |
|
|
|
const cleanUrl = window.location.origin + window.location.pathname + '#/pages/chat/chat-box?targetId=' + loginInfo.customerServiceId + '&type=PRIVATE'; |
|
|
|
window.location.href = cleanUrl; |
|
|
|
// #endif |
|
|
|
|
|
|
|
// #ifndef H5 |
|
|
|
uni.reLaunch({ |
|
|
|
url: `/pages/chat/chat-box?targetId=${loginInfo.customerServiceId}&type=PRIVATE` |
|
|
|
}); |
|
|
|
// #endif |
|
|
|
}) |
|
|
|
|
|
|
|
}).catch(err => { |
|
|
|
console.log("自动登录失败", err); |
|
|
|
}); |
|
|
|
|
|
|
|
}, |
|
|
|
|
|
|
|
getIp() { |
|
|
|
// 获取本机ip |
|
|
|
return new Promise((resolve, reject) => { |
|
|
|
@ -120,17 +174,12 @@ export default { |
|
|
|
url: 'https://api.ipify.org?format=json', |
|
|
|
method: 'GET', |
|
|
|
success: (res) => { |
|
|
|
// console.log("获取IP成功:", res.data); |
|
|
|
this.dataForm.ip = res.data.ip; |
|
|
|
// console.log("登录参数:", this.dataForm); |
|
|
|
resolve(res.data.ip); // 成功时解析Promise |
|
|
|
resolve(res.data.ip); |
|
|
|
}, |
|
|
|
fail: (err) => { |
|
|
|
// console.log("获取IP失败:", err); |
|
|
|
// 获取IP失败时,将ip设为空字符串并继续执行 |
|
|
|
this.dataForm.ip = ''; |
|
|
|
// console.log("登录参数:", this.dataForm); |
|
|
|
resolve(''); // 解析Promise,继续执行后续操作 |
|
|
|
resolve(''); |
|
|
|
} |
|
|
|
}); |
|
|
|
}); |
|
|
|
@ -141,7 +190,12 @@ export default { |
|
|
|
} |
|
|
|
}, |
|
|
|
|
|
|
|
onLoad() { |
|
|
|
onLoad(options) { |
|
|
|
// 在onLoad中直接获取options中的token |
|
|
|
if (options.token) { |
|
|
|
this.dataForm.uniqueToken = options.token; |
|
|
|
console.log("onLoad获取到token:", this.dataForm.uniqueToken); |
|
|
|
} |
|
|
|
|
|
|
|
// 延迟执行,彻底避开双加载 |
|
|
|
setTimeout(() => { |
|
|
|
@ -154,181 +208,3 @@ export default { |
|
|
|
} |
|
|
|
} |
|
|
|
</script> |
|
|
|
|
|
|
|
<!-- <style lang="scss" scoped> |
|
|
|
.login { |
|
|
|
position: relative; |
|
|
|
display: flex; |
|
|
|
flex-direction: column; |
|
|
|
overflow: hidden; |
|
|
|
|
|
|
|
// 主要内容区域 |
|
|
|
.content { |
|
|
|
position: relative; |
|
|
|
display: flex; |
|
|
|
flex-direction: column; |
|
|
|
margin-top: 120rpx; |
|
|
|
// #ifdef APP-PLUS |
|
|
|
margin-top: calc(120rpx + var(--status-bar-height)); |
|
|
|
// #endif |
|
|
|
padding: 0 60rpx; |
|
|
|
} |
|
|
|
|
|
|
|
// 头部区域 |
|
|
|
.header { |
|
|
|
text-align: center; |
|
|
|
padding: 80rpx 0; |
|
|
|
|
|
|
|
.title { |
|
|
|
color: $im-color-primary; |
|
|
|
font-size: 48rpx; |
|
|
|
font-weight: 700; |
|
|
|
margin-bottom: 20rpx; |
|
|
|
letter-spacing: 2rpx; |
|
|
|
} |
|
|
|
|
|
|
|
.subtitle { |
|
|
|
color: $im-text-color-light; |
|
|
|
font-size: 28rpx; |
|
|
|
opacity: 0.8; |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
// 表单容器 |
|
|
|
.form-container { |
|
|
|
display: flex; |
|
|
|
flex-direction: column; |
|
|
|
} |
|
|
|
|
|
|
|
// 表单样式 |
|
|
|
.form { |
|
|
|
margin-bottom: 20rpx; |
|
|
|
|
|
|
|
.form-item { |
|
|
|
position: relative; |
|
|
|
display: flex; |
|
|
|
align-items: center; |
|
|
|
padding: 0 30rpx; |
|
|
|
height: 100rpx; |
|
|
|
margin: 24rpx 0; |
|
|
|
border-radius: 25rpx; |
|
|
|
background: rgba(255, 255, 255, 0.9); |
|
|
|
border: 2rpx solid transparent; |
|
|
|
box-shadow: 0 4rpx 20rpx rgba(0, 0, 0, 0.05); |
|
|
|
transition: all 0.3s ease; |
|
|
|
|
|
|
|
&.focused { |
|
|
|
border-color: $im-color-primary; |
|
|
|
box-shadow: 0 8rpx 32rpx rgba($im-color-primary, 0.15); |
|
|
|
transform: translateY(-2rpx); |
|
|
|
} |
|
|
|
|
|
|
|
.icon-wrapper { |
|
|
|
display: flex; |
|
|
|
align-items: center; |
|
|
|
justify-content: center; |
|
|
|
width: 60rpx; |
|
|
|
height: 60rpx; |
|
|
|
margin-right: 30rpx; |
|
|
|
border-radius: 50%; |
|
|
|
background: $im-bg-active; |
|
|
|
transition: all 0.3s ease; |
|
|
|
|
|
|
|
.icon { |
|
|
|
font-size: 32rpx; |
|
|
|
color: $im-color-primary; |
|
|
|
font-weight: bold; |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
&.focused .icon-wrapper { |
|
|
|
transform: scale(1.1); |
|
|
|
} |
|
|
|
|
|
|
|
.input { |
|
|
|
flex: 1; |
|
|
|
font-size: 32rpx; |
|
|
|
color: #333; |
|
|
|
background: transparent; |
|
|
|
border: none; |
|
|
|
outline: none; |
|
|
|
|
|
|
|
&::placeholder { |
|
|
|
color: $im-text-color-light; |
|
|
|
font-size: 30rpx; |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
.icon-suffix { |
|
|
|
font-size: 36rpx; |
|
|
|
padding: 10rpx; |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
// 登录按钮 |
|
|
|
.submit-btn { |
|
|
|
height: 100rpx; |
|
|
|
border-radius: 50rpx; |
|
|
|
border: none; |
|
|
|
transition: all 0.3s ease; |
|
|
|
overflow: hidden; |
|
|
|
position: relative; |
|
|
|
width: 100%; |
|
|
|
|
|
|
|
&:active { |
|
|
|
transform: translateY(2rpx); |
|
|
|
|
|
|
|
&::before { |
|
|
|
left: 100%; |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
.btn-content { |
|
|
|
display: flex; |
|
|
|
align-items: center; |
|
|
|
justify-content: center; |
|
|
|
height: 100%; |
|
|
|
color: white; |
|
|
|
font-size: $im-font-size-large; |
|
|
|
font-weight: 600; |
|
|
|
|
|
|
|
.btn-text { |
|
|
|
margin-right: 10rpx; |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
&:active .btn-icon { |
|
|
|
transform: translateX(4rpx); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
// 底部导航 |
|
|
|
.nav-tool-bar { |
|
|
|
padding: 40rpx 0 60rpx; |
|
|
|
display: flex; |
|
|
|
align-items: center; |
|
|
|
justify-content: space-between; |
|
|
|
|
|
|
|
.nav-register { |
|
|
|
.register-link { |
|
|
|
display: flex; |
|
|
|
align-items: center; |
|
|
|
text-decoration: none; |
|
|
|
|
|
|
|
.register-text { |
|
|
|
color: $im-text-color-light; |
|
|
|
font-size: $im-font-size-small; |
|
|
|
margin-right: 8rpx; |
|
|
|
} |
|
|
|
|
|
|
|
.register-highlight { |
|
|
|
color: $im-color-primary; |
|
|
|
font-size: $im-font-size-small; |
|
|
|
font-weight: 600; |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
</style>--> |