apkt-eis/src/router/index.ts
2023-11-01 13:37:11 +07:00

703 lines
20 KiB
TypeScript

import { createRouter, createWebHistory, type RouteRecordRaw } from 'vue-router'
import { useAuthStore } from '@/stores/auth'
import HomeView from '@/views/HomeView.vue'
import TestView from '@/views/TestView.vue'
import LoginView from '@/views/LoginView.vue'
import NotFoundView from '@/views/NotFoundView.vue'
import WelcomePage from '@/components/Pages/Welcome.vue'
import EmptyPage from '@/components/Pages/EmptyPage.vue'
import qs from 'qs'
import {
GangguanTable1,
GangguanTable2,
GangguanTable3,
GangguanTable4,
GangguanTable5,
GangguanTable6,
GangguanTable7,
GangguanTable8,
GangguanTable9,
GangguanTable10,
GangguanTable11,
GangguanTable12,
GangguanTable13,
GangguanTable14,
GangguanTable15,
GangguanTable16,
GangguanTable17,
GangguanTable18,
GangguanTable19,
GangguanTable20,
} from '@/components/Pages/Gangguan'
import {
KeluhanTable1,
KeluhanTable2,
KeluhanTable3,
KeluhanTable4,
KeluhanTable5,
KeluhanTable6,
KeluhanTable7,
KeluhanTable8,
KeluhanTable9,
KeluhanTable10,
KeluhanTable11,
KeluhanTable12,
KeluhanTable13,
KeluhanTable14,
KeluhanTable15,
} from '@/components/Pages/Keluhan'
export const routes: RouteRecordRaw[] = [
{
path: '/home',
name: 'Home',
component: HomeView,
children: [
{
path: '',
name: 'Home Page',
component: WelcomePage,
},
{
path: 'gangguan',
name: 'Gangguan',
children: [
{
path: 'daftar',
name: 'Daftar',
children: [
{
path: '1',
name: 'Daftar Keluhan Dialihkan Ke Posko Lain | type-1 | sa',
component: GangguanTable1,
props: true
},
{
path: '2',
name: 'Daftar Gangguan Melapor Lebih Dari 1 Kali',
component: GangguanTable2,
},
{
path: '3',
name: 'Daftar Gangguan Response Time',
component: GangguanTable3,
},
{
path: '4',
name: 'Daftar Gangguan Recovery Time',
component: GangguanTable4,
},
{
path: '5',
name: 'Daftar Gangguan Selesai Tanpa ID Pelanggan',
component: GangguanTable5,
},
{
path: '6',
name: 'Daftar Gangguan Berdasarkan Media',
component: GangguanTable6,
},
{
path: '7',
name: 'Daftar Gangguan Diselesaikan Mobile APKT',
component: GangguanTable7,
},
],
},
{
path: 'rekapitulasi',
name: 'Rekapitulasi',
children: [
{
path: '1',
name: 'Rekapitulasi Gangguan All',
component: GangguanTable8,
},
{
path: '2',
name: 'Rekapitulasi Gangguan/Jenis Gangguan',
component: GangguanTable9,
},
{
path: '3',
name: 'Rekapitulasi Gangguan/Jenis Gangguan SE 004',
component: GangguanTable10,
},
{
path: '4',
name: 'Rekapitulasi Gangguan Per Posko',
component: GangguanTable11,
},
{
path: '5',
name: 'Rekapitulasi Gangguan Per Regu',
component: GangguanTable12,
},
{
path: '6',
name: 'Rekapitulasi Gangguan Per Tanggal',
component: GangguanTable13,
},
{
path: '7',
name: 'Rekapitulasi Gangguan Berdasarkan Media',
component: GangguanTable14,
},
{
path: '8',
name: 'Rekapitulasi Gangguan Alih Posko',
component: GangguanTable15,
},
{
path: '9',
name: 'Rekapitulasi Gangguan Diselesaikan Mobile APKT',
component: GangguanTable16,
},
{
path: '10',
name: 'Rekapitulasi Rating Per Posko',
component: GangguanTable17,
},
{
path: '11',
name: 'Rekapitulasi Rating Per Regu',
component: GangguanTable18,
},
{
path: '12',
name: 'Rekapitulasi Koreksi Transaksi Individual',
component: GangguanTable19,
},
{
path: '13',
name: 'Rekapitulasi Cleansing Transaksi TM',
component: GangguanTable20,
},
],
}
]
},
{
path: 'keluhan',
name: 'Keluhan',
children: [
{
path: 'daftar',
name: 'Daftar',
children: [
{
path: '1',
name: 'Daftar Keluhan Dialihkan Ke Unit Lain',
component: KeluhanTable1,
},
{
path: '2',
name: 'Daftar Keluhan Pelanggan Lebih Dari 1 Kali',
component: KeluhanTable2,
},
{
path: '3',
name: 'Daftar Keluhan Response Time',
component: KeluhanTable3,
},
{
path: '4',
name: 'Daftar Keluhan Recovery Time',
component: KeluhanTable4,
},
{
path: '5',
name: 'Daftar Keluhan Selesai Tanpa ID Pelanggan',
component: KeluhanTable5,
},
{
path: '6',
name: 'Daftar Keluhan Berdasarkan Media',
component: KeluhanTable6,
},
{
path: '7',
name: 'Daftar Keluhan Selesai di CC123',
component: KeluhanTable7,
},
],
},
{
path: 'rekapitulasi',
name: 'Rekapitulasi',
children: [
{
path: '1',
name: 'Rekapitulasi Keluhan All',
component: KeluhanTable8,
},
{
path: '2',
name: 'Rekapitulasi Keluhan Per Fungsi Bidang',
component: KeluhanTable9,
},
{
path: '3',
name: 'Rekapitulasi Keluhan Per Jenis Keluhan',
component: KeluhanTable10,
},
{
path: '4',
name: 'Rekapitulasi Keluhan Per Tanggal',
component: KeluhanTable11,
},
{
path: '5',
name: 'Rekapitulasi Keluhan Per Unit',
component: KeluhanTable12,
},
{
path: '6',
name: 'Rekapitulasi Keluhan Berdasarkan Media',
component: KeluhanTable13,
},
{
path: '7',
name: 'Rekapitulasi Keluhan Per Kelompok Keluhan',
component: KeluhanTable14,
},
{
path: '8',
name: 'Rekapitulasi Rating Per Unit',
component: KeluhanTable15,
},
],
}
],
},
{
path: 'monalisa',
name: 'Monalisa',
children: [
{
path: 'gangguan',
name: 'Gangguan',
children: [
{
path: 'rekapitulasi',
name: 'Rekapitulasi',
children: [
{
path: '1',
name: 'Jumlah Kali Gangguan',
component: EmptyPage,
},
{
path: '2',
name: 'Dispacthing Time (DT) Gangguan',
component: EmptyPage,
},
{
path: '3',
name: 'Recovery Time (RCT) Gangguan',
component: EmptyPage,
},
{
path: '4',
name: 'Response Time (RPT) Gangguan',
component: EmptyPage,
},
{
path: '5',
name: 'Jumlah dan Durasi RPT RCT Gangguan',
component: EmptyPage,
},
{
path: '6',
name: 'Rekapitulasi Gangguan Per Jenis Gangguan',
component: EmptyPage,
},
{
path: '7',
name: 'Rekapitulasi Lapor Ulang Gangguan',
component: EmptyPage,
},
{
path: '8',
name: 'Rekapitulasi ENS Gangguan',
component: EmptyPage,
},
{
path: '9',
name: 'Rekapitulasi Gangguan Belum Selesai',
component: EmptyPage,
},
],
},
],
},
{
path: 'keluhan',
name: 'Keluhan',
children: [
{
path: 'rekapitulasi',
name: 'Rekapitulasi',
children: [
{
path: '1',
name: 'Jumlah Kali Keluhan',
component: EmptyPage,
},
{
path: '2',
name: 'Recovery Time (RCT) Keluhan',
component: EmptyPage,
},
{
path: '3',
name: 'Response Time (RPT) Keluhan',
component: EmptyPage,
},
{
path: '4',
name: 'Jumlah dan Durasi RPT RCT Keluhan',
component: EmptyPage,
},
{
path: '5',
name: 'Rekapitulasi Gangguan Per Jenis Keluhan',
component: EmptyPage,
},
{
path: '6',
name: 'Rekapitulasi Lapor Ulang Keluhan',
component: EmptyPage,
},
{
path: '7',
name: 'Rekapitulasi Keluhan Belum Selesai',
component: EmptyPage,
},
],
},
],
},
{
path: 'kpi',
name: 'Laporan KPI',
children: [
{
path: 'bulanan',
name: 'Bulanan',
children: [
{
path: '1',
name: 'Penurunan Jumlah Komplain',
component: EmptyPage,
},
{
path: '2',
name: 'Aging Complaint',
component: EmptyPage,
},
{
path: '3',
name: 'Energy Not Sales (ENS)',
component: EmptyPage,
},
{
path: '4',
name: 'Kepatuhan dan Akurasi Dalam Pelaporan',
component: EmptyPage,
},
],
},
{
path: 'kumulatif',
name: 'Kumulatif',
children: [
{
path: '1',
name: 'Penurunan Jumlah Komplain',
component: EmptyPage,
},
{
path: '2',
name: 'Aging Complaint',
component: EmptyPage,
},
{
path: '3',
name: 'Energy Not Sales (ENS)',
component: EmptyPage,
},
{
path: '4',
name: 'Kepatuhan dan Akurasi Dalam Pelaporan',
component: EmptyPage,
},
],
}
],
},
],
},
{
path: 'check-in-out',
name: 'Check In OutCheck In Dan Check Out',
children: [
{
path: 'laporan',
name: 'Laporan Check In /Check Out (CICO)',
children: [
{
path: '1',
name: 'Laporan Check In /Check Out (CICO)',
component: EmptyPage,
},
],
},
],
},
{
path: 'anomali-pengaduan',
name: 'Anomali Penangan Pengaduan',
children: [
{
path: 'gangguan',
name: 'Gangguan',
children: [
{
path: '1',
name: 'Laporan Anomali Penangan Pengaduan Gangguan Unit',
component: EmptyPage,
},
{
path: '2',
name: 'Laporan Anomali Penangan Pengaduan Gangguan Petugas',
component: EmptyPage,
},
],
},
{
path: 'keluhan',
name: 'Keluhan',
children: [
{
path: '1',
name: 'Laporan Anomali Penangan Pengaduan Keluhan Unit',
component: EmptyPage,
},
],
},
],
},
{
path: 'ctt-kwh-periksa',
name: 'CTT & KWH Periksa',
children: [
{
path: '1',
name: 'Laporan CTT & KWH Periksa',
component: EmptyPage,
},
],
},
{
path: 'material',
name: 'Material',
children: [
{
path: 'daftar',
name: 'Daftar',
children: [
{
path: '1',
name: 'Daftar Gangguan Dan Material Yang Dipakai',
component: EmptyPage,
},
],
},
{
path: 'rekapitulasi',
name: 'Rekapitulasi',
children: [
{
path: '1',
name: 'Rekapitulasi Pemakaian Material',
component: EmptyPage,
},
],
}
],
},
{
path: 'transaksi',
name: 'Transaksi',
children: [
{
path: '1',
name: 'Transaksi APKT',
component: EmptyPage,
},
],
},
{
path: 'pencarian-data',
name: 'Pencarian Data',
children: [
{
path: '1',
name: 'Pencarian Report Number',
component: EmptyPage,
}
]
},
]
},
{
path: '/login',
name: 'Login',
component: LoginView
},
{
path: '/playground',
name: 'Playground',
component: TestView
},
{
path: '/404',
name: 'Not Found',
component: NotFoundView
},
]
export const mergeChildrenRoutes = (routes: RouteRecordRaw[]): RouteRecordRaw[] => {
const mergedRoutes: RouteRecordRaw[] = [];
for (const route of routes) {
if (route.children && route.children.length > 0) {
// Buat salinan route tanpa children
const topLevelRoute: RouteRecordRaw = { ...route, children: [] };
// Salin setiap route children ke children route paling atas
for (const childRoute of route.children) {
const fullPath = `${route.path}/${childRoute.path}`.replace(/\/+/g, '/');
const mergedChildRoute: RouteRecordRaw = { ...childRoute, path: fullPath };
topLevelRoute.children?.push(mergedChildRoute);
}
mergedRoutes.push(topLevelRoute);
} else {
// Jika route tidak memiliki children, tambahkan as is
mergedRoutes.push(route);
}
}
return mergedRoutes;
}
export const extractLeafRoutes = (routes: RouteRecordRaw[], parentPath = ''): RouteRecordRaw[] => {
const leafRoutes: RouteRecordRaw[] = [];
for (const route of routes) {
const fullPath = `${parentPath}/${route.path}`.replace(/\/+/g, '/');
if (route.children && route.children.length > 0) {
leafRoutes.push(...extractLeafRoutes(route.children, fullPath));
} else {
const leafRoute = { ...route, path: fullPath };
leafRoutes.push(leafRoute);
}
}
return leafRoutes;
}
export const fixRoute = (route: RouteRecordRaw[]): RouteRecordRaw[] => {
var newRoute: RouteRecordRaw[] = []
const getRoute = (route: RouteRecordRaw[], parent: string = '') => {
route.forEach((r) => {
if (r.children) {
if (r.component) {
const fullPath = `${parent.replace('/', '')}/${r.path.replace('/', '')}`
newRoute.push({
path: fullPath,
name: r.name,
component: r.component
} as RouteRecordRaw)
}
getRoute(r.children, `${parent}/${r.path}`)
} else {
const fullPath = `${parent.replace('/', '')}/${r.path.replace('/', '')}`
if (newRoute.find((nr) => nr.path !== '/' && nr.path === '/home' && fullPath.includes(nr.path))) {
const index = newRoute.findIndex((nr) => nr.path !== '/' && fullPath.includes(nr.path))
newRoute[index] = {
...newRoute[index], children: [...newRoute[index].children ?? [], {
path: fullPath === '/home/' ? '' : fullPath.includes('/home/') ? fullPath.replace('/home/', '') : fullPath,
name: r.name,
component: r.component
} as RouteRecordRaw]
}
} else {
newRoute.push({
path: fullPath,
name: r.name,
component: r.component
} as RouteRecordRaw)
}
}
})
}
getRoute(route)
// remove duplicate route path and sort by path length
const uniqueRoute = newRoute.filter((nr, index, self) => self.findIndex((n) => n.path === nr.path) === index).sort((a, b) => b.path.length - a.path.length)
return uniqueRoute
}
const router = createRouter({
history: createWebHistory(),
linkActiveClass: 'active',
stringifyQuery: qs.stringify,
routes: fixRoute(routes)
})
router.beforeEach((to, from, next) => {
// redirect to login page if not logged in and trying to access a restricted page
const auth = useAuthStore();
// if to is not found, redirect to 404
if (to.matched.length === 0) {
if (to.path === '/') {
if (auth.isLoggedIn) {
next('/home')
} else {
next('/login')
}
} else {
next('/404')
}
} else {
// if to is not login and user is not logged in, redirect to login
if (auth.isLoggedIn) {
// if to is login and user is logged in, redirect to home
if (to.path === '/login') {
next('/home')
} else {
next()
}
} else {
// if to is 404, redirect to 404
if (to.path !== '/404' && to.path !== '/login') {
next('/login')
} else {
next()
}
}
}
})
export default router