-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
13 changed files
with
200 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -27,3 +27,5 @@ yarn-error.log* | |
/jslib | ||
package-lock.json | ||
/demo/build | ||
|
||
/.vscode |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
import React from 'react'; | ||
import compUtils from './common'; | ||
export default (WrapComponent) => { | ||
return class ButtonComp extends React.Component { | ||
componentDidMount () { | ||
console.log('%c container didMount', 'color:red'); | ||
compUtils.bind(this); | ||
} | ||
|
||
componentWillUnmount () { | ||
console.log('%c container Unmount', 'color:red'); | ||
compUtils.unbind(this); | ||
} | ||
|
||
afterClick () { | ||
const currentModel = this.props.model; | ||
currentModel?.fireEvent('click'); | ||
} | ||
|
||
render () { | ||
const allProps = { | ||
...this.props, | ||
...this.state | ||
} | ||
return <WrapComponent {...allProps} /> | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
const compUtils = { | ||
bind: function (oThis) { | ||
const currentModel = oThis.props.model; | ||
if (currentModel) currentModel.addListener(oThis); | ||
}, | ||
unbind: function (oThis) { | ||
const currentModel = oThis.props.model; | ||
if (currentModel) currentModel.removeListener(oThis); | ||
} | ||
} | ||
|
||
export default compUtils |
34 changes: 34 additions & 0 deletions
34
templates/Project/components/_mdfComponent/containerComp.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
import React from 'react'; | ||
import compUtils from './common'; | ||
export default (WrapComponent) => { | ||
return class ControlComp extends React.Component { | ||
constructor (props) { | ||
super(); | ||
} | ||
|
||
componentDidMount () { | ||
console.log('%c container didMount', 'color:red'); | ||
compUtils.bind(this); | ||
const { viewModel, meta } = this.props; | ||
viewModel.on('updateViewMeta', args => { | ||
const { code, visible } = args; | ||
if (code == meta.cGroupCode) { | ||
this.setState({ visible }); | ||
} | ||
}, undefined, true); | ||
} | ||
|
||
componentWillUnmount () { | ||
console.log('%c container Unmount', 'color:red'); | ||
compUtils.unbind(this); | ||
} | ||
|
||
render () { | ||
const allProps = { | ||
...this.props, | ||
...this.state | ||
} | ||
return <WrapComponent {...allProps} /> | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
import React from 'react'; | ||
import compUtils from './common'; | ||
export default (WrapComponent) => { | ||
return class ControlComp extends React.Component { | ||
constructor (props) { | ||
super(); | ||
} | ||
|
||
componentDidMount () { | ||
console.log('%c container didMount', 'color:red'); | ||
compUtils.bind(this); | ||
} | ||
|
||
componentWillUnmount () { | ||
console.log('%c container Unmount', 'color:red'); | ||
compUtils.unbind(this); | ||
} | ||
|
||
/** | ||
* 输入值改变之后出发事件 | ||
* @param {*} value 当前输入框值 | ||
*/ | ||
afterValueChange = (value) => { | ||
this.props.model.setValue(value); | ||
} | ||
|
||
/** | ||
* 模型校验后的回调事件 | ||
* @param {*} val 当前校验信息 | ||
*/ | ||
validate (val) { | ||
this.setState({ | ||
err: 'has-feedback has-' + val.type, | ||
msg: val.message | ||
}); | ||
} | ||
|
||
render () { | ||
const allProps = { | ||
...this.props, | ||
...this.state, | ||
afterValueChange: this.afterValueChange | ||
} | ||
return <WrapComponent {...allProps} /> | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
import React from 'react'; | ||
import { Input } from 'yonui-ys'; | ||
|
||
import MDFComponent from './index'; | ||
import metaConfig from './metaConfig'; | ||
|
||
@MDFComponent({type: 'control'}) // @mdf 标识,参数改成对象模式,type,绑定模型是什么 | ||
class Demo extends React.Component { | ||
constructor (props) { | ||
super(props) | ||
this.state = {} | ||
} | ||
|
||
open = () => { | ||
this.setState({ | ||
open:true | ||
}) | ||
this.props.onOpen() | ||
} | ||
|
||
handleChange = (e) => { | ||
const value = e && e.target ? e.target.value : e; | ||
const { afterValueChange } = this.props | ||
if (typeof afterValueChange == 'function') | ||
afterValueChange(value); | ||
} | ||
|
||
render () { | ||
const { value } = this.props; | ||
return <div className='panel'> Demo hello!!! <Input value={value} onChange={this.handleChange} /> </div> | ||
} | ||
} | ||
|
||
export default Demo |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
|
||
import ControlComp from './controlComp' | ||
import ButtonComp from './buttonComp' | ||
import ContainerComp from './containerComp' | ||
|
||
function createComp (compInfo = {}) { | ||
const { type } = compInfo | ||
console.log('type', type); | ||
return function (targetCompent, name, descriptor) { | ||
console.log(targetCompent, name, descriptor) | ||
return getAbstractCompFactory(type, targetCompent) | ||
} | ||
} | ||
|
||
function getAbstractCompFactory (type = 'control', targetCompent) { | ||
switch (type) { | ||
case 'control': | ||
return ControlComp(targetCompent); | ||
case 'container': | ||
return ContainerComp(targetCompent); | ||
case 'button': | ||
return ButtonComp(targetCompent); | ||
default: | ||
console.log('%c 依赖基类不存在', 'color:red'); | ||
} | ||
} | ||
|
||
export default createComp |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
// const metaConfig = { | ||
// setConfig: function (data) { | ||
// console.log('metaConfig-------', data); | ||
// } | ||
// } | ||
function metaConfig (data) { | ||
console.log('metaConfig-------', data); | ||
} | ||
export default metaConfig |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Binary file not shown.