feat: label category

This commit is contained in:
Mozzie 2023-09-12 16:19:42 +08:00
parent cf79216a6e
commit 1a22bd3836
7 changed files with 48 additions and 6 deletions

View File

@ -1,4 +1,4 @@
import { baseRoutes } from "./router.config"; import { baseRoutes, commonRoutes } from "./router.config";
import { Route, RouteObject, Routes, useLocation } from "react-router-dom"; import { Route, RouteObject, Routes, useLocation } from "react-router-dom";
import { RouteGuard } from "./AuthGuard"; import { RouteGuard } from "./AuthGuard";
import { pathToRegexp } from "path-to-regexp"; import { pathToRegexp } from "path-to-regexp";
@ -16,7 +16,7 @@ export const RouterElements = () => {
/** /**
* document.title * document.title
*/ */
const currentRoute = [...baseRoutes].find((r) => const currentRoute = [...baseRoutes, ...commonRoutes].find((r) =>
pathToRegexp(location.pathname).test(r.path!) pathToRegexp(location.pathname).test(r.path!)
); );
document.title = currentRoute?.title ?? defaultTitle; document.title = currentRoute?.title ?? defaultTitle;
@ -32,9 +32,9 @@ export const RouterElements = () => {
)); ));
return ( return (
<RouteGuard ignorePaths={[]}> <RouteGuard ignorePaths={baseRoutes.map((r) => r.path!)}>
<Routes> <Routes>
{generateRoutes(baseRoutes)} {generateRoutes([...baseRoutes, ...commonRoutes])}
<Route key="notfound" path="*" element={<span>404</span>} /> <Route key="notfound" path="*" element={<span>404</span>} />
</Routes> </Routes>
</RouteGuard> </RouteGuard>

View File

@ -17,6 +17,9 @@ export const baseRoutes: (RouteObject & ExpandRouteProps)[] = [
element: <Login />, element: <Login />,
title: "登录 - CVPILOT Viewer", title: "登录 - CVPILOT Viewer",
}, },
];
export const commonRoutes: (RouteObject & ExpandRouteProps)[] = [
{ {
path: "/", path: "/",
element: <Layout />, element: <Layout />,

View File

@ -0,0 +1,22 @@
import {
Column,
CreateDateColumn,
Entity,
PrimaryGeneratedColumn,
UpdateDateColumn,
} from 'typeorm';
@Entity()
export class LabelCategory {
@PrimaryGeneratedColumn()
id: number;
@Column()
name: string;
@CreateDateColumn({ type: 'timestamp' })
createAt: Date;
@UpdateDateColumn({ type: 'timestamp' })
updateAt: Date;
}

View File

@ -1,4 +1,4 @@
import { LabelSource } from 'src/app.constant'; import { LabelSource } from '../../app.constant';
import { import {
Column, Column,
CreateDateColumn, CreateDateColumn,

View File

@ -6,6 +6,11 @@ import { LabelService } from './label.service';
export class LabelController { export class LabelController {
constructor(private readonly labelService: LabelService) {} constructor(private readonly labelService: LabelService) {}
@EventPattern({ cmd: 'dicom.label.category.create' })
async createLabelCategory(payload) {
return await this.labelService.createLabelCategory(payload);
}
@EventPattern({ cmd: 'dicom.label.create' }) @EventPattern({ cmd: 'dicom.label.create' })
async createLabel(payload) { async createLabel(payload) {
return await this.labelService.createLabel(payload); return await this.labelService.createLabel(payload);

View File

@ -3,6 +3,7 @@ import { LabelController } from './label.controller';
import { LabelService } from './label.service'; import { LabelService } from './label.service';
import { TypeOrmModule } from '@nestjs/typeorm'; import { TypeOrmModule } from '@nestjs/typeorm';
import { Label } from './entity/label.entity'; import { Label } from './entity/label.entity';
import { LabelCategory } from './entity/label.category.entity';
@Module({ @Module({
controllers: [LabelController], controllers: [LabelController],
@ -18,7 +19,7 @@ import { Label } from './entity/label.entity';
synchronize: true, synchronize: true,
timezone: 'Asia/Shanghai', // 这里设置了时区 timezone: 'Asia/Shanghai', // 这里设置了时区
}), }),
TypeOrmModule.forFeature([Label]), TypeOrmModule.forFeature([Label, LabelCategory]),
], ],
providers: [LabelService], providers: [LabelService],
}) })

View File

@ -2,13 +2,24 @@ import { Injectable } from '@nestjs/common';
import { InjectRepository } from '@nestjs/typeorm'; import { InjectRepository } from '@nestjs/typeorm';
import { Label } from './entity/label.entity'; import { Label } from './entity/label.entity';
import { Repository } from 'typeorm'; import { Repository } from 'typeorm';
import { LabelCategory } from './entity/label.category.entity';
@Injectable() @Injectable()
export class LabelService { export class LabelService {
constructor( constructor(
@InjectRepository(Label) @InjectRepository(Label)
private readonly labelRepository: Repository<Label>, private readonly labelRepository: Repository<Label>,
@InjectRepository(LabelCategory)
private readonly labelCategoryRepository: Repository<LabelCategory>,
) {} ) {}
async createLabelCategory(payload) {
console.log(payload);
return await this.labelCategoryRepository.save({
name: '默认',
});
}
async createLabel(payload) { async createLabel(payload) {
console.log(payload); console.log(payload);
return await this.labelRepository.save({ return await this.labelRepository.save({