Browse Source

增加路由守卫

pull/14/head
zq 1 month ago
parent
commit
642af783aa
  1. 28
      src/router/index.js
  2. 21
      src/views/HomeView.vue
  3. 13
      src/views/hospitalManage.vue

28
src/router/index.js

@ -34,7 +34,8 @@ const routes = [
}, },
meta: { meta: {
title: '医院管理', title: '医院管理',
hideBreadcrumb: true // 首页不显示面包屑 hideBreadcrumb: true, // 首页不显示面包屑
requiresAuth:true
} }
}, },
{ {
@ -62,9 +63,6 @@ const routes = [
meta: { meta: {
title: '编辑医院', title: '编辑医院',
breadcrumbParent: '医生信息' // 手动指定父级 breadcrumbParent: '医生信息' // 手动指定父级
// r如果想隐藏中间层级
// breadcrumbParent: '首页', // 跳过医生信息
// hideInBreadcrumb: true // 可选:隐藏当前项
} }
}, },
{ {
@ -74,9 +72,6 @@ const routes = [
meta: { meta: {
title: '微信收款', title: '微信收款',
breadcrumbParent: '编辑医院' // 手动指定父级 breadcrumbParent: '编辑医院' // 手动指定父级
// r如果想隐藏中间层级
// breadcrumbParent: '首页', // 跳过医生信息
// hideInBreadcrumb: true // 可选:隐藏当前项
} }
}, },
@ -103,7 +98,8 @@ const routes = [
name: '收款方式', name: '收款方式',
meta: { meta: {
title: '收款管理', title: '收款管理',
hideBreadcrumb: true // 首页不显示面包屑 hideBreadcrumb: true, // 首页不显示面包屑
requiresAuth:true
} }
}, },
] ]
@ -113,7 +109,22 @@ const router = new VueRouter({
base: process.env.BASE_URL, base: process.env.BASE_URL,
routes routes
}) })
router.beforeEach((to, from, next) => { router.beforeEach((to, from, next) => {
// 检查本地存储是否有nick
const hasNick = localStorage.getItem('nick');
// 如果有nick且访问的是根路径,则重定向到/hospitalManage
if (hasNick && to.path === '/') {
next('/hospitalManage');
return;
}
// 如果没有nick且尝试访问需要认证的页面(如/hospitalManage),则重定向到首页
if (!hasNick && to.meta.requiresAuth) {
next('/');
return;
}
if (whiteSlideList.includes(to.path)) { if (whiteSlideList.includes(to.path)) {
store.commit('SET_SIDEBAR', true); // 登录页面不显示侧边栏 store.commit('SET_SIDEBAR', true); // 登录页面不显示侧边栏
} else { } else {
@ -129,6 +140,7 @@ router.beforeEach((to, from, next) => {
} else { } else {
store.commit('SET_HEADER', true); // 其他页面显示顶部 store.commit('SET_HEADER', true); // 其他页面显示顶部
} }
next(); next();
}); });

21
src/views/HomeView.vue

@ -17,7 +17,7 @@
批量启用</GuipButton> 批量启用</GuipButton>
</div> </div>
<div class="right" v-if="onlyHosFlag"> <div class="right" v-if="onlyHosFlag">
<GuipButton type="system" size="form" @click="addHospital(item)">添加医院</GuipButton> <GuipButton type="system" size="form" @click="addHospitalUser">添加医院</GuipButton>
</div> </div>
<div class="right flex" v-else> <div class="right flex" v-else>
<span>搜索医生</span> <span>搜索医生</span>
@ -176,6 +176,8 @@ export default {
store.commit('SET_CUSTOMIZE', false); store.commit('SET_CUSTOMIZE', false);
store.commit('SET_SLIDER_MENU', 'menuData'); store.commit('SET_SLIDER_MENU', 'menuData');
this.getInitData() this.getInitData()
if(this.onlyHosFlag)return
// --
this.getBindpayList() this.getBindpayList()
}, },
computed: { computed: {
@ -183,8 +185,8 @@ export default {
}, },
methods: { methods: {
// //
getInitData() { async getInitData() {
this.$http('POST', '/api/admin/doctor_depart_list', { await this.$http('POST', '/api/admin/doctor_depart_list', {
name: this.doctorName name: this.doctorName
}).then(response => { }).then(response => {
if (response.code == 0) { if (response.code == 0) {
@ -209,7 +211,6 @@ export default {
depart_id: 4 depart_id: 4
}).then(response => { }).then(response => {
this.payList.push(...response.data[2],...response.data[3]) this.payList.push(...response.data[2],...response.data[3])
console.log(this.payList,response,'this.payList====00000');
}).catch(error => { }).catch(error => {
console.error(error, 'error') console.error(error, 'error')
}) })
@ -294,7 +295,7 @@ export default {
}) })
}, },
onSwitchChange1(row) { onSwitchChange1(row) {
console.log(row, '------flag'); // console.log(row, '------flag');
row.status = row.status == 0 ? 1 : 0; row.status = row.status == 0 ? 1 : 0;
this.$http('POST', '/api/admin/depart_mutil_option', { this.$http('POST', '/api/admin/depart_mutil_option', {
depart_index_ids:row.id, depart_index_ids:row.id,
@ -314,7 +315,7 @@ export default {
this.$set(this.doctorList, row) this.$set(this.doctorList, row)
}, },
batchOperate(status) { batchOperate(status) {
console.log(this.tableSelections,'this.tableSelections----'); // console.log(this.tableSelections,'this.tableSelections----');
if(!this.tableSelections || this.tableSelections.length <= 0) { if(!this.tableSelections || this.tableSelections.length <= 0) {
this.$message.error('未选择要'+(status == '0' ? '禁用':'启用')+'的科室') this.$message.error('未选择要'+(status == '0' ? '禁用':'启用')+'的科室')
return; return;
@ -386,6 +387,14 @@ export default {
query: { doctor_id: item.id } query: { doctor_id: item.id }
}) })
}, },
addHospitalUser(){
// id token
let id = this.doctor_id;
this.$router.push({
name: '医院信息',
query: { doctor_id: id }
})
},
editDoctor(item) { editDoctor(item) {
this.$router.push({ this.$router.push({
name: '医生信息', name: '医生信息',

13
src/views/hospitalManage.vue

@ -1,13 +0,0 @@
<template>
<div>
<el-form>
</el-form>
</div>
</template>
<script>
</script>
<style>
</style>
Loading…
Cancel
Save