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 { TrpcRouter } from './trpc/trpc.router';
|
||||||
import { WebSocketService } from './socket/websocket.service';
|
import { WebSocketService } from './socket/websocket.service';
|
||||||
|
|
||||||
/**
|
|
||||||
* 启动 NestJS 应用程序的引导函数
|
|
||||||
* 该函数初始化 NestJS 应用程序,配置 CORS,初始化 WebSocket 服务,应用 TRPC 中间件,并启动服务器监听指定端口
|
|
||||||
*/
|
|
||||||
async function bootstrap() {
|
async function bootstrap() {
|
||||||
// 创建 NestJS 应用实例,使用 AppModule 作为根模块
|
// 创建NestJS应用实例
|
||||||
const app = await NestFactory.create(AppModule);
|
const app = await NestFactory.create(AppModule);
|
||||||
|
|
||||||
// 启用 CORS 并允许所有来源
|
// 启用 CORS 并允许所有来源
|
||||||
app.enableCors({ //允许跨域
|
app.enableCors({
|
||||||
origin: '*',
|
origin: '*',
|
||||||
});
|
});
|
||||||
// 从 NestJS 应用实例中获取 WebSocketService 实例
|
|
||||||
|
// 获取WebSocket服务实例并初始化
|
||||||
const wsService = app.get(WebSocketService);
|
const wsService = app.get(WebSocketService);
|
||||||
// 初始化 WebSocket 服务,传入 HTTP 服务器实例
|
|
||||||
await wsService.initialize(app.getHttpServer());
|
await wsService.initialize(app.getHttpServer());
|
||||||
// 从 NestJS 应用实例中获取 TrpcRouter 实例
|
|
||||||
|
// 获取tRPC路由实例并应用中间件
|
||||||
const trpc = app.get(TrpcRouter);
|
const trpc = app.get(TrpcRouter);
|
||||||
// 应用 TRPC 中间件到 NestJS 应用实例
|
|
||||||
trpc.applyMiddleware(app);
|
trpc.applyMiddleware(app);
|
||||||
|
|
||||||
// 获取环境变量中的服务器端口,如果未设置则使用默认端口 3000
|
// 设置服务器端口,优先使用环境变量中的值,默认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,4 +1,10 @@
|
||||||
import { Injectable } from '@nestjs/common';
|
import { Injectable } from '@nestjs/common';
|
||||||
|
|
||||||
@Injectable()
|
@Injectable()
|
||||||
|
<<<<<<< HEAD
|
||||||
export class GoodsService {}
|
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 { 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';
|
||||||
// /message/find-last-one?staff-id=1
|
|
||||||
@Controller('message')
|
@Controller('message')
|
||||||
export class MessageController {
|
export class MessageController {
|
||||||
constructor(private readonly messageService: MessageService) { }
|
constructor(private readonly messageService: MessageService) { }
|
||||||
|
|
|
@ -6,9 +6,9 @@ import { DepartmentModule } from '../department/department.module';
|
||||||
import { MessageController } from './message.controller';
|
import { MessageController } from './message.controller';
|
||||||
|
|
||||||
@Module({
|
@Module({
|
||||||
imports: [DepartmentModule], //可能要用的
|
imports: [DepartmentModule],
|
||||||
providers: [MessageService, MessageRouter, TrpcService], //可以被自己使用这三个
|
providers: [MessageService, MessageRouter, TrpcService],
|
||||||
exports: [MessageService, MessageRouter], //可以被其他模块使用这两个
|
exports: [MessageService, MessageRouter],
|
||||||
controllers: [MessageController], //路由层
|
controllers: [MessageController],
|
||||||
})
|
})
|
||||||
export class MessageModule { }
|
export class MessageModule { }
|
||||||
|
|
|
@ -1,4 +1,3 @@
|
||||||
//开发数据生成服务
|
|
||||||
import { Injectable, Logger } from '@nestjs/common';
|
import { Injectable, Logger } from '@nestjs/common';
|
||||||
import { DepartmentService } from '@server/models/department/department.service';
|
import { DepartmentService } from '@server/models/department/department.service';
|
||||||
import { AppConfigService } from '@server/models/app-config/app-config.service';
|
import { AppConfigService } from '@server/models/app-config/app-config.service';
|
||||||
|
|
|
@ -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,30 +1,40 @@
|
||||||
import { Button, Tag } from 'antd'
|
import { api } from "@nice/client"
|
||||||
import { api } from '@nice/client'
|
import { apiClient } from "@web/src/utils"
|
||||||
import { useEffect, useMemo, useState } from 'react'
|
import { Button, Tag } from "antd"
|
||||||
import { apiClient } from '@web/src/utils'
|
import { useEffect, useMemo, useState } from "react"
|
||||||
|
|
||||||
function HomePage() {
|
function HomePage() {
|
||||||
const { data } = api.staff.findMany.useQuery({
|
const { data } = api.staff.findMany.useQuery({
|
||||||
take: 10
|
take: 10
|
||||||
})
|
})
|
||||||
const [counter, setCounter] = useState(0)
|
const [counter, setCounter] = useState<number>(0)
|
||||||
const counterText = useMemo(() => {
|
const counterText = useMemo(() => {
|
||||||
return `当前计数为:${counter}`
|
return `当前计数为:${counter}`
|
||||||
}, [counter])
|
}, [counter])
|
||||||
|
|
||||||
// const getData = async () => {
|
const getData = async () => {
|
||||||
// const res = await apiClient.get|{"/goods/hello"}
|
const res = await apiClient.get("/goods/hello")
|
||||||
// console.log(res)
|
console.log(res)
|
||||||
// }
|
}
|
||||||
|
useEffect(() => {
|
||||||
return <div className='p-2 sapce-y-2'>
|
getData()
|
||||||
|
}, [])
|
||||||
|
return <div className="p-2 space-y-2">
|
||||||
<Tag>{counterText}</Tag>
|
<Tag>{counterText}</Tag>
|
||||||
<div className='space-x-2'>
|
<div className="space-x-2" >
|
||||||
<Button type='primary' onClick={() => setCounter(counter + 1)}>加1</Button>
|
<Button type="primary" onClick={() => {
|
||||||
<Button danger onClick={() => setCounter(counter - 1)}>减1</Button>
|
setCounter(counter + 1)
|
||||||
|
}}>加1</Button>
|
||||||
|
<Button danger
|
||||||
|
onClick={() => {
|
||||||
|
setCounter(counter - 1)
|
||||||
|
}}
|
||||||
|
>减1</Button>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
{
|
{
|
||||||
data?.map(i => {
|
data?.map(i => {
|
||||||
return <div className='p-2 rounded shadow'>
|
return <div className="p-2 rounded border shadow">
|
||||||
<Tag>{i.username}</Tag>
|
<Tag>{i.username}</Tag>
|
||||||
</div>
|
</div>
|
||||||
})
|
})
|
||||||
|
|
|
@ -6,7 +6,7 @@ export const MainRoute: CustomRouteObject = {
|
||||||
element: <MainLayout></MainLayout>,
|
element: <MainLayout></MainLayout>,
|
||||||
children: [
|
children: [
|
||||||
{
|
{
|
||||||
index: true, //默认第一次进主页
|
index: true,
|
||||||
element: <HomePage />,
|
element: <HomePage />,
|
||||||
},
|
},
|
||||||
],
|
],
|
||||||
|
|
|
@ -330,27 +330,29 @@ model Resource {
|
||||||
@@map("resource")
|
@@map("resource")
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
//商品表
|
//商品表
|
||||||
model Goods {
|
model Goods {
|
||||||
id String @id @default(cuid())
|
id String @id @default(cuid()) // 商品ID
|
||||||
name String @unique
|
name String @unique // 商品名称
|
||||||
description String?
|
description String? // 商品描述
|
||||||
price Float @default(0.0)
|
price Float @default(0.0) // 商品价格
|
||||||
images String[] @default([])
|
images String[] @default([]) // 商品图片
|
||||||
tags Tag[] @relation("goods_tag")//多对多关系
|
tags Tag[] @relation("GoodsTags") // 多对多关系
|
||||||
reviews Review[] // 一对多关系
|
reviews Review[] // 一对多关系
|
||||||
createdAt DateTime @default(now()) @map("created_at")
|
createdAt DateTime @default(now()) @map("created_at") // 创建时间
|
||||||
updatedAt DateTime @updatedAt @map("updated_at")
|
updatedAt DateTime @updatedAt @map("updated_at") // 更新时间
|
||||||
deletedAt DateTime? @map("deleted_at")
|
deletedAt DateTime? @map("deleted_at") // 删除时间,可为空
|
||||||
@@index([name])
|
@@index([name])
|
||||||
@@map("goods")
|
@@map("goods")
|
||||||
}
|
}
|
||||||
|
|
||||||
//商品标签表
|
// 标签表
|
||||||
model Tag {
|
model Tag {
|
||||||
id String @id @default(cuid())
|
id String @id @default(cuid())
|
||||||
name String @unique
|
name String @unique
|
||||||
goods Goods[] @relation("goods_tag")
|
goods Goods[] @relation("GoodsTags")
|
||||||
createdAt DateTime @default(now()) @map("created_at")
|
createdAt DateTime @default(now()) @map("created_at")
|
||||||
updatedAt DateTime @updatedAt @map("updated_at")
|
updatedAt DateTime @updatedAt @map("updated_at")
|
||||||
deletedAt DateTime? @map("deleted_at")
|
deletedAt DateTime? @map("deleted_at")
|
||||||
|
|
Loading…
Reference in New Issue