11
main
boy_yan 2 years ago
parent 499cb76d99
commit ee593dd12e

@ -1,4 +1,10 @@
import { createRouter, createWebHashHistory } from 'vue-router'
import {
usePinia
} from '@/stores/index.js'
import { ref, watch } from 'vue';
import Login from '../views/Login.vue'
import Index from '../views/Index.vue'
import MenuList from '../views/SystemMngr/Menu/List.vue'
@ -6,85 +12,93 @@ import AdminGroupList from '../views/SystemMngr/Group/List.vue'
import AdminUserList from '../views/SystemMngr/User/List.vue'
import AdminChangPwd from '../views/SystemMngr/User/ChangPwd.vue'
import HealthCalendar from '../views/AppointmentMngr/HealthCalendar.vue'
import HealthCheckList from '../views/MedicalCenter/HealthCheckList.vue'
import healthCheckList from '../views/MedicalCenter/HealthCheckList.vue'
import Dashboard from '../views/MedicalCenter/Dashboard.vue'
const router = createRouter({
history: createWebHashHistory(import.meta.env.BASE_URL),
routes: [
{
path: '/',
name: 'login1',
component: Login
},{
path: '/login',
name: 'Login',
component: Login
},{
path: '/index',
name: 'Index',
component: Index,
children:[{
path: '/dashboard',
name: 'Dashboard',
component: Dashboard,
meta: {title: '数据面板'}
},{
path: '/menuList',
name: 'menuList',
component: MenuList,
meta: {title: '菜单管理'}
},{
path: '/groupMngr',
name: 'AdminGroupList',
component: AdminGroupList,
meta: {title: '组管理'}
},{
path: '/adminUserList',
name: 'AdminUserList',
component: AdminUserList,
meta: {title: '系统用户管理'}
},{
path: '/adminChangPwd',
name: 'AdminChangPwd',
component: AdminChangPwd,
meta: {title: '修改密码'}
},{
path: '/healthCalendar',
name: 'HealthCalendar',
component: HealthCalendar,
meta: {title: '体检日历'}
},{
path: '/healthCheckList',
name: 'HealthCheckList',
component: HealthCheckList,
meta: {title: '体检记录列表'}
}]
},
// {
// path: '/about',
// name: 'about',
// // route level code-splitting
// // this generates a separate chunk (About.[hash].js) for this route
// // which is lazy-loaded when the route is visited.
// component: () => import('../views/AboutView.vue')
// }
]
history: createWebHashHistory(import.meta.env.BASE_URL),
routes: [
{
path: '/',
name: 'login1',
component: Login
}, {
path: '/login',
name: 'Login',
component: Login
}, {
path: '/index',
name: 'Index',
component: Index,
children: [{
path: '/dashboard',
name: 'Dashboard',
component: Dashboard,
meta: { title: '数据面板' }
}, {
path: '/menuList',
name: 'menuList',
component: MenuList,
meta: { title: '菜单管理' }
}, {
path: '/groupMngr',
name: 'AdminGroupList',
component: AdminGroupList,
meta: { title: '组管理' }
}, {
path: '/adminUserList',
name: 'AdminUserList',
component: AdminUserList,
meta: { title: '系统用户管理' }
}, {
path: '/adminChangPwd',
name: 'AdminChangPwd',
component: AdminChangPwd,
meta: { title: '修改密码' }
}, {
path: '/healthCalendar',
name: 'HealthCalendar',
component: HealthCalendar,
meta: { title: '体检日历' }
}, {
path: '/healthCheckList',
name: 'HealthCheckList',
component: healthCheckList,
meta: { title: '体检记录列表' }
}]
},
]
})
// 动态添加额外的路由
function addDynamicRoutes() {
// 动态添加额外的路由
function addDynamicRoutes(list) {
// 通过某种条件判断是否需要添加额外的路由
if (1) {
router.addRoute({
path: '/dynamic',
name: 'Dynamic',
component: Login
})
}
}
// list.forEach(function(v,i){
//console.log(v.url)
router.addRoute({
path: '/a',
name: 'a',
component: HealthCalendar
})
// })
addDynamicRoutes()
}
let pinia
router.beforeEach(async (to, from) => {
pinia = usePinia()
console.log(pinia.userMenu)
watch(() => pinia.userMenu, (newValue, oldValue) => {
console.log('值发生变化', newValue);
addDynamicRoutes(newValue)
});
})
export default router

@ -2,15 +2,17 @@ import { ref, computed } from 'vue'
import { defineStore } from 'pinia'
export const usePinia = defineStore('usePinia', () => {
const count = ref(0)
//主题
const theme=ref('light')
const doubleCount = computed(() => count.value * 2)
function increment() {
count.value++
}
const themeChange=(v)=>{
theme.value=v
}
return { theme,themeChange,count, doubleCount, increment }
//用户菜单
const userMenu=ref([])
const setUserMenu=(v)=>{
userMenu.value=v
}
return { theme,themeChange,userMenu,setUserMenu}
})

@ -41,13 +41,13 @@
<script setup>
import {
Login
Login,GetAdminBaseMenuList
} from "@/api/api.js";
import {
ElMessage
} from 'element-plus'
import {
ref
ref,watch,onMounted
} from 'vue'
import { Lock, User } from '@element-plus/icons-vue'
import {
@ -56,15 +56,25 @@
import {
useDark
} from "@vueuse/core";
import {
usePinia
} from '@/stores/index.js'
const pinia=usePinia()
const isDark = useDark()
const toggleDark = () => useToggle(isDark)
let username = ref('')
let pwd = ref('')
let GetMenu=()=>{
GetAdminBaseMenuList().then(res=>{
// console.log(res)
pinia.setUserMenu(res.list)
console.log(pinia.userMenu)
// })
})
}
let login = () => { //
if (username.value == '' || pwd.value == '') return ElMessage.error('用户名和密码不能为空')
let data = { //
@ -73,20 +83,28 @@
}
//
Login(data).then(res => {
if (res.data.status == 'ok') {
sessionStorage.setItem('token', res.data.token);
sessionStorage.setItem('refreshToken', res.data.refresh_token);
// sessionStorage.setItem('tk', JSON.stringify(res.data.tk));
var token = sessionStorage.getItem('token');
if (token == res.data.token) {
window.location.href = "./#/dashboard"
GetMenu()
//window.location.href = "./#/dashboard"
}
} else {
ElMessage.error(res.data.msg)
}
})
}
</script>
<style scoped>

Loading…
Cancel
Save