路由拦截去除、单页面无感登录、公钥私钥修改、本地路由配置、路由获取不走请求

Lvtianfang
吕天方 7 months ago
parent 031a5b9eeb
commit 6f5f121d23

@ -92,3 +92,28 @@ export function getErrorMsg(){
method: 'get', method: 'get',
}) })
} }
// 登录
// export function login(data){
// return request({
// url: '/earlyWarningAudit/massEvents/login',
// method: 'psot',
// data
// })
// }
export function login(username, password) {
const data = {
username,
password,
}
return request({
url: '/earlyWarningAudit/massEvents/login',
headers: {
isToken: false,
repeatSubmit: false
},
method: 'post',
data: data
})
}

@ -1,11 +1,3 @@
/*
* @Descripttion:
* @version:
* @Author: JC9527
* @Date: 2024-03-12 17:24:11
* @LastEditors: JC9527
* @LastEditTime: 2024-09-23 10:01:04
*/
import Vue from 'vue' import Vue from 'vue'
import Cookies from 'js-cookie' import Cookies from 'js-cookie'
@ -82,6 +74,11 @@ Vue.directive('removeAriaHiddent', {
} }
}) })
/**
* 还原只需还原路由拦截文件里和注释掉本地路由配置单页面mounted里登录去掉即可
*
*/
/** /**
* If you don't want to use mock-server * If you don't want to use mock-server
* you want to use MockJs for mock api * you want to use MockJs for mock api

@ -12,45 +12,47 @@ const whiteList = ['/login', '/register']
router.beforeEach((to, from, next) => { router.beforeEach((to, from, next) => {
NProgress.start() NProgress.start()
if (getToken()) { next();
to.meta.title && store.dispatch('settings/setTitle', to.meta.title)
/* has token*/
if (to.path === '/login') {
next({ path: '/' })
NProgress.done() NProgress.done()
} else if (whiteList.indexOf(to.path) !== -1) { // if (getToken()) {
next() // to.meta.title && store.dispatch('settings/setTitle', to.meta.title)
} else { // /* has token*/
if (store.getters.roles.length === 0) { // if (to.path === '/login') {
isRelogin.show = true // next({ path: '/' })
// 判断当前用户是否已拉取完user_info信息 // NProgress.done()
store.dispatch('GetInfo').then(() => { // } else if (whiteList.indexOf(to.path) !== -1) {
isRelogin.show = false // next()
store.dispatch('GenerateRoutes').then(accessRoutes => { // } else {
// 根据roles权限生成可访问的路由表 // if (store.getters.roles.length === 0) {
router.addRoutes(accessRoutes) // 动态添加可访问路由表 // isRelogin.show = true
next({ ...to, replace: true }) // hack方法 确保addRoutes已完成 // // 判断当前用户是否已拉取完user_info信息
}) // store.dispatch('GetInfo').then(() => {
}).catch(err => { // isRelogin.show = false
store.dispatch('LogOut').then(() => { // store.dispatch('GenerateRoutes').then(accessRoutes => {
Message.error(err) // // 根据roles权限生成可访问的路由表
next({ path: '/' }) // router.addRoutes(accessRoutes) // 动态添加可访问路由表
}) // next({ ...to, replace: true }) // hack方法 确保addRoutes已完成
}) // })
} else { // }).catch(err => {
next() // store.dispatch('LogOut').then(() => {
} // Message.error(err)
} // next({ path: '/' })
} else { // })
// 没有token // })
if (whiteList.indexOf(to.path) !== -1) { // } else {
// 在免登录白名单,直接进入 // next()
next() // }
} else { // }
next(`/login?redirect=${encodeURIComponent(to.fullPath)}`) // 否则全部重定向到登录页 // } else {
NProgress.done() // // 没有token
} // if (whiteList.indexOf(to.path) !== -1) {
} // // 在免登录白名单,直接进入
// next()
// } else {
// next(`/login?redirect=${encodeURIComponent(to.fullPath)}`) // 否则全部重定向到登录页
// NProgress.done()
// }
// }
}) })
router.afterEach(() => { router.afterEach(() => {

@ -74,54 +74,54 @@ export const constantRoutes = [
// }, // },
// ] // ]
}, },
// { {
// path: '/index', path: '/index',
// component: () => import('@/views/index'), component: () => import('@/views/index'),
// name: 'Index', name: 'Index',
// meta: { title: '算法运行监测', icon: '', affix: true } meta: { title: '算法运行监测', icon: '', affix: true }
// }, },
// { {
// path: '/warningAppear', path: '/warningAppear',
// component: () => import('@/views/warningManage/warningAppear'), component: () => import('@/views/warningManage/warningAppear'),
// name: 'WarningAppear', name: 'WarningAppear',
// meta: { title: '预警呈现', icon: '', affix: true } meta: { title: '预警呈现', icon: '', affix: true }
// }, },
// { {
// path: '/groupEvent', path: '/groupEvent',
// component: () => import('@/views/warningManage/warningAudit/groupEvent'), component: () => import('@/views/warningManage/warningAudit/groupEvent'),
// name: 'GroupEvent', name: 'GroupEvent',
// meta: { title: '驾驶舱群体事件', icon: '', affix: true } meta: { title: '驾驶舱群体事件', icon: '', affix: true }
// }, },
// { {
// path: '/instancyEvent', path: '/instancyEvent',
// component: () => import('@/views/warningManage/warningAudit/instancyEvent'), component: () => import('@/views/warningManage/warningAudit/instancyEvent'),
// name: 'InstancyEvent', name: 'InstancyEvent',
// meta: { title: '驾驶舱紧急事件', icon: '', affix: true } meta: { title: '驾驶舱紧急事件', icon: '', affix: true }
// }, },
// { {
// path: '/oneToManyEvent', path: '/oneToManyEvent',
// component: () => import('@/views/warningManage/warningAudit/oneToManyEvent'), component: () => import('@/views/warningManage/warningAudit/oneToManyEvent'),
// name: 'OneToManyEvent', name: 'OneToManyEvent',
// meta: { title: '驾驶舱一人多诉事件', icon: '', affix: true } meta: { title: '驾驶舱一人多诉事件', icon: '', affix: true }
// }, },
// { {
// path: '/oneToOneEvent', path: '/oneToOneEvent',
// component: () => import('@/views/warningManage/warningAudit/oneToOneEvent'), component: () => import('@/views/warningManage/warningAudit/oneToOneEvent'),
// name: 'OneToOneEvent', name: 'OneToOneEvent',
// meta: { title: '驾驶舱同人同诉事件', icon: '', affix: true } meta: { title: '驾驶舱同人同诉事件', icon: '', affix: true }
// }, },
// { {
// path: '/emphasisEvent', path: '/emphasisEvent',
// component: () => import('@/views/warningManage/warningAudit/emphasisEvent'), component: () => import('@/views/warningManage/warningAudit/emphasisEvent'),
// name: 'EmphasisEvent', name: 'EmphasisEvent',
// meta: { title: '驾驶舱重点人员事件', icon: '', affix: true } meta: { title: '驾驶舱重点人员事件', icon: '', affix: true }
// }, },
// { {
// path: '/similarity', path: '/similarity',
// component: () => import('@/views/warningManage/warningAudit/similarity'), component: () => import('@/views/warningManage/warningAudit/similarity'),
// name: 'Similarity', name: 'Similarity',
// meta: { title: '驾驶舱相似同类事件', icon: '', affix: true } meta: { title: '驾驶舱相似同类事件', icon: '', affix: true }
// }, },
{ {
path: '/user', path: '/user',

@ -2,17 +2,16 @@ import JSEncrypt from 'jsencrypt/bin/jsencrypt.min'
// 密钥对生成 http://web.chacuo.net/netrsakeypair // 密钥对生成 http://web.chacuo.net/netrsakeypair
const publicKey = 'MFwwDQYJKoZIhvcNAQEBBQADSwAwSAJBAKoR8mX0rGKLqzcWmOzbfj64K8ZIgOdH\n' + const publicKey = 'MFwwDQYJKoZIhvcNAQEBBQADSwAwSAJBAJ2wJTZWLnLZuRppAOevdiloiXfXE3i9rAr1rBg31sj1xAnhfRuDChoo63kMyZBifeiOcNCr49GeO3j+7NlY+yMCAwEAAQ=='
'nzkXSOVOZbFu/TJhZ7rFAN+eaGkl3C4buccQd/EjEsj9ir7ijT7h96MCAwEAAQ=='
const privateKey = 'MIIBVAIBADANBgkqhkiG9w0BAQEFAASCAT4wggE6AgEAAkEAqhHyZfSsYourNxaY\n' + const privateKey = 'MIIBVQIBADANBgkqhkiG9w0BAQEFAASCAT8wggE7AgEAAkEAnbAlNlYuctm5GmkA\n'+
'7Nt+PrgrxkiA50efORdI5U5lsW79MmFnusUA355oaSXcLhu5xxB38SMSyP2KvuKN\n' + '5692KWiJd9cTeL2sCvWsGDfWyPXECeF9G4MKGijreQzJkGJ96I5w0Kvj0Z47eP7s\n'+
'PuH3owIDAQABAkAfoiLyL+Z4lf4Myxk6xUDgLaWGximj20CUf+5BKKnlrK+Ed8gA\n' + '2Vj7IwIDAQABAkEAgbPrR+BnYEy5toF8HxXx6Wl0+T/NYlkQ9ArTPTBg2PYTXSvT\n'+
'kM0HqoTt2UZwA5E2MzS4EI2gjfQhz5X28uqxAiEA3wNFxfrCZlSZHb0gn2zDpWow\n' + 'LoJqrWss688w7WIwUz5lyVKKeRFWkxe9T4RIUQIhAM6BMCzJybFtAszEgBBDdtxj\n'+
'cSxQAgiCstxGUoOqlW8CIQDDOerGKH5OmCJ4Z21v+F25WaHYPxCFMvwxpcw99Ecv\n' + 'eDiXAk3zcsqcltHE/i/PAiEAw3ulbhgLYnXJIfymCsMgnyrESOyQxKDhQOm2Pnj/\n'+
'DQIgIdhDTIqD2jfYjPTY8Jj3EDGPbH2HHuffvflECt3Ek60CIQCFRlCkHpi7hthh\n' + 'YG0CICx9Corroic2S/8falOWpTnPuCvA5L80bouV9qwUm4pjAiEAkJ4U0NHw+jJx\n'+
'YhovyloRYsM+IS9h/0BzlEAuO0ktMQIgSPT3aFAgJYwKpqRYKlLDVcflZFCKY7u3\n' + 'Tjd/D08z/wzAkcKRhyYN/tvn+2fAZjECICkVQ6VWohPiibqIdVffCwXK3jSi5SJ3\n'+
'UP8iWi1Qw0Y=' 'ddcmzYQBJFLv'
// 加密 // 加密
export function encrypt(txt) { export function encrypt(txt) {

@ -63,6 +63,9 @@
// import tabContent from "./components/algorithmTime" // import tabContent from "./components/algorithmTime"
import { getEventLogs } from "@/api/platform/index" import { getEventLogs } from "@/api/platform/index"
import { mapState, mapGetters } from 'vuex' import { mapState, mapGetters } from 'vuex'
import { login } from "@/api/eventPage"
import { setToken } from '@/utils/auth'
import { encrypt } from '@/utils/jsencrypt'
export default { export default {
// components:{ // components:{
// tabContent // tabContent
@ -89,9 +92,12 @@ export default {
...mapGetters(['debugTime']), ...mapGetters(['debugTime']),
}, },
mounted() { mounted() {
login("admin",encrypt("Suanfa@2024//**...")).then(res=>{
setToken(res.token)
this.getList(); this.getList();
this.cancalDebounce(); this.cancalDebounce();
window.addEventListener('resize', this.cancalDebounce); window.addEventListener('resize', this.cancalDebounce);
})
}, },
destroyed() { destroyed() {
window.removeEventListener('resize', this.cancalDebounce); window.removeEventListener('resize', this.cancalDebounce);

@ -85,7 +85,9 @@ import "proj4";
import "proj4leaflet"; import "proj4leaflet";
import "@/utils/lib/leaflet.ChineseTmsProviders.js"; import "@/utils/lib/leaflet.ChineseTmsProviders.js";
import "@/utils/lib/leaflet.mapCorrection.min.js"; import "@/utils/lib/leaflet.mapCorrection.min.js";
import { new100Page, colonyPage } from "@/api/eventPage" import { new100Page, colonyPage, login } from "@/api/eventPage"
import { setToken } from '@/utils/auth'
import { encrypt } from '@/utils/jsencrypt'
import urgencyAudit from '@/views/components/urgencyAudit.vue' import urgencyAudit from '@/views/components/urgencyAudit.vue'
import EventAudit from '@/views/components/eventAudit.vue' import EventAudit from '@/views/components/eventAudit.vue'
export default { export default {
@ -147,10 +149,13 @@ export default {
} }
}, },
mounted() { mounted() {
login("admin",encrypt("Suanfa@2024//**...")).then(res=>{
setToken(res.token)
this.$nextTick(() => { this.$nextTick(() => {
this.initMap(); this.initMap();
}); });
this.getList(); this.getList();
})
}, },
methods:{ methods:{
mountedMethods(){ mountedMethods(){

@ -89,7 +89,9 @@
</div> </div>
</template> </template>
<script> <script>
import { colonyPage } from "@/api/eventPage" import { colonyPage, login } from "@/api/eventPage"
import { setToken } from '@/utils/auth'
import { encrypt } from '@/utils/jsencrypt'
import EventAudit from '@/views/components/eventAudit.vue' import EventAudit from '@/views/components/eventAudit.vue'
export default { export default {
components:{ components:{
@ -104,19 +106,7 @@ export default {
time:[], time:[],
}, },
loading: false, loading: false,
tableData: [ tableData: [],
{
title:"关于大阳山景区交通拥堵问题",
firstWarnTimeDate:"2024-08-29 09:00:20",
warnFactor:"大阳山景区、交通拥堵",
msgTypeName:"8条"
},{
title:"关于大阳山景区交通拥堵问题",
firstWarnTimeDate:"2024-08-29 09:00:20",
warnFactor:"大阳山景区、交通拥堵",
msgTypeName:"8条"
},
],
tabHeader: null, tabHeader: null,
total:0, total:0,
pagination: { pagination: {
@ -129,9 +119,12 @@ export default {
} }
}, },
mounted(){ mounted(){
login("admin",encrypt("Suanfa@2024//**...")).then(res=>{
setToken(res.token)
this.getList(); this.getList();
this.cancalDebounce(); this.cancalDebounce();
window.addEventListener('resize', this.cancalDebounce); window.addEventListener('resize', this.cancalDebounce);
})
}, },
destroyed() { destroyed() {
window.removeEventListener('resize', this.cancalDebounce); window.removeEventListener('resize', this.cancalDebounce);

@ -89,7 +89,9 @@
</div> </div>
</template> </template>
<script> <script>
import { colonyPage } from "@/api/eventPage" import { colonyPage, login } from "@/api/eventPage"
import { setToken } from '@/utils/auth'
import { encrypt } from '@/utils/jsencrypt'
import EventAudit from '@/views/components/eventAudit.vue' import EventAudit from '@/views/components/eventAudit.vue'
export default { export default {
components:{ components:{
@ -104,19 +106,7 @@ export default {
time:[], time:[],
}, },
loading: false, loading: false,
tableData: [ tableData: [],
{
title:"关于大阳山景区交通拥堵问题",
firstWarnTimeDate:"2024-08-29 09:00:20",
warnFactor:"大阳山景区、交通拥堵",
msgTypeName:"8条"
},{
title:"关于大阳山景区交通拥堵问题",
firstWarnTimeDate:"2024-08-29 09:00:20",
warnFactor:"大阳山景区、交通拥堵",
msgTypeName:"8条"
},
],
tabHeader: null, tabHeader: null,
total:0, total:0,
pagination: { pagination: {
@ -129,9 +119,12 @@ export default {
} }
}, },
mounted(){ mounted(){
login("admin",encrypt("Suanfa@2024//**...")).then(res=>{
setToken(res.token)
this.getList(); this.getList();
this.cancalDebounce(); this.cancalDebounce();
window.addEventListener('resize', this.cancalDebounce); window.addEventListener('resize', this.cancalDebounce);
})
}, },
destroyed() { destroyed() {
window.removeEventListener('resize', this.cancalDebounce); window.removeEventListener('resize', this.cancalDebounce);

@ -89,7 +89,9 @@
</div> </div>
</template> </template>
<script> <script>
import { colonyPage } from "@/api/eventPage" import { colonyPage, login } from "@/api/eventPage"
import { setToken } from '@/utils/auth'
import { encrypt } from '@/utils/jsencrypt'
import urgencyAudit from '@/views/components/urgencyAudit.vue' import urgencyAudit from '@/views/components/urgencyAudit.vue'
export default { export default {
components:{ components:{
@ -104,19 +106,7 @@ export default {
time:[], time:[],
}, },
loading: false, loading: false,
tableData: [ tableData: [],
{
title:"关于大阳山景区交通拥堵问题",
firstWarnTimeDate:"2024-08-29 09:00:20",
warnFactor:"大阳山景区、交通拥堵",
msgTypeName:"8条"
},{
title:"关于大阳山景区交通拥堵问题",
firstWarnTimeDate:"2024-08-29 09:00:20",
warnFactor:"大阳山景区、交通拥堵",
msgTypeName:"8条"
},
],
tabHeader: null, tabHeader: null,
total:0, total:0,
pagination: { pagination: {
@ -131,9 +121,12 @@ export default {
} }
}, },
mounted(){ mounted(){
login("admin",encrypt("Suanfa@2024//**...")).then(res=>{
setToken(res.token)
this.getList(); this.getList();
this.cancalDebounce(); this.cancalDebounce();
window.addEventListener('resize', this.cancalDebounce); window.addEventListener('resize', this.cancalDebounce);
})
}, },
destroyed() { destroyed() {
window.removeEventListener('resize', this.cancalDebounce); window.removeEventListener('resize', this.cancalDebounce);

@ -89,7 +89,9 @@
</div> </div>
</template> </template>
<script> <script>
import { colonyPage } from "@/api/eventPage" import { colonyPage, login } from "@/api/eventPage"
import { setToken } from '@/utils/auth'
import { encrypt } from '@/utils/jsencrypt'
import EventAudit from '@/views/components/eventAudit.vue' import EventAudit from '@/views/components/eventAudit.vue'
export default { export default {
components:{ components:{
@ -104,19 +106,7 @@ export default {
time:[], time:[],
}, },
loading: false, loading: false,
tableData: [ tableData: [],
{
title:"关于大阳山景区交通拥堵问题",
firstWarnTimeDate:"2024-08-29 09:00:20",
warnFactor:"大阳山景区、交通拥堵",
msgTypeName:"8条"
},{
title:"关于大阳山景区交通拥堵问题",
firstWarnTimeDate:"2024-08-29 09:00:20",
warnFactor:"大阳山景区、交通拥堵",
msgTypeName:"8条"
},
],
tabHeader: null, tabHeader: null,
total:0, total:0,
pagination: { pagination: {
@ -129,9 +119,12 @@ export default {
} }
}, },
mounted(){ mounted(){
login("admin",encrypt("Suanfa@2024//**...")).then(res=>{
setToken(res.token)
this.getList(); this.getList();
this.cancalDebounce(); this.cancalDebounce();
window.addEventListener('resize', this.cancalDebounce); window.addEventListener('resize', this.cancalDebounce);
})
}, },
destroyed() { destroyed() {
window.removeEventListener('resize', this.cancalDebounce); window.removeEventListener('resize', this.cancalDebounce);

@ -89,7 +89,9 @@
</div> </div>
</template> </template>
<script> <script>
import { colonyPage } from "@/api/eventPage" import { colonyPage, login } from "@/api/eventPage"
import { setToken } from '@/utils/auth'
import { encrypt } from '@/utils/jsencrypt'
import EventAudit from '@/views/components/eventAudit.vue' import EventAudit from '@/views/components/eventAudit.vue'
export default { export default {
components:{ components:{
@ -104,19 +106,7 @@ export default {
time:[], time:[],
}, },
loading: false, loading: false,
tableData: [ tableData: [],
{
title:"关于大阳山景区交通拥堵问题",
firstWarnTimeDate:"2024-08-29 09:00:20",
warnFactor:"大阳山景区、交通拥堵",
msgTypeName:"8条"
},{
title:"关于大阳山景区交通拥堵问题",
firstWarnTimeDate:"2024-08-29 09:00:20",
warnFactor:"大阳山景区、交通拥堵",
msgTypeName:"8条"
},
],
tabHeader: null, tabHeader: null,
total:0, total:0,
pagination: { pagination: {
@ -129,9 +119,12 @@ export default {
} }
}, },
mounted(){ mounted(){
login("admin",encrypt("Suanfa@2024//**...")).then(res=>{
setToken(res.token)
this.getList(); this.getList();
this.cancalDebounce(); this.cancalDebounce();
window.addEventListener('resize', this.cancalDebounce); window.addEventListener('resize', this.cancalDebounce);
})
}, },
destroyed() { destroyed() {
window.removeEventListener('resize', this.cancalDebounce); window.removeEventListener('resize', this.cancalDebounce);

@ -82,7 +82,9 @@
</div> </div>
</template> </template>
<script> <script>
import { colonyEventPage } from "@/api/eventPage" import { colonyEventPage, login } from "@/api/eventPage"
import { setToken } from '@/utils/auth'
import { encrypt } from '@/utils/jsencrypt'
import relevancyEventAudit from '@/views/components/relevancyEventAudit.vue' import relevancyEventAudit from '@/views/components/relevancyEventAudit.vue'
export default { export default {
components:{ components:{
@ -109,9 +111,12 @@ export default {
} }
}, },
mounted(){ mounted(){
login("admin",encrypt("Suanfa@2024//**...")).then(res=>{
setToken(res.token)
this.getList(); this.getList();
this.cancalDebounce(); this.cancalDebounce();
window.addEventListener('resize', this.cancalDebounce); window.addEventListener('resize', this.cancalDebounce);
})
}, },
destroyed() { destroyed() {
window.removeEventListener('resize', this.cancalDebounce); window.removeEventListener('resize', this.cancalDebounce);

Loading…
Cancel
Save