This commit is contained in:
linguoqing 2025-02-23 20:31:25 +08:00
commit 399003f7af
9 changed files with 100 additions and 32 deletions

5
.vscode/extensions.json vendored Normal file
View File

@ -0,0 +1,5 @@
{
"recommendations": [
"marscode.marscode-extension"
]
}

View File

@ -4,19 +4,27 @@ import { TrpcRouter } from './trpc/trpc.router';
import { WebSocketService } from './socket/websocket.service';
async function bootstrap() {
// 创建NestJS应用实例
const app = await NestFactory.create(AppModule);
// 启用 CORS 并允许所有来源
app.enableCors({
origin: '*',
});
// 获取WebSocket服务实例并初始化
const wsService = app.get(WebSocketService);
await wsService.initialize(app.getHttpServer());
// 获取tRPC路由实例并应用中间件
const trpc = app.get(TrpcRouter);
trpc.applyMiddleware(app);
// 设置服务器端口优先使用环境变量中的值默认3000
const port = process.env.SERVER_PORT || 3000;
// 启动应用,监听指定端口
await app.listen(port);
}
// 启动应用
bootstrap();

View File

@ -3,9 +3,7 @@ import { GoodsService } from './goods.service';
import { GoodsController } from './goods.controller';
@Module({
providers: [GoodsService],
controllers:[GoodsController]
providers: [GoodsService],
controllers: [GoodsController]
})
export class GoodsModule {}

View File

@ -1,4 +1,14 @@
import { Injectable } from '@nestjs/common';
@Injectable()
<<<<<<< HEAD
export class GoodsService {}
=======
<<<<<<< HEAD
export class GoodsService {}
=======
export class GoodsService {
}
>>>>>>> 28132992c8dc4afaf9311d9ecd4ecd992e43e827
>>>>>>> 5a581fdda6e53f086e068357e1ce0cb6994ddbf2

View File

@ -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';
@Controller('message')
export class MessageController {
constructor(private readonly messageService: MessageService) { }

View File

@ -34,11 +34,9 @@ import { GoodsModule } from '@server/models/goods/goods.module';
VisitModule,
WebSocketModule,
ResourceModule,
GoodsModule,
GoodsModule
],
controllers: [],
providers: [TrpcService, TrpcRouter, Logger],
})
export class TrpcModule {}
export class TrpcModule { }

View File

@ -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;

View File

@ -1,32 +1,35 @@
import {api} from "@nice/client"
import { Button,Tag } from "antd"
import { api } from "@nice/client"
import { apiClient } from "@web/src/utils"
import { Button, Tag } from "antd"
import { useEffect, useMemo, useState } from "react"
import {useEffect,useMemo,useState} from "react"
function HomePage() {
function HomePage() {
const { data } = api.staff.findMany.useQuery({
take: 10
})
const [counter,setCounter] = useState <number>(0)
const [counter, setCounter] = useState<number>(0)
const counterText = useMemo(() => {
return `当前计数为:${counter}`
},[counter])
useEffect(() => {
console.log(data)
},[data])
}, [counter])
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">
<div className="space-x-2" >
<Button type="primary" onClick={() => {
setCounter(counter + 1)
}}>1</Button>
<Button danger
onClick={() => {
setCounter(counter - 1)
}}>1</Button>
onClick={() => {
setCounter(counter - 1)
}}
>1</Button>
</div>
{
@ -35,11 +38,8 @@ function HomePage() {
<Tag>{i.username}</Tag>
</div>
})
}
</div>
}
export default HomePage
// export { HomePage }
export default HomePage

View File

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