Merge branch 'main' of http://113.45.157.195:3003/insiinc/nice-playground
This commit is contained in:
commit
5a581fdda6
|
@ -0,0 +1,5 @@
|
|||
{
|
||||
"recommendations": [
|
||||
"marscode.marscode-extension"
|
||||
]
|
||||
}
|
|
@ -0,0 +1,7 @@
|
|||
{
|
||||
"marscode.chatLanguage": "cn",
|
||||
"marscode.codeCompletionPro": {
|
||||
"enableCodeCompletionPro": true
|
||||
},
|
||||
"marscode.enableInlineCommand": true
|
||||
}
|
|
@ -3,32 +3,28 @@ import { AppModule } from './app.module';
|
|||
import { TrpcRouter } from './trpc/trpc.router';
|
||||
import { WebSocketService } from './socket/websocket.service';
|
||||
|
||||
/**
|
||||
* 启动 NestJS 应用程序的引导函数
|
||||
* 该函数初始化 NestJS 应用程序,配置 CORS,初始化 WebSocket 服务,应用 TRPC 中间件,并启动服务器监听指定端口
|
||||
*/
|
||||
async function bootstrap() {
|
||||
// 创建 NestJS 应用实例,使用 AppModule 作为根模块
|
||||
// 创建NestJS应用实例
|
||||
const app = await NestFactory.create(AppModule);
|
||||
|
||||
// 启用 CORS 并允许所有来源
|
||||
app.enableCors({ //允许跨域
|
||||
app.enableCors({
|
||||
origin: '*',
|
||||
});
|
||||
// 从 NestJS 应用实例中获取 WebSocketService 实例
|
||||
|
||||
// 获取WebSocket服务实例并初始化
|
||||
const wsService = app.get(WebSocketService);
|
||||
// 初始化 WebSocket 服务,传入 HTTP 服务器实例
|
||||
await wsService.initialize(app.getHttpServer());
|
||||
// 从 NestJS 应用实例中获取 TrpcRouter 实例
|
||||
|
||||
// 获取tRPC路由实例并应用中间件
|
||||
const trpc = app.get(TrpcRouter);
|
||||
// 应用 TRPC 中间件到 NestJS 应用实例
|
||||
trpc.applyMiddleware(app);
|
||||
|
||||
// 获取环境变量中的服务器端口,如果未设置则使用默认端口 3000
|
||||
// 设置服务器端口,优先使用环境变量中的值,默认3000
|
||||
const port = process.env.SERVER_PORT || 3000;
|
||||
|
||||
// 启动服务器监听指定端口
|
||||
// 启动应用,监听指定端口
|
||||
await app.listen(port);
|
||||
}
|
||||
// 调用引导函数启动应用程序
|
||||
// 启动应用
|
||||
bootstrap();
|
||||
|
|
|
@ -1,4 +1,10 @@
|
|||
import { Injectable } from '@nestjs/common';
|
||||
|
||||
@Injectable()
|
||||
<<<<<<< HEAD
|
||||
export class GoodsService {}
|
||||
=======
|
||||
export class GoodsService {
|
||||
|
||||
}
|
||||
>>>>>>> 28132992c8dc4afaf9311d9ecd4ecd992e43e827
|
||||
|
|
|
@ -3,7 +3,6 @@ import { Controller, Get, Query, UseGuards } from '@nestjs/common';
|
|||
import { MessageService } from './message.service';
|
||||
import { AuthGuard } from '@server/auth/auth.guard';
|
||||
import { db, VisitType } from '@nice/common';
|
||||
// /message/find-last-one?staff-id=1
|
||||
@Controller('message')
|
||||
export class MessageController {
|
||||
constructor(private readonly messageService: MessageService) { }
|
||||
|
|
|
@ -6,9 +6,9 @@ import { DepartmentModule } from '../department/department.module';
|
|||
import { MessageController } from './message.controller';
|
||||
|
||||
@Module({
|
||||
imports: [DepartmentModule], //可能要用的
|
||||
providers: [MessageService, MessageRouter, TrpcService], //可以被自己使用这三个
|
||||
exports: [MessageService, MessageRouter], //可以被其他模块使用这两个
|
||||
controllers: [MessageController], //路由层
|
||||
imports: [DepartmentModule],
|
||||
providers: [MessageService, MessageRouter, TrpcService],
|
||||
exports: [MessageService, MessageRouter],
|
||||
controllers: [MessageController],
|
||||
})
|
||||
export class MessageModule { }
|
||||
|
|
|
@ -1,4 +1,3 @@
|
|||
//开发数据生成服务
|
||||
import { Injectable, Logger } from '@nestjs/common';
|
||||
import { DepartmentService } from '@server/models/department/department.service';
|
||||
import { AppConfigService } from '@server/models/app-config/app-config.service';
|
||||
|
|
|
@ -39,4 +39,4 @@ import { GoodsModule } from '@server/models/goods/goods.module';
|
|||
controllers: [],
|
||||
providers: [TrpcService, TrpcRouter, Logger],
|
||||
})
|
||||
export class TrpcModule {}
|
||||
export class TrpcModule { }
|
||||
|
|
|
@ -0,0 +1,51 @@
|
|||
import { useEffect } from 'react';
|
||||
import { api } from '@nice/client';
|
||||
|
||||
function People() {
|
||||
// 使用 useQuery 钩子从 API 获取数据,限制查询结果数量为 10
|
||||
const { data } = api.staff.findMany.useQuery({
|
||||
take: 10, // 限制查询结果数量
|
||||
});
|
||||
// 当 data 发生变化时,打印数据到控制台
|
||||
useEffect(() => {
|
||||
console.log(data);
|
||||
}, [data]);
|
||||
|
||||
return (
|
||||
<div>
|
||||
{
|
||||
// 遍历 data 并渲染每个元素
|
||||
data?.map((i) => {
|
||||
return (
|
||||
<table className='table-auto w-full'>
|
||||
<thead>
|
||||
<tr>
|
||||
<th className='px-4 py-2'>Username</th>
|
||||
<th className='px-4 py-2'>ID</th>
|
||||
<th className='px-4 py-2'>Showname</th>
|
||||
<th className='px-4 py-2'>Password</th>
|
||||
<th className='px-4 py-2'>Phone Number</th>
|
||||
<th className='px-4 py-2'>Order</th>
|
||||
</tr>
|
||||
</thead>
|
||||
<tbody>
|
||||
{data?.map((i) => (
|
||||
<tr key={i.id} className='hover:bg-gray-100'>
|
||||
<td className='border px-4 py-2'>{i.username}</td>
|
||||
<td className='border px-4 py-2'>{i.id}</td>
|
||||
<td className='border px-4 py-2'>{i.showname}</td>
|
||||
<td className='border px-4 py-2'>{i.password}</td>
|
||||
<td className='border px-4 py-2'>{i.phoneNumber}</td>
|
||||
<td className='border px-4 py-2'>{i.order}</td>
|
||||
</tr>
|
||||
))}
|
||||
</tbody>
|
||||
</table>
|
||||
);
|
||||
})
|
||||
}
|
||||
</div>
|
||||
);
|
||||
}
|
||||
|
||||
export default People;
|
|
@ -1,35 +1,45 @@
|
|||
import { Button, Tag } from 'antd'
|
||||
import { api } from '@nice/client'
|
||||
import { useEffect, useMemo, useState } from 'react'
|
||||
import { apiClient } from '@web/src/utils'
|
||||
import { api } from "@nice/client"
|
||||
import { apiClient } from "@web/src/utils"
|
||||
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(0)
|
||||
const [counter, setCounter] = useState<number>(0)
|
||||
const counterText = useMemo(() => {
|
||||
return `当前计数为:${counter}`
|
||||
},[counter])
|
||||
|
||||
// const getData = async () => {
|
||||
// const res = await apiClient.get|{"/goods/hello"}
|
||||
// console.log(res)
|
||||
// }
|
||||
}, [counter])
|
||||
|
||||
return <div className='p-2 sapce-y-2'>
|
||||
const getData = async () => {
|
||||
const res = await apiClient.get("/goods/hello")
|
||||
console.log(res)
|
||||
}
|
||||
useEffect(() => {
|
||||
getData()
|
||||
}, [])
|
||||
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 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 shadow'>
|
||||
data?.map(i => {
|
||||
return <div className="p-2 rounded border shadow">
|
||||
<Tag>{i.username}</Tag>
|
||||
</div>
|
||||
</div>
|
||||
})
|
||||
}
|
||||
</div>
|
||||
}
|
||||
//export {HomePage}
|
||||
export default HomePage
|
||||
// export { HomePage }
|
||||
export default HomePage
|
||||
|
|
|
@ -6,7 +6,7 @@ export const MainRoute: CustomRouteObject = {
|
|||
element: <MainLayout></MainLayout>,
|
||||
children: [
|
||||
{
|
||||
index: true, //默认第一次进主页
|
||||
index: true,
|
||||
element: <HomePage />,
|
||||
},
|
||||
],
|
||||
|
|
|
@ -330,42 +330,44 @@ model Resource {
|
|||
@@map("resource")
|
||||
}
|
||||
|
||||
|
||||
|
||||
//商品表
|
||||
model Goods{
|
||||
id String @id @default(cuid())
|
||||
name String @unique
|
||||
description String?
|
||||
price Float @default(0.0)
|
||||
images String[] @default([])
|
||||
tags Tag[] @relation("goods_tag")//多对多关系
|
||||
reviews Review[] //一对多关系
|
||||
createdAt DateTime @default(now()) @map("created_at")
|
||||
updatedAt DateTime @updatedAt @map("updated_at")
|
||||
deletedAt DateTime? @map("deleted_at")
|
||||
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("goods_tag")
|
||||
createdAt DateTime @default(now()) @map("created_at")
|
||||
updatedAt DateTime @updatedAt @map("updated_at")
|
||||
deletedAt DateTime? @map("deleted_at")
|
||||
// 标签表
|
||||
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")
|
||||
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