generated from template/vite-react-template
docs: 文档添加
This commit is contained in:
parent
f8876964b9
commit
4b4e596b0c
@ -17,7 +17,7 @@
|
|||||||
"build": "rimraf dist && bun run bun.config.mjs",
|
"build": "rimraf dist && bun run bun.config.mjs",
|
||||||
"test": "tsx test/**/*.ts",
|
"test": "tsx test/**/*.ts",
|
||||||
"clean": "rm -rf dist",
|
"clean": "rm -rf dist",
|
||||||
"pub": "npm run build && envision pack -p -u",
|
"pub": "envision pack -p -u",
|
||||||
"cmd": "tsx cmd/index.ts "
|
"cmd": "tsx cmd/index.ts "
|
||||||
},
|
},
|
||||||
"keywords": [],
|
"keywords": [],
|
||||||
|
@ -1 +1,14 @@
|
|||||||
|
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';
|
import './index.ts';
|
||||||
|
|
||||||
|
app.listen(3004, () => {
|
||||||
|
console.log('Server is running on http://localhost:3004');
|
||||||
|
});
|
||||||
|
|
||||||
|
app.onServerRequest(proxyRoute);
|
||||||
|
@ -1,15 +1,2 @@
|
|||||||
import { proxyRoute, initProxy } from '@kevisual/local-proxy/proxy.ts';
|
import './app.ts';
|
||||||
initProxy({
|
|
||||||
pagesDir: './pages',
|
|
||||||
watch: true,
|
|
||||||
home: '/root/tickets',
|
|
||||||
});
|
|
||||||
import { app } from './app.ts';
|
|
||||||
|
|
||||||
import './routes/ticket/list.ts';
|
import './routes/ticket/list.ts';
|
||||||
|
|
||||||
app.listen(3004, () => {
|
|
||||||
console.log('Server is running on http://localhost:3004');
|
|
||||||
});
|
|
||||||
|
|
||||||
app.onServerRequest(proxyRoute);
|
|
||||||
|
@ -23,29 +23,15 @@ app
|
|||||||
key: 'list',
|
key: 'list',
|
||||||
})
|
})
|
||||||
.define(async (ctx) => {
|
.define(async (ctx) => {
|
||||||
const searchForm = ctx.query?.data || {} as SearchTicketsParams;
|
const searchForm = ctx.query?.data || ({} as SearchTicketsParams);
|
||||||
const {
|
const { current = 1, pageSize = 10, search, status, type, sort = 'createdAt', order = 'desc', uid, startDate, endDate } = searchForm;
|
||||||
current = 1,
|
|
||||||
pageSize = 10,
|
|
||||||
search,
|
|
||||||
status,
|
|
||||||
type,
|
|
||||||
sort = 'createdAt',
|
|
||||||
order = 'desc',
|
|
||||||
uid,
|
|
||||||
startDate,
|
|
||||||
endDate
|
|
||||||
} = searchForm;
|
|
||||||
|
|
||||||
// 构建查询条件
|
// 构建查询条件
|
||||||
let where: any = {};
|
let where: any = {};
|
||||||
|
|
||||||
// 如果提供了搜索关键词,同时搜索标题和描述
|
// 如果提供了搜索关键词,同时搜索标题和描述
|
||||||
if (search) {
|
if (search) {
|
||||||
where[Op.or] = [
|
where[Op.or] = [{ title: { [Op.like]: `%${search}%` } }, { description: { [Op.like]: `%${search}%` } }];
|
||||||
{ title: { [Op.like]: `%${search}%` } },
|
|
||||||
{ description: { [Op.like]: `%${search}%` } }
|
|
||||||
];
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// 添加其他过滤条件
|
// 添加其他过滤条件
|
||||||
@ -93,14 +79,24 @@ app
|
|||||||
.define(async (ctx) => {
|
.define(async (ctx) => {
|
||||||
const data = ctx.query?.data || {};
|
const data = ctx.query?.data || {};
|
||||||
const { id, ...updateData } = 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) {
|
if (!ticket) {
|
||||||
ctx.throw(404, 'Ticket not found');
|
ctx.throw(404, 'Ticket not found');
|
||||||
}
|
}
|
||||||
await ticket.update(updateData);
|
if (!isNew) {
|
||||||
|
await ticket.update(updateData);
|
||||||
|
}
|
||||||
ctx.body = ticket;
|
ctx.body = ticket;
|
||||||
})
|
})
|
||||||
.addTo(app);
|
.addTo(app);
|
||||||
|
@ -39,10 +39,12 @@ TicketModel.init(
|
|||||||
type: {
|
type: {
|
||||||
type: DataTypes.STRING,
|
type: DataTypes.STRING,
|
||||||
allowNull: false,
|
allowNull: false,
|
||||||
|
defaultValue: 'rule',
|
||||||
},
|
},
|
||||||
title: {
|
title: {
|
||||||
type: DataTypes.STRING,
|
type: DataTypes.STRING,
|
||||||
allowNull: false,
|
allowNull: false,
|
||||||
|
defaultValue: '未命名票据',
|
||||||
},
|
},
|
||||||
description: {
|
description: {
|
||||||
type: DataTypes.TEXT,
|
type: DataTypes.TEXT,
|
||||||
@ -56,10 +58,11 @@ TicketModel.init(
|
|||||||
price: {
|
price: {
|
||||||
type: DataTypes.STRING,
|
type: DataTypes.STRING,
|
||||||
allowNull: false,
|
allowNull: false,
|
||||||
|
defaultValue: '0',
|
||||||
},
|
},
|
||||||
uid: {
|
uid: {
|
||||||
type: DataTypes.STRING,
|
type: DataTypes.STRING,
|
||||||
allowNull: false,
|
allowNull: true,
|
||||||
},
|
},
|
||||||
createdAt: {
|
createdAt: {
|
||||||
type: DataTypes.DATE,
|
type: DataTypes.DATE,
|
||||||
@ -77,4 +80,4 @@ TicketModel.init(
|
|||||||
},
|
},
|
||||||
);
|
);
|
||||||
|
|
||||||
await TicketModel.sync({ alter: true })
|
await TicketModel.sync({ alter: true });
|
||||||
|
@ -5,7 +5,7 @@
|
|||||||
<meta charset="UTF-8" />
|
<meta charset="UTF-8" />
|
||||||
<link rel="icon" type="image/svg+xml" href="/vite.svg" />
|
<link rel="icon" type="image/svg+xml" href="/vite.svg" />
|
||||||
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
|
<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" />
|
<link rel="stylesheet" href="/src/index.css" />
|
||||||
<style>
|
<style>
|
||||||
html,
|
html,
|
||||||
|
@ -1,5 +1,5 @@
|
|||||||
{
|
{
|
||||||
"name": "vite-react",
|
"name": "tickets",
|
||||||
"private": true,
|
"private": true,
|
||||||
"version": "0.0.1",
|
"version": "0.0.1",
|
||||||
"type": "module",
|
"type": "module",
|
||||||
@ -11,7 +11,7 @@
|
|||||||
"postbuild2": "pnpm build:css",
|
"postbuild2": "pnpm build:css",
|
||||||
"postbuild": "rsync -av --delete ./dist/* ./backend/pages/root/tickets",
|
"postbuild": "rsync -av --delete ./dist/* ./backend/pages/root/tickets",
|
||||||
"preview": "vite preview",
|
"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"
|
"serve": "cd backend && bun --watch src/dev.ts"
|
||||||
},
|
},
|
||||||
"files": [
|
"files": [
|
||||||
@ -22,7 +22,7 @@
|
|||||||
"dependencies": {
|
"dependencies": {
|
||||||
"@ant-design/icons": "^6.0.0",
|
"@ant-design/icons": "^6.0.0",
|
||||||
"@ant-design/v5-patch-for-react-19": "^1.0.3",
|
"@ant-design/v5-patch-for-react-19": "^1.0.3",
|
||||||
"@kevisual/router": "0.0.22",
|
"@kevisual/router": "0.0.23",
|
||||||
"antd": "^5.26.1",
|
"antd": "^5.26.1",
|
||||||
"clsx": "^2.1.1",
|
"clsx": "^2.1.1",
|
||||||
"dayjs": "^1.11.13",
|
"dayjs": "^1.11.13",
|
||||||
|
Loading…
x
Reference in New Issue
Block a user