ant-design-vue/components/vc-tree-select/demo/big-data-generator.js

64 lines
1.8 KiB
JavaScript
Raw Normal View History

2018-07-11 09:51:20 +00:00
import PropTypes from '../../_util/vue-types'
import { generateData, calcTotal } from './util'
const Gen = {
props: {
x: PropTypes.number.def(20),
y: PropTypes.number.def(18),
z: PropTypes.number.def(1),
},
data () {
return {
nums: '',
}
},
mounted () {
this.$refs.x.value = this.x
this.$refs.y.value = this.y
this.$refs.z.value = this.z
const vals = this.getVals()
this.$emit('gen', generateData(vals.x, vals.y, vals.z))
},
methods: {
onGen (e) {
e.preventDefault()
const vals = this.getVals()
this.$emit('gen', generateData(vals.x, vals.y, vals.z))
this.nums = calcTotal(vals.x, vals.y, vals.z)
},
getVals () {
return {
x: parseInt(this.$refs.x.value, 10),
y: parseInt(this.$refs.y.value, 10),
z: parseInt(this.$refs.z.value, 10),
}
},
},
render () {
const { x, y, z } = this
return (<div style={{ padding: '0 20px' }}>
<h2>big data generator</h2>
<form onSubmit={this.onGen}>
<span style={{ marginRight: '10px' }}>
x: <input ref='x' type='number' min='1' required style={{ width: '50px' }} />
</span>
<span style={{ marginRight: '10px' }}>
y: <input ref='y' type='number' min='1' required style={{ width: '50px' }} />
</span>
<span style={{ marginRight: '10px' }}>
z: <input ref='z' type='number' min='1' required style={{ width: '50px' }} />
</span>
<button type='submit'>Generate</button>
<p>total nodes: {this.nums || calcTotal(x, y, z)}</p>
</form>
<p style={{ fontSize: '12px' }}>
x每一级下的节点总数y每级节点里有y个节点存在子节点z树的level层级数0表示一级
</p>
</div>)
},
}
export default Gen