2019-01-12 03:33:27 +00:00
|
|
|
|
import PropTypes from '../../_util/vue-types';
|
|
|
|
|
import { generateData, calcTotal } from './util';
|
2018-07-11 09:51:20 +00:00
|
|
|
|
|
|
|
|
|
const Gen = {
|
|
|
|
|
props: {
|
|
|
|
|
x: PropTypes.number.def(20),
|
|
|
|
|
y: PropTypes.number.def(18),
|
|
|
|
|
z: PropTypes.number.def(1),
|
|
|
|
|
},
|
2019-01-12 03:33:27 +00:00
|
|
|
|
data() {
|
2018-07-11 09:51:20 +00:00
|
|
|
|
return {
|
|
|
|
|
nums: '',
|
2019-01-12 03:33:27 +00:00
|
|
|
|
};
|
2018-07-11 09:51:20 +00:00
|
|
|
|
},
|
|
|
|
|
|
2019-01-12 03:33:27 +00:00
|
|
|
|
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));
|
2018-07-11 09:51:20 +00:00
|
|
|
|
},
|
|
|
|
|
methods: {
|
2019-01-12 03:33:27 +00:00
|
|
|
|
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);
|
2018-07-11 09:51:20 +00:00
|
|
|
|
},
|
2019-01-12 03:33:27 +00:00
|
|
|
|
getVals() {
|
2018-07-11 09:51:20 +00:00
|
|
|
|
return {
|
|
|
|
|
x: parseInt(this.$refs.x.value, 10),
|
|
|
|
|
y: parseInt(this.$refs.y.value, 10),
|
|
|
|
|
z: parseInt(this.$refs.z.value, 10),
|
2019-01-12 03:33:27 +00:00
|
|
|
|
};
|
2018-07-11 09:51:20 +00:00
|
|
|
|
},
|
|
|
|
|
},
|
|
|
|
|
|
2019-01-12 03:33:27 +00:00
|
|
|
|
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>
|
|
|
|
|
);
|
2018-07-11 09:51:20 +00:00
|
|
|
|
},
|
2019-01-12 03:33:27 +00:00
|
|
|
|
};
|
2018-07-11 09:51:20 +00:00
|
|
|
|
|
2019-01-12 03:33:27 +00:00
|
|
|
|
export default Gen;
|