Commit 4015b637 authored by Bill's avatar Bill

fix: 内容管理bug

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