Add employee code assignment function
This commit is contained in:
+49
-14
@@ -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>
|
||||
|
||||
Reference in New Issue
Block a user