修复 options 中配置 visibleOn hiddenOn 不同步问题

This commit is contained in:
liaoxuezhi 2019-05-28 17:30:48 +08:00
parent b9a30e6f7d
commit 5246df3d8d
4 changed files with 46 additions and 7 deletions

View File

@ -26,7 +26,7 @@ title: 快速开始
简单说明以上配置信息。
- `$schema` 这个字段可以忽略,他是指定当前 JSON 配置是符合指定路径 https://houtai.baidu.com/v2/schemas/page.json 的 JSON SCHEMA 文件描述的。PS: 编辑器就是靠这个描述文件提示的,可以 hover 到字段上看效果。
- `type` 指定渲染器类型,这里指定的类型为 `page`。 更多渲染器类型可以去[这里面查看](./renderers)。
- `type` 指定渲染器类型,这里指定的类型为 `page`。 更多渲染器类型可以去[这里面查看](./renderers.md)。
- `title` 从 title 开始就是对应的渲染模型上的属性了。这里用来指定标题内容。
- `subTitle` 副标题.
- `remark` 标题上面的提示信息

24
scraper-config.json Normal file
View File

@ -0,0 +1,24 @@
{
"index_name": "gh_pages",
"start_urls": [
"https://baidu.github.io/amis/#/docs/getting-started",
"https://baidu.github.io/amis/#/docs/advanced",
"https://baidu.github.io/amis/#/docs/renderers",
"https://baidu.github.io/amis/#/docs/sdk",
"https://baidu.github.io/amis/#/docs/dev",
"https://baidu.github.io/amis/#/docs/style"
],
"js_render": true,
"js_wait": 2,
"use_anchors": true,
"selectors": {
"lvl0": ".markdown-body h1",
"lvl1": ".markdown-body h2",
"lvl2": ".markdown-body h3",
"lvl3": ".markdown-body h4",
"lvl4": ".markdown-body h5",
"text": ".markdown-body p, .markdown-body li"
},
"min_indexed_level": 0,
"nb_hits": 838
}

View File

@ -73,6 +73,7 @@ export function registerOptionsControl(config: OptionsConfig) {
this.handleToggle = this.handleToggle.bind(this);
this.handleToggleAll = this.handleToggleAll.bind(this);
this.setOptions = this.setOptions.bind(this);
this.syncOptions = this.syncOptions.bind(this);
this.setLoading = this.setLoading.bind(this);
this.inputRef = this.inputRef.bind(this);
this.reload = this.reload.bind(this);
@ -167,7 +168,7 @@ export function registerOptionsControl(config: OptionsConfig) {
// todo 优化 name 变化情况。
}
if (props.value !== nextProps.value) {
if (props.value !== nextProps.value || formItem.expressionsInOptions) {
formItem.syncOptions();
}
@ -352,6 +353,11 @@ export function registerOptionsControl(config: OptionsConfig) {
formItem && formItem.setOptions(normalizeOptions(options || []));
}
syncOptions() {
const formItem = this.props.formItem as IFormItemStore;
formItem && formItem.syncOptions();
}
setLoading(value:boolean) {
const formItem = this.props.formItem as IFormItemStore;
formItem && formItem.setLoading(value);
@ -374,6 +380,7 @@ export function registerOptionsControl(config: OptionsConfig) {
loading={formItem ? formItem.loading : false}
setLoading={this.setLoading}
setOptions={this.setOptions}
syncOptions={this.syncOptions}
/>
)
}

View File

@ -68,6 +68,7 @@ export const FormItemStore = types
joinValues: true,
extractValue: false,
options: types.optional(types.array(types.frozen()), []),
expressionsInOptions: false,
selectedOptions: types.optional(types.frozen(), []),
filteredOptions: types.optional(types.frozen(), []),
})
@ -393,12 +394,18 @@ export const FormItemStore = types
const value = self.value;
const selected = Array.isArray(value) ? value.map(item=>item && item.hasOwnProperty(self.valueField || 'value') ? item[self.valueField || 'value'] : item)
: typeof value === 'string' ? value.split(self.delimiter || ',') : [value && value.hasOwnProperty(self.valueField || 'value') ? value[self.valueField || 'value'] : value];
let expressionsInOptions = false;
let filteredOptions = self.options
.filter((item:any) =>
item.visibleOn ? evalExpression(item.visibleOn, form.data) !== false
: item.hiddenOn ? evalExpression(item.hiddenOn, form.data) !== true
: (item.visible !== false || item.hidden !== true)
)
.filter((item:any) => {
if (!expressionsInOptions && (item.visibleOn || item.hiddenOn)) {
expressionsInOptions = true;
}
return item.visibleOn ? evalExpression(item.visibleOn, form.data) !== false
: item.hiddenOn ? evalExpression(item.hiddenOn, form.data) !== true
: (item.visible !== false || item.hidden !== true);
})
.map((item:any, index) => {
const disabled = evalExpression(item.disabledOn, form.data);
@ -416,6 +423,7 @@ export const FormItemStore = types
return newItem;
});
self.expressionsInOptions = expressionsInOptions;
const flattened:Array<any> = flattenTree(filteredOptions);
const selectedOptions:Array<any> = [];