From 33fa961618c3bb4aa2a3b3c1a9fc1d0784539612 Mon Sep 17 00:00:00 2001 From: franktrue Date: Mon, 22 May 2023 21:27:10 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BD=BF=E7=94=A8cookies=E4=BF=9D=E5=AD=98?= =?UTF-8?q?=E9=82=80=E8=AF=B7=E7=A0=81?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/router/index.js | 5 +++-- src/utils/ruoyi.js | 11 +++++++++++ src/views/register.vue | 3 ++- 3 files changed, 16 insertions(+), 3 deletions(-) diff --git a/src/router/index.js b/src/router/index.js index ce97069..94cc0ad 100644 --- a/src/router/index.js +++ b/src/router/index.js @@ -30,9 +30,10 @@ export const constantRoutes = [ path: '/m/:code', redirect: (to) => { // 保存参数到本地缓存或 cookie - localStorage.setItem('inviteCode', to.params.code) + // localStorage.setItem('inviteCode', to.params.code) // 如果需要使用 cookie,可以使用 document.cookie = 'inviteCode=' + to.params.code - return '/register' + document.cookie = 'inviteCode=' + to.params.code+'; domain=api2gpt.com; path=/' + window.location.href = 'https://www.api2gpt.com' } }, { diff --git a/src/utils/ruoyi.js b/src/utils/ruoyi.js index 2714962..626ef48 100644 --- a/src/utils/ruoyi.js +++ b/src/utils/ruoyi.js @@ -244,3 +244,14 @@ export function getNormalPath(p) { export function blobValidate(data) { return data.type !== 'application/json' } + +// 定义获取 cookie 的函数 +export function getCookie(name) { + const regexp = new RegExp('(^| )' + name + '=([^;]*)(;|$)') + const result = document.cookie.match(regexp) + if (result) { + return result[2] + } else { + return null + } +} \ No newline at end of file diff --git a/src/views/register.vue b/src/views/register.vue index 708af27..7f81e94 100644 --- a/src/views/register.vue +++ b/src/views/register.vue @@ -95,11 +95,12 @@