1
+ ; ( function ( $ ) {
2
+ var input_style = 'style="width: 90%;"' ;
3
+
4
+ var html_header = '<div id="setting_about" style="font-size: 16px;">' +
5
+ ' <div>' +
6
+ ' <h3 style="padding: 9px 0;" class="text-success">安装确认</h3>' +
7
+ ' <p style="line-height:24px;">下面是你安装配置信息, 请确认无误后, 点击上方「确定并提交」按钮</p><hr>' ;
8
+ var html_install_info = { } ;
9
+ var html_footer = '<hr><h3 style="padding: 5px 0;" class="text-info">联系我们</h3>' +
10
+ ' <p style="line-height:24px;">在线交流: <a target="_blank" href="https://discord.gg/Uzh5nUf">https://discord.gg/Uzh5nUf</a><br>GitHub: <a href="http://github.com/antswordproject/ant" target="_blank">http://github.com/antswordproject/ant</a></p>' +
11
+ ' <h3 style="padding: 5px 0;" class="text-danger">免责声明</h3>' +
12
+ ' <p style="line-height:24px;">本站仅提供一个学习与交流的平台,请勿用于其他非法用途,否则删除帐号并自行承担由此带来的风险!</p>' +
13
+ ' </div>' +
14
+ '</div>' ;
15
+
16
+ var noxss = function ( str ) {
17
+ return str . replace ( / & / g, "&" )
18
+ . replace ( / > / g, ">" )
19
+ . replace ( / < / g, "<" )
20
+ . replace ( / " / g, """ ) ;
21
+ } ;
22
+
23
+ var install_keys = [ 'create_admin' ] ;
24
+
25
+ var ADDON = {
26
+ ui : {
27
+ create_admin : {
28
+ parent_step : '' ,
29
+ next_step : 'submit_form' ,
30
+ name : 'create_admin' ,
31
+ header : '创建管理员' ,
32
+ fields : [ {
33
+ type : 'email' ,
34
+ field : 'email' ,
35
+ required : true ,
36
+ html : {
37
+ caption : '邮箱' ,
38
+ attr : input_style
39
+ }
40
+ } , {
41
+ type : 'text' ,
42
+ field : 'nickname' ,
43
+ required : true ,
44
+ html : {
45
+ caption : '昵称' ,
46
+ attr : input_style
47
+ }
48
+ } , {
49
+ type : 'password' ,
50
+ field : 'password' ,
51
+ required : true ,
52
+ html : {
53
+ caption : '密码' ,
54
+ attr : input_style
55
+ }
56
+ } , {
57
+ type : 'password' ,
58
+ field : 'password1' ,
59
+ required : true ,
60
+ html : {
61
+ caption : '重复密码' ,
62
+ attr : input_style
63
+ }
64
+ } ] ,
65
+ record : JSON . parse ( localStorage . getItem ( 'create_admin' ) ) || { } ,
66
+ toolbar : {
67
+ items : [ {
68
+ type : 'button' ,
69
+ caption : '下一步' ,
70
+ icon : 'fa fa-step-forward' ,
71
+ onClick : function ( ) {
72
+ var self = w2ui [ 'create_admin' ] ;
73
+ if ( self . validate ( ) . length === 0 ) {
74
+ if ( self . record . password . length < 6 ) {
75
+ $ ( '#password' ) . val ( '' ) . focus ( ) ;
76
+ return ADDON . warning ( '密码长度不得少于6位!' ) ;
77
+ }
78
+ if ( self . record . password !== self . record . password1 ) {
79
+ $ ( "#password1" ) . val ( '' ) . focus ( ) ;
80
+ return ADDON . warning ( '两次输入的密码不一致!' ) ;
81
+ }
82
+ var _t_html = '' ;
83
+ _t_html += '<h4 style="padding: 5px 0;" class="text-info" style="color:#e24444">管理员</h4>' ;
84
+ _t_html += '<p style="margin-left: 20px;line-height:24px;">邮箱: ' + noxss ( self . record . email ) + '</p>' ;
85
+ _t_html += '<p style="margin-left: 20px;line-height:24px;">昵称: ' + noxss ( self . record . nickname ) + '</p>' ;
86
+ html_install_info [ 'create_admin' ] = _t_html ;
87
+ w2ui . submit_form . formHTML = '<div class="w2ui-page page-0">' + html_header + ( Object . values ( html_install_info ) . join ( "" ) ) + html_footer + '</div>' ;
88
+ w2ui . submit_form . reload ( ) ;
89
+ localStorage . setItem ( 'create_admin' , JSON . stringify ( self . record ) ) ;
90
+ w2ui . sidebar . disable ( 'install_' + self . name )
91
+ w2ui . sidebar . enable ( 'install_' + self . next_step )
92
+ w2ui . sidebar . click ( 'install_' + self . next_step )
93
+ } ;
94
+ }
95
+ } , {
96
+ type : 'break'
97
+ } ]
98
+ }
99
+ } ,
100
+ submit_form : {
101
+ parent_step : 'create_admin' ,
102
+ next_step : '' ,
103
+ name : 'submit_form' ,
104
+ header : '确认信息' ,
105
+ formHTML : (
106
+ html_header + ( Object . values ( html_install_info ) . join ( "" ) ) + html_footer
107
+ ) ,
108
+ toolbar : {
109
+ items : [ {
110
+ type : 'button' ,
111
+ caption : '上一步' ,
112
+ icon : 'fa fa-step-backward' ,
113
+ onClick : function ( ) {
114
+ var self = w2ui [ 'submit_form' ] ;
115
+ w2ui . sidebar . disable ( 'install_' + self . name )
116
+ w2ui . sidebar . enable ( 'install_' + self . parent_step )
117
+ w2ui . sidebar . click ( 'install_' + self . parent_step )
118
+ }
119
+ } , {
120
+ type : 'button' ,
121
+ caption : '确定并提交' ,
122
+ icon : 'fa fa-save' ,
123
+ onClick : function ( ) {
124
+ var self = w2ui [ 'submit_form' ] ;
125
+ var post_data = { } ;
126
+ install_keys . map ( function ( key ) {
127
+ var temp = JSON . parse ( localStorage . getItem ( key ) ) || { } ;
128
+ post_data [ key ] = temp ;
129
+ } ) ;
130
+ ADDON . lock ( '安装中..' )
131
+ $ . post ( '/addons/ant.install/install' , post_data , function ( data ) {
132
+ ADDON . unlock ( ) ;
133
+ if ( data . ret ) {
134
+ ADDON . success ( '安装成功!' ) ;
135
+ localStorage . setItem ( 'login_user' , post_data [ 'create_admin' ] [ 'email' ] ) ;
136
+ install_keys . map ( function ( key ) { // 移除本地存储
137
+ localStorage . removeItem ( key ) ;
138
+ } ) ;
139
+ // 重新加载页面
140
+ window . location . href = window . location . origin ;
141
+ } else {
142
+ ADDON . error ( '安装失败!<br>' + data . err ) ;
143
+ }
144
+ } )
145
+ }
146
+ } ]
147
+ }
148
+ }
149
+ } ,
150
+ init : function ( ) {
151
+ $ ( ) . w2form ( this . ui . create_admin ) ;
152
+ $ ( ) . w2form ( this . ui . submit_form ) ;
153
+ ANT . addonLoaded . reg ( function ( ) {
154
+ w2ui [ 'sidebar' ] . click ( 'install_create_admin' ) ;
155
+ } ) ;
156
+ }
157
+ } ;
158
+
159
+ ANT . initAddon ( {
160
+ id : 'ant_install' ,
161
+ text : '系统安装' ,
162
+ group : true ,
163
+ expanded : true ,
164
+ nodes : [ {
165
+ id : 'install_create_admin' ,
166
+ text : '创建管理员' ,
167
+ icon : 'fa fa-user' ,
168
+ disabled : false ,
169
+ onClick : function ( ) {
170
+ ADDON . content ( w2ui [ 'create_admin' ] ) ;
171
+ }
172
+ } , {
173
+ id : 'install_submit_form' ,
174
+ text : '确认信息' ,
175
+ icon : 'fa fa-check' ,
176
+ disabled : true ,
177
+ onClick : function ( ) {
178
+ ADDON . content ( w2ui [ 'submit_form' ] ) ;
179
+ }
180
+ } ]
181
+ } , ADDON ) ;
182
+
183
+ ANT . addonLoaded . reg ( function ( ) {
184
+ ANT . ROUTE . run ( ) ;
185
+ } )
186
+ } ) ( jQuery ) ;
0 commit comments