Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
J
jinfa-admin
Project
Project
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
linweijiong
jinfa-admin
Commits
4015b637
Commit
4015b637
authored
Jul 19, 2021
by
Bill
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
fix: 内容管理bug
parent
2b3fa50c
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
25 additions
and
29 deletions
+25
-29
schema.tsx
src/pages/content/category/schema.tsx
+6
-0
useInitialValues.tsx
src/pages/content/hooks/useInitialValues.tsx
+4
-5
infomationInfo.tsx
src/pages/content/infomation/infomationInfo.tsx
+15
-24
No files found.
src/pages/content/category/schema.tsx
View file @
4015b637
...
...
@@ -44,6 +44,12 @@ export const classSchema: ISchema = {
"x-component-props"
:
{
placeholder
:
'最多100个字符,50个汉字'
},
"x-rules"
:
[
{
limitByte
:
true
,
maxByte
:
100
}
]
},
level
:
{
type
:
'string'
,
...
...
src/pages/content/hooks/useInitialValues.tsx
View file @
4015b637
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
}
src/pages/content/infomation/infomationInfo.tsx
View file @
4015b637
...
...
@@ -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)
})
})
onField
ValueChange$('layout.categoryLayout.*(firstCategoryId,secondCategoryId, thirdly
CategoryId)').subscribe(({ value, props, name }) => {
const matchName = name.match(/(.*?)Id/)
onField
InputChange$('layout.categoryLayout.*(firstCategoryId,second
CategoryId)').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);
},
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment