diff --git a/src/filters/index.ts b/src/filters/index.ts new file mode 100644 index 0000000..36d7ae1 --- /dev/null +++ b/src/filters/index.ts @@ -0,0 +1,17 @@ +// Set utils function parseTime to filter +export { parseTime } from '@/utils' + +// Filter for article status +export const articleStatusFilter = (status: string) => { + const statusMap: { [key: string]: string } = { + published: 'success', + draft: 'info', + deleted: 'danger' + } + return statusMap[status] +} + +// Filter to uppercase the first character +export const uppercaseFirstChar = (str: string) => { + return str.charAt(0).toUpperCase() + str.slice(1) +} diff --git a/src/main.ts b/src/main.ts index 85e43a5..db3c823 100644 --- a/src/main.ts +++ b/src/main.ts @@ -15,6 +15,7 @@ import '@/icons/components' import '@/permission' import { AppModule } from '@/store/modules/app' import * as directives from '@/directives' +import * as filters from '@/filters' Vue.use(ElementUI, { size: AppModule.size, @@ -29,6 +30,10 @@ Vue.use(SvgIcon, { Object.keys(directives).forEach(key => { Vue.directive(key, (directives as { [key: string ]: DirectiveOptions })[key]) }) +// Register global filter functions +Object.keys(filters).forEach(key => { + Vue.filter(key, (filters as { [key: string ]: Function })[key]) +}) // Register global directives Vue.config.productionTip = false