|
|
|
|
|
|
|
|
ProForm, |
|
|
ProForm, |
|
|
FormControlRender, |
|
|
FormControlRender, |
|
|
ProFormDependency, |
|
|
ProFormDependency, |
|
|
ProFormSwitch |
|
|
|
|
|
|
|
|
ProFormSwitch, |
|
|
|
|
|
ProFormCascader |
|
|
} from '@ant-design/pro-components'; |
|
|
} from '@ant-design/pro-components'; |
|
|
import { ConfigProvider, Flex, Space, Modal, message, Image, Row, Col, Switch, Form, Typography } from 'antd'; |
|
|
import { ConfigProvider, Flex, Space, Modal, message, Image, Row, Col, Switch, Form, Typography } from 'antd'; |
|
|
import { addArticle, updateArticle, listSection, GetArticleDetail } from '@/apis/api'; |
|
|
import { addArticle, updateArticle, listSection, GetArticleDetail } from '@/apis/api'; |
|
|
|
|
|
|
|
|
import DragUpload from '@/components/Common/dragupload'; |
|
|
import DragUpload from '@/components/Common/dragupload'; |
|
|
import RichComponent from '@/components/Common/rich'; |
|
|
import RichComponent from '@/components/Common/rich'; |
|
|
|
|
|
|
|
|
const selectfieldNames = { label: 'name', value: 'id' }; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
import { isArrayOfType } from '@/utils/dataHelper'; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
const selectfieldNames = { label: 'name', value: 'id' }; |
|
|
|
|
|
const cascaderfieldNames = { label: 'name', value: 'id', children: 'childs' }; |
|
|
|
|
|
|
|
|
const PagesMainInformationArticleCreate: React.FC = ({ dispatch, dictModel, openModel, id }: any) => { |
|
|
const PagesMainInformationArticleCreate: React.FC = ({ dispatch, dictModel, openModel, id }: any) => { |
|
|
const formRef = useRef<ProFormInstance>(); |
|
|
const formRef = useRef<ProFormInstance>(); |
|
|
const [openPreview, setOpenPreview] = useState(false); |
|
|
const [openPreview, setOpenPreview] = useState(false); |
|
|
|
|
|
|
|
|
if (id) { |
|
|
if (id) { |
|
|
let res = await GetArticleDetail({ id: id }) |
|
|
let res = await GetArticleDetail({ id: id }) |
|
|
setUploadedFilephotoName(res.data.cover_img) |
|
|
setUploadedFilephotoName(res.data.cover_img) |
|
|
|
|
|
res.data.section_arr = [res.data.section_name] |
|
|
setDetail(res.data) |
|
|
setDetail(res.data) |
|
|
return res.data; |
|
|
return res.data; |
|
|
} else { |
|
|
} else { |
|
|
|
|
|
|
|
|
}} |
|
|
}} |
|
|
onFinish={async (values) => { |
|
|
onFinish={async (values) => { |
|
|
values.cover_img = uploadedFilephotoName ? uploadedFilephotoName : ''; |
|
|
values.cover_img = uploadedFilephotoName ? uploadedFilephotoName : ''; |
|
|
console.log(values) |
|
|
|
|
|
|
|
|
|
|
|
if (id) { |
|
|
if (id) { |
|
|
values.id = id; |
|
|
values.id = id; |
|
|
|
|
|
// 判断是字符串数组还是数字数组 |
|
|
|
|
|
if (isArrayOfType(values.section_arr, 'string')) { |
|
|
|
|
|
// 是字符串 |
|
|
|
|
|
values.section_id = detail?.section_id |
|
|
|
|
|
} else { |
|
|
|
|
|
values.section_id = values.section_arr.length > 0 ? values.section_arr[values.section_arr.length - 1] : 0; |
|
|
|
|
|
delete values.section_arr; |
|
|
|
|
|
} |
|
|
let res = await updateArticle(values) |
|
|
let res = await updateArticle(values) |
|
|
message.success('提交成功') |
|
|
message.success('提交成功') |
|
|
dispatch({ type: 'openModel/getOpenModal', payload: false }) |
|
|
dispatch({ type: 'openModel/getOpenModal', payload: false }) |
|
|
} else { |
|
|
} else { |
|
|
|
|
|
values.section_id = values.section_arr.length > 0 ? values.section_arr[values.section_arr.length - 1] : 0; |
|
|
|
|
|
delete values.section_arr; |
|
|
let res = await addArticle(values) |
|
|
let res = await addArticle(values) |
|
|
message.success('提交成功') |
|
|
message.success('提交成功') |
|
|
dispatch({ type: 'openModel/getOpenModal', payload: false }) |
|
|
dispatch({ type: 'openModel/getOpenModal', payload: false }) |
|
|
|
|
|
|
|
|
/> |
|
|
/> |
|
|
|
|
|
|
|
|
<Row gutter={[16, 16]}> |
|
|
<Row gutter={[16, 16]}> |
|
|
{ |
|
|
|
|
|
|
|
|
{ |
|
|
detail ? |
|
|
detail ? |
|
|
<Col span={24} style={{ display: 'flex' }}> |
|
|
<Col span={24} style={{ display: 'flex' }}> |
|
|
<UploadModel multiple={false} form_name="cover_img" image_length={1} uploadTxt="上传封面图" image_type={3} onUploadComplete={handleFileUploadedphoto}></UploadModel> |
|
|
<UploadModel multiple={false} form_name="cover_img" image_length={1} uploadTxt="上传封面图" image_type={3} onUploadComplete={handleFileUploadedphoto}></UploadModel> |
|
|
|
|
|
|
|
|
</> |
|
|
</> |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
<ProFormSelect |
|
|
|
|
|
|
|
|
<ProFormCascader |
|
|
|
|
|
label="栏目/频道" |
|
|
|
|
|
name="section_arr" |
|
|
|
|
|
fieldProps={{ |
|
|
|
|
|
fieldNames: cascaderfieldNames, |
|
|
|
|
|
changeOnSelect: true |
|
|
|
|
|
}} |
|
|
|
|
|
placeholder="请选择栏目/频道" |
|
|
|
|
|
request={(keyword) => |
|
|
|
|
|
listSection({ page: 1, pagesize: 100, keyword: keyword.keyWords }).then(res => { |
|
|
|
|
|
return res.data.sections; |
|
|
|
|
|
}) |
|
|
|
|
|
} |
|
|
|
|
|
/> |
|
|
|
|
|
|
|
|
|
|
|
{/* <ProFormSelect |
|
|
showSearch |
|
|
showSearch |
|
|
name="section_id" |
|
|
name="section_id" |
|
|
label="栏目/频道" |
|
|
label="栏目/频道" |
|
|
|
|
|
|
|
|
return res.data.sections; |
|
|
return res.data.sections; |
|
|
}) |
|
|
}) |
|
|
} |
|
|
} |
|
|
/> |
|
|
|
|
|
|
|
|
/> */} |
|
|
<Row gutter={[16, 16]}> |
|
|
<Row gutter={[16, 16]}> |
|
|
<Col span={24}> |
|
|
<Col span={24}> |
|
|
<Form.Item |
|
|
<Form.Item |