Commit 4015b637 authored by Bill's avatar Bill

fix: 内容管理bug

parent 2b3fa50c
...@@ -44,6 +44,12 @@ export const classSchema: ISchema = { ...@@ -44,6 +44,12 @@ export const classSchema: ISchema = {
"x-component-props": { "x-component-props": {
placeholder: '最多100个字符,50个汉字' placeholder: '最多100个字符,50个汉字'
}, },
"x-rules": [
{
limitByte: true,
maxByte: 100
}
]
}, },
level: { level: {
type: 'string', type: 'string',
......
import React, { useEffect, useState } from 'react'; import React, { useEffect, useState } from 'react';
const useInitialValues = (params, service) => { const useInitialValues = (params, service) => {
const [state, setState] = useState({}) const [state, setState] = useState(null)
useEffect(() => { useEffect(() => {
if(params.id) { if(params.id) {
service(params).then((data) => { service(params).then((data) => {
......
...@@ -18,7 +18,7 @@ import { GetManageContentCategoryAllResponse } from '@/services/PlatformApi'; ...@@ -18,7 +18,7 @@ import { GetManageContentCategoryAllResponse } from '@/services/PlatformApi';
import { COLUMN_CATEGORY } from '@/constants/const/content'; import { COLUMN_CATEGORY } from '@/constants/const/content';
const actions = createFormActions(); const actions = createFormActions();
const { onFieldValueChange$ } = FormEffectHooks const { onFieldValueChange$, onFieldInputChange$ } = FormEffectHooks
const { TextArea } = Input; const { TextArea } = Input;
...@@ -31,13 +31,13 @@ type ColumnType = 0 | 1 | 2; ...@@ -31,13 +31,13 @@ type ColumnType = 0 | 1 | 2;
type ColumnListType = { type ColumnListType = {
label: string, label: string,
value: number, value: number,
type: 1 | 2 type: 1 | 2 | number & {}
} }
const InfomationInfo = () => { const InfomationInfo = () => {
useCustomValidator(); useCustomValidator();
const { id, preview } = usePageStatus(); const { id, preview } = usePageStatus();
const [isTop, setIsTop] = useState(1); // const [isTop, setIsTop] = useState(1);
const [labelIds, setLabelIds] = useState<number[]>([]); const [labelIds, setLabelIds] = useState<number[]>([]);
const [submitLoading, setSubmitLoading ] = useState(false); const [submitLoading, setSubmitLoading ] = useState(false);
const [unsaved, setUnsaved] = useState(true); const [unsaved, setUnsaved] = useState(true);
...@@ -92,24 +92,28 @@ const InfomationInfo = () => { ...@@ -92,24 +92,28 @@ const InfomationInfo = () => {
}, []) }, [])
useEffect(() => { useEffect(() => {
const data = initialValues.data || {} if(initialValues === null) {
return;
}
const data = initialValues!.data || {}
const content = data.content; const content = data.content;
if(content) { if(content) {
const editorState = BraftEditor.createEditorState(content); const editorState = BraftEditor.createEditorState(content);
actions.setFieldValue('layout.contentLayout.content', editorState); actions.setFieldValue('layout.contentLayout.content', editorState);
} }
setFormStatus('layout.contentLayout.content', 'readOnly', isView); setFormStatus('layout.contentLayout.content', 'readOnly', isView);
/** @tofix 这里写的不是很好, 这里分类联动应该单独一个组件抽离 */
if(category) { if(category) {
actions.setFieldValue('layout.categoryLayout.firstCategoryName', data.firstCategoryName); actions.setFieldValue('layout.categoryLayout.firstCategoryName', data.firstCategoryName);
const secondCategory = category.filter((_row) => _row.id === data.firstCategoryId)[0]?.list || []; const secondCategory = category.filter((_row) => _row.id === data.firstCategoryId)[0]?.list || [];
const options = secondCategory.map((_row: any) => ({label: _row.name, value: _row.id, children: _row.list })) const options = secondCategory.map((_row: any) => ({label: _row.name, value: _row.id, children: _row.list }))
setFormStatus('layout.categoryLayout.secondCategoryId', 'options', options); setFormStatus('layout.categoryLayout.secondCategoryId', 'options', options);
actions.setFieldValue('layout.categoryLayout.secondCategoryId', data.secondCategoryId); // actions.setFieldValue('layout.categoryLayout.secondCategoryId', data.secondCategoryId);
const thirdCategory = options.filter((_row) => _row.value === data.secondCategoryId)[0]?.children || []; const thirdCategory = options.filter((_row) => _row.value === data.secondCategoryId)[0]?.children || [];
const thirdOptions = thirdCategory.map((_row: any) => ({label: _row.name, value: _row.id, children: _row.list })) const thirdOptions = thirdCategory.map((_row: any) => ({label: _row.name, value: _row.id, children: _row.list }))
setFormStatus('layout.categoryLayout.thirdlyCategoryId', 'options', thirdOptions); setFormStatus('layout.categoryLayout.thirdlyCategoryId', 'options', thirdOptions);
actions.setFieldValue('layout.categoryLayout.thirdlyCategoryId', data.thirdlyCategoryId); // actions.setFieldValue('layout.categoryLayout.thirdlyCategoryId', data.thirdlyCategoryId);
} }
if (column) { if (column) {
const targetColumn = column.filter((_item) => _item.value === data.columnId)[0]; const targetColumn = column.filter((_item) => _item.value === data.columnId)[0];
...@@ -121,7 +125,7 @@ const InfomationInfo = () => { ...@@ -121,7 +125,7 @@ const InfomationInfo = () => {
} }
} }
setFormStatus('layout.imageUpload', 'imgUrl', data.imageUrl) setFormStatus('layout.imageUpload', 'imgUrl', data.imageUrl)
setIsTop(data.top); // setIsTop(data.top);
setLabelIds(data.labelIds) setLabelIds(data.labelIds)
setFormStatus('layout.labelIds', 'seletedTag', data.labelIds) setFormStatus('layout.labelIds', 'seletedTag', data.labelIds)
}, [initialValues, category, column]) }, [initialValues, category, column])
...@@ -130,7 +134,6 @@ const InfomationInfo = () => { ...@@ -130,7 +134,6 @@ const InfomationInfo = () => {
const content = value.content.toHTML(); const content = value.content.toHTML();
const tempPostData = { const tempPostData = {
...value, ...value,
top: isTop,
type: type, type: type,
labelIds: labelIds || [], labelIds: labelIds || [],
content: content, content: content,
...@@ -163,7 +166,7 @@ const InfomationInfo = () => { ...@@ -163,7 +166,7 @@ const InfomationInfo = () => {
> >
<Card> <Card>
<SchemaForm <SchemaForm
initialValues={initialValues?.data} value={initialValues?.data}
onSubmit={handleSubmit} onSubmit={handleSubmit}
schema={infomationInfoSchema} schema={infomationInfoSchema}
editable={isAdd || isEdit} editable={isAdd || isEdit}
...@@ -174,7 +177,6 @@ const InfomationInfo = () => { ...@@ -174,7 +177,6 @@ const InfomationInfo = () => {
CustomUpload, CustomTags, CustomEditor, CustomUpload, CustomTags, CustomEditor,
}} }}
effects={($) => { effects={($) => {
onFieldValueChange$('layout.columnId').subscribe(({ value }) => { onFieldValueChange$('layout.columnId').subscribe(({ value }) => {
actions.setFieldState('layout.columnId', state => { actions.setFieldState('layout.columnId', state => {
const currentType = state.props["x-component-props"]!.options?.filter((_row) => _row.value === value)[0]; const currentType = state.props["x-component-props"]!.options?.filter((_row) => _row.value === value)[0];
...@@ -182,16 +184,14 @@ const InfomationInfo = () => { ...@@ -182,16 +184,14 @@ const InfomationInfo = () => {
setType(currentType ? currentType.type : 0) setType(currentType ? currentType.type : 0)
}) })
}) })
onFieldValueChange$('layout.categoryLayout.*(firstCategoryId,secondCategoryId, thirdlyCategoryId)').subscribe(({ value, props, name }) => { onFieldInputChange$('layout.categoryLayout.*(firstCategoryId,secondCategoryId)').subscribe(({ value, props, name }) => {
const matchName = name.match(/(.*?)Id/) const matchName = name.match(/(.*?)Id/);
if(matchName?.length !== 2) { if(matchName?.length !== 2) {
return return
} }
const target = props["x-component-props"]!.options.filter((_row) => _row.value === value)[0]; const target = props["x-component-props"]!.options.filter((_row) => _row.value === value)[0];
actions.setFieldValue(`layout.categoryLayout.${matchName[1]}Name`, target?.label) actions.setFieldValue(`layout.categoryLayout.${matchName[1]}Name`, target?.label)
if(name === 'thirdlyCategoryId') {
return;
}
const childrenName = name === 'firstCategoryId' ? 'secondCategoryId' : 'thirdlyCategoryId'; const childrenName = name === 'firstCategoryId' ? 'secondCategoryId' : 'thirdlyCategoryId';
const optionChildren = target?.children || []; const optionChildren = target?.children || [];
const list = optionChildren?.map((_item) => ({ label: _item.name, value: _item.id, children: _item.list }) ); const list = optionChildren?.map((_item) => ({ label: _item.name, value: _item.id, children: _item.list }) );
...@@ -203,15 +203,6 @@ const InfomationInfo = () => { ...@@ -203,15 +203,6 @@ const InfomationInfo = () => {
}} }}
expressionScope={{ expressionScope={{
isTop: (
<Checkbox
checked={!!isTop}
onChange={(e) => setIsTop(e.target.checked ? 1 : 0)}
disabled={false}
>
置顶
</Checkbox>
),
tagOnChange: (value) => { tagOnChange: (value) => {
setLabelIds(value); setLabelIds(value);
}, },
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment