useAlarmScope.js 887 B

123456789101112131415161718
  1. import { computed } from 'vue'
  2. import { useRoute, useRouter } from 'vue-router'
  3. import usePermissionStore from '@/store/modules/permission'
  4. import { ElMessage } from 'element-plus'
  5. import { scopeFromRoute, findAlarmMenu } from './alarmOperationsModel'
  6. export function useAlarmScope() {
  7. const route = useRoute(), router = useRouter(), permissions = usePermissionStore()
  8. const scope = computed(() => scopeFromRoute(route.query))
  9. const scopeKey = computed(() => JSON.stringify(scope.value))
  10. const menu = leaf => findAlarmMenu(permissions.sidebarRouters, leaf, scope.value.rootTypeId)
  11. const navigate = (leaf, extra = {}) => {
  12. const target = menu(leaf)
  13. if (!target) return ElMessage.warning('当前账号未配置该功能菜单')
  14. return router.push({ path: target.path, query: { ...target.query, ...extra } })
  15. }
  16. return { scope, scopeKey, route, menu, navigate }
  17. }