From 36fcdc4af38c6bd301e4ae2773c5dc6601104f6f Mon Sep 17 00:00:00 2001 From: xy <271556543@qq.com> Date: Thu, 20 Jul 2023 09:48:27 +0800 Subject: [PATCH] =?UTF-8?q?2023-7-20=20=E5=8D=95=E7=82=B9=E7=99=BB?= =?UTF-8?q?=E5=BD=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/api/other/index.js | 9 +++++++++ src/permission.js | 18 ++++++++++++++++-- 2 files changed, 25 insertions(+), 2 deletions(-) create mode 100644 src/api/other/index.js diff --git a/src/api/other/index.js b/src/api/other/index.js new file mode 100644 index 0000000..59bae55 --- /dev/null +++ b/src/api/other/index.js @@ -0,0 +1,9 @@ +import request from "@/utils/request"; + +export function ossLogin (data) { + return request({ + url: '/api/admin/auth/oss-login', + method: 'post', + data + }) +} diff --git a/src/permission.js b/src/permission.js index d9f1c48..28c91fc 100644 --- a/src/permission.js +++ b/src/permission.js @@ -3,8 +3,9 @@ import store from './store' import { Message } from 'element-ui' import NProgress from 'nprogress' // progress bar import 'nprogress/nprogress.css' // progress bar style -import { getToken } from '@/utils/auth' // get token from cookie +import { getToken,setToken } from '@/utils/auth' // get token from cookie import getPageTitle from '@/utils/get-page-title' +import { ossLogin } from '@/api/other' NProgress.configure({ showSpinner: false }) // NProgress Configuration @@ -18,8 +19,21 @@ router.beforeEach(async(to, from, next) => { document.title = getPageTitle(to.meta.title) // determine whether the user has logged in - const hasToken = getToken() + let queryStr = window.location.href.split('?')[1]?.split('&') + let query = {} + queryStr?.forEach(i => { + let index = i.indexOf('=') + query[i.slice(0,index)] = i.slice(index+1) + }) + + if (query.sstt_token) { + const res = await ossLogin({jtcl_token: query.sstt_token}) + setToken(res.access_token) + store.commit('user/SET_TOKEN',res.access_token) + } + + const hasToken = getToken() if (hasToken) { if (to.path === '/login') { // if is logged in, redirect to the home page