@@ -1144,16 +1144,23 @@ window.ComponentSortable = class {
1144
1144
} ;
1145
1145
1146
1146
window . ComponentCascadeLine = class {
1147
- constructor ( name , select , url , movable = true ) {
1147
+ constructor ( name , select , url , options ) {
1148
1148
if ( ! Array . isArray ( select ) ) {
1149
1149
console . error ( 'CascadeLine param select must be array!' ) ;
1150
1150
return ;
1151
1151
}
1152
1152
this . name = name ;
1153
- this . movable = movable ;
1153
+ this . OPTIONS = Object . assign ( {
1154
+ movable : true ,
1155
+ exchange :true ,
1156
+ insert :true ,
1157
+ update :true ,
1158
+ delete :true
1159
+ } , options ) ;
1154
1160
this . DOM = document . getElementById ( name ) ;
1155
1161
this . URL = url ;
1156
- this . make ( ) . makeSelect ( select ) . makeHeader ( ) ;
1162
+ this . make ( ) . makeSelect ( select ) ;
1163
+ if ( this . OPTIONS . insert ) this . makeHeader ( ) ;
1157
1164
1158
1165
let search = document . querySelector ( `#${ this . name } .dot-search` ) ;
1159
1166
search . addEventListener ( 'input' , ( ) => {
@@ -1162,6 +1169,7 @@ window.ComponentCascadeLine = class {
1162
1169
} , 700 ) ;
1163
1170
} ) ;
1164
1171
1172
+ if ( ! this . OPTIONS . movable ) return ;
1165
1173
for ( let D of this . DOM . querySelectorAll ( 'i.right' ) ) {
1166
1174
this . nodeMigrate ( D ) ;
1167
1175
}
@@ -1237,7 +1245,6 @@ window.ComponentCascadeLine = class {
1237
1245
this . CONTENT_DOM . append ( stackDom ) ;
1238
1246
}
1239
1247
this . STACKS = this . CONTENT_DOM . childNodes ;
1240
- return this ;
1241
1248
}
1242
1249
1243
1250
insertLabelDom ( data , index , stack ) {
@@ -1252,25 +1259,25 @@ window.ComponentCascadeLine = class {
1252
1259
div . addEventListener ( "contextmenu" , ( e ) => {
1253
1260
e . preventDefault ( ) ;
1254
1261
if ( e . target instanceof HTMLElement ) e . target . click ( ) ;
1255
- _component . contextmenu ( e , [
1256
- {
1257
- title : '新增' , func : ( ) => {
1258
- this . nodeInsert ( div , data , stack ) ;
1259
- }
1260
- } ,
1261
- {
1262
- title : '修改' , func : ( ) => {
1263
- this . nodeUpdate ( div , data ) ;
1264
- }
1265
- } ,
1266
- {
1267
- title : '删除' , func : ( ) => {
1268
- this . nodeDelete ( div , data , stack ) ;
1269
- }
1262
+ let settings = [ ] ;
1263
+ if ( this . OPTIONS . insert ) settings . push ( {
1264
+ title : '新增' , func : ( ) => {
1265
+ this . nodeInsert ( div , data , stack ) ;
1266
+ }
1267
+ } ) ;
1268
+ if ( this . OPTIONS . update ) settings . push ( {
1269
+ title : '修改' , func : ( ) => {
1270
+ this . nodeUpdate ( div , data ) ;
1270
1271
}
1271
- ] ) ;
1272
+ } ) ;
1273
+ if ( this . OPTIONS . delete ) settings . push ( {
1274
+ title : '删除' , func : ( ) => {
1275
+ this . nodeDelete ( div , data , stack ) ;
1276
+ }
1277
+ } ) ;
1278
+ _component . contextmenu ( e , settings ) ;
1272
1279
} ) ;
1273
- if ( this . movable ) div . insertAdjacentHTML ( 'afterbegin' , `<i class="right">${ _component . move } </i>` ) ;
1280
+ if ( this . OPTIONS . movable ) div . insertAdjacentHTML ( 'afterbegin' , `<i class="right">${ _component . move } </i>` ) ;
1274
1281
return div ;
1275
1282
}
1276
1283
0 commit comments