1
- let _componentCommonBlock = {
1
+
2
+ let _componentMegaBlock = {
2
3
_loadingSvg :"<svg version=\"1.1\" style='width: 100%;height:100px' xmlns=\"http://www.w3.org/2000/svg\" xmlns:xlink=\"http://www.w3.org/1999/xlink\" x=\"0px\" y=\"0px\"\n" +
3
4
" width=\"40px\" height=\"40px\" viewBox=\"0 0 40 40\" enable-background=\"new 0 0 40 40\" xml:space=\"preserve\">\n" +
4
5
" <path opacity=\"0.2\" fill=\"#000\" d=\"M20.201,5.169c-8.254,0-14.946,6.692-14.946,14.946c0,8.255,6.692,14.946,14.946,14.946\n" +
@@ -25,16 +26,14 @@ let _componentCommonBlock = {
25
26
xhr . open ( method , url , true ) ;
26
27
xhr . timeout = 30000 ;
27
28
var token = document . querySelector ( 'meta[name="csrf-token"]' ) . getAttribute ( 'content' ) ;
28
- xhr . setRequestHeader ( "Content-type" , "application/text;charset=UTF-8" ) ;
29
29
xhr . setRequestHeader ( "X-CSRF-TOKEN" , token ) ;
30
30
if ( method == 'GET' ) {
31
31
xhr . responseType = "text" ;
32
32
xhr . send ( null ) ;
33
33
} else {
34
- xhr . setRequestHeader ( 'Content-type' , 'application/json;charset=UTF-8' ) ;
35
34
xhr . setRequestHeader ( "X-Requested-With" , "XMLHttpRequest" ) ;
36
35
xhr . responseType = "json" ;
37
- xhr . send ( JSON . stringify ( data ) ) ;
36
+ xhr . send ( data ) ;
38
37
}
39
38
xhr . onreadystatechange = function ( ) {
40
39
if ( xhr . readyState == xhr . DONE && xhr . status == 200 ) {
@@ -49,7 +48,7 @@ let _componentCommonBlock = {
49
48
} ;
50
49
51
50
function _componentAlert ( message , time = 1 , callback = function ( ) { } ) {
52
- var div = document . createElement ( 'div' ) ;
51
+ let div = document . createElement ( 'div' ) ;
53
52
div . innerHTML = message ;
54
53
let w = window . innerWidth / 2 - 140 ;
55
54
let h = window . innerHeight / 2 - 145 ;
@@ -66,33 +65,33 @@ function _componentAlert(message,time=1,callback=function () {}) {
66
65
67
66
function componentDot ( name , selected , options ) {
68
67
function tagSelect ( ) {
69
- var cdom = this . cloneNode ( true ) ;
68
+ let cdom = this . cloneNode ( true ) ;
70
69
cdom . addEventListener ( 'click' , tagCancel ) ;
71
70
document . getElementById ( name + '-select' ) . appendChild ( cdom ) ;
72
71
this . remove ( ) ;
73
72
addVal ( ) ;
74
73
}
75
74
function tagCancel ( ) {
76
- var cdom = this . cloneNode ( true ) ;
75
+ let cdom = this . cloneNode ( true ) ;
77
76
cdom . addEventListener ( 'click' , tagSelect ) ;
78
77
document . getElementById ( name + '-content' ) . appendChild ( cdom ) ;
79
78
this . remove ( ) ;
80
79
addVal ( ) ;
81
80
}
82
81
function addVal ( ) {
83
- var val = '' ;
82
+ let val = '' ;
84
83
document . getElementById ( name + '-select' ) . childNodes . forEach ( function ( n ) {
85
84
val += parseInt ( n . getAttribute ( 'data-id' ) ) + "," ;
86
85
} ) ;
87
86
val = val . replace ( / , $ / g, '' ) ;
88
87
dataInput . value = val
89
88
}
90
- var DOM = document . getElementById ( name ) ;
91
- var selected_dom = '' ;
92
- var options_dom = '' ;
93
- var selected_tag = '' ;
89
+ let DOM = document . getElementById ( name ) ;
90
+ let selected_dom = '' ;
91
+ let options_dom = '' ;
92
+ let selected_tag = '' ;
94
93
95
- for ( var i in options ) {
94
+ for ( let i in options ) {
96
95
if ( selected . indexOf ( parseInt ( i ) ) > - 1 ) {
97
96
selected_dom += "<div class='btn btn-success btn-sm v-tag' data-id='" + i + "'>" + options [ i ] . name + "</div>" ;
98
97
selected_tag += i + ',' ;
@@ -101,7 +100,7 @@ function componentDot(name,selected,options) {
101
100
options_dom += "<div class='btn btn-primary btn-sm v-tag' data-id='" + i + "'>" + options [ i ] . name + "</div>" ;
102
101
}
103
102
104
- var html = '<style>.v-tag{margin-right: 4px;margin-bottom: 4px}</style>' +
103
+ let html = '<style>.v-tag{margin-right: 4px;margin-bottom: 4px}</style>' +
105
104
'<div style="width: 100%;display: grid; grid-template-rows: 42px 140px;border: 1px solid #ccc;border-radius: 5px">' +
106
105
'<div style="display:flex;background: #e1ffa8bf;"><div style="width:120px;background: #e1ffa8bf;">' +
107
106
'<input id="' + name + '-search" type="text" class="form-control" placeholder="搜索名称"></div>' +
@@ -111,22 +110,23 @@ function componentDot(name,selected,options) {
111
110
options_dom +
112
111
'</div>' +
113
112
'</div>' ;
114
- DOM . innerHTML = html ;
113
+ DOM . insertAdjacentHTML ( 'afterbegin' , html ) ;
114
+
115
115
/*hidden data container*/
116
- var dataInput = document . createElement ( 'input' ) ;
116
+ let dataInput = document . createElement ( 'input' ) ;
117
117
dataInput . setAttribute ( 'name' , name ) ;
118
118
dataInput . setAttribute ( 'type' , 'hidden' ) ;
119
119
dataInput . value = '' ;
120
120
DOM . appendChild ( dataInput ) ;
121
121
122
- _componentCommonBlock . _nodesBindEvent ( document . getElementById ( name + '-select' ) . getElementsByClassName ( "v-tag" ) , 'click' , tagCancel ) ;
123
- _componentCommonBlock . _nodesBindEvent ( document . getElementById ( name + '-content' ) . getElementsByClassName ( "v-tag" ) , 'click' , tagSelect ) ;
122
+ _componentMegaBlock . _nodesBindEvent ( document . getElementById ( name + '-select' ) . getElementsByClassName ( "v-tag" ) , 'click' , tagCancel ) ;
123
+ _componentMegaBlock . _nodesBindEvent ( document . getElementById ( name + '-content' ) . getElementsByClassName ( "v-tag" ) , 'click' , tagSelect ) ;
124
124
document . getElementById ( name + '-search' ) . addEventListener ( 'input' , function ( ) {
125
- var search = this . value ;
125
+ let search = this . value ;
126
126
if ( search == '' ) {
127
127
return ;
128
128
}
129
- var contentDom = document . getElementById ( name + '-content' ) ;
129
+ let contentDom = document . getElementById ( name + '-content' ) ;
130
130
for ( let element of contentDom . getElementsByClassName ( "v-tag" ) ) {
131
131
if ( element . innerText . indexOf ( search ) != - 1 ) {
132
132
contentDom . insertBefore ( element , contentDom . firstChild ) ;
@@ -205,9 +205,9 @@ function componentLine(name,columns,data) {
205
205
head += '<th style="width: 30px"></th></tr>' ;
206
206
foot += '<th style="width: 30px" class="JsonTableInsert"></th></tr>' ;
207
207
208
- dom . innerHTML = '<style>#' + name + ' tbody::-webkit-scrollbar { width: 0 !important }</style>' +
208
+ dom . insertAdjacentHTML ( 'afterbegin' , '<style>#' + name + ' tbody::-webkit-scrollbar { width: 0 !important }</style>' +
209
209
'<table class="table table-striped table-bordered table-hover table-responsive">' +
210
- '<thead>' + head + '</thead></table>' ;
210
+ '<thead>' + head + '</thead></table>' ) ;
211
211
/*hidden data container*/
212
212
var dataInput = document . createElement ( 'input' ) ;
213
213
dataInput . setAttribute ( 'name' , name ) ;
@@ -316,7 +316,7 @@ function componentPlane(url,method='POST'){
316
316
_loadingNode :null ,
317
317
_request : function ( url ) {
318
318
this . _loading ( ) ;
319
- _componentCommonBlock . _request ( url , 'GET' , { } , function ( response ) {
319
+ _componentMegaBlock . _request ( url , 'GET' , { } , function ( response ) {
320
320
Form . _loading ( true ) ;
321
321
$ ( '.modal-body' ) . append ( response ) ;
322
322
$ ( '.modal-body button[type="submit"]' ) . click ( function ( ) {
@@ -328,16 +328,10 @@ function componentPlane(url,method='POST'){
328
328
obj . setAttribute ( 'disabled' , 'disabled' ) ;
329
329
obj . innerText = '提交中...' ;
330
330
let form = Form . _modalBodyNode . getElementsByTagName ( 'form' ) [ 0 ] ;
331
- let data = { } ;
332
331
let formdata = new FormData ( form ) ;
333
- formdata . forEach ( ( value , key ) => {
334
- if ( ! data [ key ] ) {
335
- data [ key ] = formdata . getAll ( key ) . length > 1 ? formdata . getAll ( key ) : formdata . get ( key ) ;
336
- }
337
- } ) ;
338
332
339
- _componentCommonBlock . _request ( url , method , data , function ( response ) {
340
- if ( response . code == 1 ) {
333
+ _componentMegaBlock . _request ( url , method , formdata , function ( response ) {
334
+ if ( response . code == 0 ) {
341
335
window . location . reload ( ) ;
342
336
} else {
343
337
_componentAlert ( response . message , 3 , function ( ) {
@@ -368,7 +362,7 @@ function componentPlane(url,method='POST'){
368
362
if ( this . _loadingNode instanceof HTMLElement ) {
369
363
return ;
370
364
}
371
- let svg = _componentCommonBlock . _loadingSvg ;
365
+ let svg = _componentMegaBlock . _loadingSvg ;
372
366
let loading = document . createElement ( 'div' ) ;
373
367
loading . style = 'width: 100%;height: 100px;' ;
374
368
loading . innerHTML = svg ;
@@ -430,3 +424,4 @@ function componentPlane(url,method='POST'){
430
424
431
425
432
426
427
+
0 commit comments