2024.02.23

This commit is contained in:
linguoqing 2025-02-23 20:25:45 +08:00
parent 62bd20c906
commit 3c698caa02
9 changed files with 159 additions and 12 deletions

7
.vscode/settings.json vendored Normal file
View File

@ -0,0 +1,7 @@
{
"marscode.chatLanguage": "cn",
"marscode.codeCompletionPro": {
"enableCodeCompletionPro": true
},
"marscode.enableInlineCommand": true
}

View File

@ -0,0 +1,41 @@
import { Controller, Get, Query, Param } from '@nestjs/common';
@Controller('goods')
export class GoodsController {
constructor() {
console.log('goods controller')
}
// 示例1基本查询参数
@Get('hello')
getHello(@Query('name') name?: string) {
return {
message: 'Hello World!',
name: name || 'Guest'
};
}
// 示例2路径参数
@Get('detail/:id')
getDetail(@Param('id') id: string) {
return {
id: id,
detail: `Detail for product ${id}`
};
}
// 示例3多个查询参数
@Get('search')
searchProducts(
@Query('keyword') keyword: string,
@Query('page') page: number = 1,
@Query('limit') limit: number = 10
) {
return {
keyword,
page,
limit,
results: []
};
}
}

View File

@ -0,0 +1,11 @@
import { Module } from '@nestjs/common';
import { GoodsService } from './goods.service';
import { GoodsController } from './goods.controller';
@Module({
providers: [GoodsService],
controllers:[GoodsController]
})
export class GoodsModule {}

View File

@ -0,0 +1,4 @@
import { Injectable } from '@nestjs/common';
@Injectable()
export class GoodsService {}

View File

@ -16,6 +16,7 @@ import { RoleMapModule } from '@server/models/rbac/rbac.module';
import { TransformModule } from '@server/models/transform/transform.module';
import { ResourceModule } from '@server/models/resource/resource.module';
import { GoodsModule } from '@server/models/goods/goods.module';
@Module({
imports: [
@ -33,6 +34,9 @@ import { ResourceModule } from '@server/models/resource/resource.module';
VisitModule,
WebSocketModule,
ResourceModule,
GoodsModule,
],
controllers: [],
providers: [TrpcService, TrpcRouter, Logger],

View File

@ -1,10 +1,45 @@
import { api } from "@nice/client"
import { useEffect } from "react"
import {api} from "@nice/client"
import { Button,Tag } from "antd"
import {useEffect,useMemo,useState} from "react"
function HomePage() {
const { data } = api.staff.findMany.useQuery({
take: 10
})
const [counter,setCounter] = useState <number>(0)
const counterText = useMemo(() => {
return `当前计数为:${counter}`
},[counter])
export default function HomePage() {
const { data } = api.staff.findMany.useQuery({ take: 10 })
useEffect(() => {
console.log(data)
}, [data])
return <>Home</>
},[data])
return <div className="p-2 space-y-2">
<Tag>{counterText}</Tag>
<div className="space-x-2">
<Button type="primary" onClick={() => {
setCounter(counter + 1)
}}>1</Button>
<Button danger
onClick={() => {
setCounter(counter - 1)
}}>1</Button>
</div>
{
data?.map(i => {
return <div className="p-2 rounded border shadow">
<Tag>{i.username}</Tag>
</div>
})
}
</div>
}
export default HomePage

View File

@ -27,7 +27,8 @@ server {
# 压缩HTTP版本
gzip_http_version 1.1;
# 压缩的文件类型
gzip_types text/plain
gzip_types
text/plain
text/css
application/json
application/javascript

View File

@ -6,7 +6,9 @@
"scripts": {
"test": "echo \"Error: no test specified\" && exit 1",
"dev": "pnpm run --parallel dev",
"db:clear": "pnpm --filter common run db:clear"
"db:clear": "pnpm --filter common run db:clear",
"studio" :"pnpm --filter common run studio"
},
"keywords": [],
"author": "insiinc",

View File

@ -329,3 +329,45 @@ model Resource {
@@index([createdAt])
@@map("resource")
}
//商品表
model Goods {
id String @id @default(cuid()) // 商品ID
name String @unique // 商品名称
description String? // 商品描述
price Float @default(0.0) // 商品价格
images String[] @default([]) // 商品图片
tags Tag[] @relation("GoodsTags") // 多对多关系
reviews Review[] // 一对多关系
createdAt DateTime @default(now()) @map("created_at") // 创建时间
updatedAt DateTime @updatedAt @map("updated_at") // 更新时间
deletedAt DateTime? @map("deleted_at") // 删除时间,可为空
@@index([name])
@@map("goods")
}
// 标签表
model Tag {
id String @id @default(cuid())
name String @unique
goods Goods[] @relation("GoodsTags")
createdAt DateTime @default(now()) @map("created_at")
updatedAt DateTime @updatedAt @map("updated_at")
deletedAt DateTime? @map("deleted_at")
@@map("tag")
}
model Review {
id String @id @default(cuid())
content String
rating Int @default(0)
goodsId String @map("goods_id")
goods Goods @relation(fields: [goodsId], references: [id])
createdAt DateTime @default(now()) @map("created_at")
updatedAt DateTime @updatedAt @map("updated_at")
deletedAt DateTime? @map("deleted_at")
@@index([goodsId])
@@index([rating])
@@map("review")
}