This commit is contained in:
linfeng 2025-03-26 13:03:18 +08:00
parent 14b977b28a
commit 4716f5e863
2 changed files with 48 additions and 16 deletions

View File

@ -3,7 +3,7 @@ import { areaOptions } from "@web/src/data/area-options";
export const defaultFields = [
// 基本信息组
{ name: 'username', label: '用户名', type: 'text',required: true, group: '基本信息', order: 1 },
{ name: 'showname', label: '显示名称', type: 'text', group: '基本信息', order: 2 },
// { name: 'showname', label: '显示名称', type: 'text', group: '基本信息', order: 2 },
{ name: 'idNumber', label: '身份证号', type: 'text', group: '基本信息', order: 3 },
{ name: 'officerId', label: '警号', type: 'text', group: '基本信息', order: 4 },
{ name: 'phoneNumber', label: '手机号', type: 'text', group: '基本信息', order: 5 },
@ -35,6 +35,7 @@ export const defaultFields = [
group: '基本信息',
order: 9 },
{ name: 'source', label: '来源', type: 'text', group: '基本信息', order: 10 },
{name: 'department', label: '部门', type: 'text', group: '基本信息', order: 11 },
// 政治信息组
{ name: 'politicalStatus',
@ -145,13 +146,15 @@ export const defaultFields = [
type: 'text',
group: '鉴定信息',
order: 32 ,
dependsOn: {field: 'hasCert', value: '是'}},
dependsOn: {field: 'hasCert', value: '是'},
isSystem: false},
{ name: 'certWork',
label: '鉴定工种',
type: 'text',
group: '鉴定信息',
order: 33 ,
dependsOn: {field: 'hasCert', value: '是'}},
dependsOn: {field: 'hasCert', value: '是'},
isSystem: false},
{ name: 'hasCert',
label: '是否参加鉴定',
type: 'radio',
@ -160,7 +163,8 @@ export const defaultFields = [
{ label: '否', value: '否' },
],
group: '鉴定信息',
order: 34 },
order: 34 ,
isSystem: false},
// 工作信息组
{ name: 'equipment', label: '操作维护装备', type: 'textarea', group: '工作信息', order: 35 },

View File

@ -1,5 +1,3 @@
"use client";
import { Button, Form, Input, Select, DatePicker, Radio, message, Modal, Cascader, InputNumber } from "antd";
import { useState, useMemo } from "react";
import { useStaff } from "@nice/client";
@ -9,7 +7,8 @@ import InfoCard from './infoCard';
const StaffInfoWrite = () => {
const [form] = Form.useForm();
const [loading, setLoading] = useState(false);
const { create, useCustomFields } = useStaff();
// 修改使用的hook方法
const { create, setCustomFieldValue, useCustomFields } = useStaff();
const { data: fields, isLoading: fieldsLoading } = useCustomFields();
const [infoCards, setInfoCards] = useState<any[]>([]);
const handleAdd = ( content: string) => {
@ -62,15 +61,44 @@ const StaffInfoWrite = () => {
const onFinish = async (values: any) => {
try {
setLoading(true);
const formattedValues = {
...values,
birthplace: values.birthplace?.join('/'),
};
await create.mutateAsync({
data: formattedValues
// 创建基础员工记录
const staff = await create.mutateAsync({
data: {
username: values.username,
password: '123456'
}
});
// 过滤有效字段并转换值
const validEntries = Object.entries(values)
.filter(([_, value]) => value !== undefined && value !== null && value !== '')
.map(([fieldName, value]) => {
const field = fields?.find((f: any) => f.name === fieldName);
let processedValue = value;
// 处理特殊字段类型
if (field?.type === 'date' && value instanceof moment) {
processedValue = value.format('YYYY-MM-DD');
} else if (field?.type === 'cascader' && Array.isArray(value)) {
processedValue = value.join('/');
}
return { field, value: processedValue };
})
.filter(item => item.field?.id); // 过滤有效字段定义
// 批量提交自定义字段
await Promise.all(
validEntries.map(({ field, value }) =>
setCustomFieldValue.mutateAsync({
staffId: staff.id,
fieldId: field.id,
value: String(value)
})
)
);
message.success("信息提交成功");
} catch (error) {
console.error('提交出错:', error);