UNPKG

16.5 kBJavaScriptView Raw
1/* eslint-disable */
2import React, {Component, PropTypes} from 'react'
3import {render} from 'react-dom'
4import debounce from '@beisen/es6-promise-debounce'
5import ConfigureStore from './app/configureStore';
6import { Provider, connect } from 'react-redux';
7import usReducers from './app/modules/BaseTree';
8import * as usActions from './app/modules/BaseTree';
9import Immutable from 'immutable';
10import { toJS } from 'immutable';
11
12const store = ConfigureStore(usReducers) ;
13
14
15import AutoTree from './src/index.js';
16@connect(
17 state => state.toJS(),
18 {...usActions}
19)
20class Demo extends Component{
21 constructor(props){
22 super(props);
23 this.state = {
24 // hidden:false,
25 popShow:true,
26 target: "",
27 defaultDropValue: '132321321',
28 defaultValue: '1,2,3',
29 treeMaxheight: '',
30 isFetching: true
31 }
32 this.popClose = this.popClose.bind(this);
33 this.removeComponent = this.removeComponent.bind(this);
34 }
35 popClose() {
36 let self = this;
37 this.setState({
38 popShow: !this.state.popShow
39 })
40 }
41 removeComponent() {
42 this.setState({
43 popShow: false
44 })
45 }
46 resizeMaxheight = () => {
47 // let inputNode = this.refs.autoFormInput;
48 let treeMaxheight = parseInt(document.documentElement.clientHeight * 0.8 - 150) + 'px';
49 this.setState({treeMaxheight:treeMaxheight});
50 }
51 componentDidMount() {
52 if(this.refs.dirButton!=undefined){
53 let target = this.refs.dirButton.getBoundingClientRect();
54 this.state.target = target;
55 this.setState(this.state);
56 }
57 let self = this;
58 setTimeout(function() {
59 // self.props.getAutoTreeData(self.props.getAutoTreeDataAPI,'','');
60 self.setState({isFetching:false})
61 },500)
62 // if(status == 'edit') {
63 this.resizeMaxheight();
64 window.addEventListener('resize',debounce(function(){
65 self.resizeMaxheight();
66 },200),false)
67 // }
68 }
69 clearAutoTreeData() {
70 this.props.clearAutoTreeData();
71 }
72
73 // clearValue = () => {
74 // this.setState({defaultValue:''});
75 // }
76
77 test = () => {
78 this.setState({defaultValue:""})
79 }
80
81 // setAutoTreeData(){
82 // this.setState({autoTreeData:[
83 // {
84 // id:'0',
85 // name:'100990ajksdhfoiqhwieofhsdhfajshdfjahsdjkfhaksdhfajsdhfquwehfkjasdhfkajshdfjasbdvasnbkjsdfbksjhdf',
86 // pname:'我是爸爸'
87 // },{
88 // id:'1',
89 // name:'100990',
90 // pname:'我是爸爸'
91 // },{
92 // id:'2',
93 // name:'123123123123'
94 // },{
95 // id:'3',
96 // name:'1qweqweqwe'
97 // },{
98 // id:'4',
99 // name:'1asdfasdf'
100 // },{
101 // id:'5',
102 // name:'23123123'
103 // },{
104 // id:'6',
105 // name:'1asdadssdasdasd'
106 // },{
107 // id:'7',
108 // name:'10dsfgergsdfgsdfg0'
109 // },{
110 // id:'8',
111 // name:'1435467867543'
112 // },{
113 // id:'9',
114 // name:'sdfgwer1fasdfasdf'
115 // },{
116 // id:'10',
117 // name:'23434534534511435345'
118 // },{
119 // id:'11',
120 // name:'sdfsdfgsdfgsdfg111'
121 // },{
122 // id:'12',
123 // name:'sdvsdfgsfgweger11222'
124 // },{
125 // id:'13',
126 // name:'dfgrgw2211'
127 // }
128 // ]})
129 // }
130
131 render () {
132 let self = this;
133 const options = {
134 required: true,
135 disabled: false,
136 sync: false, //true:同步,false:异步
137 status: 'edit', //edit,search
138 single: false,
139 isFetching: this.state.isFetching,
140 isSearchAutoTreeEdit:false,
141 hiddenTip: false,
142 sideTip: false,
143 showDropDown: true,
144 totalCount: 100,
145 helpMsg: 'aaaaaa',
146 autoTreeData: [
147 {
148 id:'0',
149 name:'100990ajksdhfoiqhwieofhsdhfajshdfjahsdjkfhaksdhfajsdhfquwehfkjasdhfkajshdfjasbdvasnbkjsdfbksjhdf',
150 pname:'我是爸爸'
151 },{
152 id:'1',
153 name:'100990',
154 pname:'我是爸爸'
155 },{
156 id:'2',
157 name:'123123123123'
158 },{
159 id:'3',
160 name:'1qweqweqwe'
161 },{
162 id:'4',
163 name:'1asdfasdf'
164 },{
165 id:'5',
166 name:'23123123'
167 },{
168 id:'6',
169 name:'1asdadssdasdasd'
170 },{
171 id:'7',
172 name:'10dsfgergsdfgsdfg0'
173 },{
174 id:'8',
175 name:'1435467867543'
176 },{
177 id:'9',
178 name:'sdfgwer1fasdfasdf'
179 },{
180 id:'10',
181 name:'23434534534511435345'
182 },{
183 id:'11',
184 name:'sdfsdfgsdfgsdfg111'
185 },{
186 id:'12',
187 name:'sdvsdfgsfgweger11222'
188 },{
189 id:'13',
190 name:'dfgrgw2211'
191 }
192 ],
193 defaultValue: '',
194 defaultStatus: false,
195 componentId:"1",
196 errorStatus: false, //是否报错
197 errorMsg:"出错了~~~!", //报错信息
198 // showText:'请输入正确信息',
199 labelText: '选择部门', //左侧 label 文字
200 // placeholder: '', // input placeholder
201 lablePos: true, //label位置,true时在左边,false在上边
202 lableTxt: false, //label中文字对齐方式,true左对齐,false右对齐
203 autoTreeSearchCallBack: (val,filters) => {this.setState({defaultDropValue:filters})},
204 keyUpCallBack: (event, value) => {}, // input keyup输入回调
205 itemCallBack: (data) => {
206
207 }, // 点击回调
208 focusCallBack: (value) => {
209 // setTimeout(function() {
210 // self.setState({isFetching:false})
211 // },5500)
212 console.log('点击了')
213 let self = this;
214 setTimeout(function() {
215 // self.props.getAutoTreeData(self.props.getAutoTreeDataAPI,'','');
216 },500)
217 }, // input keyup输入回调
218 blurCallBack: (event) => {}, // 点击回调
219 changeCallBack: (event,value,inputValue) => {}, // input keyup输入回调
220 clearCallback: () => {},
221 showPopCallback: () =>{},
222 unmountCallBack: () => {},
223 searchSubmitCallBack: (value) =>{console.log(value)},
224 submitCallBack: (data) =>{console.log(data)},
225 onCloseCallback:(value)=>this.clearAutoTreeData(),
226 setSessionCallBack:() => {},
227 itemCloseCallBack: (data) => {console.log(data)}
228 }
229 const options1 = {
230 required: true,
231 disabled: false,
232 sync: false,
233 status: 'edit', //edit,search
234 showDropDown: true,
235 hiddenTip: false,
236 sideTip: false,
237 single: false,
238 isSearchAutoTreeEdit:true,
239 autoTreeData: [{
240 id:'0',
241 name:'100990'
242 },
243 {
244 id:'1',
245 name:'asdfasdf'
246 }],
247 componentId:"2",
248 errorStatus: false, //是否报错
249 errorMsg:"出错了~~~!", //报错信息
250 labelText: '选择部门1', //左侧 label 文字
251 showText:'请输入正确信息',
252 placeholder: '输入部门名称1', // input placeholder
253 lablePos: false, //label位置,true时在左边,false在上边
254 lableTxt: false, //label中文字对齐方式,true左对齐,false右对齐
255 autoTreeSearchCallBack: (val) => console.log(val),
256 findAllSearch: (val) => console.log(val),
257 keyUpCallBack: (event, value) => console.log(event, value), // input keyup输入回调
258 itemCallBack: (data) => {
259 // this.setState({_defaultValue:data[0].name})
260 }, // 点击回调
261 focusCallBack: (value) => {
262 let self = this;
263 console.log('2focusCallBack')
264 // setTimeout(function() {
265 // self.props.getAutoTreeData(self.props.getAutoTreeDataAPI,'','');
266 // },500)
267 }, // input keyup输入回调
268 blurCallBack: (event) => console.log(event), // 点击回调
269 changeCallBack: (event,value,inputValue) => {console.log(event, value,inputValue)}, // input keyup输入回调
270 clearCallback: ()=>{console.log('clearCallback')},
271 searchSubmitCallBack: (value) =>{console.log(value)},
272 setSessionCallBack:() => {}
273 }
274 const options2 = {
275 required: true,
276 disabled: false,
277 readOnly: false,
278 sync: false,
279 status: 'edit', //edit,search
280 defaultValue: "321321,321321,321321",
281 showDropDown: true,
282 hiddenTip: false,
283 sideTip: false,
284 single: true,
285 selectDate: [
286 {
287 name:"12321321"
288 }
289 ],
290 isFetching: false,
291 isSearchAutoTreeEdit:true,
292 defaultValueObj:{
293 id:"0"
294 ,name:"100990"
295 },
296 autoTreeData: [{
297 id:'0',
298 name:'100990'
299 },
300 {
301 id:'1',
302 name:'asdfasdf'
303 }],
304 treeData:[{
305 "id": "32025",
306 "name": "技术体系阿斯顿发送到发送到发送到发送到发送到发送到发送到发送的方式打发当时发生的发生的",
307 "path": "32025.",
308 "pid": "0",
309 "level": "1",
310 "has_child":false,
311 "clickable":false
312 }],
313 componentId:"3",
314 errorStatus: true, //是否报错
315 errorMsg:"出错了~~~!", //报错信息
316 helpMsg:"dsadas",
317 labelText: '选择部门11', //左侧 label 文字
318 showText:'请输入正确信1息',
319 placeholder: '输入部门2名称1', // input placeholder
320 lablePos: true, //label位置,true时在左边,false在上边
321 lableTxt: false, //label中文字对齐方式,true左对齐,false右对齐
322 autoTreeSearchCallBack: (val) => console.log(val),
323 keyUpCallBack: (event, value) => console.log(event, value), // input keyup输入回调
324 itemCallBack: (data) => {
325 console.log(data)
326 // this.setState({_defaultValue:data[0].name})
327 }, // 点击回调
328 focusCallBack: (value) => {
329 let self = this;
330 setTimeout(function() {
331 self.setState({isFetching:false})
332 },500)
333 // console.log('2focusCallBack')
334 // setTimeout(function() {
335 // self.props.getAutoTreeData(self.props.getAutoTreeDataAPI,'','');
336 // },500)
337 }, // input keyup输入回调
338 blurCallBack: (event) => console.log(event), // 点击回调
339 changeCallBack: (event,value,inputValue) => {console.log(event, value,inputValue)}, // input keyup输入回调
340 clearCallback: ()=>{console.log('clearCallback')},
341 searchSubmitCallBack: (value) =>{console.log(value)},
342 setSessionCallBack:() => {}
343 }
344
345 const options3 = {
346 required: true,
347 disabled: false,
348 sync: false,
349 status: 'search', //edit,search
350 showDropDown: true,
351 hiddenTip: false,
352 sideTip: false,
353 isSearchAutoTreeEdit:true,
354 single: true,
355 autoTreeData: [{
356 id:'0',
357 name:'100990'
358 },
359 {
360 id:'1',
361 name:'asdfasdf'
362 }],
363 componentId:"3",
364 errorStatus: false, //是否报错
365 errorMsg:"出错3了~~~!", //报错信息
366 labelText: '选择部22门11', //左侧 label 文字
367 showText:'请输入正2确信1息',
368 placeholder: '2输入部门2名称1', // input placeholder
369 autoTreeSearchCallBack: (val) => console.log(val),
370 keyUpCallBack: (event, value) => console.log(event, value), // input keyup输入回调
371 itemCallBack: (data) => {
372 console.log(data)
373 // this.setState({_defaultValue:data[0].name})
374 }, // 点击回调
375 focusCallBack: (value) => {
376 let self = this;
377 console.log(value)
378 console.log('3focusCallBack')
379 setTimeout(function() {
380 self.props.getAutoTreeData(self.props.getAutoTreeDataAPI,'','');
381 },500)
382 }, // input keyup输入回调
383 blurCallBack: (event) => console.log(event), // 点击回调
384 changeCallBack: (event,value,inputValue) => {console.log(event, value,inputValue)}, // input keyup输入回调
385 clearCallback: ()=>{console.log('clearCallback')},
386 searchSubmitCallBack: (value) =>{console.log(value)},
387 setSessionCallBack:() => {}
388 }
389 const treeData = {
390 toggle: true,
391 treeData: this.props.treeData,
392 async: 1, //1异步 0同步
393 id:1, //异步请求的第一层数据pid,非必须
394 sidebarScene:false, // false或该字段没有,则为非sidebar交互方式
395 // scrollBar:true, //false则不使用
396 initGetData:true, //默认为tree,是否组件在首次渲染时请求数据,树组件默认会在DidMount时执行getTreeData方法去请求数据
397 postData:[],
398 methodType:'GET',
399 isFetching:this.state.isFetching,
400 getTreeData:function(id,treeAsync,getUrl,postData,methodType) {
401 console.log(id,treeAsync,getUrl,postData,methodType)
402 self.props.getTreeData(getUrl,id);
403 },
404 getTreeDataAPI: '' || 'http://localhost:3001/getTreeData' //请求接口
405 ,style:{
406 "maxHeight":this.state.treeMaxheight
407 }
408 ,clearTreeData:function() {console.log('clearTreeData')}
409 }
410 const DropDownData = {
411 "title":"" //input框前的文字标识,可为空
412 ,"placeholder":"搜索" /**没有值的时候显示的内容(string)**/
413 ,"defaultValue": this.state.defaultDropValue //默认值
414 ,"openListView":false // 是否打开下拉框
415 ,"errorStatus":true // 错误状态
416 ,"errorMsg":"出错了~~~!" //错误信息
417 ,multiple: false //下拉菜单为单选或者多选,true为多选,false为单选,默认为false
418 ,"children":[
419 {
420 "value":0
421 ,"text":"本级别及所有下级"
422 ,"isActive":false //点击效果,默认为false
423 ,"isChecked":false //是否被选中,默认为false
424 }
425 ,{
426 "value":1
427 ,"text":"本级别"
428 ,"isActive":false
429 ,"isChecked":false
430 }
431 ,{
432 "value":2
433 ,"text":"本本级别及直接下级"
434 ,"isActive":false
435 ,"isChecked":false
436 }
437 ,{
438 "value":3
439 ,"text":"直接下级"
440 ,"isActive":false
441 ,"isChecked":false
442 }
443 ,{
444 "value":4
445 ,"text":"全部下级"
446 ,"isActive":false
447 ,"isChecked":false
448 }
449 ] /** MenuItem **/
450 ,"hidden":false //是否显示\
451 ,"disabled":false //是否禁用
452 ,"required":false //是否显示必选星号
453 ,"iconName":"pc-sys-arrowdown-nomal-svg" //右侧下拉按钮的样式
454 ,"onClick":function(event, target, val){} /**点击后事件回调;event:事件,target: 事件对象,val:抛出的值**/
455 ,"onBlur":function(event, val){} /**失去焦点后事件回调event:val:input抛出的值**/ /**change后事件回调event:事件,target: 事件对象,val:input中值改变的值**/
456 ,"onFocus":function(event, val){} /**获取焦点后事件回调event:事件,val:抛出的input中的值**/
457 }
458 let popTree = this.state.popShow?<AutoTree {...options} {...this.props} {...this.state} popClose={this.popClose} DropDownData={DropDownData} treeData={treeData} removeComponent={this.removeComponent} />:"";
459 let popTree1 = this.state.popShow?<AutoTree {...options1} {...this.props} {...this.state} popClose={this.popClose} DropDownData={DropDownData} treeData={treeData} removeComponent={this.removeComponent} />:"";
460 let popTree2 = this.state.popShow?<AutoTree {...options2} {...this.props} {...this.state} popClose={this.popClose} DropDownData={DropDownData} treeData={treeData} removeComponent={this.removeComponent} />:"";
461 let popTree3 = this.state.popShow?<AutoTree {...options3} {...this.props} {...this.state} popClose={this.popClose} DropDownData={DropDownData} treeData={treeData} removeComponent={this.removeComponent} />:"";
462
463 return (
464 <div style={{marginTop:'50px',height:"700px"}}>
465 <button onClick={this.test}>重置value</button>
466 <div>
467 {popTree2}
468 </div>
469 <div style={{marginLeft: '500px'}}>
470 {popTree1}
471 </div>
472 <div style={{marginTop: '700px'}}>
473 {/*popTree2*/}
474 </div>
475 <div>
476 </div>
477 </div>
478 )
479 }
480}
481
482/*
483
484
485
486*/
487
488
489// {options.status=='search'?<button className="btn" ref="dirButton" style={{'marginTop':'50px','marginLeft':'100px'}} onClick = {this.popClose} >天天向上</button>:''}
490
491render(
492 <Provider store={store}>
493 <Demo />
494 </Provider>,
495 document.getElementById('content')
496);