Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
嗨向前出发
form-render
提交
696726ea
F
form-render
项目概览
嗨向前出发
/
form-render
与 Fork 源项目一致
从无法访问的项目Fork
通知
1
Star
0
Fork
0
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
0
列表
看板
标记
里程碑
合并请求
0
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
F
form-render
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
0
Issue
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
提交
Issue看板
前往新版Gitcode,体验更适合开发者的 AI 搜索 >>
提交
696726ea
编写于
5月 27, 2021
作者:
F
FateRiddle
浏览文件
操作
浏览文件
下载
差异文件
Merge branch 'dev' of github.com:alibaba/form-render into dev
上级
d694c513
a2e2474a
变更
8
隐藏空白更改
内联
并排
Showing
8 changed file
with
67 addition
and
68 deletion
+67
-68
tools/schema-generator/package.json
tools/schema-generator/package.json
+1
-1
tools/schema-generator/src/FR/RenderField.js
tools/schema-generator/src/FR/RenderField.js
+3
-2
tools/schema-generator/src/FRWrapper.js
tools/schema-generator/src/FRWrapper.js
+4
-37
tools/schema-generator/src/Main.js
tools/schema-generator/src/Main.js
+3
-19
tools/schema-generator/src/Right/GlobalSettings.js
tools/schema-generator/src/Right/GlobalSettings.js
+2
-5
tools/schema-generator/src/Right/ItemSettings.js
tools/schema-generator/src/Right/ItemSettings.js
+6
-3
tools/schema-generator/src/Settings/index.js
tools/schema-generator/src/Settings/index.js
+32
-1
tools/schema-generator/src/utils.js
tools/schema-generator/src/utils.js
+16
-0
未找到文件。
tools/schema-generator/package.json
浏览文件 @
696726ea
{
"name"
:
"fr-generator"
,
"version"
:
"2.
0.3
"
,
"version"
:
"2.
1.1
"
,
"scripts"
:
{
"build"
:
"father-build"
,
"prepare"
:
"npm run build"
,
...
...
tools/schema-generator/src/FR/RenderField.js
浏览文件 @
696726ea
...
...
@@ -73,8 +73,9 @@ const RenderField = ({
const
usefulWidgetProps
=
transformProps
({
value
:
data
||
schema
.
default
,
checked
:
data
,
disabled
:
schema
[
'
disabled
'
],
readOnly
:
schema
[
'
readOnly
'
],
disabled
:
schema
.
disabled
,
readOnly
:
schema
.
readOnly
,
format
:
schema
.
format
,
onChange
,
schema
,
...
schema
[
'
props
'
],
...
...
tools/schema-generator/src/FRWrapper.js
浏览文件 @
696726ea
...
...
@@ -11,8 +11,8 @@ import {
flattenToData
,
looseJsonParse
,
isObject
,
oldSchemaToNew
,
newSchemaToOld
,
schemaToState
,
}
from
'
./utils
'
;
import
{
Ctx
,
StoreCtx
}
from
'
./context
'
;
import
FR
from
'
./FR
'
;
...
...
@@ -90,28 +90,12 @@ function Wrapper(
setState
({
schemaForImport
:
e
.
target
.
value
});
};
// 收口点 propsSchema 到 schema 的转换(一共就3个入口:defaultValue,importSchema,setValue)
// TODO: 3个入口可能还是太多了,是不是考虑在外面裹一层
// TODO2: 导入这边看看会不会传一个乱写的schema就crash
const
importSchema
=
()
=>
{
try
{
const
value
=
transformFrom
(
looseJsonParse
(
local
.
schemaForImport
));
let
_isNewVersion
=
true
;
if
(
value
&&
value
.
propsSchema
)
{
_isNewVersion
=
false
;
}
const
schema
=
oldSchemaToNew
(
value
);
setGlobal
(
state
=>
({
schema
,
formData
:
{},
setGlobal
(()
=>
({
selected
:
undefined
,
isNewVersion
:
_isNewVersion
,
frProps
:
{
...
state
.
frProps
,
column
:
schema
.
column
,
displayType
:
schema
.
displayType
,
labelWidth
:
schema
.
labelWidth
,
},
...
schemaToState
(
value
),
}));
}
catch
(
error
)
{
message
.
info
(
'
格式不对哦,请重新尝试
'
);
// 可以加个格式哪里不对的提示
...
...
@@ -141,29 +125,12 @@ function Wrapper(
const
getValue
=
()
=>
displaySchema
;
// 收口点 propsSchema 到 schema
// setValue 外部用于修改大schema,叫setSchema比较合适
// TODO: 这次顶层的props传递改动和整理后,确保这个api还是正确的
const
setValue
=
value
=>
{
try
{
// TODO: 这里默认使用setValue的同学不使用ui:Schema
let
_isNewVersion
=
true
;
if
(
value
&&
value
.
propsSchema
)
{
_isNewVersion
=
false
;
}
const
schema
=
oldSchemaToNew
(
value
);
setGlobal
(
state
=>
({
...
state
,
schema
,
formData
:
{},
selected
:
undefined
,
isNewVersion
:
_isNewVersion
,
frProps
:
{
...
state
.
frProps
,
column
:
schema
.
column
,
displayType
:
schema
.
displayType
,
labelWidth
:
schema
.
labelWidth
,
},
...
schemaToState
(
value
),
}));
}
catch
(
error
)
{
console
.
error
(
error
);
...
...
tools/schema-generator/src/Main.js
浏览文件 @
696726ea
...
...
@@ -10,7 +10,7 @@ import list from './widgets/antd/list';
import
'
./atom.less
'
;
import
'
./Main.less
'
;
import
'
antd/dist/antd.less
'
;
import
{
oldSchemaToNew
}
from
'
./utils
'
;
import
{
schemaToState
}
from
'
./utils
'
;
const
DEFAULT_SCHEMA
=
{
type
:
'
object
'
,
...
...
@@ -48,9 +48,7 @@ function App(props, ref) {
const
frwRef
=
ref
||
useRef
();
const
[
state
,
setState
]
=
useSet
({
formData
:
{},
frProps
:
{
displayType
:
'
row
'
,
},
// form-render 的全局props等
frProps
:
{},
// form-render 的全局 props 等
hovering
:
undefined
,
// 目前没有用到
isNewVersion
:
true
,
// 用schema字段,还是用propsSchema字段,这是一个问题
preview
:
false
,
// preview = false 是编辑模式
...
...
@@ -61,21 +59,7 @@ function App(props, ref) {
// 收口点 propsSchema 到 schema 的转换 (一共3处,其他两个是 importSchema 和 setValue,在 FRWrapper 文件)
useEffect
(()
=>
{
const
schema
=
defaultValue
?
transformFrom
(
defaultValue
)
:
DEFAULT_SCHEMA
;
if
(
!
schema
)
return
;
if
(
schema
.
propsSchema
)
{
setState
({
isNewVersion
:
false
});
}
else
{
setState
({
isNewVersion
:
true
});
}
setState
({
schema
:
oldSchemaToNew
(
schema
),
// 旧的转新的,新的不变
formData
:
schema
.
formData
||
{},
frProps
:
{
column
:
schema
.
column
,
displayType
:
schema
.
displayType
,
labelWidth
:
schema
.
labelWidth
,
},
});
if
(
schema
)
setState
(
schemaToState
(
schema
));
},
[
defaultValue
]);
const
{
...
...
tools/schema-generator/src/Right/GlobalSettings.js
浏览文件 @
696726ea
...
...
@@ -6,12 +6,9 @@ import { useStore, useGlobal } from '../hooks';
export
default
function
GlobalSettings
()
{
const
form
=
useForm
();
const
[
innerUpdate
,
setInnerUpdate
]
=
useState
(
false
);
const
{
widgets
,
frProps
,
userProps
}
=
useStore
();
const
{
widgets
,
frProps
,
userProps
=
{}
}
=
useStore
();
const
setGlobal
=
useGlobal
();
const
globalSettings
=
userProps
&&
userProps
.
globalSettings
?
userProps
.
globalSettings
:
defaultGlobalSettings
;
const
globalSettings
=
userProps
.
globalSettings
||
defaultGlobalSettings
;
const
onDataChange
=
value
=>
{
setInnerUpdate
(
true
);
...
...
tools/schema-generator/src/Right/ItemSettings.js
浏览文件 @
696726ea
...
...
@@ -69,7 +69,7 @@ export default function ItemSettings() {
// setting 该显示什么的计算,要把选中组件的 schema 和它对应的 widgets 的整体 schema 进行拼接
try
{
const
item
=
flatten
[
selected
];
if
(
!
item
)
return
;
if
(
!
item
||
selected
===
'
#
'
)
return
;
setReady
(
false
);
// 算 widgetList
const
_settings
=
Array
.
isArray
(
settings
)
...
...
@@ -88,13 +88,16 @@ export default function ItemSettings() {
if
(
hideId
)
delete
properties
.
$id
;
form
.
setValues
(
item
.
schema
);
setSettingSchema
({
type
:
'
object
'
,
displayType
:
'
column
'
,
properties
,
});
setTimeout
(()
=>
setReady
(
true
),
0
);
form
.
setValues
(
item
.
schema
);
setTimeout
(()
=>
{
setReady
(
true
);
onDataChange
(
form
.
getValues
());
},
0
);
}
catch
(
error
)
{
console
.
log
(
error
);
}
...
...
tools/schema-generator/src/Settings/index.js
浏览文件 @
696726ea
...
...
@@ -11,6 +11,21 @@ export const defaultCommonSettings = {
title
:
'
标题
'
,
type
:
'
string
'
,
},
type
:
{
title
:
'
类型
'
,
type
:
'
string
'
,
hidden
:
'
{{true}}
'
,
},
widget
:
{
title
:
'
组件
'
,
type
:
'
string
'
,
hidden
:
'
{{true}}
'
,
},
format
:
{
title
:
'
格式
'
,
type
:
'
string
'
,
hidden
:
'
{{true}}
'
,
},
description
:
{
title
:
'
说明
'
,
type
:
'
string
'
,
...
...
@@ -322,7 +337,6 @@ export const elements = [
name
:
'
checkboxes
'
,
schema
:
{
title
:
'
多选
'
,
description
:
'
点击多选
'
,
type
:
'
array
'
,
widget
:
'
checkboxes
'
,
items
:
{
...
...
@@ -445,6 +459,10 @@ export const layouts = [
},
},
setting
:
{
items
:
{
type
:
'
object
'
,
hidden
:
'
{{true}}
'
,
},
min
:
{
title
:
'
最小长度
'
,
type
:
'
number
'
,
...
...
@@ -486,6 +504,10 @@ export const layouts = [
},
},
setting
:
{
items
:
{
type
:
'
object
'
,
hidden
:
'
{{true}}
'
,
},
min
:
{
title
:
'
最小长度
'
,
type
:
'
number
'
,
...
...
@@ -531,6 +553,10 @@ export const layouts = [
},
},
setting
:
{
items
:
{
type
:
'
object
'
,
hidden
:
'
{{true}}
'
,
},
min
:
{
title
:
'
最小长度
'
,
type
:
'
number
'
,
...
...
@@ -572,6 +598,10 @@ export const layouts = [
},
},
setting
:
{
items
:
{
type
:
'
object
'
,
hidden
:
'
{{true}}
'
,
},
min
:
{
title
:
'
最小长度
'
,
type
:
'
number
'
,
...
...
@@ -694,6 +724,7 @@ export const defaultGlobalSettings = {
displayType
:
{
title
:
'
标签展示模式
'
,
type
:
'
string
'
,
default
:
'
row
'
,
enum
:
[
'
row
'
,
'
column
'
],
enumNames
:
[
'
同行
'
,
'
单独一行
'
],
widget
:
'
radio
'
,
...
...
tools/schema-generator/src/utils.js
浏览文件 @
696726ea
...
...
@@ -588,6 +588,22 @@ export const newSchemaToOld = setting => {
return
setting
;
};
export
const
schemaToState
=
value
=>
{
const
schema
=
oldSchemaToNew
(
value
);
const
frProps
=
Object
.
keys
(
schema
).
reduce
((
rst
,
cur
)
=>
{
if
([
'
type
'
,
'
properties
'
].
includes
(
cur
))
return
rst
;
return
{
...
rst
,
[
cur
]:
schema
[
cur
]
};
},
{});
const
isNewVersion
=
!
(
value
&&
value
.
propsSchema
);
return
{
schema
,
frProps
,
formData
:
schema
.
formData
||
{},
isNewVersion
,
};
};
export
function
defaultGetValueFromEvent
(
valuePropName
,
...
args
)
{
const
event
=
args
[
0
];
if
(
event
&&
event
.
target
&&
valuePropName
in
event
.
target
)
{
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录