mirror of
https://gitee.com/baidu/amis.git
synced 2024-11-30 02:48:55 +08:00
commit
e64f80a947
@ -9,21 +9,10 @@ import {
|
||||
import {
|
||||
iRendererStore,
|
||||
} from './iRenderer';
|
||||
import {
|
||||
IRendererStore
|
||||
} from './index';
|
||||
import {
|
||||
FormItemStore,
|
||||
IFormItemStore
|
||||
} from './formItem';
|
||||
import {
|
||||
Api,
|
||||
Payload,
|
||||
fetchOptions
|
||||
} from '../types';
|
||||
import {
|
||||
extendObject
|
||||
} from '../utils/helper';
|
||||
import {FormStore, IFormStore} from './form';
|
||||
|
||||
export const UniqueGroup = types
|
||||
|
@ -23,7 +23,6 @@ import {
|
||||
setVariable,
|
||||
deleteVariable,
|
||||
cloneObject,
|
||||
extendObject,
|
||||
createObject,
|
||||
difference,
|
||||
guid
|
||||
@ -98,7 +97,7 @@ export const FormStore = ServiceStore
|
||||
|
||||
function setValues(values:object, tag?:object) {
|
||||
self.updateData(values, tag);
|
||||
|
||||
|
||||
// 同步 options
|
||||
syncOptions();
|
||||
}
|
||||
@ -132,7 +131,7 @@ export const FormStore = ServiceStore
|
||||
writable: false,
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
setVariable(data, name, value);
|
||||
self.data = data;
|
||||
|
||||
@ -168,7 +167,7 @@ export const FormStore = ServiceStore
|
||||
writable: false,
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
deleteVariable(data, name);
|
||||
self.data = data;
|
||||
}
|
||||
@ -198,7 +197,7 @@ export const FormStore = ServiceStore
|
||||
|
||||
self.markSaving(true);
|
||||
const json:Payload = yield (getRoot(self) as IRendererStore).fetcher(api, data, options);
|
||||
|
||||
|
||||
|
||||
if (!json.ok) {
|
||||
// 验证错误
|
||||
@ -243,7 +242,7 @@ export const FormStore = ServiceStore
|
||||
// 已经销毁了,不管这些数据了。
|
||||
return;
|
||||
}
|
||||
|
||||
|
||||
self.markSaving(false);
|
||||
// console.error(e.stack);`
|
||||
(getRoot(self) as IRendererStore).notify('error', e.message);
|
||||
@ -254,7 +253,7 @@ export const FormStore = ServiceStore
|
||||
const submit:(fn?:(values:object) => Promise<any>, hooks?: Array<() => Promise<any>>) => Promise<any> = flow(function *submit(fn:any, hooks?: Array<() => Promise<any>>) {
|
||||
self.submited = true;
|
||||
self.submiting = true;
|
||||
|
||||
|
||||
try {
|
||||
let valid = yield validate(hooks);
|
||||
|
||||
|
@ -6,7 +6,6 @@ import {
|
||||
getRoot
|
||||
} from "mobx-state-tree";
|
||||
import {
|
||||
FormStore,
|
||||
IFormStore
|
||||
} from './form';
|
||||
import {
|
||||
@ -165,10 +164,10 @@ export const FormItemStore = types
|
||||
return [];
|
||||
}
|
||||
|
||||
const selected = Array.isArray(value) ? value.map(item=>item && item.hasOwnProperty(self.valueField || 'value') ? item[self.valueField || 'value'] : item)
|
||||
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];
|
||||
const selectedOptions:Array<any> = [];
|
||||
|
||||
|
||||
self.filteredOptions.forEach((item:any) => {
|
||||
let idx = findIndex(selected, seleced => {
|
||||
return isObject(seleced) ? seleced === item[self.valueField || 'value'] :String(item[self.valueField || 'value']) === String(seleced)
|
||||
@ -179,7 +178,7 @@ export const FormItemStore = types
|
||||
selectedOptions.push(item);
|
||||
}
|
||||
});
|
||||
|
||||
|
||||
selected.forEach((item, index) => {
|
||||
let unMatched = value && value[index] || item;
|
||||
|
||||
@ -189,7 +188,7 @@ export const FormItemStore = types
|
||||
[self.labelField || 'label']: item,
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
unMatched && selectedOptions.push(unMatched);
|
||||
});
|
||||
|
||||
@ -355,7 +354,7 @@ export const FormItemStore = types
|
||||
let options:Array<IOption> = json.data.options || json.data.items || json.data.rows || json.data || [];
|
||||
options = normalizeOptions(options as any);
|
||||
setOptions(options);
|
||||
|
||||
|
||||
if (json.data && typeof (json.data as any).value !== "undefined") {
|
||||
onChange && onChange((json.data as any).value);
|
||||
} else if (clearValue) {
|
||||
@ -392,26 +391,26 @@ export const FormItemStore = types
|
||||
|
||||
const form = self.form;
|
||||
const value = self.value;
|
||||
const selected = Array.isArray(value) ? value.map(item=>item && item.hasOwnProperty(self.valueField || 'value') ? item[self.valueField || 'value'] : item)
|
||||
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 filteredOptions = self.options
|
||||
.filter((item:any) =>
|
||||
.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)
|
||||
)
|
||||
.map((item:any, index) => {
|
||||
|
||||
|
||||
const disabled = evalExpression(item.disabledOn, form.data);
|
||||
const newItem = item.disabledOn
|
||||
? (
|
||||
self.filteredOptions.length > index && self.filteredOptions[index].disabled === disabled
|
||||
self.filteredOptions.length > index && self.filteredOptions[index].disabled === disabled
|
||||
? self.filteredOptions[index]
|
||||
: {
|
||||
...item,
|
||||
disabled: disabled
|
||||
}
|
||||
)
|
||||
)
|
||||
: item;
|
||||
|
||||
return newItem;
|
||||
@ -419,7 +418,7 @@ export const FormItemStore = types
|
||||
|
||||
const flattened:Array<any> = flattenTree(filteredOptions);
|
||||
const selectedOptions:Array<any> = [];
|
||||
|
||||
|
||||
selected.forEach((item, index) => {
|
||||
let idx = findIndex(flattened, target => {
|
||||
return isObject(item) ? item === target[self.valueField || 'value'] : String(target[self.valueField || 'value']) === String(item)
|
||||
@ -437,7 +436,7 @@ export const FormItemStore = types
|
||||
__unmatched: true
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
unMatched && selectedOptions.push(unMatched);
|
||||
}
|
||||
});
|
||||
|
@ -5,13 +5,10 @@ import {
|
||||
SnapshotIn
|
||||
} from "mobx-state-tree";
|
||||
import {
|
||||
cloneObject,
|
||||
extendObject,
|
||||
createObject,
|
||||
isObjectShallowModified
|
||||
createObject
|
||||
} from '../utils/helper';
|
||||
import {IRendererStore} from './index';
|
||||
import { Action } from "../types";
|
||||
import { dataMapping } from "../utils/tpl-builtin";
|
||||
|
||||
export const iRendererStore = types
|
||||
@ -47,11 +44,11 @@ export const iRendererStore = types
|
||||
self.pristine = data;
|
||||
self.data = data;
|
||||
},
|
||||
|
||||
|
||||
reset() {
|
||||
self.data = self.pristine;
|
||||
},
|
||||
|
||||
|
||||
updateData(data:object = {}, tag?: object) {
|
||||
const prev = self.data;
|
||||
let newData;
|
||||
@ -64,32 +61,32 @@ export const iRendererStore = types
|
||||
} else {
|
||||
newData = extendObject(self.data, data);
|
||||
}
|
||||
|
||||
|
||||
Object.defineProperty(newData, '__prev', {
|
||||
value: {...prev},
|
||||
enumerable: false,
|
||||
configurable: false,
|
||||
writable: false,
|
||||
});
|
||||
|
||||
|
||||
self.data = newData;
|
||||
},
|
||||
|
||||
|
||||
setCurrentAction(action:object) {
|
||||
self.action = action;
|
||||
},
|
||||
|
||||
|
||||
openDialog(ctx: any, additonal?:object, callback?: (ret:any) => void) {
|
||||
let proto = ctx.__super ? ctx.__super : self.data;
|
||||
|
||||
|
||||
if (additonal) {
|
||||
proto = createObject(proto, additonal);
|
||||
}
|
||||
|
||||
|
||||
const data = createObject(proto, {
|
||||
...ctx
|
||||
});
|
||||
|
||||
|
||||
if (self.action.dialog && self.action.dialog.data) {
|
||||
self.dialogData = createObject(proto, {
|
||||
...dataMapping(self.action.dialog.data, data)
|
||||
@ -103,7 +100,7 @@ export const iRendererStore = types
|
||||
dialogCallbacks.set(self.dialogData, callback);
|
||||
}
|
||||
},
|
||||
|
||||
|
||||
closeDialog(result?:any) {
|
||||
const callback = dialogCallbacks.get(self.dialogData);
|
||||
|
||||
@ -114,18 +111,18 @@ export const iRendererStore = types
|
||||
setTimeout(() => callback(result), 200);
|
||||
}
|
||||
},
|
||||
|
||||
|
||||
openDrawer(ctx: any, additonal?:object, callback?: (ret:any) => void) {
|
||||
let proto = ctx.__super ? ctx.__super : self.data;
|
||||
|
||||
|
||||
if (additonal) {
|
||||
proto = createObject(proto, additonal);
|
||||
}
|
||||
|
||||
|
||||
const data = createObject(proto, {
|
||||
...ctx
|
||||
});
|
||||
|
||||
|
||||
if (self.action.drawer.data) {
|
||||
self.drawerData = dataMapping(self.action.drawer.data, data);
|
||||
} else {
|
||||
@ -137,7 +134,7 @@ export const iRendererStore = types
|
||||
dialogCallbacks.set(self.drawerData, callback);
|
||||
}
|
||||
},
|
||||
|
||||
|
||||
closeDrawer(result?:any) {
|
||||
const callback = dialogCallbacks.get(self.drawerData);
|
||||
self.drawerOpen = false;
|
||||
|
@ -9,7 +9,6 @@ import {
|
||||
import {
|
||||
iRendererStore,
|
||||
} from './iRenderer';
|
||||
import { resolveVariable } from "../utils/tpl-builtin";
|
||||
import isEqual = require('lodash/isEqual');
|
||||
import find = require('lodash/find');
|
||||
import { createObject, isObject } from "../utils/helper";
|
||||
@ -171,7 +170,7 @@ export const ListStore = iRendererStore
|
||||
item = isObject(item) ? item : {
|
||||
item: item
|
||||
};
|
||||
|
||||
|
||||
return {
|
||||
id: String((item as any)[self.primaryField] || key),
|
||||
index: key,
|
||||
|
Loading…
Reference in New Issue
Block a user