Browse Source

修改导航菜单

zs 1 year ago
parent
commit
46e760f941

+ 68 - 0
src/controller/platform/tags.controller.ts

@@ -0,0 +1,68 @@
+import { Body, Controller, Del, Get, Inject, Param, Post, Query } from '@midwayjs/decorator';
+import { BaseController } from 'free-midway-component';
+import { TagsService } from '../../service/platform/tags.service';
+import { CDTO_tags, CVO_tags, FVO_tags, QDTO_tags, QVO_tags, UDTO_tags, UVAO_tags } from '../../interface/platform/tags.interface';
+import { ApiResponse, ApiTags, ApiQuery } from '@midwayjs/swagger';
+import { Validate } from '@midwayjs/validate';
+@ApiTags(['标签'])
+@Controller('/tags')
+export class TagsController extends BaseController {
+  @Inject()
+  service: TagsService;
+
+  @Post('/')
+  @Validate()
+  @ApiResponse({ type: CVO_tags })
+  async create(@Body() data: CDTO_tags) {
+    const dbData = await this.service.create(data);
+    const result = new CVO_tags(dbData);
+    return result;
+  }
+  @Get('/', { description: 'ignore' })
+  @ApiQuery({ name: 'query' })
+  @ApiResponse({ type: QVO_tags })
+  async query(@Query() filter: QDTO_tags, @Query('skip') skip: number, @Query('limit') limit: number) {
+    const list = await this.service.query(filter, { skip, limit, sort: { sort: 1 } });
+    const data = [];
+    for (const i of list) {
+      const newData = new QVO_tags(i);
+      data.push(newData);
+    }
+    const total = await this.service.count(filter);
+    return { data, total };
+  }
+
+  @Get('/:id')
+  @ApiResponse({ type: FVO_tags })
+  async fetch(@Param('id') id: string) {
+    const data = await this.service.fetch(id);
+    const result = new FVO_tags(data);
+    return result;
+  }
+
+  @Post('/:id')
+  @Validate()
+  @ApiResponse({ type: UVAO_tags })
+  async update(@Param('id') id: string, @Body() body: UDTO_tags) {
+    const result = await this.service.updateOne(id, body);
+    return result;
+  }
+
+  @Del('/:id')
+  @Validate()
+  async delete(@Param('id') id: string) {
+    await this.service.delete(id);
+    return 'ok';
+  }
+  async createMany(...args: any[]) {
+    throw new Error('Method not implemented.');
+  }
+
+  async updateMany(...args: any[]) {
+    throw new Error('Method not implemented.');
+  }
+
+  async deleteMany(...args: any[]) {
+    throw new Error('Method not implemented.');
+  }
+}

+ 23 - 0
src/entity/platform/tags.entity.ts

@@ -0,0 +1,23 @@
+import { modelOptions, prop } from '@typegoose/typegoose';
+import { BaseModel } from 'free-midway-component';
+@modelOptions({
+  schemaOptions: { collection: 'tags' },
+})
+export class Tags extends BaseModel {
+  @prop({ required: false, index: true, zh: '标题' })
+  title: string;
+  @prop({ required: false, index: true, zh: '类型', default: '1' })
+  type: string;
+  @prop({ required: false, index: false, zh: '路由' })
+  href: string;
+  @prop({ required: false, index: false, zh: '英文标题' })
+  English: string;
+  @prop({ required: false, index: false, zh: '子菜单' })
+  children: Array<any>;
+  @prop({ required: false, index: false, zh: '排序' })
+  sort: number;
+  @prop({ required: false, index: false, zh: '备注' })
+  remark: string;
+  @prop({ required: false, index: false, zh: '是否使用', default: '0' })
+  is_use: string;
+}

+ 100 - 0
src/interface/platform/tags.interface.ts

@@ -0,0 +1,100 @@
+import { Rule, RuleType } from '@midwayjs/validate';
+import { ApiProperty } from '@midwayjs/swagger';
+import { SearchBase } from 'free-midway-component';
+import get = require('lodash/get');
+const dealVO = (cla, data) => {
+  for (const key in cla) {
+    const val = get(data, key);
+    if (val || val === 0) cla[key] = val;
+  }
+};
+export class FVO_tags {
+  constructor(data: object) {
+    dealVO(this, data);
+  }
+  @ApiProperty({ description: '数据id' })
+  _id: string = undefined;
+  @ApiProperty({ description: '标题' })
+  'title': string = undefined;
+  @ApiProperty({ description: '类型' })
+  'type': string = undefined;
+  @ApiProperty({ description: '路由' })
+  'href': string = undefined;
+  @ApiProperty({ description: '排序' })
+  'sort': number = undefined;
+  @ApiProperty({ description: '英文标题' })
+  'English': string = undefined;
+  @ApiProperty({ description: '子菜单' })
+  'children': Array<any> = undefined;
+  @ApiProperty({ description: '备注' })
+  'remark': string = undefined;
+  @ApiProperty({ description: '是否使用' })
+  'is_use': string = undefined;
+}
+
+export class QDTO_tags extends SearchBase {
+  constructor() {
+    const like_prop = [];
+    const props = ['title', 'type'];
+    const mapping = [];
+    super({ like_prop, props, mapping });
+  }
+  @ApiProperty({ description: '标题' })
+  'title': string = undefined;
+  @ApiProperty({ description: '类型' })
+  'type': string = undefined;
+}
+
+export class QVO_tags extends FVO_tags {
+  constructor(data: object) {
+    super(data);
+    dealVO(this, data);
+  }
+}
+
+export class CDTO_tags {
+  @ApiProperty({ description: '标题' })
+  @Rule(RuleType['string']().empty(''))
+  'title': string = undefined;
+  @ApiProperty({ description: '类型' })
+  @Rule(RuleType['string']().empty(''))
+  'type': string = undefined;
+  @ApiProperty({ description: '路由' })
+  @Rule(RuleType['string']().empty(''))
+  'href': string = undefined;
+  @ApiProperty({ description: '英文标题' })
+  @Rule(RuleType['string']().empty(''))
+  'English': string = undefined;
+  @ApiProperty({ description: '排序' })
+  @Rule(RuleType['number']().empty(''))
+  'sort': number = undefined;
+  @ApiProperty({ description: '子菜单' })
+  @Rule(RuleType['array']().empty(''))
+  'children': Array<any> = undefined;
+  @ApiProperty({ description: '备注' })
+  @Rule(RuleType['string']().empty(''))
+  'remark': string = undefined;
+  @ApiProperty({ description: '是否使用' })
+  @Rule(RuleType['string']().empty(''))
+  'is_use': string = undefined;
+}
+
+export class CVO_tags extends FVO_tags {
+  constructor(data: object) {
+    super(data);
+    dealVO(this, data);
+  }
+}
+
+export class UDTO_tags extends CDTO_tags {
+  @ApiProperty({ description: '数据id' })
+  @Rule(RuleType['string']().empty(''))
+  _id: string = undefined;
+}
+
+export class UVAO_tags extends FVO_tags {
+  constructor(data: object) {
+    super(data);
+    dealVO(this, data);
+  }
+}

+ 11 - 0
src/service/platform/tags.service.ts

@@ -0,0 +1,11 @@
+import { Provide } from '@midwayjs/decorator';
+import { InjectEntityModel } from '@midwayjs/typegoose';
+import { ReturnModelType } from '@typegoose/typegoose';
+import { BaseService } from 'free-midway-component';
+import { Tags } from '../../entity/platform/tags.entity';
+type modelType = ReturnModelType<typeof Tags>;
+@Provide()
+export class TagsService extends BaseService<modelType> {
+  @InjectEntityModel(Tags)
+  model: modelType;
+}