docs: 文档添加

This commit is contained in:
熊潇 2025-06-20 11:16:55 +08:00
parent f8876964b9
commit 4b4e596b0c
8 changed files with 52 additions and 49 deletions

View File

@ -1,3 +1,7 @@
# 启动
> 所有的命令,在当前根目录下运行即可
## env
安装 node 环境

View File

@ -17,7 +17,7 @@
"build": "rimraf dist && bun run bun.config.mjs",
"test": "tsx test/**/*.ts",
"clean": "rm -rf dist",
"pub": "npm run build && envision pack -p -u",
"pub": "envision pack -p -u",
"cmd": "tsx cmd/index.ts "
},
"keywords": [],

View File

@ -1 +1,14 @@
import './index.ts';
import { proxyRoute, initProxy } from '@kevisual/local-proxy/proxy.ts';
initProxy({
pagesDir: './pages',
watch: true,
home: '/root/tickets',
});
import { app } from './app.ts';
import './index.ts';
app.listen(3004, () => {
console.log('Server is running on http://localhost:3004');
});
app.onServerRequest(proxyRoute);

View File

@ -1,15 +1,2 @@
import { proxyRoute, initProxy } from '@kevisual/local-proxy/proxy.ts';
initProxy({
pagesDir: './pages',
watch: true,
home: '/root/tickets',
});
import { app } from './app.ts';
import './app.ts';
import './routes/ticket/list.ts';
app.listen(3004, () => {
console.log('Server is running on http://localhost:3004');
});
app.onServerRequest(proxyRoute);

View File

@ -23,36 +23,22 @@ app
key: 'list',
})
.define(async (ctx) => {
const searchForm = ctx.query?.data || {} as SearchTicketsParams;
const {
current = 1,
pageSize = 10,
search,
status,
type,
sort = 'createdAt',
order = 'desc',
uid,
startDate,
endDate
} = searchForm;
const searchForm = ctx.query?.data || ({} as SearchTicketsParams);
const { current = 1, pageSize = 10, search, status, type, sort = 'createdAt', order = 'desc', uid, startDate, endDate } = searchForm;
// 构建查询条件
let where: any = {};
// 如果提供了搜索关键词,同时搜索标题和描述
if (search) {
where[Op.or] = [
{ title: { [Op.like]: `%${search}%` } },
{ description: { [Op.like]: `%${search}%` } }
];
where[Op.or] = [{ title: { [Op.like]: `%${search}%` } }, { description: { [Op.like]: `%${search}%` } }];
}
// 添加其他过滤条件
if (status) where.status = status;
if (type) where.type = type;
if (uid) where.uid = uid;
// 日期范围过滤
if (startDate || endDate) {
const dateFilter: any = {};
@ -65,14 +51,14 @@ app
const validSortFields = ['id', 'title', 'status', 'type', 'price', 'createdAt', 'updatedAt'];
const sortField = validSortFields.includes(sort) ? sort : 'createdAt';
const sortOrder = order?.toUpperCase() === 'ASC' ? 'ASC' : 'DESC';
const { rows, count } = await TicketModel.findAndCountAll({
where,
offset: (current - 1) * pageSize,
limit: pageSize,
order: [[sortField, sortOrder]],
});
ctx.body = {
list: rows,
pagination: {
@ -93,14 +79,24 @@ app
.define(async (ctx) => {
const data = ctx.query?.data || {};
const { id, ...updateData } = data;
if (!id) {
ctx.throw(400, 'ID is required for update');
let ticket: TicketModel;
let isNew = false;
if (id) {
ticket = await TicketModel.findByPk(id);
if (!ticket) {
ctx.throw(404, 'Ticket not found');
}
} else {
isNew = true;
ticket = await TicketModel.create({ ...updateData });
}
const ticket = await TicketModel.findByPk(id);
if (!ticket) {
ctx.throw(404, 'Ticket not found');
}
await ticket.update(updateData);
if (!isNew) {
await ticket.update(updateData);
}
ctx.body = ticket;
})
.addTo(app);

View File

@ -39,10 +39,12 @@ TicketModel.init(
type: {
type: DataTypes.STRING,
allowNull: false,
defaultValue: 'rule',
},
title: {
type: DataTypes.STRING,
allowNull: false,
defaultValue: '未命名票据',
},
description: {
type: DataTypes.TEXT,
@ -56,10 +58,11 @@ TicketModel.init(
price: {
type: DataTypes.STRING,
allowNull: false,
defaultValue: '0',
},
uid: {
type: DataTypes.STRING,
allowNull: false,
allowNull: true,
},
createdAt: {
type: DataTypes.DATE,
@ -77,4 +80,4 @@ TicketModel.init(
},
);
await TicketModel.sync({ alter: true })
await TicketModel.sync({ alter: true });

View File

@ -5,7 +5,7 @@
<meta charset="UTF-8" />
<link rel="icon" type="image/svg+xml" href="/vite.svg" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<title>Vite + React + TS</title>
<title>工单系统</title>
<link rel="stylesheet" href="/src/index.css" />
<style>
html,

View File

@ -1,5 +1,5 @@
{
"name": "vite-react",
"name": "tickets",
"private": true,
"version": "0.0.1",
"type": "module",
@ -11,7 +11,7 @@
"postbuild2": "pnpm build:css",
"postbuild": "rsync -av --delete ./dist/* ./backend/pages/root/tickets",
"preview": "vite preview",
"pub": "envision deploy ./dist -k vite-react -v 0.0.1",
"pub": "envision deploy ./dist -k tickets -v 0.0.1 -u",
"serve": "cd backend && bun --watch src/dev.ts"
},
"files": [
@ -22,7 +22,7 @@
"dependencies": {
"@ant-design/icons": "^6.0.0",
"@ant-design/v5-patch-for-react-19": "^1.0.3",
"@kevisual/router": "0.0.22",
"@kevisual/router": "0.0.23",
"antd": "^5.26.1",
"clsx": "^2.1.1",
"dayjs": "^1.11.13",