@@ -72,12 +72,20 @@ function _componentAlert(message, time = 1, callback = function () {
72
72
}
73
73
74
74
class ComponentDot {
75
+ MODE = {
76
+ insert :'insert' ,
77
+ delete :'delete'
78
+ } ;
75
79
constructor ( name , selected , select ) {
76
80
this . name = name ;
77
81
this . DOM = document . getElementById ( name ) ;
82
+ if ( ! Array . isArray ( selected ) ) {
83
+ console . error ( 'Dot param selected is not array!' ) ;
84
+ return ;
85
+ }
78
86
this . make ( selected , select ) ;
79
87
this . selected_data = selected ;
80
- this . select_data = this . selected_data . map ( ( x ) => x ) ;
88
+ this . select_data = selected . slice ( 0 ) ;
81
89
this . insert_data = [ ] ;
82
90
this . delete_data = [ ] ;
83
91
@@ -102,7 +110,7 @@ class ComponentDot {
102
110
}
103
111
104
112
let html = `<div class="dlp-dot" ><div class="dot-top"><input type="text" class="dlp dot-search" placeholder="搜索名称"><div id="${ this . name } -select" class="dot-selected dlp-scroll">${ selected_dom } </div></div><div class="dot-select dlp-scroll">${ select_dom } </div></div>
105
- <input name="${ this . name } [select]" value='${ JSON . stringify ( this . select_data ) } ' type="hidden"><input name="${ this . name } [insert]" value="[]" type="hidden"><input name="${ this . name } [delete]" value="[]" type="hidden">` ;
113
+ <input name="${ this . name } [select]" value='${ JSON . stringify ( selected ) } ' type="hidden"><input name="${ this . name } [insert]" value="[]" type="hidden"><input name="${ this . name } [delete]" value="[]" type="hidden">` ;
106
114
this . DOM . insertAdjacentHTML ( 'afterbegin' , html ) ;
107
115
this . SELECTED_DOM = document . querySelector ( `#${ this . name } .dot-selected` ) ;
108
116
this . CONTENT_DOM = document . querySelector ( `#${ this . name } .dot-select` ) ;
@@ -116,7 +124,7 @@ class ComponentDot {
116
124
cdom . addEventListener ( 'click' , this . tagCancel . bind ( this , cdom ) , false ) ;
117
125
this . SELECTED_DOM . appendChild ( cdom ) ;
118
126
element . remove ( ) ;
119
- this . tagCal ( cdom , ' insert' ) ;
127
+ this . tagCal ( cdom , this . MODE . insert ) ;
120
128
this . SELECTED_DOM . scrollTop = this . SELECTED_DOM . scrollHeight ;
121
129
}
122
130
@@ -125,12 +133,12 @@ class ComponentDot {
125
133
cdom . addEventListener ( 'click' , this . tagSelect . bind ( this , cdom ) , false ) ;
126
134
this . CONTENT_DOM . appendChild ( cdom ) ;
127
135
element . remove ( ) ;
128
- this . tagCal ( cdom , ' delete' ) ;
136
+ this . tagCal ( cdom , this . MODE . delete ) ;
129
137
}
130
138
131
139
tagCal ( cdom , operate ) {
132
- let id = cdom . getAttribute ( 'data-id' ) ;
133
- if ( operate == ' insert' ) {
140
+ let id = parseInt ( cdom . getAttribute ( 'data-id' ) ) ;
141
+ if ( operate == this . MODE . insert ) {
134
142
if ( this . select_data . indexOf ( id ) == - 1 ) {
135
143
this . select_data . push ( id ) ;
136
144
this . selectInputDOM . value = JSON . stringify ( this . select_data ) ;
@@ -146,7 +154,7 @@ class ComponentDot {
146
154
}
147
155
return ;
148
156
}
149
- if ( operate == ' delete' ) {
157
+ if ( operate == this . MODE . delete ) {
150
158
let index = this . select_data . indexOf ( id ) ;
151
159
if ( index != - 1 ) {
152
160
this . select_data . splice ( index , 1 ) ;
@@ -181,14 +189,22 @@ class ComponentDot {
181
189
}
182
190
183
191
class ComponentCascadeDot {
192
+ MODE = {
193
+ insert :'insert' ,
194
+ delete :'delete'
195
+ } ;
184
196
constructor ( name , selected , select , options ) {
185
197
this . name = name ;
186
198
this . DOM = document . getElementById ( name ) ;
187
199
this . OPTIONS = Object . assign ( {
188
200
select_dimensional : [ ]
189
201
} , options ) ;
190
- this . selected_data = Object . keys ( selected ) ;
191
- this . select_data = this . selected_data . map ( ( x ) => x ) ;
202
+ if ( ! Array . isArray ( selected ) ) {
203
+ console . error ( 'CascadeDot param selected is not array!' ) ;
204
+ return ;
205
+ }
206
+ this . selected_data = selected ;
207
+ this . select_data = selected . slice ( 0 ) ;
192
208
this . insert_data = [ ] ;
193
209
this . delete_data = [ ] ;
194
210
this . make ( ) . makeSelect ( select ) ;
@@ -279,6 +295,7 @@ class ComponentCascadeDot {
279
295
}
280
296
281
297
selectActive ( stack , element ) {
298
+ this . tagCal ( parseInt ( element . getAttribute ( 'data-id' ) ) , this . MODE . insert ) ;
282
299
let currentStackDocuments = this . STACKS [ stack ] . childNodes ;
283
300
let parentNode = JSON . parse ( element . getAttribute ( 'data-parent-nodes-id' ) ) . pop ( ) ;
284
301
currentStackDocuments . forEach ( ( D , index ) => {
@@ -361,7 +378,7 @@ class ComponentCascadeDot {
361
378
}
362
379
363
380
tagCal ( id , operate ) {
364
- if ( operate == ' insert' ) {
381
+ if ( operate == this . MODE . insert ) {
365
382
if ( this . select_data . indexOf ( id ) == - 1 ) {
366
383
this . select_data . push ( id ) ;
367
384
this . selectInputDOM . value = JSON . stringify ( this . select_data ) ;
@@ -377,7 +394,7 @@ class ComponentCascadeDot {
377
394
}
378
395
return ;
379
396
}
380
- if ( operate == ' delete' ) {
397
+ if ( operate == this . MODE . delete ) {
381
398
let index = this . select_data . indexOf ( id ) ;
382
399
if ( index != - 1 ) {
383
400
this . select_data . splice ( index , 1 ) ;
0 commit comments