123
This commit is contained in:
parent
3af6216828
commit
d13e197c82
|
@ -30,6 +30,7 @@ export class BaseService<
|
||||||
A extends DelegateArgs<D> = DelegateArgs<D>,
|
A extends DelegateArgs<D> = DelegateArgs<D>,
|
||||||
R extends DelegateReturnTypes<D> = DelegateReturnTypes<D>,
|
R extends DelegateReturnTypes<D> = DelegateReturnTypes<D>,
|
||||||
> {
|
> {
|
||||||
|
[x: string]: any;
|
||||||
protected ORDER_INTERVAL = 100;
|
protected ORDER_INTERVAL = 100;
|
||||||
/**
|
/**
|
||||||
* Initializes the BaseService with the specified model.
|
* Initializes the BaseService with the specified model.
|
||||||
|
@ -152,27 +153,27 @@ export class BaseService<
|
||||||
* @example
|
* @example
|
||||||
* const newUser = await service.create({ data: { name: 'John Doe' } });
|
* const newUser = await service.create({ data: { name: 'John Doe' } });
|
||||||
*/
|
*/
|
||||||
async create(args: A['create'], params?: any): Promise<R['create']> {
|
// async create(args: A['create'], params?: any): Promise<R['create']> {
|
||||||
try {
|
// try {
|
||||||
if (this.enableOrder && !(args as any).data.order) {
|
// if (this.enableOrder && !(args as any).data.order) {
|
||||||
// 查找当前最大的 order 值
|
// // 查找当前最大的 order 值
|
||||||
const maxOrderItem = (await this.getModel(params?.tx).findFirst({
|
// const maxOrderItem = (await this.getModel(params?.tx).findFirst({
|
||||||
orderBy: { order: 'desc' },
|
// orderBy: { order: 'desc' },
|
||||||
})) as any;
|
// })) as any;
|
||||||
// 设置新记录的 order 值
|
// // 设置新记录的 order 值
|
||||||
const newOrder = maxOrderItem
|
// const newOrder = maxOrderItem
|
||||||
? maxOrderItem.order + this.ORDER_INTERVAL
|
// ? maxOrderItem.order + this.ORDER_INTERVAL
|
||||||
: 1;
|
// : 1;
|
||||||
// 将 order 添加到创建参数中
|
// // 将 order 添加到创建参数中
|
||||||
(args as any).data.order = newOrder;
|
// (args as any).data.order = newOrder;
|
||||||
}
|
// }
|
||||||
return this.getModel(params?.tx).create(args as any) as Promise<
|
// return this.getModel(params?.tx).create(args as any) as Promise<
|
||||||
R['create']
|
// R['create']
|
||||||
>;
|
// >;
|
||||||
} catch (error) {
|
// } catch (error) {
|
||||||
this.handleError(error, 'create');
|
// this.handleError(error, 'create');
|
||||||
}
|
// }
|
||||||
}
|
// }
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Creates multiple new records with the given data.
|
* Creates multiple new records with the given data.
|
||||||
|
|
|
@ -1,5 +1,6 @@
|
||||||
import { Table, Select, Form, Button, Space, InputNumber, Modal } from 'antd';
|
import { Table, Select, Form, Button, Space, InputNumber, Modal, message } from 'antd';
|
||||||
import { useState } from 'react';
|
import { useState, useEffect } from 'react';
|
||||||
|
import { api } from '@nice/client';
|
||||||
|
|
||||||
// 模拟接口调用函数
|
// 模拟接口调用函数
|
||||||
const addAgeRangeApi = async (start: number, end: number | null) => {
|
const addAgeRangeApi = async (start: number, end: number | null) => {
|
||||||
|
@ -14,14 +15,25 @@ const addScoreStandardApi = async (score: number, standards: (number | null)[])
|
||||||
|
|
||||||
export default function AssessmentStandardPage() {
|
export default function AssessmentStandardPage() {
|
||||||
const [form] = Form.useForm();
|
const [form] = Form.useForm();
|
||||||
const [ageRanges, setAgeRanges] = useState<{ start: number; end: number; label: string; }[]>([
|
const [standardForm] = Form.useForm();
|
||||||
{ start: 18, end: 24, label: '18-24岁' },
|
const [ageRanges, setAgeRanges] = useState<{ start: number; end: number | null; label: string; }[]>([]);
|
||||||
{ start: 25, end: 34, label: '25-34岁' },
|
const [dataSource, setDataSource] = useState<any[]>([]);
|
||||||
{ start: 35, end: 44, label: '35-44岁' },
|
const [loading, setLoading] = useState(false);
|
||||||
{ start: 45, end: null, label: '45岁以上' },
|
// 新增状态控制模态框显示隐藏
|
||||||
]);
|
const [isModalVisible, setIsModalVisible] = useState(false);
|
||||||
const [isAgeModalVisible, setIsAgeModalVisible] = useState(false);
|
// 新增状态存储年龄范围起始值
|
||||||
const [isScoreModalVisible, setIsScoreModalVisible] = useState(false);
|
const [startAge, setStartAge] = useState<number | null>(null);
|
||||||
|
// 新增状态存储年龄范围结束值
|
||||||
|
const [endAge, setEndAge] = useState<number | null>(null);
|
||||||
|
|
||||||
|
// TRPC mutations
|
||||||
|
// const createStandardMutation = api.sportStandard.createStandard.useMutation();
|
||||||
|
// const updateStandardMutation = api.sportStandard.update.useMutation();
|
||||||
|
// const standardsQuery = api.sportStandard.findMany.useQuery({
|
||||||
|
// include: {
|
||||||
|
// project: true
|
||||||
|
// }
|
||||||
|
// });
|
||||||
|
|
||||||
const columns = [
|
const columns = [
|
||||||
{
|
{
|
||||||
|
@ -45,64 +57,121 @@ export default function AssessmentStandardPage() {
|
||||||
];
|
];
|
||||||
|
|
||||||
const handleStandardChange = (score: number, ageIndex: number, value: number | null) => {
|
const handleStandardChange = (score: number, ageIndex: number, value: number | null) => {
|
||||||
// 处理标准值变化
|
const newDataSource = dataSource.map(item => {
|
||||||
|
if (item.score === score) {
|
||||||
|
return {
|
||||||
|
...item,
|
||||||
|
[`standard_${ageIndex}`]: value
|
||||||
|
};
|
||||||
|
}
|
||||||
|
return item;
|
||||||
|
});
|
||||||
|
setDataSource(newDataSource);
|
||||||
};
|
};
|
||||||
|
|
||||||
const showAgeModal = () => {
|
const handleAddAgeRange = () => {
|
||||||
setIsAgeModalVisible(true);
|
// 点击按钮显示模态框
|
||||||
|
setIsModalVisible(true);
|
||||||
};
|
};
|
||||||
|
|
||||||
const handleAgeOk = async (values: any) => {
|
const handleOk = async () => {
|
||||||
const { start, end } = values;
|
if (startAge === null) {
|
||||||
await addAgeRangeApi(start, end);
|
message.error('请输入起始年龄');
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
try {
|
||||||
|
// 调用模拟接口
|
||||||
|
await addAgeRangeApi(startAge, endAge);
|
||||||
const newRange = {
|
const newRange = {
|
||||||
start,
|
start: startAge,
|
||||||
end,
|
end: endAge,
|
||||||
label: end ? `${start}-${end}岁` : `${start}岁以上`,
|
label: endAge ? `${startAge}-${endAge}岁` : `${startAge}岁以上`
|
||||||
};
|
};
|
||||||
setAgeRanges([...ageRanges, newRange]);
|
setAgeRanges([...ageRanges, newRange]);
|
||||||
setIsAgeModalVisible(false);
|
setIsModalVisible(false);
|
||||||
|
message.success('年龄范围添加成功');
|
||||||
|
} catch (error) {
|
||||||
|
console.error('添加年龄范围失败:', error);
|
||||||
|
message.error('添加年龄范围失败');
|
||||||
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
const handleAgeCancel = () => {
|
const handleCancel = () => {
|
||||||
setIsAgeModalVisible(false);
|
// 关闭模态框
|
||||||
|
setIsModalVisible(false);
|
||||||
};
|
};
|
||||||
|
|
||||||
const showScoreModal = () => {
|
const handleSave = async () => {
|
||||||
setIsScoreModalVisible(true);
|
try {
|
||||||
|
const values = await form.validateFields();
|
||||||
|
const { projectId, gender, personType, ageRanges} = values;
|
||||||
|
|
||||||
|
// 将表格数据转换为后端需要的格式
|
||||||
|
const scoreTable: Record<string, number[]> = {};
|
||||||
|
dataSource.forEach(row => {
|
||||||
|
const standards = ageRanges?.map((_, index) => row[`standard_${index}`]);
|
||||||
|
scoreTable[row.score] = standards;
|
||||||
|
});
|
||||||
|
|
||||||
|
|
||||||
|
setLoading(true);
|
||||||
|
await api.sportStandard.createStandard.useMutation().mutateAsync({
|
||||||
|
data: {
|
||||||
|
projectId,
|
||||||
|
gender,
|
||||||
|
personType,
|
||||||
|
ageRanges: ageRanges.map(range => ({
|
||||||
|
start: range.start,
|
||||||
|
end: range.end,
|
||||||
|
label: range.label
|
||||||
|
})),
|
||||||
|
scoreTable
|
||||||
|
}
|
||||||
|
});
|
||||||
|
message.success('保存成功');
|
||||||
|
} catch (error) {
|
||||||
|
console.error('保存失败:', error);
|
||||||
|
message.error('保存失败');
|
||||||
|
} finally {
|
||||||
|
setLoading(false);
|
||||||
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
const handleScoreOk = async (values: any) => {
|
useEffect(() => {
|
||||||
const { score, standards } = values;
|
// 初始化表格数据
|
||||||
await addScoreStandardApi(score, standards);
|
const initialData = [
|
||||||
// 这里可以更新表格的数据源
|
{ score: 100, standard_0: null, standard_1: null, standard_2: null, standard_3: null },
|
||||||
setIsScoreModalVisible(false);
|
{ score: 90, standard_0: null, standard_1: null, standard_2: null, standard_3: null },
|
||||||
};
|
];
|
||||||
|
setDataSource(initialData);
|
||||||
const handleScoreCancel = () => {
|
}, []);
|
||||||
setIsScoreModalVisible(false);
|
|
||||||
};
|
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<div className="p-6">
|
<div className="p-6">
|
||||||
<h1 className="text-2xl font-bold mb-6">考核标准管理</h1>
|
<h1 className="text-2xl font-bold mb-6">考核标准管理</h1>
|
||||||
<Button onClick={showAgeModal} className="mb-2">添加年龄范围</Button>
|
|
||||||
<Button onClick={showScoreModal} className="mb-2 ml-2">添加分数标准</Button>
|
|
||||||
<Form form={form} layout="vertical">
|
<Form form={form} layout="vertical">
|
||||||
<Space size="large" className="mb-6">
|
<Space size="large" className="mb-6">
|
||||||
<Form.Item label="项目" name="projectId">
|
<Form.Item
|
||||||
|
label="项目"
|
||||||
|
name="projectId"
|
||||||
|
rules={[{ required: true, message: '请选择考核项目' }]}
|
||||||
|
>
|
||||||
<Select
|
<Select
|
||||||
style={{ width: 200 }}
|
style={{ width: 200 }}
|
||||||
placeholder="选择考核项目"
|
placeholder="选择考核项目"
|
||||||
options={[
|
options={[
|
||||||
{ value: '1', label: '引体向上' },
|
{ value: '1', label: '引体向上' },
|
||||||
{ value: '2', label: '3000米跑' },
|
{ value: '2', label: '3000米跑' },
|
||||||
// 更多项目...
|
|
||||||
]}
|
]}
|
||||||
/>
|
/>
|
||||||
</Form.Item>
|
</Form.Item>
|
||||||
|
|
||||||
<Form.Item label="性别" name="gender">
|
<Form.Item
|
||||||
|
label="性别"
|
||||||
|
name="gender"
|
||||||
|
rules={[{ required: true, message: '请选择性别' }]}
|
||||||
|
>
|
||||||
<Select
|
<Select
|
||||||
style={{ width: 120 }}
|
style={{ width: 120 }}
|
||||||
placeholder="选择性别"
|
placeholder="选择性别"
|
||||||
|
@ -113,68 +182,64 @@ export default function AssessmentStandardPage() {
|
||||||
/>
|
/>
|
||||||
</Form.Item>
|
</Form.Item>
|
||||||
|
|
||||||
<Form.Item label="人员类型" name="personType">
|
<Form.Item
|
||||||
|
label="人员类型"
|
||||||
|
name="personType"
|
||||||
|
rules={[{ required: true, message: '请选择人员类型' }]}
|
||||||
|
>
|
||||||
<Select
|
<Select
|
||||||
style={{ width: 160 }}
|
style={{ width: 160 }}
|
||||||
placeholder="选择人员类型"
|
placeholder="选择人员类型"
|
||||||
options={[
|
options={[
|
||||||
{ value: 'OFFICER', label: '警员' },
|
{ value: 'officer', label: '警员' },
|
||||||
{ value: 'STAFF', label: '职工' },
|
{ value: 'civilian', label: '职工' },
|
||||||
]}
|
]}
|
||||||
/>
|
/>
|
||||||
</Form.Item>
|
</Form.Item>
|
||||||
|
|
||||||
|
<Form.Item label="添加年龄范围" name="ageRanges">
|
||||||
|
<Button type="primary" onClick={handleAddAgeRange}>
|
||||||
|
添加年龄范围
|
||||||
|
</Button>
|
||||||
|
</Form.Item>
|
||||||
</Space>
|
</Space>
|
||||||
|
|
||||||
<Table
|
<Table
|
||||||
columns={columns}
|
columns={columns}
|
||||||
dataSource={[
|
dataSource={dataSource}
|
||||||
{ score: 100, standard_0: 20, standard_1: 18, standard_2: 15, standard_3: 12 },
|
|
||||||
{ score: 90, standard_0: 18, standard_1: 16, standard_2: 13, standard_3: 10 },
|
|
||||||
{ score: 80, standard_0: 16, standard_1: 14, standard_2: 11, standard_3: 8 },
|
|
||||||
// 更多分数标准...
|
|
||||||
]}
|
|
||||||
bordered
|
bordered
|
||||||
pagination={false}
|
pagination={false}
|
||||||
scroll={{ x: 'max-content' }}
|
scroll={{ x: 'max-content' }}
|
||||||
|
loading={loading}
|
||||||
|
rowKey="score"
|
||||||
/>
|
/>
|
||||||
|
|
||||||
<div className="mt-6">
|
<div className="mt-6">
|
||||||
<Button type="primary">保存标准</Button>
|
<Button type="primary" onClick={handleSave} loading={loading}>
|
||||||
|
保存标准
|
||||||
|
</Button>
|
||||||
</div>
|
</div>
|
||||||
</Form>
|
</Form>
|
||||||
|
|
||||||
|
{/* 模态框组件 */}
|
||||||
<Modal
|
<Modal
|
||||||
title="添加年龄范围"
|
title="添加年龄范围"
|
||||||
visible={isAgeModalVisible}
|
visible={isModalVisible}
|
||||||
onOk={form.submit}
|
onOk={handleOk}
|
||||||
onCancel={handleAgeCancel}
|
onCancel={handleCancel}
|
||||||
>
|
>
|
||||||
<Form form={form} onFinish={handleAgeOk}>
|
<Form.Item label="起始年龄" required>
|
||||||
<Form.Item name="start" label="起始年龄" rules={[{ required: true }]}>
|
<InputNumber
|
||||||
<InputNumber min={1} />
|
value={startAge}
|
||||||
|
onChange={(value) => setStartAge(value)}
|
||||||
|
/>
|
||||||
</Form.Item>
|
</Form.Item>
|
||||||
<Form.Item name="end" label="结束年龄">
|
<Form.Item label="结束年龄">
|
||||||
<InputNumber min={1} />
|
<InputNumber
|
||||||
|
value={endAge}
|
||||||
|
onChange={(value) => setEndAge(value)}
|
||||||
|
/>
|
||||||
</Form.Item>
|
</Form.Item>
|
||||||
</Form>
|
|
||||||
</Modal>
|
|
||||||
|
|
||||||
<Modal
|
|
||||||
title="添加分数标准"
|
|
||||||
visible={isScoreModalVisible}
|
|
||||||
onOk={form.submit}
|
|
||||||
onCancel={handleScoreCancel}
|
|
||||||
>
|
|
||||||
<Form form={form} onFinish={handleScoreOk}>
|
|
||||||
<Form.Item name="score" label="分数" rules={[{ required: true }]}>
|
|
||||||
<InputNumber min={0} />
|
|
||||||
</Form.Item>
|
|
||||||
{ageRanges.map((range, index) => (
|
|
||||||
<Form.Item key={index} name={`standards[${index}]`} label={range.label}>
|
|
||||||
<InputNumber min={0} />
|
|
||||||
</Form.Item>
|
|
||||||
))}
|
|
||||||
</Form>
|
|
||||||
</Modal>
|
</Modal>
|
||||||
</div>
|
</div>
|
||||||
);
|
);
|
||||||
|
|
Loading…
Reference in New Issue