6eb4c219 by renchao@pashanhoo.com

style:合并dev

2 parents aa12e755 6642bd08
{
"TITLE": "不动产登记系统",
"SERVERAPI": "/bdcdj"
"SERVERAPI": "/bdcdj",
"ip": "http://192.168.2.38"
}
\ No newline at end of file
......
{
"TITLE": "不动产登记系统",
"SERVERAPI": "/bdcdj"
"SERVERAPI": "/bdcdj",
"ip": "http://192.168.2.38"
}
\ No newline at end of file
......
{
"TITLE": "不动产登记系统",
"SERVERAPI": "service-bdcdj-th"
"SERVERAPI": "service-bdcdj-th",
"ip": "http://192.168.2.38"
}
\ No newline at end of file
......
<!--
* @Description:
* @Autor: renchao
* @LastEditTime: 2023-05-30 15:08:51
* @LastEditTime: 2023-05-31 15:33:18
-->
<!DOCTYPE html>
<html>
......@@ -19,7 +19,19 @@
</head>
<script>
window.baseUrl = location.origin || location.protocol + '//' + location.host
const authorization = "bearer ATT-7-TiYJVcoDnfhNGs160E6MbQ-QA9Ot3Tby"
window._config = {
// 是否微服务模式,业务系统根据需要读取
cloudEnable: false,
// 是否启用单点登录
casEnable: true,
// cas 基地址
casBaseURL: 'http://192.168.2.38/cas',
services: {
// 配置到 contextPath 前一级
management: 'http://192.168.2.38',
business: 'http://localhost:7001'
}
}
fetch('<%= BASE_URL %>config.json')
.then(response => response.json())
.then(config => {
......
......@@ -27,6 +27,7 @@
</div>
</template>
<script>
import axios from 'axios'
import { mapGetters } from 'vuex'
import NoticeBar from '@/components/NoticeBar/index'
import {
......@@ -72,9 +73,20 @@
})
},
logout () {
const url = baseUrl + "/sso-logout?redirect_uri=" + baseUrl + "/bdcdj";
window.open(url, "_self");
sessionStorage.removeItem("navList");
axios.post(this.BASE_API.ip + "/management/logout").then(() => {
localStorage.removeItem('token')
if (window._config.casEnable) {
window.location.href = window._config.casBaseURL + '/logout?service=' + encodeURIComponent(window.location.href);
} else {
this.$router.push({
path: '/login',
replace: true,
query: {
redirect: router.currentRoute.value.fullPath
}
})
}
})
},
themeChange (val) {
......
/*
* @Description:
* @Autor: renchao
* @LastEditTime: 2023-05-31 08:48:44
* @LastEditTime: 2023-05-30 15:28:52
*/
import Vue from 'vue'
import App from './App'
......
/*
* @Description: 项目权限
* @Autor: renchao
* @LastEditTime: 2023-05-16 14:10:26
* @LastEditTime: 2023-05-31 15:55:14
*/
import Vue from 'vue'
import router from './router'
import store from './store'
import axios from 'axios'
import { getMenuInfo } from '@/api/user'
import { getUrlParam } from '@/utils/operation'
import NProgress from 'nprogress' // progress bar
import 'nprogress/nprogress.css' // progress bar style
import getPageTitle from '@/utils/get-page-title'
......@@ -19,6 +21,42 @@ router.beforeEach(async (to, from, next) => {
document.title = getPageTitle(to.meta.title)
let hasAddDict = store.state.dict.addDict
let hasAddRoute = store.state.permission.addRoutes
// cas操作
const token = localStorage.getItem("token")
if (to.path === '/login') {
if (token) {
next('/')
} else {
next()
}
return
}
if (window._config.casEnable === true) {
let locationUrl = window.location.protocol + '//' + window.location.host + window.location.pathname;
if (!token) {
let ticket = getUrlParam('ticket');
if (ticket) {
axios.get(Vue.prototype.BASE_API.ip + "/management/cas/validate", {
params: {
'ticket': ticket,
'service': locationUrl
}
}).then(async (res) => {
localStorage.setItem('token', res.data.content.accessToken)
window.location.href = localStorage.getItem('location')
}).catch(e => {
console.log(e)
})
} else {
localStorage.setItem("location", window.location.href)
window.location.href = window._config.casBaseURL + '/login?service=' + encodeURIComponent(locationUrl);
permission()
}
} else {
permission()
}
async function permission () {
if (!hasAddDict) {
store.dispatch('dict/generateDic')
}
......@@ -38,6 +76,24 @@ router.beforeEach(async (to, from, next) => {
next('/home')
}
}
}
} else {
if (!token) {
const redirectData = {
path: '/login',
replace: true,
}
if (to.path) {
redirectData.query = {
...redirectData.query,
redirect: to.path,
};
}
next(redirectData)
return
}
next()
}
NProgress.done()
})
router.afterEach(to => {
......
/*
* @Description: 全局路由
* @Autor: renchao
* @LastEditTime: 2023-05-16 14:09:37
* @LastEditTime: 2023-05-26 17:11:19
*/
import Vue from 'vue'
import Router from 'vue-router'
......
@import "~@/styles/mixin.scss";
.dialogBox {
border-radius: 8px;
border-radius: 4px;
overflow: hidden;
background: #FFFFFF;
box-shadow: 0 2px 12px 0 rgba(0, 0, 0, 0.10);
......@@ -8,15 +8,33 @@
.dialog_title {
display: flex;
position: relative;
top: -2px;
top: -4px;
b {
@include flex-center;
display: flex;
justify-content:left;
align-items: center;
flex: 1;
width: 100%;
margin-left: 10px;
width: 79px;
height: 12px;
font-size: 16px;
font-family: AlibabaPuHuiTi_2_65_Medium;
color: #31333C;
line-height: 10px;
}
}
.dialog_title::before{
content: "";
display: block;
width: 4px;
height: 18px;
background: #2E74D8;
position: absolute;
top: -4px;
left: 0px;
}
.dialog_full {
position: absolute;
top: 0;
......@@ -46,10 +64,7 @@
}
.el-dialog__header {
margin-bottom: 10px;
color: #FFFFFF;
background-color: #FCFDFD;
border-bottom: 1px solid #E4EBF4;
background: linear-gradient(270deg, #F2F3FB 0%, #5C95E5 100%);
}
.el-dialog__body {
......
......@@ -110,3 +110,26 @@ export function down (index, data) {
data.splice(index, 0, downData);
}
}
export function getUrlParam (paraName) {
let url = document.location.toString();
let arrObj = url.split('?');
if (arrObj.length > 1) {
let arrPara = arrObj[1].split('&');
let arr;
for (let i = 0; i < arrPara.length; i++) {
arr = arrPara[i].split('=');
if (arr != null && arr[0] === paraName) {
const index = arr[1].indexOf("#");
return arr[1].substring(0, index);
}
}
return '';
} else {
return '';
}
}
......
/*
* @Description: 此文件主要创建 axios 实例,然后添加请求拦截器和响应拦截器
* @Autor: renchao
* @LastEditTime: 2023-05-16 14:07:58
* @LastEditTime: 2023-05-31 15:30:02
*/
import axios from 'axios'
import { Message } from 'element-ui'
......@@ -23,13 +23,14 @@ const service = axios.create({
// request interceptor
service.interceptors.request.use(
config => {
// do something before request is sent
if (process.env.NODE_ENV === "production") {
return config;
const token = localStorage.getItem('token')
// 添加请求头
if (token) {
config.headers['Authorization'] = "Bearer " + token
} else {
config.headers.Authorization = authorization;
return config;
config.headers.delete('Authorization')
}
return config;
},
error => {
// do something with request error
......@@ -55,6 +56,27 @@ service.interceptors.response.use(
},
error => {
endLoadingSubCount()
if (error.response.status === 401) {
//todo: 需要解决 一个页面多个请求,刷新后此处会触发多次
if (window.__isNeedLogin) {
window.__isNeedLogin = false
this.$message.error('token失效,请重新登录');
let locationUrl = window.location.protocol + '//' + window.location.host + window.location.pathname;
localStorage.removeItem('token')
if (window._config.casEnable) {
window.location.href = window._config.casBaseURL + '/logout?service=' + encodeURIComponent(locationUrl);
} else {
router.replace({
path: '/login',
query: {
redirect: router.currentRoute.value.fullPath
}
})
return false
}
}
} else {
// 对响应错误做点什么
Message({
message: '服务器异常,请联系管理员',
......@@ -62,6 +84,7 @@ service.interceptors.response.use(
duration: 5 * 1000,
customClass: 'messageIndex'
})
}
return Promise.reject(error);
}
)
......