From bf2d7cadad74537dff164bf93e6f97dea55be1f0 Mon Sep 17 00:00:00 2001 From: yaoyuhao Date: Mon, 18 Nov 2024 09:49:16 +0800 Subject: [PATCH] =?UTF-8?q?=E5=8F=96=E6=B6=88cookie=EF=BC=8C=E4=B8=80?= =?UTF-8?q?=E5=BE=8B=E7=94=A8token=E5=88=A4=E6=96=AD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/App.vue | 16 ++++++++-------- src/utils/request.js | 14 +++++++------- src/view/guide.vue | 14 +++++++------- 3 files changed, 22 insertions(+), 22 deletions(-) diff --git a/src/App.vue b/src/App.vue index 7f83a74..edec5d4 100644 --- a/src/App.vue +++ b/src/App.vue @@ -20,14 +20,14 @@ const resetTimer = () => { ElMessage.error("长时间未操作,请重新登录"); window.removeEventListener("mousemove", resetTimer); window.removeEventListener("keydown", resetTimer); - const cookies = document.cookie.split(";"); - for (let i = 0; i < cookies.length; i++) { - const cookie = cookies[i]; - const eqPos = cookie.indexOf("="); - const name = eqPos > -1 ? cookie.substr(0, eqPos) : cookie; - document.cookie = - name + "=;expires=Thu, 01 Jan 1970 00:00:00 GMT; path=/;"; - } + // const cookies = document.cookie.split(";"); + // for (let i = 0; i < cookies.length; i++) { + // const cookie = cookies[i]; + // const eqPos = cookie.indexOf("="); + // const name = eqPos > -1 ? cookie.substr(0, eqPos) : cookie; + // document.cookie = + // name + "=;expires=Thu, 01 Jan 1970 00:00:00 GMT; path=/;"; + // } let backurl = window.location.href; tools.data.set("backUrl", backurl); tools.data.remove('token'); diff --git a/src/utils/request.js b/src/utils/request.js index e5fc36c..bc76688 100644 --- a/src/utils/request.js +++ b/src/utils/request.js @@ -30,13 +30,13 @@ axios.interceptors.response.use( if (error.response.status == 401) { ElMessage.error("请重新登录!"); // 清空cook - const cookies = document.cookie.split(";"); - for (let i = 0; i < cookies.length; i++) { - const cookie = cookies[i]; - const eqPos = cookie.indexOf("="); - const name = eqPos > -1 ? cookie.substr(0, eqPos) : cookie; - document.cookie = name + "=;expires=Thu, 01 Jan 1970 00:00:00 GMT; path=/;"; - } + // const cookies = document.cookie.split(";"); + // for (let i = 0; i < cookies.length; i++) { + // const cookie = cookies[i]; + // const eqPos = cookie.indexOf("="); + // const name = eqPos > -1 ? cookie.substr(0, eqPos) : cookie; + // document.cookie = name + "=;expires=Thu, 01 Jan 1970 00:00:00 GMT; path=/;"; + // } let backurl=window.location.href; tools.data.set("backUrl",backurl); diff --git a/src/view/guide.vue b/src/view/guide.vue index 2860500..d47e82f 100644 --- a/src/view/guide.vue +++ b/src/view/guide.vue @@ -201,11 +201,11 @@ const login = () => { const decodedText = decrypt(encryptedText, ENCODED_KEY); // console.log("Decrypted Text:", decodedText); var tokenU = decodedText; - if (getCookie("lytoken")) { - } else { - document.cookie = `lytoken=${tokenU}`; - } - var token = getCookie("lytoken"); + // if (getCookie("lytoken")) { + // } else { + // document.cookie = `lytoken=${tokenU}`; + // } + var token = tokenU; tools.data.set("token", token); tools.data.set("type", 2); getMenu(); @@ -216,9 +216,9 @@ const login = () => { tools.data.remove("backUrl"); } } else { - var tokenPd = getCookie("lytoken"); + // var tokenPd = getCookie("lytoken"); var tokenLogin=tools.data.get("token"); - if (!tokenPd && !tokenLogin) { + if (!tokenLogin) { window.location.href = "https://jzzf.longyou.gov.cn:998/api/login?returnURL=" + window.location.href;