mirror of
https://gitee.com/baidu/amis.git
synced 2024-11-30 10:59:42 +08:00
支持 cookie 获取
This commit is contained in:
parent
3ad95846b9
commit
b0fb4781d9
@ -641,6 +641,15 @@ function parseJson(str: string, defaultValue?: any) {
|
||||
}
|
||||
}
|
||||
|
||||
function getCookie(name: string) {
|
||||
const value = `; ${document.cookie}`;
|
||||
const parts = value.split(`; ${name}=`);
|
||||
if (parts.length === 2) {
|
||||
return parts.pop()!.split(';').shift();
|
||||
}
|
||||
return undefined;
|
||||
}
|
||||
|
||||
export const resolveVariable = (path?: string, data: any = {}): any => {
|
||||
if (!path || !data || typeof path !== 'string') {
|
||||
return undefined;
|
||||
@ -672,6 +681,9 @@ export const resolveVariable = (path?: string, data: any = {}): any => {
|
||||
}
|
||||
|
||||
return undefined;
|
||||
} else if (ns === 'cookie') {
|
||||
const key = varname.replace(/^{|}$/g, '').trim();
|
||||
return getCookie(key);
|
||||
}
|
||||
|
||||
if (varname === '$$') {
|
||||
|
Loading…
Reference in New Issue
Block a user