From b0fb4781d922aeda564bcb4a0b7bee47a59014c0 Mon Sep 17 00:00:00 2001 From: 2betop <2betop.cn@gmail.com> Date: Fri, 21 May 2021 16:28:31 +0800 Subject: [PATCH] =?UTF-8?q?=E6=94=AF=E6=8C=81=20cookie=20=E8=8E=B7?= =?UTF-8?q?=E5=8F=96?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/utils/tpl-builtin.ts | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/src/utils/tpl-builtin.ts b/src/utils/tpl-builtin.ts index 177e77367..5bcea9997 100644 --- a/src/utils/tpl-builtin.ts +++ b/src/utils/tpl-builtin.ts @@ -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 === '$$') {