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

Initial commit

parents
Pipeline #5999 canceled with stages
export default {
cjs: 'rollup',
esm: 'rollup',
}
/yarn.lock
/package-lock.json
/dist
/.docz
/node_modules
**/*.md
**/*.mdx
package.json
.umi
.umi-production
{
"singleQuote": true,
"trailingComma": "all",
"printWidth": 100,
"overrides": [
{
"files": ".prettierrc",
"options": { "parser": "json" }
}
]
}
The MIT License (MIT)
Copyright (c) 2019-present ()
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in
all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
THE SOFTWARE.
# @umi-material/apollo_form_pase
## Usage
```sh
umi block https://github.com//tree/master/apollo_form_pase
```
## LICENSE
MIT
{
"name": "apollo_form_pase",
"version": "0.0.1",
"description": "",
"main": "dist/index.js",
"module": "dist/index.esm.js",
"authors": {
"name": "",
"email": ""
},
"repository": "/apollo_form_pase",
"scripts": {
"dev": "father doc dev",
"build": "father build"
},
"devDependencies": {
"father": "^2.16.0"
},
"license": "MIT"
}
\ No newline at end of file
export const HandleClass = {
getBehaviors: (behaviorValue, componentData) => { //获取全量behaviors的taggets
const behaviors = componentData.behaviors || [];
const behavior = behaviors.find(ls => ls.behaviorValue === behaviorValue) || {};
return (behavior.targets || '').split(',');
},
'showComponent': { //控制组件显,需要处理其他组件的隐
name: '控制组件显隐',
fun: ({ behavior = {}, formData, componentData, value }) => {
const newFormData = formData.slice();
const targets = (behavior.targets || '').split(',');
const allTargets = HandleClass.getBehaviors(behavior.behaviorValue, componentData); //所有的依赖关系包含需要显示与隐藏的控件
newFormData.forEach(ls => {
if (allTargets.includes(ls.name)) {
// 现只做条件相等处理
const display = String(behavior.params) === String(value) && targets.includes(ls.name) ? 1 : 0;
ls.behaviorResult = {
...ls.behaviorResult,
display,
}
}
})
return newFormData
}
},
'changeParams': {
name: '修改business,请求参数',
fun: ({ behavior = {}, formData, componentData, value }, resertValue) => {
const newFormData = formData.slice();
const targets = (behavior.targets || '').split(',');
targets.forEach(ls => {
const index = newFormData.findIndex(item => item.name === ls);
const obj = newFormData[index] || {};
const paramsJson = {};
paramsJson[componentData.name] = value;
paramsJson['fieldMessage'] = `请输入${componentData.title}`;
obj.behaviorResult = {
...obj.behaviorResult,
paramsJson,
}
resertValue && resertValue({ key: ls });
obj.value = void 0; //将目标组件清空
});
return newFormData
}
}
}
\ No newline at end of file
.button {
color: red;
}
import { HandleClass } from './behavior';
class HandleBehavior {
constructor(props) {
this.formData = null;
}
initBehavior = (formData) => {
if (!this.formData) {
this.formData = formData
}
if (!this.formData) return
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 })
})
return this;
}
getFormData = () => {
return this.formData
}
handleFormaterValue = (value, item) => {
if (!value) return value;
if (Array.isArray(value) && value.length) {
return value[0].value;
}
if (typeof value === 'object' && value) {
return value.value;
}
return value;
}
/*
* 处理行为方法
*/
handleBehavior = ({ currentValue, componentData = {}, eventType, formData }) => {
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 })
});
}
onChangeBehavior = ({ event, value, componentData, behaviors }) => {
if (!event.behaviors || !Array.isArray(event.behaviors)) return;
event.behaviors.forEach(item => {
this.handleBehaviorType({ value, behavior: item, componentData, behaviors });
});
}
handleBehaviorType = ({ value, behavior, behaviors, componentData }) => {
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);
}
resertValueCallback = ({ key, value }) => {
const componentData = this.formData.find(ls => ls.name === key) || {};
this.handleBehavior({ currentValue: value, componentData })
}
}
export default HandleBehavior
---
name: Home
route: /
order: -1
sidebar: true
---
import HandleBehavior from './';
# Button Component
## new HandleBehavior({formData})
## instance{initBehavior(formData)}
## Large Button
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