Skip to content

Commit

Permalink
feat:navigatorTo-请求头
Browse files Browse the repository at this point in the history
  • Loading branch information
ananzhusen committed Sep 14, 2024
1 parent a6717b0 commit 38aeb64
Showing 1 changed file with 14 additions and 11 deletions.
25 changes: 14 additions & 11 deletions packages/core/src/core.ts
Original file line number Diff line number Diff line change
Expand Up @@ -550,7 +550,9 @@ export class Meta2d {
const netWork = this.store.options.navigatorNetWork;
const collection = (location.href.includes('2d.')||location.href.includes('/2d'))?'2d':'v';
const res: Response = await fetch((netWork?.url||`/api/data/${collection}/get`) + (netWork?.method==='GET'?`?id=${id}`:''), {
headers: netWork?.headers || {},
headers: {
Authorization: `Bearer ${this.getCookie('token') || localStorage.getItem('token')|| new URLSearchParams(location.search).get('token') || ''}`,
},
method: netWork?.method || 'POST',
body: netWork?.method === 'GET' ?undefined : JSON.stringify({id:id}) as any,
});
Expand Down Expand Up @@ -2350,19 +2352,20 @@ export class Meta2d {
}
}

getCookie(name: string) {
let arr: RegExpMatchArray | null;
const reg = new RegExp('(^| )' + name + '=([^;]*)(;|$)');
if ((arr = document.cookie.match(reg))) {
return decodeURIComponent(arr[2]);
} else {
return '';
}
}

//获取动态参数
getDynamicParam(key: string) {
function getCookie(name: string) {
let arr: RegExpMatchArray | null;
const reg = new RegExp('(^| )' + name + '=([^;]*)(;|$)');
if ((arr = document.cookie.match(reg))) {
return decodeURIComponent(arr[2]);
} else {
return '';
}
}
let params = queryURLParams();
let value = params[key] || localStorage[key] || getCookie(key) || '';
let value = params[key] || localStorage[key] || this.getCookie(key) || '';
return value;
}

Expand Down

0 comments on commit 38aeb64

Please sign in to comment.