Add employee code assignment function

This commit is contained in:
2026-03-02 12:58:05 +08:00
parent d2dac6091e
commit 76ea5a2e06
9 changed files with 1068 additions and 160 deletions
+49 -14
View File
@@ -1,18 +1,28 @@
import { useState, useEffect } from 'react';
import { Input, Button, Card, message, Spin, Result } from 'antd';
import { Input, Button, Card, message, Spin, Result, Tag } from 'antd';
import { QrcodeOutlined, SearchOutlined, ArrowLeftOutlined, CheckCircleOutlined, CloseCircleOutlined } from '@ant-design/icons';
import { serialApi } from '@/services/api';
import { employeeSerialApi } from '@/services/api';
import type { Serial } from '@/types';
import './styles/PublicQuery.css';
import logo from '@/assets/img/logo.png?url';
import beian from '@/assets/img/beian.png?url';
interface EmployeeSerialResult {
serialNumber: string;
companyName: string;
department: string;
employeeName: string;
isActive: boolean;
createdAt: string;
}
function PublicQueryPage() {
const [serialNumber, setSerialNumber] = useState('');
const [loading, setLoading] = useState(false);
const [result, setResult] = useState<Serial | null>(null);
const [result, setResult] = useState<Serial | EmployeeSerialResult | null>(null);
const [error, setError] = useState<string | null>(null);
const [showResult, setShowResult] = useState(false);
const [serialType, setSerialType] = useState<'company' | 'employee'>('company');
const performQuery = async (serialToQuery: string) => {
setLoading(true);
@@ -20,8 +30,14 @@ function PublicQueryPage() {
setResult(null);
try {
const data = await serialApi.query(serialToQuery);
setResult(data);
const response = await employeeSerialApi.queryAll(serialToQuery);
if (response.type === 'employee') {
setSerialType('employee');
setResult(response.data as EmployeeSerialResult);
} else {
setSerialType('company');
setResult(response.data as Serial);
}
} catch (err: any) {
setError(err.message || '查询失败');
setResult(null);
@@ -104,16 +120,19 @@ function PublicQueryPage() {
</div>
) : result ? (
<div className="success-container">
{result.status !== 'active' ? (
{(result as any).isActive === false || (result as any).status === 'inactive' ? (
<Result
icon={<CloseCircleOutlined style={{ color: '#ff4d4f', fontSize: '72px' }} />}
title="授权已吊销"
subTitle={`序列号验证通过,但已被吊销。企业:${result.companyName}`}
title={serialType === 'employee' ? "员工身份已吊销" : "授权已吊销"}
subTitle={serialType === 'employee'
? `序列号验证通过,但已被吊销。企业:${(result as EmployeeSerialResult).companyName}`
: `序列号验证通过,但已被吊销。企业:${(result as Serial).companyName}`
}
/>
) : (
<Result
icon={<CheckCircleOutlined style={{ color: '#52c41a', fontSize: '72px' }} />}
title="授权有效"
title={serialType === 'employee' ? "员工身份有效" : "授权有效"}
subTitle="您的序列号已验证通过"
/>
)}
@@ -127,14 +146,30 @@ function PublicQueryPage() {
<span className="label"></span>
<span className="value">{result.companyName}</span>
</div>
<div className="detail-item">
<span className="label"></span>
<span className="value">{new Date(result.validUntil).toLocaleString('zh-CN')}</span>
</div>
{serialType === 'employee' && (result as EmployeeSerialResult).department && (
<>
<div className="detail-item">
<span className="label"></span>
<span className="value">{(result as EmployeeSerialResult).department}</span>
</div>
<div className="detail-item">
<span className="label"></span>
<span className="value">{(result as EmployeeSerialResult).employeeName}</span>
</div>
</>
)}
{serialType !== 'employee' && (result as Serial).validUntil && (
<div className="detail-item">
<span className="label"></span>
<span className="value">{new Date((result as Serial).validUntil).toLocaleString('zh-CN')}</span>
</div>
)}
<div className="detail-item">
<span className="label"></span>
<span className="value status">
{result.status === 'active' ? '有效' : '已吊销'}
<Tag color={(result as any).isActive === false || (result as any).status === 'inactive' ? 'red' : 'green'}>
{(result as any).isActive === false || (result as any).status === 'inactive' ? '已吊销' : '有效'}
</Tag>
</span>
</div>
</div>