fmui-base 2.1.83 → 2.1.85

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,548 @@
1
+ import React from 'react';
2
+
3
+ import Boxs from 'saltui/lib/Boxs';
4
+ import SearchBar from 'saltui/lib/SearchBar';
5
+ import Button from 'saltui/lib/Button';
6
+ import Popup from 'saltui/lib/Popup';
7
+
8
+ const {HBox, Box,VBox} = Boxs;
9
+ import Variables from '../../db/variables';
10
+ import './tree.less';
11
+
12
+
13
+ class Item extends React.Component{
14
+
15
+ checked(id) {
16
+ this.props.checked(id);
17
+ }
18
+ showSubList(id) {
19
+ this.props.showSubList(id);
20
+ }
21
+
22
+
23
+ render() {
24
+ let t = this;
25
+ return (
26
+ <div>
27
+ {
28
+ this.props.todoList.map((item, key) => {
29
+ return (
30
+ <div>
31
+ <HBox vAlign="center" className="dd-bottom-border ">
32
+ <Box className="t-PL16" onClick={this.checked.bind(t, item.id)}>
33
+ <div
34
+ className={item.checked ? 't-checkbox-field-icon-list' : 't-checkbox-field-icon-list un-checked'}>
35
+ <i className="iconfont icon-checked t-FCf t-FS14"></i>
36
+ </div>
37
+ </Box>
38
+ <Box className="t-PT12 t-PB12 t-PL10 t-PR6">
39
+ <i className="iconfont icon-personnelregister t-FCd t-FS20"></i>
40
+ </Box>
41
+ <HBox flex={1} onClick={this.showSubList.bind(t, item.id)}>
42
+ <Box flex={1} className="t-FS16 t-PL4 t-PR10 t-omit t-WB">{item.name}</Box>
43
+ <Box
44
+ className={(item.todo == null || item.todo == undefined || item.todo.length == 0) ? "t-DN" : "t-PR16"}>
45
+ <i
46
+ className={item.showSubList ? "iconfont icon-arrow-up t-rotate-180 t-FCc" : "iconfont icon-arrow-up t-rotate-90 t-FCc"}></i>
47
+ </Box>
48
+ </HBox>
49
+ </HBox>
50
+ <div className={item.showSubList ? "" : "t-DN"}>
51
+ {item.showSubList ?
52
+ <Item todoList={item.todo} showSubList={(id) => {
53
+ this.showSubList(id)
54
+ }} checked={(id) => {
55
+ this.checked(id)
56
+ }}/>
57
+ : ""}
58
+ </div>
59
+ </div>
60
+ )
61
+ })
62
+ }
63
+
64
+ </div>
65
+ )
66
+ }
67
+ };
68
+
69
+ export default class Page extends React.Component {
70
+ constructor(props) {
71
+ super(props);
72
+
73
+ var u = navigator.userAgent;
74
+ var isAndroid = u.indexOf('Android') > -1 || u.indexOf('Adr') > -1; //android终端
75
+ var isiOS = !!u.match(/\(i[^;]+;( U;)? CPU.+Mac OS X/); //ios终端
76
+ var height='';
77
+ if(isAndroid==true){
78
+ height = window.screen.height-70-44-58+"px";
79
+ }else if(isiOS==true){
80
+ height = window.screen.availHeight-70-44-27+"px";
81
+ }else {
82
+ if(window.screen.availHeight) {
83
+ height = '550px';
84
+ }
85
+ }
86
+ this.state = {
87
+ //全选按钮
88
+ checkedAll: false,
89
+
90
+ //单选状态 radio checkbox
91
+ checkbox: "checkbox",
92
+
93
+ //已选择数据 只保存最高级
94
+ selectData: [],
95
+ //数据
96
+ data: [],
97
+ //处理后的数据
98
+ todoList: [],
99
+
100
+ //搜索 值
101
+ search:"",
102
+ //搜索出来的数组
103
+ searchArr:[],
104
+ isSearch:1,
105
+ visible:false,
106
+
107
+ placeholder :"",
108
+
109
+ height:height,
110
+ };
111
+ }
112
+
113
+ componentWillMount() {
114
+ //this.initData();
115
+ }
116
+
117
+ /*// 子组件初始化
118
+ initState() {
119
+
120
+ }*/
121
+
122
+ //初始化数据
123
+ initState() {
124
+ let t = this;
125
+ //数据
126
+ let datas = t.props.data;
127
+ let selectData = t.props.value;
128
+ // 是否显示
129
+ let visible = t.props.visible;
130
+
131
+ // 搜索提示语
132
+ let placeholder = t.props.placeholder;
133
+ if(placeholder == '' || placeholder == null){
134
+ placeholder = "搜索";
135
+ }
136
+
137
+
138
+ if(selectData == null){
139
+ selectData = [];
140
+ }else{
141
+ if(t.props.checked == 'radio'){
142
+ selectData = [];
143
+ selectData.push(t.props.value);
144
+ }
145
+ }
146
+ if(datas == null){
147
+ datas = [];
148
+ }
149
+
150
+ let dataArray = [];
151
+
152
+ datas.forEach(function (data) {
153
+ let checked = false;
154
+ selectData.forEach(function (select) {
155
+ if (select.id == data.id) {
156
+ checked = true;
157
+ }
158
+ })
159
+ let pid = data.pId;
160
+ let id = data.id;
161
+ let name = data.name;
162
+ let objTemp = {
163
+ "checked": checked,
164
+ "showSubList": false,
165
+ "show": true,
166
+ "pid": pid,
167
+ "id": id,
168
+ "name": name
169
+ }
170
+ dataArray.push(objTemp);
171
+
172
+ })
173
+ t.setState({
174
+ data: dataArray,
175
+ selectData:selectData,
176
+ visible:visible,
177
+ checkbox:t.props.checked,
178
+ placeholder:placeholder,
179
+ }, () => {
180
+ if(t.state.checkbox != 'radio'){
181
+ selectData.forEach(function (select) {
182
+ t.bindCheckAll(select.id, true);
183
+ })
184
+ t.bindCheck();
185
+ }
186
+ t.getTreeFa()
187
+ })
188
+ }
189
+
190
+ //获取父级节点 传入子节点查询
191
+ getTreeFa() {
192
+ let t = this;
193
+ let dataArray = [];
194
+ t.state.data.forEach(function (data) {
195
+ var pid = data.pid;
196
+ if (pid == '' || pid == null) {
197
+ dataArray.push(data);
198
+ }
199
+ })
200
+ let data = t.data2treeDG(t.state.data, dataArray);
201
+ let checkedAll = true;
202
+ for (let i = 0; i < t.state.data.length; i++) {
203
+ if (!t.state.data[i].checked) {
204
+ checkedAll = false;
205
+ }
206
+ }
207
+
208
+ t.setState({
209
+ todoList: data,
210
+ checkedAll: checkedAll
211
+ }, () => {
212
+ let ttt = t.deepTraversal(t.state.todoList);
213
+ let select = [];
214
+ for (let i = 0; i < ttt.length; i++) {
215
+ select.push({"id": ttt[i].id, "pid": ttt[i].pid,"name":ttt[i].name,"value":ttt[i].id,"text":ttt[i].name});
216
+ }
217
+ t.setState({selectData: select})
218
+ })
219
+ }
220
+
221
+ //子节点拼接
222
+ data2treeDG(datas, dataArray) {
223
+ let t = this;
224
+ //已经选中的
225
+ let selectData = t.state.selectData;
226
+ for (let j = 0; j < dataArray.length; j++) {
227
+ let dataArrayIndex = dataArray[j];
228
+ let childrenArray = [];
229
+ let id1 = dataArrayIndex.id;
230
+
231
+ for (let i = 0; i < datas.length; i++) {
232
+ let data = datas[i];
233
+ let pid = data.pid;
234
+ if (pid == id1) {//判断是否为儿子节点
235
+ childrenArray.push(data);
236
+ }
237
+ }
238
+ dataArrayIndex.todo = childrenArray;
239
+ if (childrenArray.length > 0) {//有儿子节点则递归
240
+ t.data2treeDG(datas, childrenArray);
241
+ }
242
+
243
+ }
244
+ return dataArray;
245
+ }
246
+
247
+ //深度优先遍历 ,非递归方法
248
+ deepTraversal(node) {
249
+ let nodes = [];
250
+ for (let i = 0; i < node.length; i++) {
251
+ let stack = [];//同来存放将来要访问的节点
252
+ stack.push(node[i]);
253
+ while (stack.length != 0) {
254
+ let item = stack.pop();//正在访问的节点
255
+ if (item.checked) {
256
+ nodes.push(item);
257
+ }
258
+ let childrens = item.todo;
259
+ //将现在访问点的节点的子节点存入stack,供将来访问
260
+ if (!item.checked) {
261
+ for (let i = childrens.length - 1; i >= 0; i--) {
262
+ stack.push(childrens[i]);
263
+ }
264
+ }
265
+ }
266
+ }
267
+ return nodes;
268
+ }
269
+
270
+
271
+ componentDidMount() {
272
+
273
+ }
274
+
275
+ //检查父节点节点需要选中
276
+ bindCheck() {
277
+ let t = this;
278
+ let data = t.state.data;
279
+ for (let i = 0; i < data.length; i++) {
280
+ let ch = false;
281
+ let end = true;
282
+ for (let j = 0; j < data.length; j++) {
283
+ if (data[i].id == data[j].pid) {
284
+ end = false;
285
+ ch = data[j].checked;
286
+ if (!data[j].checked) {
287
+ break;
288
+ }
289
+ }
290
+ }
291
+ if (end) {
292
+ continue;
293
+ }
294
+ if (data[i].checked != ch) {
295
+ data[i].checked = ch;
296
+ i = -1;
297
+ }
298
+
299
+ }
300
+ }
301
+
302
+ //遍历子节点 选中或取消选中
303
+ bindCheckAll(id, checked) {
304
+ let t = this;
305
+ let data = t.state.data;
306
+ for (let i = 0; i < data.length; i++) {
307
+ if (id == data[i].pid) {
308
+ data[i].checked = checked;
309
+ t.bindCheckAll(data[i].id, checked);
310
+ }
311
+ }
312
+ }
313
+
314
+
315
+
316
+ //选中
317
+ checked(id) {
318
+ let t = this;
319
+ let json = t.state.data;
320
+ if (t.state.checkbox == 'radio') {
321
+ for (let i = 0; i < json.length; i++) {
322
+ json[i].checked = false;
323
+ }
324
+ }
325
+ // debugger;
326
+ for (let i = 0; i < json.length; i++) {
327
+ if (id == json[i].id) {
328
+ if (t.state.checkbox == 'radio') {
329
+ json[i].checked = true;
330
+ } else {
331
+ json[i].checked = !json[i].checked;
332
+ t.bindCheckAll(id, json[i].checked);
333
+ }
334
+ }
335
+ }
336
+ // debugger;
337
+ if (t.state.checkbox != 'radio') {
338
+ t.bindCheck();
339
+ }
340
+ t.setState({
341
+ data: json
342
+ }, () => {
343
+ if(t.state.search != ''){
344
+ t.onSearch(t.state.search);
345
+ }
346
+ t.getTreeFa()
347
+ })
348
+ }
349
+
350
+
351
+ //叶子展开
352
+ showSubList(id) {
353
+ let t = this;
354
+ let json = t.state.data;
355
+ for (let i = 0; i < json.length; i++) {
356
+ if (id == json[i].id) {
357
+ json[i].showSubList = !json[i].showSubList;
358
+ break;
359
+ }
360
+ }
361
+ t.setState({
362
+ data: json
363
+ }, () => {
364
+ t.getTreeFa()
365
+ })
366
+ }
367
+
368
+
369
+ //确定
370
+ makesure() {
371
+ let t = this;
372
+ t.setState({
373
+ visible: false
374
+ }, () => {
375
+ let returnData = t.state.selectData;
376
+ if(t.state.checkbox == 'radio'){
377
+ if(returnData.length > 0){
378
+ returnData = returnData[0];
379
+ }else{
380
+ returnData = {};
381
+ }
382
+ }
383
+ this.props.onChange(returnData);
384
+ });
385
+ }
386
+
387
+ //取消
388
+ cancel() {
389
+ // $("#App").removeAttr("style");
390
+ // $(document).scrollTop(this.props.top);
391
+
392
+ // this.setState({
393
+ // visible: false
394
+ // });
395
+ history.back();
396
+ }
397
+
398
+ //全选按钮
399
+ selectAll() {
400
+ let t = this;
401
+ let isCheck = t.state.checkedAll;
402
+ let data = t.state.data;
403
+ t.setState({checkedAll: !t.state.checkedAll});
404
+ for (let i = 0; i < data.length; i++) {
405
+ data[i].checked = !isCheck;
406
+ }
407
+ t.getTreeFa();
408
+ }
409
+
410
+ //搜索
411
+ onSearch(value){
412
+ let t = this;
413
+ let data = t.state.data;
414
+ let searchArr = [];
415
+ for(let i = 0 ; i < data.length ; i ++){
416
+ if(data[i].name.indexOf(value)!=-1){
417
+ console.log(data[i].name);
418
+ console.log(value);
419
+ searchArr.push({"id":data[i].id,"name":data[i].name,"checked":data[i].checked});
420
+ }
421
+ }
422
+ t.setState({searchArr:searchArr,isSearch:3})
423
+ }
424
+
425
+
426
+ // 点击蒙层关闭
427
+ closMask(){
428
+ this.props.closMask(this);
429
+ }
430
+
431
+ render() {
432
+ const t = this;
433
+ const props = {
434
+ locale: 'zh_CN',
435
+ placeholder:t.state.placeholder,
436
+ instantSearch: false,
437
+ hasHistory: true,
438
+ searchDelay: 450,
439
+ onEnter: () => {
440
+ },
441
+ onExit: () => {
442
+ t.setState({search:"",searchArr:[],isSearch:2})
443
+ },
444
+ onChange: (value) => {
445
+ },
446
+ onSearch: (value) => {
447
+ t.setState({search:value,isSearch:3})
448
+ t.onSearch(value);
449
+ },
450
+ };
451
+
452
+ return (
453
+ <div >
454
+ <Popup
455
+ content={
456
+
457
+
458
+ <div className="t-BCf" style={{width:300}}>
459
+ <SearchBar {...props} />
460
+ <div className="dd-popup-container" style={{overflow:"auto" ,width:"100%",height:t.state.height}}>
461
+ <div className={(t.state.searchArr.length == 0 && t.state.isSearch==3 )
462
+ || (t.state.searchArr.length == 0 && t.state.isSearch==2 && t.state.data.length ==0 )
463
+ || t.state.data.length ==0?"nodata-wrapper":"t-DN"}>
464
+ <VBox vAlign="center" hAlign="center" className="nodata">
465
+ <Box>
466
+ <div>
467
+ <img src={Variables.nodataIcon} alt="" style={{width: 68 + 'px'}} />
468
+ </div>
469
+ </Box>
470
+ <Box className="t-FCc">
471
+ {t.state.isSearch == 3?'无搜索结果':'暂无数据'}
472
+ </Box>
473
+ </VBox>
474
+ </div>
475
+ <div
476
+ className={this.state.checkbox == 'radio' || (t.state.searchArr.length != 0 || t.state.search != "")?"t-DN":"t-PL16 t-PR16 t-PT10 t-PB10 dd-top-border dd-bottom-border" }>
477
+ <HBox vAlign="center">
478
+ <HBox onClick={t.selectAll.bind(t)}>
479
+ <div
480
+ className={this.state.checkedAll ? 't-checkbox-field-icon-list' : "t-checkbox-field-icon-list un-checked"}>
481
+ <i className="iconfont icon-checked t-FCf t-FS14"></i>
482
+ </div>
483
+ </HBox>
484
+ <Box flex={1} className="t-ML10">
485
+ 全选
486
+ </Box>
487
+ </HBox>
488
+ </div>
489
+ <div
490
+ className={this.state.checkbox == 'radio' || (t.state.searchArr.length != 0 || t.state.search != "")?"t-DN":"dd-bottom-border" }
491
+ style={{height:5,width:"100%",backgroundColor:"#eee"}}></div>
492
+ {
493
+ t.state.searchArr.length == 0 && t.state.search == ''?
494
+ <div style={{marginBottom: 70}}>
495
+ <Item todoList={t.state.todoList} showSubList={(id) => {
496
+ t.showSubList(id)
497
+ }} checked={(id) => {
498
+ this.checked(id)
499
+ }}/> </div>:
500
+ <div style={{marginBottom: 70}}>
501
+ {
502
+ t.state.searchArr.map((item,key)=>(
503
+ <div>
504
+ <HBox vAlign="center" className="dd-bottom-border ">
505
+ <Box className="t-PL16" onClick={this.checked.bind(this,item.id)}>
506
+ <div className={item.checked?'t-checkbox-field-icon-list':'t-checkbox-field-icon-list un-checked'} >
507
+ <i className="iconfont icon-checked t-FCf t-FS14"></i>
508
+ </div>
509
+ </Box>
510
+ <Box className="t-PT12 t-PB12 t-PL10 t-PR6"><i className="iconfont icon-personnelregister t-FCd t-FS20"></i></Box>
511
+ <HBox flex={1} >
512
+ <Box flex={1} className="t-FS16 t-PL4 t-PR10 t-omit t-WB">{item.name}</Box>
513
+ </HBox>
514
+ </HBox>
515
+ </div>
516
+ ))
517
+ }
518
+ </div>
519
+ }
520
+ </div>
521
+
522
+ <HBox vAlign="center" className="t-bottom-fixed t-P16 t-PT10 t-PB10">
523
+ <Box flex={1}>
524
+
525
+ </Box>
526
+ <Box className="t-MR4">
527
+ <Button type="secondary" size="small" display="inline" onClick={t.cancel.bind(t)}>取消</Button>
528
+ </Box>
529
+ <Box>
530
+ <Button type="primary" size="small" display="inline" onClick={t.makesure.bind(t)}>确定</Button>
531
+ </Box>
532
+ </HBox>
533
+
534
+ </div>
535
+
536
+ }
537
+ animationType="slide-left"
538
+ onMaskClick={() => { this.setState({ visible: false });this.closMask(); }}
539
+ visible={this.state.visible}
540
+ >
541
+ {null}
542
+ </Popup>
543
+ </div>
544
+ );
545
+ }
546
+ }
547
+
548
+