修改友情分类管理和友情管理bug
This commit is contained in:
Binary file not shown.
Before Width: | Height: | Size: 4.2 KiB After Width: | Height: | Size: 2.6 KiB |
@ -62,7 +62,6 @@ const FileUpload: React.FC<FileUploadProps> = ({
|
|||||||
|
|
||||||
// 监听value变化
|
// 监听value变化
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
|
|
||||||
// 处理字符串URL值(这是关键修复)
|
// 处理字符串URL值(这是关键修复)
|
||||||
if (typeof value === 'string' && value) {
|
if (typeof value === 'string' && value) {
|
||||||
const file: Partial<UploadFile> = {
|
const file: Partial<UploadFile> = {
|
||||||
|
@ -26,14 +26,15 @@ export const useFriendLinkDict = () => {
|
|||||||
};
|
};
|
||||||
|
|
||||||
// 友情链接分类类型选项
|
// 友情链接分类类型选项
|
||||||
|
// type int 是 类型(0.普通展示、1.重点展示)
|
||||||
const categoryTypeOptions = [
|
const categoryTypeOptions = [
|
||||||
{
|
{
|
||||||
label: intl.formatMessage({ id: 'friendLink.category.type.normal' }),
|
label: intl.formatMessage({ id: 'friendLink.category.type.normal' }),
|
||||||
value: 'normal',
|
value: '0',
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
label: intl.formatMessage({ id: 'friendLink.category.type.featured' }),
|
label: intl.formatMessage({ id: 'friendLink.category.type.featured' }),
|
||||||
value: 'featured',
|
value: '1',
|
||||||
},
|
},
|
||||||
];
|
];
|
||||||
|
|
||||||
|
@ -4,6 +4,7 @@ import { Card, Form, Input, Button, message, Tabs, Spin } from 'antd';
|
|||||||
import WangEditor from '@/components/WangEidtor/WangEidtor';
|
import WangEditor from '@/components/WangEidtor/WangEidtor';
|
||||||
import { getAboutUs, updateAboutUs, AboutUsRequest } from '@/servers/api/about';
|
import { getAboutUs, updateAboutUs, AboutUsRequest } from '@/servers/api/about';
|
||||||
import styles from './aboutManage.less';
|
import styles from './aboutManage.less';
|
||||||
|
import FileUpload from '@/components/FileUpload'
|
||||||
|
|
||||||
const { TabPane } = Tabs;
|
const { TabPane } = Tabs;
|
||||||
|
|
||||||
@ -44,6 +45,8 @@ const AboutManage: React.FC = () => {
|
|||||||
contactsEmailEn: response.data.contactsEmailEn,
|
contactsEmailEn: response.data.contactsEmailEn,
|
||||||
contactsConsult: response.data.contactsConsult,
|
contactsConsult: response.data.contactsConsult,
|
||||||
contactsConsultEn: response.data.contactsConsultEn,
|
contactsConsultEn: response.data.contactsConsultEn,
|
||||||
|
// address_img varchar(255) 地址地图图片
|
||||||
|
addressImg: response.data.addressImg,
|
||||||
});
|
});
|
||||||
} else {
|
} else {
|
||||||
message.error(response.message || intl.formatMessage({ id: 'aboutManage.fetchFailed' }));
|
message.error(response.message || intl.formatMessage({ id: 'aboutManage.fetchFailed' }));
|
||||||
@ -72,15 +75,19 @@ const AboutManage: React.FC = () => {
|
|||||||
const values = await form.validateFields();
|
const values = await form.validateFields();
|
||||||
setSubmitting(true);
|
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 = {
|
const submitData: AboutUsRequest = {
|
||||||
...aboutData,
|
...aboutData,
|
||||||
...values,
|
...formattedValues,
|
||||||
};
|
};
|
||||||
|
|
||||||
// 保留原有的addressImg,如果没有则设置为空字符串
|
|
||||||
submitData.addressImg = aboutData?.addressImg || '';
|
|
||||||
|
|
||||||
const response = await updateAboutUs(submitData);
|
const response = await updateAboutUs(submitData);
|
||||||
if (response && response.success) {
|
if (response && response.success) {
|
||||||
message.success(intl.formatMessage({ id: 'aboutManage.saveSuccess' }));
|
message.success(intl.formatMessage({ id: 'aboutManage.saveSuccess' }));
|
||||||
@ -141,6 +148,30 @@ const AboutManage: React.FC = () => {
|
|||||||
layout="vertical"
|
layout="vertical"
|
||||||
initialValues={aboutData || {}}
|
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}>
|
<Tabs activeKey={activeTabKey} onChange={handleTabChange}>
|
||||||
<TabPane tab={intl.formatMessage({ id: 'aboutManage.form.chineseTab' })} key="zh">
|
<TabPane tab={intl.formatMessage({ id: 'aboutManage.form.chineseTab' })} key="zh">
|
||||||
<Form.Item
|
<Form.Item
|
||||||
|
@ -2,7 +2,7 @@ import React, { useState, useEffect } from 'react';
|
|||||||
import { useIntl } from 'umi';
|
import { useIntl } from 'umi';
|
||||||
import { Card, Table, Button, Modal, Form, Input, Space, message, Select, TreeSelect, Popconfirm, Tag } from 'antd';
|
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 { 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 { useFriendLinkDict } from '@/dicts/friendLinkDict';
|
||||||
import styles from './friendLinkManage.less';
|
import styles from './friendLinkManage.less';
|
||||||
|
|
||||||
@ -76,16 +76,20 @@ const FriendLinkCategory: React.FC = () => {
|
|||||||
|
|
||||||
// 处理编辑分类
|
// 处理编辑分类
|
||||||
const handleEditCategory = (record: API.CategoryType) => {
|
const handleEditCategory = (record: API.CategoryType) => {
|
||||||
|
getCategoryDetail(record.id).then((res: API.Response<API.CategoryType>) => {
|
||||||
|
if (res.success && res.data) {
|
||||||
setIsEdit(true);
|
setIsEdit(true);
|
||||||
setCurrentCategory(record);
|
setCurrentCategory(res.data);
|
||||||
form.setFieldsValue({
|
form.setFieldsValue({
|
||||||
name: record.name,
|
name: res.data.name,
|
||||||
type: record.type,
|
type: res.data.type,
|
||||||
parentId: record.parentId,
|
parentId: res.data.parentId,
|
||||||
orderBy: record.orderBy,
|
orderBy: res.data.orderBy,
|
||||||
remark: record.remark,
|
remark: res.data.remark,
|
||||||
});
|
});
|
||||||
setModalVisible(true);
|
setModalVisible(true);
|
||||||
|
}
|
||||||
|
});
|
||||||
};
|
};
|
||||||
|
|
||||||
// 处理删除分类
|
// 处理删除分类
|
||||||
|
@ -109,18 +109,19 @@ const FriendLinkManage: React.FC = () => {
|
|||||||
.then((res: API.Response<API.LinkType>) => {
|
.then((res: API.Response<API.LinkType>) => {
|
||||||
if (res.success && res.data) {
|
if (res.success && res.data) {
|
||||||
const detail = res.data;
|
const detail = res.data;
|
||||||
console.log('Detail data:', detail);
|
|
||||||
|
|
||||||
// 设置表单初始值,包括缩略图URL
|
// 设置表单初始值
|
||||||
form.setFieldsValue({
|
const formValues = {
|
||||||
name: detail.name,
|
name: detail.name,
|
||||||
nameEn: detail.nameEn,
|
nameEn: detail.nameEn,
|
||||||
url: detail.url,
|
url: detail.url,
|
||||||
orderBy: parseInt(detail.orderBy),
|
orderBy: parseInt(detail.orderBy),
|
||||||
classificationId: detail.classificationId,
|
classificationId: detail.classificationId,
|
||||||
// 设置为URL字符串,组件会自动处理
|
// 直接使用缩略图URL字符串
|
||||||
thumbnail: detail.thumbnail,
|
thumbnail: detail.thumbnail || '',
|
||||||
});
|
};
|
||||||
|
|
||||||
|
form.setFieldsValue(formValues);
|
||||||
} else {
|
} else {
|
||||||
message.error(intl.formatMessage({ id: 'friendLink.detail.failed' }));
|
message.error(intl.formatMessage({ id: 'friendLink.detail.failed' }));
|
||||||
}
|
}
|
||||||
@ -236,14 +237,21 @@ const FriendLinkManage: React.FC = () => {
|
|||||||
// 处理表单提交
|
// 处理表单提交
|
||||||
const handleModalSubmit = () => {
|
const handleModalSubmit = () => {
|
||||||
form.validateFields().then(async (values) => {
|
form.validateFields().then(async (values) => {
|
||||||
console.log('Form values:', values);
|
|
||||||
try {
|
try {
|
||||||
// 现在thumbnail字段已经直接是URL字符串,不需要额外处理
|
// 处理表单数据
|
||||||
const formData = {
|
const formData = { ...values };
|
||||||
...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;
|
let res;
|
||||||
if (isEdit) {
|
if (isEdit) {
|
||||||
@ -350,12 +358,7 @@ const FriendLinkManage: React.FC = () => {
|
|||||||
<div className="filter-action-row">
|
<div className="filter-action-row">
|
||||||
<div></div>
|
<div></div>
|
||||||
<div className="right-buttons">
|
<div className="right-buttons">
|
||||||
<Button
|
<Button type="primary" ghost icon={<PlusOutlined />} onClick={handleAdd}>
|
||||||
type="primary"
|
|
||||||
ghost
|
|
||||||
icon={<PlusOutlined />}
|
|
||||||
onClick={handleAdd}
|
|
||||||
>
|
|
||||||
{intl.formatMessage({ id: 'friendLink.add' })}
|
{intl.formatMessage({ id: 'friendLink.add' })}
|
||||||
</Button>
|
</Button>
|
||||||
<Button
|
<Button
|
||||||
@ -368,7 +371,10 @@ const FriendLinkManage: React.FC = () => {
|
|||||||
</Button>
|
</Button>
|
||||||
{selectedRowKeys.length > 0 && (
|
{selectedRowKeys.length > 0 && (
|
||||||
<span className="selected-count">
|
<span className="selected-count">
|
||||||
{intl.formatMessage({ id: 'friendLink.selectedCount' }, { count: selectedRowKeys.length })}
|
{intl.formatMessage(
|
||||||
|
{ id: 'friendLink.selectedCount' },
|
||||||
|
{ count: selectedRowKeys.length },
|
||||||
|
)}
|
||||||
</span>
|
</span>
|
||||||
)}
|
)}
|
||||||
</div>
|
</div>
|
||||||
@ -470,8 +476,18 @@ const FriendLinkManage: React.FC = () => {
|
|||||||
<Form.Item
|
<Form.Item
|
||||||
name="thumbnail"
|
name="thumbnail"
|
||||||
label={intl.formatMessage({ id: 'friendLink.thumbnail' })}
|
label={intl.formatMessage({ id: 'friendLink.thumbnail' })}
|
||||||
getValueFromEvent={(e) => {
|
normalize={(value) => {
|
||||||
return e[0].url;
|
if (typeof value === 'string' && value) {
|
||||||
|
return [
|
||||||
|
{
|
||||||
|
uid: '-1',
|
||||||
|
name: 'thumbnail.jpg',
|
||||||
|
status: 'done',
|
||||||
|
url: value,
|
||||||
|
}
|
||||||
|
];
|
||||||
|
}
|
||||||
|
return value;
|
||||||
}}
|
}}
|
||||||
rules={[
|
rules={[
|
||||||
{
|
{
|
||||||
@ -484,7 +500,7 @@ const FriendLinkManage: React.FC = () => {
|
|||||||
maxCount={1}
|
maxCount={1}
|
||||||
maxSize={2}
|
maxSize={2}
|
||||||
allowedTypes={['jpg', 'png']}
|
allowedTypes={['jpg', 'png']}
|
||||||
listType="picture"
|
listType="picture-card"
|
||||||
tip={intl.formatMessage(
|
tip={intl.formatMessage(
|
||||||
{ id: 'component.fileUpload.fileTypeTip' },
|
{ id: 'component.fileUpload.fileTypeTip' },
|
||||||
{ types: 'JPG, PNG' },
|
{ types: 'JPG, PNG' },
|
||||||
|
Reference in New Issue
Block a user