转译之前的url:
http://101.66.135.62:8088/#/home?token=FDXAueTmcdlGLc6X+ui+b=jCLINhNLS4hBDb+zESxxBPA8edkb7GbnFNyHEu1pw68VrgZ5=1c6i0Dv0vSEa2aZMLIzwZzKAE4XVNXNI3dAKXXvRMZw=iH3V0aSuXcIm3
转译之后的的url:
// 方法一:处理url编码
getQueryString(token) {
while (token.indexOf('%20') >= 0) token = token.replace(/%20/, '+') // 空格
while (
token.indexOf('%3D') >= 0 // '='
)
token = token.replace(/%3D/, '=')
while (
token.indexOf('%2F') >= 0 // '/'
)
token = token.replace(/%2F/, '/')
return token
},
// 方法一:
getTokenToUrl() {
var url = window.location.href
console.log('url==', url)
var querys = url.substring(url.indexOf('?') + 1).split('&')
var result = []
for (var i = 0; i < querys.length; i++) {
var temp = querys[i].split('=')
if (temp.length < 2) {
result[temp[0]] = ''
} else {
result[temp[0]] = temp[1]
}
}
this.currentToken = this.getQueryString(result.token)
console.log('token==', this.currentToken)
},
// 方法二:
sessionIdFunc(key) {
const urlSessionId = new URLSearchParams(window.location.hash.slice(window.location.hash.indexOf('?')))
const paramSessionId = urlSessionId.get(key)
return paramSessionId
},
// 获取用户名
async getAccount() {
// 方法二:
let newToken = decodeURIComponent(this.sessionIdFunc('token')).replaceAll(' ', '+')
let params = {
token: newToken // 通过url截取获得 方法二
// token: this.currentToken // 通过url截取获得 方法一
}
await this.$Api
.getAccount(params)
.then(res => {
console.log('this.username==', res)
this.username = res.data.data.account
})
.catch(error => {
this.$Toast(error.data.message)
})
},
// 获取token
async getTokenAuth() {
let params = {
username: this.username
// username: 'al-wangwf'
}
await this.$Api.getAuth(params).then(res => {
setToken(res.data.data)
})
},