From b2dd4a83226325cea0e11f79ea9fa040e809dd6c Mon Sep 17 00:00:00 2001
From: Wangwei <870653736@qq.com>
Date: Tue, 20 Dec 2022 10:58:08 +0800
Subject: [PATCH] =?UTF-8?q?add:=E6=96=B0=E7=89=88cas=E6=8E=A5=E5=85=A5?=
=?UTF-8?q?=E6=96=B9=E6=A1=88?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
---
public/index.html | 3 ++-
src/api/auth.js | 2 +-
src/components/Header.vue | 4 +--
src/mixins/mixins.js | 5 ++--
src/router.js | 56 ++++++++++++++++++++-------------------
src/store/index.js | 3 ++-
src/utils/cookie.js | 6 ++---
7 files changed, 41 insertions(+), 38 deletions(-)
diff --git a/public/index.html b/public/index.html
index cb4784b..06869a5 100644
--- a/public/index.html
+++ b/public/index.html
@@ -10,8 +10,9 @@
帆软学院-培养企业亟需的数据人才
+ content="帆软学院专注于培养企业亟需的数据人才。课程方向包括FineReport、FineBI、简道云、FineDataLink、数知鸟、阿米巴、数据分析、python、Linux、数据库、java、JavaScript等。" />
+
diff --git a/src/api/auth.js b/src/api/auth.js
index 9972c52..e173f51 100644
--- a/src/api/auth.js
+++ b/src/api/auth.js
@@ -83,7 +83,7 @@ export function getUserCode(sid) {
*/
export function casLogin(ticket) {
return request({
- url:`/v1/user/cas/login/?ticket=${ticket}&service=${process.env.VUE_APP_EDU_URL}/`,
+ url:`/v1/user/cas/login/?appmodel=edu&ticket=${ticket}&redirect=/&service=${process.env.VUE_APP_EDU_URL}/`,
method: "get"
})
}
diff --git a/src/components/Header.vue b/src/components/Header.vue
index 3d3f18d..f8223be 100644
--- a/src/components/Header.vue
+++ b/src/components/Header.vue
@@ -139,9 +139,7 @@
diff --git a/src/mixins/mixins.js b/src/mixins/mixins.js
index 950d256..e57ed22 100644
--- a/src/mixins/mixins.js
+++ b/src/mixins/mixins.js
@@ -7,10 +7,11 @@
*/
//import { getToken } from "@/utils/cookie";
import store from '@/store'
-// import { useRoute } from 'vue-router'
+import { useRoute } from 'vue-router'
export const mixins = {
data() {
+ const route = useRoute();
return {
com_user_token: store.getters.get_token,
com_edu_url: process.env.VUE_APP_EDU_URL || 'https://edu.fanruan.com',
@@ -20,7 +21,7 @@ export const mixins = {
com_pass_url: process.env.VUE_APP_PASS_URL || 'https://fanruanclub.com',
com_cert_url:process.env.VUE_APP_CERT_URL || 'https://cert.fanruan.com',
com_jump_url:encodeURIComponent(window.location.href),
- com_login_url:process.env.VUE_APP_ID_URL+'/signin/'+'?app=edu&protocol=cas&referrer='+window.location.href
+ com_login_url:process.env.VUE_APP_ID_URL+'/cas/login?service='+process.env.VUE_APP_EDU_URL+'/v1/user/cas/edu/login/?redirect='+route.fullPath
}
},
created() {
diff --git a/src/router.js b/src/router.js
index 4a263a5..e308163 100644
--- a/src/router.js
+++ b/src/router.js
@@ -1,8 +1,8 @@
import { createRouter, createWebHistory } from 'vue-router';
import Layout from '@/layout/index.vue';
import store from '@/store';
-import { refreshToken, casLogin } from '@/api/auth';
-import '@/utils/fineClubSDK';
+import { refreshToken } from '@/api/auth';
+// import '@/utils/fineClubSDK';
import { getUid, getExpiresTime } from '@/utils/cookie';
import { delUrlParams } from '@/utils/urlQuery';
@@ -345,16 +345,17 @@ let getdate = parseInt(new Date().getTime() / 1000);
router.beforeEach((to, from, next) => {
// const { title } = to.meta;
// document.title = getPageTitle(title);
-
+ // console.log('to====',to);
+
const get_ticket = to.query.ticket || 0;
const get_type = to.query.type ? to.query.type : '0';
- // ticket空执行删除
+ // ticket空执行删除
const is_ticket_null = new URL(window.location);
- if(is_ticket_null.searchParams.has("ticket")){
- if(get_ticket===0 || get_ticket=='null'){
+ if (is_ticket_null.searchParams.has("ticket")) {
+ if (get_ticket === 0 || get_ticket == 'null') {
console.log('ticket空');
- parent.window.location.replace(process.env.VUE_APP_ID_URL+'/login/token/logout?referrer='+encodeURIComponent(process.env.VUE_APP_EDU_URL));
+ parent.window.location.replace(process.env.VUE_APP_ID_URL + '/login/token/logout?referrer=' + encodeURIComponent(process.env.VUE_APP_EDU_URL));
}
}
@@ -365,7 +366,25 @@ router.beforeEach((to, from, next) => {
return getUid() || 0;
}
window.fineClub.config({ app, getLoginUid, debug: isDev, dev: isDev });
- window.fineClub.autoReloadOnLoginChange({ loginUrl: process.env.VUE_APP_ID_URL + '/login/signin/?app=edu&protocol=cas&referrer=' + encodeURIComponent(window.location.href) });
+
+ // 监听登录
+ function callback(data) {
+ console.log('callback_data', data);
+ if (!get_ticket && data.uid > 0) {
+ console.log('跳转到通行证登录');
+ let ticket_login_url = '/v1/user/cas/get/ticket/?redirect='+to.path+'&service='+process.env.VUE_APP_EDU_URL+'/v1/user/cas/edu/login/';
+ window.location.href = ticket_login_url;
+ }
+ if (!data.uid) {
+ console.log('监听到登出', 'del_token');
+ store.commit('del_token');
+ window.location.reload();
+ }
+ }
+ window.fineClub.onLoginChange(callback);
+ // if(!getUid()){
+ // callback({uid:73851});
+ // }
if (to.meta.title) {
document.title = to.meta.title;
@@ -386,28 +405,11 @@ router.beforeEach((to, from, next) => {
setTimeout(function () {
next();
}, 500);
- } else if (get_ticket) {
- casLogin(get_ticket).then((res) => {
- if (res.code === 200 && res.status != -1) {
- console.log('casLogin', res);
- store.commit('set_token', res.data);
- setTimeout(function () {
- // parent.window.location.replace(process.env.VUE_APP_EDU_URL + to.path);
- // parent.location.reload();
- let jumpUrl = delUrlParams(location.href,['ticket','sid']);
- console.log('jumpUrl',jumpUrl);
- parent.window.location.replace(jumpUrl);
- }, 250);
- } else {
- next();
- }
- });
-
- } else if (get_type === 'logout') {
+ }else if (get_type === 'logout') {
console.log('logout', 'del_token');
store.commit('del_token');
setTimeout(function () {
- let jumpUrl = delUrlParams(location.href,['type']);
+ let jumpUrl = delUrlParams(location.href, ['type']);
window.location.replace(jumpUrl);
// next();
}, 500);
diff --git a/src/store/index.js b/src/store/index.js
index f1daf1e..efaf8d1 100644
--- a/src/store/index.js
+++ b/src/store/index.js
@@ -47,13 +47,14 @@ export default createStore({
Cookies.set(AppIdKey, data.client.appid, { expires: days });
Cookies.set(UidKey, data.client.uid, { expires: days });
Cookies.set(expiresTimeKey, data.expires_time, { expires: days });
- localStorage.setItem(RefreshTokenKey, data.refresh_token);
+ Cookies.set(RefreshTokenKey, data.refresh_token, { expires: days });
},
del_token(state) {
state.fr_access_token = "";
state.fr_appid = "";
state.fr_uid = "";
+ Cookies.remove(RefreshTokenKey);
Cookies.remove(AccessTokenKey);
Cookies.remove(AppIdKey);
Cookies.remove(UidKey);
diff --git a/src/utils/cookie.js b/src/utils/cookie.js
index 8b89537..73f8953 100644
--- a/src/utils/cookie.js
+++ b/src/utils/cookie.js
@@ -32,13 +32,13 @@ export function removeToken() {
}
export function getRefreshToken() {
- return localStorage.getItem(RefreshTokenKey);
+ return Cookies.get(RefreshTokenKey);
}
export function setRefreshToken(refreshToken) {
- return localStorage.setItem(RefreshTokenKey, refreshToken);
+ return Cookies.set(RefreshTokenKey, refreshToken);
}
export function removeRefreshToken() {
- return localStorage.removeItem(RefreshTokenKey);
+ return Cookies.remove(RefreshTokenKey);
}
export function getAppId() {