fix: harden real backend workflows and channel connections

This commit is contained in:
hectorzhao
2026-07-06 17:54:53 +08:00
parent 8cca361441
commit b5132d7f4e
47 changed files with 2530 additions and 314 deletions
+26 -28
View File
@@ -1,13 +1,11 @@
import { useEffect, useMemo, useState } from 'react';
import { useNavigate, useParams } from 'react-router-dom';
import { ImagePlus } from 'lucide-react';
import { adminApi, type TenantOption } from '@/api/adminApi';
import { Breadcrumb, Button, Input, Select, Textarea } from '@/components/ui';
import { adminApi, type FileRef, type TenantOption } from '@/api/adminApi';
import { Breadcrumb, Button, FileActions, Input, Select, Textarea } from '@/components/ui';
type EnterpriseForm = {
name: string;
code: string;
status: string;
creditCode: string;
province: string;
city: string;
@@ -18,6 +16,7 @@ type EnterpriseForm = {
contactEmail: string;
photoFileObjectId: string;
photoFileName: string;
photoContentType: string;
};
type EnterpriseFormErrors = Partial<Record<keyof EnterpriseForm, string>>;
@@ -44,8 +43,6 @@ const cityOptionsByProvince: Record<string, Array<{ label: string; value: string
const emptyForm: EnterpriseForm = {
name: '',
code: '',
status: 'active',
creditCode: '',
province: '',
city: '',
@@ -56,14 +53,13 @@ const emptyForm: EnterpriseForm = {
contactEmail: '',
photoFileObjectId: '',
photoFileName: '',
photoContentType: '',
};
function formFromTenant(tenant: TenantOption): EnterpriseForm {
const profile = tenant.enterpriseProfile;
return {
name: tenant.name,
code: tenant.code,
status: tenant.status,
creditCode: profile?.creditCode ?? '',
province: profile?.province ?? '',
city: profile?.city ?? '',
@@ -74,6 +70,7 @@ function formFromTenant(tenant: TenantOption): EnterpriseForm {
contactEmail: profile?.contactEmail ?? '',
photoFileObjectId: profile?.photoFileObjectId ?? '',
photoFileName: profile?.photoFileObjectId ? '已上传企业照片' : '',
photoContentType: '',
};
}
@@ -117,7 +114,6 @@ export function AdminCustomerFormPage() {
function validateForm() {
const nextErrors: EnterpriseFormErrors = {};
if (!form.name.trim()) nextErrors.name = '请填写企业名称';
if (!form.code.trim()) nextErrors.code = '请填写企业编码';
if (!form.creditCode.trim()) nextErrors.creditCode = '请填写统一社会信用代码';
if (!form.contactName.trim()) nextErrors.contactName = '请填写联系人姓名';
if (!form.contactPhone.trim()) nextErrors.contactPhone = '请填写手机号';
@@ -128,7 +124,7 @@ export function AdminCustomerFormPage() {
function submitForm() {
if (!validateForm()) return;
setSaving(true);
const { photoFileName, ...payload } = form;
const { photoContentType, photoFileName, ...payload } = form;
const request = isEdit && enterpriseId
? adminApi.updateTenant(enterpriseId, payload)
: adminApi.createTenant(payload);
@@ -143,13 +139,22 @@ export function AdminCustomerFormPage() {
setUploadingPhoto(true);
adminApi.uploadFileObject(file, { purpose: 'enterprise_photo', prefix: 'enterprise-photos' })
.then((fileObject) => {
setForm((current) => ({ ...current, photoFileObjectId: fileObject.id, photoFileName: fileObject.fileName }));
setForm((current) => ({
...current,
photoContentType: fileObject.contentType,
photoFileObjectId: fileObject.id,
photoFileName: fileObject.fileName,
}));
setError('');
})
.catch((failure: Error) => setError(failure.message || '企业照片上传失败'))
.finally(() => setUploadingPhoto(false));
}
const photoFile: FileRef | null = form.photoFileObjectId
? { contentType: form.photoContentType, fileName: form.photoFileName || '企业照片', fileObjectId: form.photoFileObjectId }
: null;
return (
<section className="page-stack enterprise-form-page">
<div className="page-heading">
@@ -182,22 +187,22 @@ export function AdminCustomerFormPage() {
type="file"
/>
</label>
<FileActions file={photoFile} />
<p>{form.photoFileObjectId ? `文件对象:${form.photoFileObjectId}` : '支持 JPG、PNG、WebP,上传后随企业档案保存。'}</p>
</div>
<div className="form-grid form-grid--two">
<Input error={errors.name} label="企业名称" onChange={(event) => updateForm('name', event.target.value)} placeholder="请填写企业全称" required value={form.name} />
<Input error={errors.code} label="企业编码" onChange={(event) => updateForm('code', event.target.value)} placeholder="请填写唯一企业编码" required value={form.code} />
<Input
error={errors.creditCode}
hint="修改此项将同步更新该企业档案。"
label="统一社会信用代码"
onChange={(event) => updateForm('creditCode', event.target.value)}
placeholder="请填写统一社会信用代码或纳税识别号"
required
value={form.creditCode}
/>
</div>
<Input
error={errors.creditCode}
hint="修改此项将同步更新该企业档案。"
label="统一社会信用代码"
onChange={(event) => updateForm('creditCode', event.target.value)}
placeholder="请填写统一社会信用代码或纳税识别号"
required
value={form.creditCode}
/>
<div className="form-grid form-grid--two">
<Select label="省/直辖市" onChange={(event) => updateForm('province', event.target.value)} options={provinceOptions} value={form.province} />
@@ -235,13 +240,6 @@ export function AdminCustomerFormPage() {
<Input error={errors.contactPhone} label="手机号" onChange={(event) => updateForm('contactPhone', event.target.value)} placeholder="请填写企业联系人手机号" required value={form.contactPhone} />
<Input label="电子邮箱" onChange={(event) => updateForm('contactEmail', event.target.value)} placeholder="请填写企业联系人邮箱" type="email" value={form.contactEmail} />
</div>
<Select
label="企业状态"
onChange={(event) => updateForm('status', event.target.value)}
options={[{ label: '正常', value: 'active' }, { label: '禁用', value: 'disabled' }]}
value={form.status}
/>
</section>
<div className="enterprise-form-footer">