Merge branch 'main' of http://113.45.157.195:3003/insiinc/nice-playground
This commit is contained in:
commit
a152600c30
|
@ -0,0 +1,5 @@
|
||||||
|
{
|
||||||
|
"recommendations": [
|
||||||
|
"marscode.marscode-extension"
|
||||||
|
]
|
||||||
|
}
|
|
@ -0,0 +1,7 @@
|
||||||
|
{
|
||||||
|
"marscode.chatLanguage": "cn",
|
||||||
|
"marscode.codeCompletionPro": {
|
||||||
|
"enableCodeCompletionPro": true
|
||||||
|
},
|
||||||
|
"marscode.enableInlineCommand": true
|
||||||
|
}
|
|
@ -4,19 +4,27 @@ import { TrpcRouter } from './trpc/trpc.router';
|
||||||
import { WebSocketService } from './socket/websocket.service';
|
import { WebSocketService } from './socket/websocket.service';
|
||||||
|
|
||||||
async function bootstrap() {
|
async function bootstrap() {
|
||||||
|
// 创建NestJS应用实例
|
||||||
const app = await NestFactory.create(AppModule);
|
const app = await NestFactory.create(AppModule);
|
||||||
|
|
||||||
// 启用 CORS 并允许所有来源
|
// 启用 CORS 并允许所有来源
|
||||||
app.enableCors({
|
app.enableCors({
|
||||||
origin: '*',
|
origin: '*',
|
||||||
});
|
});
|
||||||
|
|
||||||
|
// 获取WebSocket服务实例并初始化
|
||||||
const wsService = app.get(WebSocketService);
|
const wsService = app.get(WebSocketService);
|
||||||
await wsService.initialize(app.getHttpServer());
|
await wsService.initialize(app.getHttpServer());
|
||||||
|
|
||||||
|
// 获取tRPC路由实例并应用中间件
|
||||||
const trpc = app.get(TrpcRouter);
|
const trpc = app.get(TrpcRouter);
|
||||||
trpc.applyMiddleware(app);
|
trpc.applyMiddleware(app);
|
||||||
|
|
||||||
|
// 设置服务器端口,优先使用环境变量中的值,默认3000
|
||||||
const port = process.env.SERVER_PORT || 3000;
|
const port = process.env.SERVER_PORT || 3000;
|
||||||
|
|
||||||
|
// 启动应用,监听指定端口
|
||||||
await app.listen(port);
|
await app.listen(port);
|
||||||
}
|
}
|
||||||
|
// 启动应用
|
||||||
bootstrap();
|
bootstrap();
|
||||||
|
|
|
@ -1,17 +1,20 @@
|
||||||
import { Controller, Get, Param, Query } from '@nestjs/common';
|
import { Controller, Get, Query, Param } from '@nestjs/common';
|
||||||
|
|
||||||
@Controller('goods')
|
@Controller('goods')
|
||||||
export class GoodsController {
|
export class GoodsController {
|
||||||
constructor() {
|
constructor() {
|
||||||
console.log('goods Controller');
|
console.log('goods controller')
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// 示例1:基本查询参数
|
||||||
@Get('hello')
|
@Get('hello')
|
||||||
getHello(): string {
|
getHello(@Query('name') name?: string) {
|
||||||
return 'Hello World!';
|
return {
|
||||||
|
message: 'Hello World!',
|
||||||
|
name: name || 'Guest'
|
||||||
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
// 示例2:路径参数
|
// 示例2:路径参数
|
||||||
@Get('detail/:id')
|
@Get('detail/:id')
|
||||||
getDetail(@Param('id') id: string) {
|
getDetail(@Param('id') id: string) {
|
||||||
|
@ -36,4 +39,3 @@ export class GoodsController {
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -1,10 +1,9 @@
|
||||||
import { Module } from '@nestjs/common';
|
import { Module } from '@nestjs/common';
|
||||||
import { GoodsService } from './goods.servers';
|
import { GoodsService } from './goods.service';
|
||||||
import { GoodsController } from './goods.controller';
|
import { GoodsController } from './goods.controller';
|
||||||
|
|
||||||
|
|
||||||
@Module({
|
@Module({
|
||||||
providers: [GoodsService],
|
providers: [GoodsService],
|
||||||
controllers: [GoodsController]
|
controllers: [GoodsController],
|
||||||
})
|
})
|
||||||
export class GoodsModule {}
|
export class GoodsModule {}
|
||||||
|
|
|
@ -0,0 +1,6 @@
|
||||||
|
import { Injectable } from '@nestjs/common';
|
||||||
|
|
||||||
|
@Injectable()
|
||||||
|
export class GoodsService {
|
||||||
|
|
||||||
|
}
|
|
@ -3,7 +3,6 @@ import { Controller, Get, Query, UseGuards } from '@nestjs/common';
|
||||||
import { MessageService } from './message.service';
|
import { MessageService } from './message.service';
|
||||||
import { AuthGuard } from '@server/auth/auth.guard';
|
import { AuthGuard } from '@server/auth/auth.guard';
|
||||||
import { db, VisitType } from '@nice/common';
|
import { db, VisitType } from '@nice/common';
|
||||||
|
|
||||||
@Controller('message')
|
@Controller('message')
|
||||||
export class MessageController {
|
export class MessageController {
|
||||||
constructor(private readonly messageService: MessageService) { }
|
constructor(private readonly messageService: MessageService) { }
|
||||||
|
|
|
@ -34,9 +34,9 @@ import { GoodsModule } from '@server/models/goods/goods.module';
|
||||||
VisitModule,
|
VisitModule,
|
||||||
WebSocketModule,
|
WebSocketModule,
|
||||||
ResourceModule,
|
ResourceModule,
|
||||||
GoodsModule,
|
GoodsModule
|
||||||
],
|
],
|
||||||
controllers: [],
|
controllers: [],
|
||||||
providers: [TrpcService, TrpcRouter, Logger],
|
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,80 +1,45 @@
|
||||||
// import { api, useStaff } from "@nice/client"
|
|
||||||
// //import { useAuth } from "@web/src/providers/auth-provider";
|
|
||||||
// import { Button, Tag } from "antd";
|
|
||||||
// import { useEffect, useMemo, useState } from "react";
|
|
||||||
// import PersonCard from './personcard';
|
|
||||||
|
|
||||||
// function HomePage(){
|
|
||||||
// // function HomePage(){
|
|
||||||
// // const {data} = api.staff.findMany.useQuery({
|
|
||||||
// // take: 5
|
|
||||||
// // })
|
|
||||||
// // //const {user,}=useAuth()
|
|
||||||
// // //const {update,create}=useStaff()
|
|
||||||
// // const [counter, setCounter] = useState(0)
|
|
||||||
// // const counterText=useMemo(()=>{
|
|
||||||
// // return `当前计数为:${counter}`
|
|
||||||
// // },[counter])
|
|
||||||
// // const test=async ()=>{
|
|
||||||
|
|
||||||
// // await update.mutateAsync({
|
|
||||||
// // where: {
|
|
||||||
// // username: user?.username
|
|
||||||
// // },
|
|
||||||
// // data: {
|
|
||||||
// // username: "test"
|
|
||||||
// // }
|
|
||||||
// // })
|
|
||||||
// // }
|
|
||||||
// // useEffect(()=>{
|
|
||||||
// // console.log(data)
|
|
||||||
// // },[data])
|
|
||||||
// return (
|
|
||||||
// <div>
|
|
||||||
// <h1>主页</h1>
|
|
||||||
// {/* 调用 PersonCard 组件 */}
|
|
||||||
// <PersonCard />
|
|
||||||
// </div>
|
|
||||||
// );
|
|
||||||
// };
|
|
||||||
|
|
||||||
|
|
||||||
// // return <div className="p-2 space-y-2">
|
|
||||||
// // <Tag>当前计数为:{counter}</Tag>
|
|
||||||
// // <div className="p-z space-x-2">
|
|
||||||
// // <Button type="primary" onClick={()=>{setCounter(counter + 1)}}>加1</Button>
|
|
||||||
// // <Button danger onClick={()=>{setCounter(counter - 1)}}>减1</Button>
|
|
||||||
// // <div/>
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
// export default HomePage;
|
|
||||||
// // export {HomePage};//main-route那里也需要加括号
|
|
||||||
|
|
||||||
import React, { useEffect } from 'react';
|
|
||||||
import { api } from "@nice/client"
|
import { api } from "@nice/client"
|
||||||
|
import { apiClient } from "@web/src/utils"
|
||||||
|
import { Button, Tag } from "antd"
|
||||||
|
import { useEffect, useMemo, useState } from "react"
|
||||||
|
|
||||||
function PersonCard(){
|
function HomePage() {
|
||||||
const {data} = api.staff.findMany.useQuery({
|
const { data } = api.staff.findMany.useQuery({
|
||||||
take: 15
|
take: 10
|
||||||
})
|
})
|
||||||
|
const [counter, setCounter] = useState<number>(0)
|
||||||
|
const counterText = useMemo(() => {
|
||||||
|
return `当前计数为:${counter}`
|
||||||
|
}, [counter])
|
||||||
|
|
||||||
useEffect(()=>{
|
const getData = async () => {
|
||||||
console.log(data)
|
const res = await apiClient.get("/goods/hello")
|
||||||
},[data])
|
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>
|
||||||
|
|
||||||
|
{
|
||||||
return (
|
data?.map(i => {
|
||||||
<div>
|
return <div className="p-2 rounded border shadow">
|
||||||
{data?.map((i, index) => (
|
<Tag>{i.username}</Tag>
|
||||||
<div key={index} className="bg-blue rounded-lg shadow-sm p-6 hover:shadow-md transition-shadow duration-300">
|
|
||||||
<div className="flex items-center">
|
|
||||||
<h3 className="text-lg font-semibold text-gray-900">{i.username}</h3>
|
|
||||||
</div>
|
|
||||||
</div>
|
|
||||||
))}
|
|
||||||
</div>
|
</div>
|
||||||
);
|
})
|
||||||
|
}
|
||||||
|
</div>
|
||||||
}
|
}
|
||||||
|
// export { HomePage }
|
||||||
export default PersonCard;
|
export default HomePage
|
||||||
|
|
|
@ -5,7 +5,7 @@
|
||||||
"main": "index.js",
|
"main": "index.js",
|
||||||
"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"
|
"studio": "pnpm --filter common run studio"
|
||||||
},
|
},
|
||||||
|
|
|
@ -330,6 +330,8 @@ model Resource {
|
||||||
@@map("resource")
|
@@map("resource")
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
//商品表
|
//商品表
|
||||||
model Goods {
|
model Goods {
|
||||||
id String @id @default(cuid()) // 商品ID
|
id String @id @default(cuid()) // 商品ID
|
||||||
|
|
Loading…
Reference in New Issue