xxx
This commit is contained in:
parent
62bd20c906
commit
436948ed32
|
@ -84,4 +84,4 @@ export class DepartmentController {
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
|
@ -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: []
|
||||||
|
};
|
||||||
|
}
|
||||||
|
}
|
|
@ -0,0 +1,13 @@
|
||||||
|
import { Module } from '@nestjs/common';
|
||||||
|
import { GoodsService } from './goods.service';
|
||||||
|
import { GoodsController } from './goods.controller';
|
||||||
|
|
||||||
|
@Module({
|
||||||
|
|
||||||
|
providers: [GoodsService],
|
||||||
|
controllers:[GoodsController]
|
||||||
|
|
||||||
|
|
||||||
|
})
|
||||||
|
|
||||||
|
export class GoodsModule {}
|
|
@ -0,0 +1,4 @@
|
||||||
|
import { Injectable } from '@nestjs/common';
|
||||||
|
|
||||||
|
@Injectable()
|
||||||
|
export class GoodsService {}
|
|
@ -16,6 +16,7 @@ import { RoleMapModule } from '@server/models/rbac/rbac.module';
|
||||||
import { TransformModule } from '@server/models/transform/transform.module';
|
import { TransformModule } from '@server/models/transform/transform.module';
|
||||||
|
|
||||||
import { ResourceModule } from '@server/models/resource/resource.module';
|
import { ResourceModule } from '@server/models/resource/resource.module';
|
||||||
|
import { GoodsModule } from '@server/models/goods/goods.module';
|
||||||
|
|
||||||
@Module({
|
@Module({
|
||||||
imports: [
|
imports: [
|
||||||
|
@ -33,6 +34,7 @@ import { ResourceModule } from '@server/models/resource/resource.module';
|
||||||
VisitModule,
|
VisitModule,
|
||||||
WebSocketModule,
|
WebSocketModule,
|
||||||
ResourceModule,
|
ResourceModule,
|
||||||
|
GoodsModule,
|
||||||
],
|
],
|
||||||
controllers: [],
|
controllers: [],
|
||||||
providers: [TrpcService, TrpcRouter, Logger],
|
providers: [TrpcService, TrpcRouter, Logger],
|
||||||
|
|
|
@ -1,10 +1,53 @@
|
||||||
import { api } from "@nice/client"
|
import { api } from "@nice/client";
|
||||||
import { useEffect } from "react"
|
import { apiClient } from "@web/src/utils";
|
||||||
|
|
||||||
export default function HomePage() {
|
import { Button, Tag } from "antd";
|
||||||
const { data } = api.staff.findMany.useQuery({ take: 10 })
|
|
||||||
useEffect(() => {
|
import { useEffect, useMemo, useState } from "react";
|
||||||
console.log(data)
|
function HomePage() {
|
||||||
}, [data])
|
// 使用 useQuery 钩子从 API 获取数据
|
||||||
return <>Home</>
|
|
||||||
}
|
const { data } = api.staff.findMany.useQuery({
|
||||||
|
take: 10
|
||||||
|
});
|
||||||
|
|
||||||
|
// 定义 counter 状态和更新函数
|
||||||
|
const [counter, setCounter] = useState<number>(0);
|
||||||
|
|
||||||
|
// 使用 useMemo 记忆化 counterText,仅在 counter 变化时重新计算
|
||||||
|
const counterText = useMemo(() => {
|
||||||
|
return `当前计数为: ${counter}`;
|
||||||
|
}, [counter]);
|
||||||
|
|
||||||
|
const getData = async()=>{
|
||||||
|
const res = @wait apiClient.get(*/goods/hello*)
|
||||||
|
console.log(res)
|
||||||
|
}
|
||||||
|
|
||||||
|
// 使用 useEffect 在 data 变化时打印 data
|
||||||
|
useEffect(() => {
|
||||||
|
apiClient.get(“/goods/hello”)
|
||||||
|
}, [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 存在,遍历并渲染每个项目的 username */}
|
||||||
|
{data?.map((item) => (
|
||||||
|
<div className="p-2 rounded border shadow" key={item.username}>
|
||||||
|
<Tag>{item.username}</Tag>
|
||||||
|
</div>
|
||||||
|
))}
|
||||||
|
</div>
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
export default HomePage;
|
|
@ -27,7 +27,8 @@ server {
|
||||||
# 压缩HTTP版本
|
# 压缩HTTP版本
|
||||||
gzip_http_version 1.1;
|
gzip_http_version 1.1;
|
||||||
# 压缩的文件类型
|
# 压缩的文件类型
|
||||||
gzip_types text/plain
|
gzip_types
|
||||||
|
text/plain
|
||||||
text/css
|
text/css
|
||||||
application/json
|
application/json
|
||||||
application/javascript
|
application/javascript
|
||||||
|
@ -90,8 +91,8 @@ server {
|
||||||
add_header 'Access-Control-Allow-Origin' '$http_origin' always;
|
add_header 'Access-Control-Allow-Origin' '$http_origin' always;
|
||||||
add_header 'Access-Control-Allow-Credentials' 'true' always;
|
add_header 'Access-Control-Allow-Credentials' 'true' always;
|
||||||
add_header 'Access-Control-Allow-Methods' 'GET, OPTIONS' always;
|
add_header 'Access-Control-Allow-Methods' 'GET, OPTIONS' always;
|
||||||
add_header 'Access-Control-Allow-Headers'
|
add_header 'Access-Control-Allow-Headers'
|
||||||
'DNT,X-CustomHeader,Keep-Alive,User-Agent,X-Requested-With,If-Modified-Since,Cache-Control,Content-Type,Authorization'
|
'DNT,X-CustomHeader,Keep-Alive,User-Agent,X-Requested-With,If-Modified-Since,Cache-Control,Content-Type,Authorization'
|
||||||
always;
|
always;
|
||||||
}
|
}
|
||||||
# 内部认证服务位置
|
# 内部认证服务位置
|
||||||
|
@ -110,4 +111,4 @@ server {
|
||||||
proxy_set_header Host $host;
|
proxy_set_header Host $host;
|
||||||
proxy_set_header X-Query-Params $query_string;
|
proxy_set_header X-Query-Params $query_string;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -6,7 +6,8 @@
|
||||||
"scripts": {
|
"scripts": {
|
||||||
"test": "echo \"Error: no test specified\" && exit 1",
|
"test": "echo \"Error: no test specified\" && exit 1",
|
||||||
"dev": "pnpm run --parallel dev",
|
"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": [],
|
"keywords": [],
|
||||||
"author": "insiinc",
|
"author": "insiinc",
|
||||||
|
|
|
@ -245,13 +245,8 @@ model PostAncestry {
|
||||||
|
|
||||||
// 复合索引优化
|
// 复合索引优化
|
||||||
// 索引建议
|
// 索引建议
|
||||||
@@index([ancestorId]) // 针对祖先的查询
|
|
||||||
@@index([descendantId]) // 针对后代的查询
|
|
||||||
@@index([ancestorId, descendantId]) // 组合索引,用于查询特定的祖先-后代关系
|
|
||||||
@@index([relDepth]) // 根据关系深度的查询
|
|
||||||
@@map("post_ancestry")
|
|
||||||
}
|
|
||||||
|
|
||||||
|
}
|
||||||
model Message {
|
model Message {
|
||||||
id String @id @default(cuid())
|
id String @id @default(cuid())
|
||||||
url String?
|
url String?
|
||||||
|
@ -328,4 +323,47 @@ model Resource {
|
||||||
@@index([type])
|
@@index([type])
|
||||||
@@index([createdAt])
|
@@index([createdAt])
|
||||||
@@map("resource")
|
@@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")
|
||||||
|
}
|
Loading…
Reference in New Issue