mirror of
https://github.com/CorentinTh/it-tools.git
synced 2025-04-25 17:26:15 -04:00
feat: component base
This commit is contained in:
parent
02dafd6a2f
commit
6e0c369398
17 changed files with 1482 additions and 1006 deletions
33
mixins/tool-routes.ts
Normal file
33
mixins/tool-routes.ts
Normal file
|
@ -0,0 +1,33 @@
|
|||
import {Component, Vue} from 'nuxt-property-decorator'
|
||||
import {RouteConfig} from '@nuxt/types/config/router'
|
||||
import {ToolConfig} from '~/types/ToolConfig'
|
||||
import {capitalise} from '~/utils/string'
|
||||
|
||||
export type ToolRouteConfig = RouteConfig & {config: ToolConfig}
|
||||
|
||||
@Component
|
||||
export class ToolRoutes extends Vue {
|
||||
toolRoutesFlat : ToolRouteConfig[] = []
|
||||
toolRoutesSections : {[key: string]: ToolRouteConfig[]} = {}
|
||||
|
||||
async mounted() {
|
||||
const routes = this.$router.options.routes?.filter(r => r.meta?.isTool) || []
|
||||
|
||||
for (const route of routes) {
|
||||
if ('component' in route) {
|
||||
// @ts-ignore
|
||||
const component = await route.component()
|
||||
const routeConfig = {...route, config: component.options.methods.config()} as ToolRouteConfig
|
||||
this.toolRoutesFlat.push(routeConfig)
|
||||
|
||||
const sectionKey = capitalise(route.meta.section).replace(/_/g, ' ')
|
||||
|
||||
if (!(sectionKey in this.toolRoutesSections)) {
|
||||
this.toolRoutesSections[sectionKey] = []
|
||||
}
|
||||
|
||||
this.toolRoutesSections[sectionKey].push(routeConfig)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue