main
ts 71 lines 2.03 KB
Raw
1 import type { RouteLocationRaw } from "vue-router"
2 import { useRouter } from "vue-router"
3
4 export function useNavigation() {
5 const router = useRouter()
6
7 function routerConstructor(route: RouteLocationRaw) {
8 return {
9 navigate: () => router.push(route),
10 replace: () => router.replace(route),
11 valueOf: () => router.resolve(route).href,
12 toString: () => router.resolve(route).href,
13 fullUrl: () => {
14 const resolved = router.resolve(route)
15 return `${window.location.protocol}//${window.location.host}${resolved.href}`
16 }
17 }
18 }
19
20 function routeEventSearch(params?: { customer_code?: string; source_name?: string; query?: string }) {
21 const routeQuery: Record<string, string> = {}
22 if (params?.customer_code) routeQuery.customer_code = params.customer_code
23 if (params?.source_name) routeQuery.source_name = params.source_name
24 if (params?.query) routeQuery.query = params.query
25 return routerConstructor({ name: "EventSearch", query: routeQuery })
26 }
27
28 function routeAlertsList() {
29 return routerConstructor({ name: "AlertsList" })
30 }
31
32 function routeAlertDetails(alertId: number) {
33 return routerConstructor({ name: "AlertDetails", params: { id: alertId.toString() } })
34 }
35
36 function routeCasesList() {
37 return routerConstructor({ name: "CasesList" })
38 }
39
40 function routeCaseDetails(caseId: number) {
41 return routerConstructor({ name: "CaseDetails", params: { id: caseId.toString() } })
42 }
43
44 function routeDashboardsList() {
45 return routerConstructor({ name: "DashboardsList" })
46 }
47
48 function routeDashboardViewer(dashboardId: number) {
49 return routerConstructor({ name: "DashboardView", params: { id: dashboardId.toString() } })
50 }
51
52 function routeAgentsList() {
53 return routerConstructor({ name: "AgentsList" })
54 }
55
56 function routeAgentDetails(agentId: string) {
57 return routerConstructor({ name: "AgentDetails", params: { id: agentId } })
58 }
59
60 return {
61 routeEventSearch,
62 routeAlertsList,
63 routeAlertDetails,
64 routeCasesList,
65 routeCaseDetails,
66 routeDashboardsList,
67 routeDashboardViewer,
68 routeAgentsList,
69 routeAgentDetails
70 }
71 }