Browse Source

add:新版cas接入方案

pull/2/head
Wangwei 2 years ago
parent
commit
b2dd4a8322
  1. 3
      public/index.html
  2. 2
      src/api/auth.js
  3. 4
      src/components/Header.vue
  4. 5
      src/mixins/mixins.js
  5. 42
      src/router.js
  6. 3
      src/store/index.js
  7. 6
      src/utils/cookie.js

3
public/index.html

@ -10,8 +10,9 @@
<title>帆软学院-培养企业亟需的数据人才</title> <title>帆软学院-培养企业亟需的数据人才</title>
<meta name="keywords" content="帆软学院,帆软培训,帆软视频,帆软教程,帆软课程,数据分析培训,大数据培训" /> <meta name="keywords" content="帆软学院,帆软培训,帆软视频,帆软教程,帆软课程,数据分析培训,大数据培训" />
<meta name="description" <meta name="description"
content="帆软学院专注于培养企业亟需的数据人才。课程方向包括FineReport、FineBI、简道云、数知鸟、阿米巴、数据分析、python、Linux、数据库、java、JavaScript等。" /> content="帆软学院专注于培养企业亟需的数据人才。课程方向包括FineReport、FineBI、简道云、FineDataLink、数知鸟、阿米巴、数据分析、python、Linux、数据库、java、JavaScript等。" />
<link rel="stylesheet" href="//at.alicdn.com/t/font_2400577_ckl19e6hyau.css"> <link rel="stylesheet" href="//at.alicdn.com/t/font_2400577_ckl19e6hyau.css">
<script type="text/javascript" src="https://cdn.fanruanclub.com/prod/dist/js/fineClubSDK.js"></script>
<!-- <script type="text/javascript" src="<%= BASE_URL %>js/ckplayer/ckplayer.min.js"></script> --> <!-- <script type="text/javascript" src="<%= BASE_URL %>js/ckplayer/ckplayer.min.js"></script> -->
</head> </head>

2
src/api/auth.js

@ -83,7 +83,7 @@ export function getUserCode(sid) {
*/ */
export function casLogin(ticket) { export function casLogin(ticket) {
return request({ 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" method: "get"
}) })
} }

4
src/components/Header.vue

@ -139,9 +139,7 @@
</template> </template>
</el-dropdown> </el-dropdown>
<div v-else class="loginReg flex-1"> <div v-else class="loginReg flex-1">
<a class="loginbtn" :href="com_id_url+'/login/signin/'+'?app=edu&protocol=cas&referrer='+wwwUrl" <a class="loginbtn" :href="com_id_url+'/cas/login?service='+com_edu_url+'/v1/user/cas/edu/login/?redirect='+$route.fullPath">登录</a>
v-if="com_node_env==='dist'">登录</a>
<a class="loginbtn" :href="com_id_url+'/signin/'+'?app=edu&protocol=cas&referrer='+wwwUrl" v-else>登录</a>
</div> </div>
</nav> </nav>

5
src/mixins/mixins.js

@ -7,10 +7,11 @@
*/ */
//import { getToken } from "@/utils/cookie"; //import { getToken } from "@/utils/cookie";
import store from '@/store' import store from '@/store'
// import { useRoute } from 'vue-router' import { useRoute } from 'vue-router'
export const mixins = { export const mixins = {
data() { data() {
const route = useRoute();
return { return {
com_user_token: store.getters.get_token, com_user_token: store.getters.get_token,
com_edu_url: process.env.VUE_APP_EDU_URL || 'https://edu.fanruan.com', 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_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_cert_url:process.env.VUE_APP_CERT_URL || 'https://cert.fanruan.com',
com_jump_url:encodeURIComponent(window.location.href), 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() { created() {

42
src/router.js

@ -1,8 +1,8 @@
import { createRouter, createWebHistory } from 'vue-router'; import { createRouter, createWebHistory } from 'vue-router';
import Layout from '@/layout/index.vue'; import Layout from '@/layout/index.vue';
import store from '@/store'; import store from '@/store';
import { refreshToken, casLogin } from '@/api/auth'; import { refreshToken } from '@/api/auth';
import '@/utils/fineClubSDK'; // import '@/utils/fineClubSDK';
import { getUid, getExpiresTime } from '@/utils/cookie'; import { getUid, getExpiresTime } from '@/utils/cookie';
import { delUrlParams } from '@/utils/urlQuery'; import { delUrlParams } from '@/utils/urlQuery';
@ -345,6 +345,7 @@ let getdate = parseInt(new Date().getTime() / 1000);
router.beforeEach((to, from, next) => { router.beforeEach((to, from, next) => {
// const { title } = to.meta; // const { title } = to.meta;
// document.title = getPageTitle(title); // document.title = getPageTitle(title);
// console.log('to====',to);
const get_ticket = to.query.ticket || 0; const get_ticket = to.query.ticket || 0;
const get_type = to.query.type ? to.query.type : '0'; const get_type = to.query.type ? to.query.type : '0';
@ -365,7 +366,25 @@ router.beforeEach((to, from, next) => {
return getUid() || 0; return getUid() || 0;
} }
window.fineClub.config({ app, getLoginUid, debug: isDev, dev: isDev }); 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) { if (to.meta.title) {
document.title = to.meta.title; document.title = to.meta.title;
@ -386,23 +405,6 @@ router.beforeEach((to, from, next) => {
setTimeout(function () { setTimeout(function () {
next(); next();
}, 500); }, 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'); console.log('logout', 'del_token');
store.commit('del_token'); store.commit('del_token');

3
src/store/index.js

@ -47,13 +47,14 @@ export default createStore({
Cookies.set(AppIdKey, data.client.appid, { expires: days }); Cookies.set(AppIdKey, data.client.appid, { expires: days });
Cookies.set(UidKey, data.client.uid, { expires: days }); Cookies.set(UidKey, data.client.uid, { expires: days });
Cookies.set(expiresTimeKey, data.expires_time, { 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) { del_token(state) {
state.fr_access_token = ""; state.fr_access_token = "";
state.fr_appid = ""; state.fr_appid = "";
state.fr_uid = ""; state.fr_uid = "";
Cookies.remove(RefreshTokenKey);
Cookies.remove(AccessTokenKey); Cookies.remove(AccessTokenKey);
Cookies.remove(AppIdKey); Cookies.remove(AppIdKey);
Cookies.remove(UidKey); Cookies.remove(UidKey);

6
src/utils/cookie.js

@ -32,13 +32,13 @@ export function removeToken() {
} }
export function getRefreshToken() { export function getRefreshToken() {
return localStorage.getItem(RefreshTokenKey); return Cookies.get(RefreshTokenKey);
} }
export function setRefreshToken(refreshToken) { export function setRefreshToken(refreshToken) {
return localStorage.setItem(RefreshTokenKey, refreshToken); return Cookies.set(RefreshTokenKey, refreshToken);
} }
export function removeRefreshToken() { export function removeRefreshToken() {
return localStorage.removeItem(RefreshTokenKey); return Cookies.remove(RefreshTokenKey);
} }
export function getAppId() { export function getAppId() {

Loading…
Cancel
Save