修改友情分类管理和友情管理bug

This commit is contained in:
linxd
2025-07-14 12:05:13 +08:00
parent 087d84a08b
commit cd1ab80a5d
6 changed files with 90 additions and 39 deletions

Binary file not shown.

Before

Width:  |  Height:  |  Size: 4.2 KiB

After

Width:  |  Height:  |  Size: 2.6 KiB

View File

@ -62,7 +62,6 @@ const FileUpload: React.FC<FileUploadProps> = ({
// 监听value变化
useEffect(() => {
// 处理字符串URL值这是关键修复
if (typeof value === 'string' && value) {
const file: Partial<UploadFile> = {

View File

@ -26,14 +26,15 @@ export const useFriendLinkDict = () => {
};
// 友情链接分类类型选项
// type int 是 类型(0.普通展示、1.重点展示)
const categoryTypeOptions = [
{
label: intl.formatMessage({ id: 'friendLink.category.type.normal' }),
value: 'normal',
value: '0',
},
{
label: intl.formatMessage({ id: 'friendLink.category.type.featured' }),
value: 'featured',
value: '1',
},
];

View File

@ -4,6 +4,7 @@ import { Card, Form, Input, Button, message, Tabs, Spin } from 'antd';
import WangEditor from '@/components/WangEidtor/WangEidtor';
import { getAboutUs, updateAboutUs, AboutUsRequest } from '@/servers/api/about';
import styles from './aboutManage.less';
import FileUpload from '@/components/FileUpload'
const { TabPane } = Tabs;
@ -44,6 +45,8 @@ const AboutManage: React.FC = () => {
contactsEmailEn: response.data.contactsEmailEn,
contactsConsult: response.data.contactsConsult,
contactsConsultEn: response.data.contactsConsultEn,
// address_img varchar(255) 地址地图图片
addressImg: response.data.addressImg,
});
} else {
message.error(response.message || intl.formatMessage({ id: 'aboutManage.fetchFailed' }));
@ -72,15 +75,19 @@ const AboutManage: React.FC = () => {
const values = await form.validateFields();
setSubmitting(true);
// 处理上传文件字段
const formattedValues = { ...values };
if (values.addressImg && Array.isArray(values.addressImg) && values.addressImg.length > 0) {
// 如果addressImg是文件数组提取URL
formattedValues.addressImg = values.addressImg[0]?.url || '';
}
// 准备提交数据
const submitData: AboutUsRequest = {
...aboutData,
...values,
...formattedValues,
};
// 保留原有的addressImg如果没有则设置为空字符串
submitData.addressImg = aboutData?.addressImg || '';
const response = await updateAboutUs(submitData);
if (response && response.success) {
message.success(intl.formatMessage({ id: 'aboutManage.saveSuccess' }));
@ -141,6 +148,30 @@ const AboutManage: React.FC = () => {
layout="vertical"
initialValues={aboutData || {}}
>
<Form.Item
name="addressImg"
label="地址图片"
rules={[{ required: true, message: '请上传地址图片' }]}
normalize={(value) => {
if (typeof value === 'string') {
return [
{
uid: '-1',
name: 'image.jpg',
status: 'done',
url: value,
}
];
}
return value;
}}
>
<FileUpload
maxCount={1}
maxSize={2}
listType="picture-card"
/>
</Form.Item>
<Tabs activeKey={activeTabKey} onChange={handleTabChange}>
<TabPane tab={intl.formatMessage({ id: 'aboutManage.form.chineseTab' })} key="zh">
<Form.Item

View File

@ -2,7 +2,7 @@ import React, { useState, useEffect } from 'react';
import { useIntl } from 'umi';
import { Card, Table, Button, Modal, Form, Input, Space, message, Select, TreeSelect, Popconfirm, Tag } from 'antd';
import { PlusOutlined, DeleteOutlined, ExclamationCircleOutlined, EditOutlined } from '@ant-design/icons';
import { getCategoryList, getAllCategories, addCategory, updateCategory, deleteCategory } from '@/servers/api/friendLink';
import { getCategoryList, getAllCategories, addCategory, updateCategory, deleteCategory,getCategoryDetail } from '@/servers/api/friendLink';
import { useFriendLinkDict } from '@/dicts/friendLinkDict';
import styles from './friendLinkManage.less';
@ -76,16 +76,20 @@ const FriendLinkCategory: React.FC = () => {
// 处理编辑分类
const handleEditCategory = (record: API.CategoryType) => {
setIsEdit(true);
setCurrentCategory(record);
form.setFieldsValue({
name: record.name,
type: record.type,
parentId: record.parentId,
orderBy: record.orderBy,
remark: record.remark,
getCategoryDetail(record.id).then((res: API.Response<API.CategoryType>) => {
if (res.success && res.data) {
setIsEdit(true);
setCurrentCategory(res.data);
form.setFieldsValue({
name: res.data.name,
type: res.data.type,
parentId: res.data.parentId,
orderBy: res.data.orderBy,
remark: res.data.remark,
});
setModalVisible(true);
}
});
setModalVisible(true);
};
// 处理删除分类

View File

@ -109,18 +109,19 @@ const FriendLinkManage: React.FC = () => {
.then((res: API.Response<API.LinkType>) => {
if (res.success && res.data) {
const detail = res.data;
console.log('Detail data:', detail);
// 设置表单初始值包括缩略图URL
form.setFieldsValue({
// 设置表单初始值
const formValues = {
name: detail.name,
nameEn: detail.nameEn,
url: detail.url,
orderBy: parseInt(detail.orderBy),
classificationId: detail.classificationId,
// 设置为URL字符串组件会自动处理
thumbnail: detail.thumbnail,
});
// 直接使用缩略图URL字符串
thumbnail: detail.thumbnail || '',
};
form.setFieldsValue(formValues);
} else {
message.error(intl.formatMessage({ id: 'friendLink.detail.failed' }));
}
@ -236,14 +237,21 @@ const FriendLinkManage: React.FC = () => {
// 处理表单提交
const handleModalSubmit = () => {
form.validateFields().then(async (values) => {
console.log('Form values:', values);
try {
// 现在thumbnail字段已经直接是URL字符串不需要额外处理
const formData = {
...values,
};
// 处理表单数据
const formData = { ...values };
console.log('Submitting form data:', formData);
// 处理缩略图字段
if (formData.thumbnail && Array.isArray(formData.thumbnail) && formData.thumbnail.length > 0) {
// 提取URL
formData.thumbnail = formData.thumbnail[0]?.url || '';
} else if (typeof formData.thumbnail === 'string' && formData.thumbnail) {
// 如果已经是字符串URL直接使用
// 这种情况可能出现在编辑模式下
formData.thumbnail = formData.thumbnail;
} else {
formData.thumbnail = '';
}
let res;
if (isEdit) {
@ -350,12 +358,7 @@ const FriendLinkManage: React.FC = () => {
<div className="filter-action-row">
<div></div>
<div className="right-buttons">
<Button
type="primary"
ghost
icon={<PlusOutlined />}
onClick={handleAdd}
>
<Button type="primary" ghost icon={<PlusOutlined />} onClick={handleAdd}>
{intl.formatMessage({ id: 'friendLink.add' })}
</Button>
<Button
@ -368,7 +371,10 @@ const FriendLinkManage: React.FC = () => {
</Button>
{selectedRowKeys.length > 0 && (
<span className="selected-count">
{intl.formatMessage({ id: 'friendLink.selectedCount' }, { count: selectedRowKeys.length })}
{intl.formatMessage(
{ id: 'friendLink.selectedCount' },
{ count: selectedRowKeys.length },
)}
</span>
)}
</div>
@ -470,8 +476,18 @@ const FriendLinkManage: React.FC = () => {
<Form.Item
name="thumbnail"
label={intl.formatMessage({ id: 'friendLink.thumbnail' })}
getValueFromEvent={(e) => {
return e[0].url;
normalize={(value) => {
if (typeof value === 'string' && value) {
return [
{
uid: '-1',
name: 'thumbnail.jpg',
status: 'done',
url: value,
}
];
}
return value;
}}
rules={[
{
@ -484,7 +500,7 @@ const FriendLinkManage: React.FC = () => {
maxCount={1}
maxSize={2}
allowedTypes={['jpg', 'png']}
listType="picture"
listType="picture-card"
tip={intl.formatMessage(
{ id: 'component.fileUpload.fileTypeTip' },
{ types: 'JPG, PNG' },