登录优化
This commit is contained in:
parent
d483b4e58e
commit
a18d6cb959
@ -1,22 +1,11 @@
|
|||||||
import JSEncrypt from 'jsencrypt/bin/jsencrypt'
|
import JSEncrypt from 'jsencrypt/bin/jsencrypt.min'
|
||||||
|
|
||||||
// 密钥对生成 http://web.chacuo.net/netrsakeypair
|
// 密钥对生成 http://web.chacuo.net/netrsakeypair
|
||||||
|
|
||||||
const publicKey = '-----BEGIN PUBLIC KEY-----MIGfMA0GCSqGSIb3DQEBAQUAA4GNADCBiQKBgQDlJjf2lmK4zrpiATJSYfjkP2YhZ3SzKO0kqgX3Hg9o4NrgRgg9Abxw9vwZL7Weg22cJmahkx6waRYo8wXDqa2adJPntp60SAwWXou4cQTzHlySGQAC2U4CX54iHsKgqY7ifD2gmqJAkDnQkSXl4OKDTISnZcmlwIwo3Tj8jb9TWwIDAQAB-----END PUBLIC KEY-----';
|
const publicKey = 'MFwwDQYJKoZIhvcNAQEBBQADSwAwSAJBALj0zjON+EVdBsnMcR4Uj+jOYgp5ZipftQZ1utW8KvVioz+RSaotF1JHt59q9SC/mZcWWpbpcEqQ3WyyyCC33msCAwEAAQ=='
|
||||||
|
|
||||||
const privateKey = '-----BEGIN ENCRYPTED PRIVATE KEY-----MIICxjBABgkqhkiG9w0BBQ0wMzAbBgkqhkiG9w0BBQwwDgQIV5E4J9jebHICAggAMBQGCCqGSIb3DQMHBAhdEG1zo87qTASCAoB8kR8KXgHIOQJIppp/2qGb+I8qcx/++Mb3yCAceHRMFZyczqlbKlwaDWzUVS3PQwbktb4s2coJt1uq/YL8CxAP/EJyMWsqiJxSl+4Mql0cHPhociwC7avGLtB+J2+BJU/ytF4u+/sSRGeSddoqx2glmGtYuF9U' +
|
const privateKey =
|
||||||
'qv3jVElfUUOr3iq0aGSQRjCguVHk8fW1vy6QYi9ipPT0/BjWu4NutRLr9TI+Sy/4' +
|
'MIIBVAIBADANBgkqhkiG9w0BAQEFAASCAT4wggE6AgEAAkEAuPTOM434RV0GycxxHhSP6M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||||
'U/T0f/ibcUf9Q9YXZQQkv1NOwmDtAB1KvHIkh2LALc/BY4qEoUyEVtLg' +
|
|
||||||
'-----END ENCRYPTED PRIVATE KEY-----'
|
|
||||||
|
|
||||||
// 加密
|
// 加密
|
||||||
export function encrypt(txt) {
|
export function encrypt(txt) {
|
||||||
|
|||||||
@ -13,74 +13,74 @@ export default {
|
|||||||
init(url) {
|
init(url) {
|
||||||
const connection = new signalR.HubConnectionBuilder()
|
const connection = new signalR.HubConnectionBuilder()
|
||||||
.withUrl(url, { accessTokenFactory: () => getToken() })
|
.withUrl(url, { accessTokenFactory: () => getToken() })
|
||||||
.withAutomaticReconnect()//自动重新连接
|
.withAutomaticReconnect() //自动重新连接
|
||||||
.configureLogging(signalR.LogLevel.Information)
|
.configureLogging(signalR.LogLevel.Warning)
|
||||||
.build();
|
.build()
|
||||||
this.SR = connection;
|
this.SR = connection
|
||||||
// 断线重连
|
// 断线重连
|
||||||
connection.onclose(async () => {
|
connection.onclose(async () => {
|
||||||
console.log('断开连接了')
|
console.log('断开连接了')
|
||||||
console.assert(connection.state === signalR.HubConnectionState.Disconnected);
|
console.assert(connection.state === signalR.HubConnectionState.Disconnected)
|
||||||
// 建议用户重新刷新浏览器
|
// 建议用户重新刷新浏览器
|
||||||
await this.start();
|
await this.start()
|
||||||
})
|
})
|
||||||
|
|
||||||
connection.onreconnected(() => {
|
connection.onreconnected(() => {
|
||||||
console.log('断线重新连接成功')
|
console.log('断线重新连接成功')
|
||||||
})
|
})
|
||||||
this.receiveMsg(connection);
|
this.receiveMsg(connection)
|
||||||
// 启动
|
// 启动
|
||||||
// this.start();
|
// this.start();
|
||||||
},
|
},
|
||||||
/**
|
/**
|
||||||
* 调用 this.signalR.start().then(async () => { await this.SR.invoke("method")})
|
* 调用 this.signalR.start().then(async () => { await this.SR.invoke("method")})
|
||||||
* @returns
|
* @returns
|
||||||
*/
|
*/
|
||||||
async start() {
|
async start() {
|
||||||
var that = this;
|
var that = this
|
||||||
|
|
||||||
try {
|
try {
|
||||||
//使用async和await 或 promise的then 和catch 处理来自服务端的异常
|
//使用async和await 或 promise的then 和catch 处理来自服务端的异常
|
||||||
await this.SR.start();
|
await this.SR.start()
|
||||||
//console.assert(this.SR.state === signalR.HubConnectionState.Connected);
|
//console.assert(this.SR.state === signalR.HubConnectionState.Connected);
|
||||||
console.log('signalR 连接成功了', this.SR.state);
|
console.log('signalR 连接成功了', this.SR.state)
|
||||||
return true;
|
return true
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
that.failNum--;
|
that.failNum--
|
||||||
console.log(`失败重试剩余次数${that.failNum}`, error)
|
console.log(`失败重试剩余次数${that.failNum}`, error)
|
||||||
if (that.failNum > 0) {
|
if (that.failNum > 0) {
|
||||||
setTimeout(async () => {
|
setTimeout(async () => {
|
||||||
await this.SR.start()
|
await this.SR.start()
|
||||||
}, 5000);
|
}, 5000)
|
||||||
}
|
}
|
||||||
return false;
|
return false
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
// 接收消息处理
|
// 接收消息处理
|
||||||
receiveMsg(connection) {
|
receiveMsg(connection) {
|
||||||
connection.on("onlineNum", (data) => {
|
connection.on('onlineNum', (data) => {
|
||||||
store.dispatch("socket/changeOnlineNum", data);
|
store.dispatch('socket/changeOnlineNum', data)
|
||||||
});
|
})
|
||||||
// 接收欢迎语
|
// 接收欢迎语
|
||||||
connection.on("welcome", (data) => {
|
connection.on('welcome', (data) => {
|
||||||
console.log('welcome', data)
|
console.log('welcome', data)
|
||||||
Notification.info(data)
|
Notification.info(data)
|
||||||
});
|
})
|
||||||
// 接收后台手动推送消息
|
// 接收后台手动推送消息
|
||||||
connection.on("receiveNotice", (title, data) => {
|
connection.on('receiveNotice', (title, data) => {
|
||||||
Notification({
|
Notification({
|
||||||
type: 'info',
|
type: 'info',
|
||||||
title: title,
|
title: title,
|
||||||
message: data,
|
message: data,
|
||||||
dangerouslyUseHTMLString: true,
|
dangerouslyUseHTMLString: true,
|
||||||
duration: 0
|
duration: 0,
|
||||||
})
|
})
|
||||||
})
|
})
|
||||||
// 接收系统通知/公告
|
// 接收系统通知/公告
|
||||||
connection.on("moreNotice", (data) => {
|
connection.on('moreNotice', (data) => {
|
||||||
if (data.code == 200) {
|
if (data.code == 200) {
|
||||||
store.dispatch("socket/getNoticeList", data.data);
|
store.dispatch('socket/getNoticeList', data.data)
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
}
|
},
|
||||||
}
|
}
|
||||||
|
|||||||
@ -49,6 +49,7 @@
|
|||||||
import { getCodeImg } from '@/api/system/login'
|
import { getCodeImg } from '@/api/system/login'
|
||||||
import Cookies from 'js-cookie'
|
import Cookies from 'js-cookie'
|
||||||
import defaultSettings from '@/settings'
|
import defaultSettings from '@/settings'
|
||||||
|
import { encrypt, decrypt } from '@/utils/jsencrypt'
|
||||||
|
|
||||||
export default {
|
export default {
|
||||||
name: 'Login',
|
name: 'Login',
|
||||||
@ -111,7 +112,7 @@ export default {
|
|||||||
|
|
||||||
this.loginForm = {
|
this.loginForm = {
|
||||||
username: username === undefined ? this.loginForm.username : username,
|
username: username === undefined ? this.loginForm.username : username,
|
||||||
password: password === undefined ? this.loginForm.password : password,
|
password: password === undefined ? this.loginForm.password : decrypt(password),
|
||||||
rememberMe: rememberMe === undefined ? false : Boolean(rememberMe),
|
rememberMe: rememberMe === undefined ? false : Boolean(rememberMe),
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
@ -121,7 +122,7 @@ export default {
|
|||||||
this.loading = true
|
this.loading = true
|
||||||
if (this.loginForm.rememberMe) {
|
if (this.loginForm.rememberMe) {
|
||||||
Cookies.set('username', this.loginForm.username, { expires: 30 })
|
Cookies.set('username', this.loginForm.username, { expires: 30 })
|
||||||
Cookies.set('password', this.loginForm.password, {
|
Cookies.set('password', encrypt(this.loginForm.password), {
|
||||||
expires: 30,
|
expires: 30,
|
||||||
})
|
})
|
||||||
Cookies.set('rememberMe', this.loginForm.rememberMe, {
|
Cookies.set('rememberMe', this.loginForm.rememberMe, {
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user