Commit eea939d2 authored by 满振华's avatar 满振华

修改控件展示

parent 4924e20d
......@@ -26,7 +26,9 @@ export const HandleClass = {
},
'changeParams': {
name: '修改business,请求参数',
fun: ({ behavior = {}, formData, componentData, value }, resertValue) => {
fun: ({ behavior = {}, formData, componentData, value, handleType }, resertValue) => {
// handleType 为init时不处理值的问题
const newFormData = formData.slice();
const targets = (behavior.targets || '').split(',');
targets.forEach(ls => {
......@@ -40,7 +42,10 @@ export const HandleClass = {
paramsJson,
}
resertValue && resertValue({ key: ls });
obj.value = void 0; //将目标组件清空
if (handleType !== 'init') {
obj.value = void 0; //将目标组件清空
}
});
return newFormData
......
......@@ -12,7 +12,7 @@ class HandleBehavior {
this.formData.map(item => {
if (!item.behaviors || !Array.isArray(item.behaviors) || item.behaviors.length === 0) return;
const value = this.handleFormaterValue(item.value, item);
this.handleBehavior({ currentValue: value, componentData: item })
this.handleBehavior({ currentValue: value, componentData: item, handleType: 'init' })
})
return this;
}
......@@ -33,28 +33,28 @@ class HandleBehavior {
/*
* 处理行为方法
*/
handleBehavior = ({ currentValue, componentData = {}, eventType, formData }) => {
handleBehavior = ({ currentValue, componentData = {}, eventType, formData, handleType }) => {
this.formData = formData || this.formData;
const value = this.handleFormaterValue((currentValue || componentData.value), componentData);
const events = componentData.events || []
const behaviors = componentData.behaviors || [];
const changeEvents = eventType ? events.filter(ls => ls.eventValue === 'onChange') : events;
changeEvents.forEach(event => {
this.onChangeBehavior({ event, value, componentData, behaviors })
this.onChangeBehavior({ event, value, componentData, behaviors, handleType })
});
}
onChangeBehavior = ({ event, value, componentData, behaviors }) => {
onChangeBehavior = ({ event, value, componentData, behaviors, handleType }) => {
if (!event.behaviors || !Array.isArray(event.behaviors)) return;
event.behaviors.forEach(item => {
this.handleBehaviorType({ value, behavior: item, componentData, behaviors });
this.handleBehaviorType({ value, behavior: item, componentData, behaviors, handleType });
});
}
handleBehaviorType = ({ value, behavior, behaviors, componentData }) => {
handleBehaviorType = ({ value, behavior, behaviors, componentData, handleType }) => {
const behaviorInstance = HandleClass[behavior.behaviorValue];
if (!behaviorInstance || !behaviorInstance.fun) return;
let formData = this.formData;
this.formData = behaviorInstance.fun({ value, behavior, behaviors, formData, componentData }, this.resertValueCallback);
this.formData = behaviorInstance.fun({ value, behavior, behaviors, formData, componentData, handleType }, this.resertValueCallback);
}
resertValueCallback = ({ key, value }) => {
const componentData = this.formData.find(ls => ls.name === key) || {};
......
......@@ -6,11 +6,22 @@ sidebar: true
---
import HandleBehavior from './';
import {data} from './test/json.js'
# Button Component
## new HandleBehavior({formData})
## instance{initBehavior(formData)}
<html>
<body>
<div>ddd
<script>
console.log(1)
</script>
</div>
</body>
</html>
......
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta http-equiv="X-UA-Compatible" content="ie=edge">
<title>Document</title>
</head>
<body>
<script src="../../dist/index.js">
</script>
</body>
</html>
\ No newline at end of file
This diff is collapsed.
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