Commit cf2895b4 by zhengxiao

docs(changeset): uid 和 accessToken 优先从链接获取

parent c8945665
---
'@ydl-packages/toolkit': patch
---
uid 和 accessToken 优先从链接获取
{ {
"name": "@ydl-packages/toolkit", "name": "@ydl-packages/toolkit",
"version": "1.0.8-beta.2", "version": "1.0.10",
"description": "", "description": "",
"main": "./dist/index.umd.js", "main": "./dist/index.umd.js",
"scripts": { "scripts": {
......
...@@ -9,8 +9,8 @@ defaultRequest.interceptors.request.use((config) => { ...@@ -9,8 +9,8 @@ defaultRequest.interceptors.request.use((config) => {
return { return {
...config, ...config,
headers: { headers: {
uid: Utils.getCookie(UID), uid: Utils.getQueryString(UID) || Utils.getCookie(UID),
accessToken: Utils.getCookie(ACCESS_TOKEN) accessToken: Utils.getQueryString(ACCESS_TOKEN) || Utils.getCookie(ACCESS_TOKEN)
}, },
} }
}) })
......
...@@ -13,4 +13,14 @@ export class Utils { ...@@ -13,4 +13,14 @@ export class Utils {
static setCookie(key: 'uid' | 'accessToken', value: string): void { static setCookie(key: 'uid' | 'accessToken', value: string): void {
Cookies.set(key, value) Cookies.set(key, value)
} }
// 获取链接上的参数
static getQueryString(name: 'uid' | 'accessToken'): string | null {
const reg = new RegExp('(^|&)' + name + '=([^&]*)(&|$)', 'i')
const r = window.location.search.substr(1).match(reg)
if (r != null) {
return decodeURI(r[2])
}
return null
}
} }
\ No newline at end of file
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