mirror of
https://github.com/CorentinTh/it-tools.git
synced 2025-04-27 10:06:16 -04:00
feat: externalized tool configuration
This commit is contained in:
parent
c3adfe30ec
commit
690bd099ef
31 changed files with 387 additions and 300 deletions
12
mixins/tool-config.mixin.ts
Normal file
12
mixins/tool-config.mixin.ts
Normal file
|
@ -0,0 +1,12 @@
|
|||
import {Component, Vue} from 'nuxt-property-decorator'
|
||||
import {ToolConfig} from '~/types/ToolConfig'
|
||||
|
||||
@Component
|
||||
export class ToolConfigMixin extends Vue {
|
||||
public $toolConfig!: ToolConfig;
|
||||
|
||||
beforeCreate() {
|
||||
// @ts-ignore
|
||||
this.$toolConfig = this.$options.__toolConfig
|
||||
}
|
||||
}
|
|
@ -1,37 +0,0 @@
|
|||
import {Component, Vue} from 'nuxt-property-decorator'
|
||||
import {ToolRouteConfig} from '~/types/ToolConfig'
|
||||
import {capitalise} from '~/utils/string'
|
||||
|
||||
|
||||
@Component
|
||||
export class ToolRoutesMixin extends Vue {
|
||||
toolRoutesFlat : ToolRouteConfig[] = []
|
||||
toolRoutesSections : {[key: string]: ToolRouteConfig[]} = {}
|
||||
|
||||
async created() {
|
||||
const routes = this.$router.options.routes?.filter((r1, i, a) => r1.meta?.isTool && a.findIndex(r2 => r2.path.split('/').pop() === r1.path.split('/').pop()) === i) || []
|
||||
const flat: ToolRouteConfig[] = []
|
||||
const sections: { [key: string]: ToolRouteConfig[] } = {}
|
||||
|
||||
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
|
||||
flat.push(routeConfig)
|
||||
|
||||
const sectionKey = capitalise(route.meta.section).replace(/_/g, ' ')
|
||||
|
||||
if (!(sectionKey in sections)) {
|
||||
sections[sectionKey] = []
|
||||
}
|
||||
|
||||
sections[sectionKey].push(routeConfig)
|
||||
}
|
||||
}
|
||||
|
||||
this.toolRoutesSections = sections
|
||||
this.toolRoutesFlat = flat
|
||||
}
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue