11
main
boy_yan 2 years ago
parent 499cb76d99
commit ee593dd12e

@ -1,4 +1,10 @@
import { createRouter, createWebHashHistory } from 'vue-router' import { createRouter, createWebHashHistory } from 'vue-router'
import {
usePinia
} from '@/stores/index.js'
import { ref, watch } from 'vue';
import Login from '../views/Login.vue' import Login from '../views/Login.vue'
import Index from '../views/Index.vue' import Index from '../views/Index.vue'
import MenuList from '../views/SystemMngr/Menu/List.vue' import MenuList from '../views/SystemMngr/Menu/List.vue'
@ -6,9 +12,10 @@ import AdminGroupList from '../views/SystemMngr/Group/List.vue'
import AdminUserList from '../views/SystemMngr/User/List.vue' import AdminUserList from '../views/SystemMngr/User/List.vue'
import AdminChangPwd from '../views/SystemMngr/User/ChangPwd.vue' import AdminChangPwd from '../views/SystemMngr/User/ChangPwd.vue'
import HealthCalendar from '../views/AppointmentMngr/HealthCalendar.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' import Dashboard from '../views/MedicalCenter/Dashboard.vue'
const router = createRouter({ const router = createRouter({
history: createWebHashHistory(import.meta.env.BASE_URL), history: createWebHashHistory(import.meta.env.BASE_URL),
routes: [ routes: [
@ -16,75 +23,82 @@ const router = createRouter({
path: '/', path: '/',
name: 'login1', name: 'login1',
component: Login component: Login
},{ }, {
path: '/login', path: '/login',
name: 'Login', name: 'Login',
component: Login component: Login
},{ }, {
path: '/index', path: '/index',
name: 'Index', name: 'Index',
component: Index, component: Index,
children:[{ children: [{
path: '/dashboard', path: '/dashboard',
name: 'Dashboard', name: 'Dashboard',
component: Dashboard, component: Dashboard,
meta: {title: '数据面板'} meta: { title: '数据面板' }
},{ }, {
path: '/menuList', path: '/menuList',
name: 'menuList', name: 'menuList',
component: MenuList, component: MenuList,
meta: {title: '菜单管理'} meta: { title: '菜单管理' }
},{ }, {
path: '/groupMngr', path: '/groupMngr',
name: 'AdminGroupList', name: 'AdminGroupList',
component: AdminGroupList, component: AdminGroupList,
meta: {title: '组管理'} meta: { title: '组管理' }
},{ }, {
path: '/adminUserList', path: '/adminUserList',
name: 'AdminUserList', name: 'AdminUserList',
component: AdminUserList, component: AdminUserList,
meta: {title: '系统用户管理'} meta: { title: '系统用户管理' }
},{ }, {
path: '/adminChangPwd', path: '/adminChangPwd',
name: 'AdminChangPwd', name: 'AdminChangPwd',
component: AdminChangPwd, component: AdminChangPwd,
meta: {title: '修改密码'} meta: { title: '修改密码' }
},{ }, {
path: '/healthCalendar', path: '/healthCalendar',
name: 'HealthCalendar', name: 'HealthCalendar',
component: HealthCalendar, component: HealthCalendar,
meta: {title: '体检日历'} meta: { title: '体检日历' }
},{ }, {
path: '/healthCheckList', path: '/healthCheckList',
name: 'HealthCheckList', name: 'HealthCheckList',
component: HealthCheckList, component: healthCheckList,
meta: {title: '体检记录列表'} 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')
// }
] ]
}) })
// 动态添加额外的路由 // 动态添加额外的路由
function addDynamicRoutes() { function addDynamicRoutes(list) {
// 通过某种条件判断是否需要添加额外的路由 // 通过某种条件判断是否需要添加额外的路由
if (1) { // list.forEach(function(v,i){
//console.log(v.url)
router.addRoute({ router.addRoute({
path: '/dynamic', path: '/a',
name: 'Dynamic', name: 'a',
component: Login 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 export default router

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

Loading…
Cancel
Save