Merge branch 'dev' of github.com:jetlinks/jetlinks-ui-vue into dev
This commit is contained in:
commit
9fd6044e56
|
|
@ -14,56 +14,45 @@ const router = createRouter({
|
|||
}
|
||||
})
|
||||
|
||||
const filterPath = [
|
||||
'/form',
|
||||
'/search'
|
||||
]
|
||||
|
||||
router.beforeEach((to, from, next) => {
|
||||
// TODO 切换路由取消请求
|
||||
const isFilterPath = filterPath.includes(to.path)
|
||||
if (isFilterPath) {
|
||||
next()
|
||||
} else {
|
||||
const token = getToken()
|
||||
if (token) {
|
||||
if (to.path === LoginPath) {
|
||||
next({ path: '/' })
|
||||
} else {
|
||||
const userInfo = useUserInfo()
|
||||
const system = useSystem()
|
||||
const menu = useMenuStore()
|
||||
|
||||
if (!menu.siderMenus.length) {
|
||||
userInfo.getUserInfo().then(() => {
|
||||
system.getSystemVersion().then((menuData: any[]) => {
|
||||
menuData.forEach(r => {
|
||||
router.addRoute('base', r)
|
||||
})
|
||||
// router.addRoute('base',{
|
||||
// path: '/:pathMatch(.*)',
|
||||
// name: 'error',
|
||||
// component: () => NotFindPage
|
||||
// })
|
||||
|
||||
next({ ...to, replace: true })
|
||||
})
|
||||
}).catch(() => {
|
||||
cleanToken()
|
||||
next({ path: LoginPath })
|
||||
})
|
||||
} else {
|
||||
next()
|
||||
}
|
||||
}
|
||||
|
||||
const token = getToken()
|
||||
if (token) {
|
||||
if (to.path === LoginPath) {
|
||||
next({ path: '/' })
|
||||
} else {
|
||||
if (to.path === LoginPath) {
|
||||
next()
|
||||
const userInfo = useUserInfo()
|
||||
const system = useSystem()
|
||||
const menu = useMenuStore()
|
||||
if (!menu.siderMenus.length) {
|
||||
userInfo.getUserInfo().then(() => {
|
||||
system.getSystemVersion().then((menuData: any[]) => {
|
||||
menuData.forEach(r => {
|
||||
router.addRoute('base', r)
|
||||
})
|
||||
router.addRoute('base',{
|
||||
path: '/:pathMatch(.*)',
|
||||
name: 'error',
|
||||
component: () => NotFindPage
|
||||
})
|
||||
|
||||
next({ ...to, replace: true })
|
||||
})
|
||||
}).catch(() => {
|
||||
cleanToken()
|
||||
next({ path: LoginPath })
|
||||
})
|
||||
} else {
|
||||
next({ path: LoginPath })
|
||||
next()
|
||||
}
|
||||
}
|
||||
|
||||
} else {
|
||||
if (to.path === LoginPath) {
|
||||
next()
|
||||
} else {
|
||||
next({ path: LoginPath })
|
||||
}
|
||||
}
|
||||
})
|
||||
|
||||
|
|
|
|||
|
|
@ -36,54 +36,60 @@ type MenuStateType = {
|
|||
siderMenus: MenuItem[]
|
||||
}
|
||||
|
||||
// export const useMenusStore = defineStore('menu', () => {
|
||||
// const state = reactive<MenuStateType>({
|
||||
// menus: {},
|
||||
// siderMenus: []
|
||||
// })
|
||||
//
|
||||
// const hasPermission = (code: string | string[]) => {
|
||||
// if (!code || !(code as string[]).length) {
|
||||
// console.warn(`function hasPermission: 没有传入${code}`)
|
||||
// return false
|
||||
// }
|
||||
//
|
||||
// }
|
||||
//
|
||||
// const queryMenuTree = (): Promise<any[]> => {
|
||||
//
|
||||
// }
|
||||
//
|
||||
// return {
|
||||
// state,
|
||||
// hasPermission,
|
||||
// queryMenuTree
|
||||
// }
|
||||
// })
|
||||
|
||||
export const useMenuStore = defineStore({
|
||||
id: 'menu',
|
||||
state: () => ({
|
||||
state: (): MenuStateType => ({
|
||||
menus: {},
|
||||
siderMenus: []
|
||||
}),
|
||||
getters: {
|
||||
hasPermission(state) {
|
||||
return (menuCode: string | string[]) => {
|
||||
if (!menuCode) {
|
||||
return (code: string | string[]) => {
|
||||
if (!code) {
|
||||
return true
|
||||
}
|
||||
if (!!Object.keys(state.menus).length) {
|
||||
if (typeof menuCode === 'string') {
|
||||
return !!this.menus[menuCode].buttons
|
||||
let codes: string[] = []
|
||||
|
||||
if (typeof code === 'string') {
|
||||
codes.push(code)
|
||||
} else {
|
||||
codes = code
|
||||
}
|
||||
return menuCode.some(code => !!this.menus[code])
|
||||
|
||||
return codes.some(_c => {
|
||||
const menu_code = _c.split(':')
|
||||
if (menu_code.length > 1) {
|
||||
return !!this.menus[menu_code[0]]?.buttons?.includes(menu_code[1])
|
||||
}
|
||||
return false
|
||||
})
|
||||
}
|
||||
return false
|
||||
}
|
||||
}
|
||||
},
|
||||
actions: {
|
||||
hasMenu(code: string) {
|
||||
return this.menus[code]?.path
|
||||
},
|
||||
/**
|
||||
* 路由跳转
|
||||
* @param name 菜单code
|
||||
* @param params 路由参数
|
||||
* @param query 路由参数
|
||||
*/
|
||||
jumpPage(name: string, params?: Record<string, any>, query?: Record<string, any>) {
|
||||
const path = this.hasMenu(name)
|
||||
if (path) {
|
||||
router.push({
|
||||
name, params, query
|
||||
})
|
||||
} else {
|
||||
console.warn(`没有找到对应的页面: ${name}`)
|
||||
}
|
||||
},
|
||||
queryMenuTree(isCommunity = false): Promise<any[]> {
|
||||
return new Promise(async (res) => {
|
||||
//过滤非集成的菜单
|
||||
|
|
@ -94,11 +100,11 @@ export const useMenuStore = defineStore({
|
|||
const handleMenuItem = (menu: any) => {
|
||||
if (isArray(menu)) {
|
||||
menu.forEach(menuItem => {
|
||||
this.menus[menuItem.code] = {
|
||||
this.menus[menuItem.name] = {
|
||||
path: menuItem.path,
|
||||
buttons: menuItem.buttons
|
||||
buttons: menuItem.meta.buttons
|
||||
}
|
||||
if (menuItem.children && menuItem.length) {
|
||||
if (menuItem.children && menuItem.children.length) {
|
||||
handleMenuItem(menuItem.children)
|
||||
}
|
||||
})
|
||||
|
|
@ -114,7 +120,7 @@ export const useMenuStore = defineStore({
|
|||
}
|
||||
})
|
||||
this.siderMenus = silderMenus
|
||||
console.log('silderMenus', silderMenus)
|
||||
console.log('menusData', menusData)
|
||||
res(menusData)
|
||||
}
|
||||
})
|
||||
|
|
|
|||
|
|
@ -95,30 +95,4 @@ export const modifySearchColumnValue = (e: any, column: object) => {
|
|||
});
|
||||
});
|
||||
return e;
|
||||
};
|
||||
|
||||
// /**
|
||||
// * 根据code返回对应的菜单path
|
||||
// * @param code 菜单code
|
||||
// */
|
||||
// export const getMenu = (code: string): string | undefined => {
|
||||
// const menuStore = useMenuStore()
|
||||
// return menuStore.menus[code]?.path
|
||||
// }
|
||||
//
|
||||
// /**
|
||||
// * 根据菜单code跳转对应路由
|
||||
// * @param code 菜单code
|
||||
// * @param params 路由params参数
|
||||
// * @param query 路由query参数
|
||||
// */
|
||||
// export const jumpPath = (code: string, params?: any, query?: any) => {
|
||||
// const path = getMenu(code)
|
||||
// if (path) {
|
||||
// router.push({
|
||||
// path, params, query
|
||||
// })
|
||||
// } else {
|
||||
// console.warn(`menus中没有${code}`)
|
||||
// }
|
||||
// }
|
||||
};
|
||||
|
|
@ -178,7 +178,7 @@ const findDetailRouteItem = (code: string, url: string): Partial<MenuItem> | nul
|
|||
const detailComponent = resolveComponent(`${code}/Detail`)
|
||||
if (detailComponent) {
|
||||
return {
|
||||
url: `${url}/Detail/:id`,
|
||||
url: `${url}/detail/:id`,
|
||||
code: `${code}/Detail`,
|
||||
component: detailComponent,
|
||||
name: '详情信息',
|
||||
|
|
@ -227,12 +227,13 @@ export function filterAsnycRouter(asyncRouterMap: any, parentCode = '', level =
|
|||
_route.children = _menusData
|
||||
silder.children = _silderMenus
|
||||
const showChildren = _route.children.some((r: any) => !r.meta.hideInMenu)
|
||||
if (showChildren) {
|
||||
|
||||
if (showChildren && _route.children.length) {
|
||||
_route.component = level === 1 ? BasicLayoutPage : BlankLayoutPage
|
||||
_route.redirect = route.children[0].url
|
||||
} else {
|
||||
const myComponent = resolveComponent(route.code)
|
||||
_route.component = myComponent ? myComponent : BlankLayoutPage;
|
||||
// _route.component = myComponent ? myComponent : BlankLayoutPage;
|
||||
if (!!myComponent) {
|
||||
_route.component = myComponent;
|
||||
_route.children.map((r: any) => menusData.push(r))
|
||||
|
|
|
|||
|
|
@ -151,12 +151,15 @@ import {
|
|||
import type { ActionsType } from '@/components/Table/index.vue';
|
||||
import { getImage } from '@/utils/comm';
|
||||
import { message } from 'ant-design-vue';
|
||||
import { useMenuStore } from 'store/menu'
|
||||
|
||||
const router = useRouter();
|
||||
const instanceRef = ref<Record<string, any>>({});
|
||||
const params = ref<Record<string, any>>({});
|
||||
const current = ref<Record<string, any>>({});
|
||||
|
||||
const menuStory = useMenuStore()
|
||||
|
||||
const statusMap = new Map();
|
||||
statusMap.set('enabled', 'success');
|
||||
statusMap.set('disabled', 'error');
|
||||
|
|
@ -209,19 +212,14 @@ const columns = [
|
|||
* 新增
|
||||
*/
|
||||
const handleAdd = () => {
|
||||
router.push('/iot/northbound/AliCloud/detail/:id');
|
||||
menuStory.jumpPage('Northbound/AliCloud/Detail', { id: ':id'})
|
||||
};
|
||||
|
||||
/**
|
||||
* 查看
|
||||
*/
|
||||
const handleView = (id: string) => {
|
||||
router.push({
|
||||
path: '/iot/northbound/AliCloud/detail/' + id,
|
||||
query: {
|
||||
type: 'view'
|
||||
}
|
||||
});
|
||||
menuStory.jumpPage('Northbound/AliCloud/Detail', { id }, { type: 'view'})
|
||||
};
|
||||
|
||||
const getActions = (
|
||||
|
|
@ -249,12 +247,7 @@ const getActions = (
|
|||
},
|
||||
icon: 'EditOutlined',
|
||||
onClick: () => {
|
||||
router.push({
|
||||
path: '/iot/northbound/AliCloud/detail/' + data.id,
|
||||
query: {
|
||||
type: 'edit'
|
||||
}
|
||||
});
|
||||
menuStory.jumpPage('Northbound/AliCloud/Detail', { id: data.id }, { type: 'edit'})
|
||||
},
|
||||
},
|
||||
{
|
||||
|
|
@ -147,11 +147,13 @@ import { query, _undeploy, _deploy, _delete, queryProductList, queryTypes } from
|
|||
import type { ActionsType } from '@/components/Table/index.vue';
|
||||
import { getImage } from '@/utils/comm';
|
||||
import { message } from 'ant-design-vue';
|
||||
import { useMenuStore } from 'store/menu'
|
||||
|
||||
const router = useRouter();
|
||||
const instanceRef = ref<Record<string, any>>({});
|
||||
const params = ref<Record<string, any>>({});
|
||||
const current = ref<Record<string, any>>({});
|
||||
const menuStory = useMenuStore()
|
||||
|
||||
const statusMap = new Map();
|
||||
statusMap.set('enabled', 'success');
|
||||
|
|
@ -236,20 +238,14 @@ const columns = [
|
|||
* 新增
|
||||
*/
|
||||
const handleAdd = () => {
|
||||
router.push('/iot/northbound/DuerOS/detail/:id');
|
||||
menuStory.jumpPage('Northbound/DuerOS/Detail', { id: ':id'})
|
||||
};
|
||||
|
||||
/**
|
||||
* 查看
|
||||
*/
|
||||
const handleView = (id: string) => {
|
||||
// router.push('/iot/northbound/DuerOS/detail/' + id);
|
||||
router.push({
|
||||
path: '/iot/northbound/DuerOS/detail/' + id,
|
||||
query: {
|
||||
type: 'view',
|
||||
},
|
||||
});
|
||||
menuStory.jumpPage('Northbound/DuerOS/Detail', { id }, { type: 'view' })
|
||||
};
|
||||
|
||||
const getActions = (
|
||||
|
|
@ -277,12 +273,7 @@ const getActions = (
|
|||
},
|
||||
icon: 'EditOutlined',
|
||||
onClick: () => {
|
||||
router.push({
|
||||
path: '/iot/northbound/DuerOS/detail/' + data.id,
|
||||
query: {
|
||||
type: 'edit',
|
||||
},
|
||||
});
|
||||
menuStory.jumpPage('Northbound/DuerOS/Detail', { id: data.id }, { type: 'edit' })
|
||||
},
|
||||
},
|
||||
{
|
||||
Loading…
Reference in New Issue