Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
A
antSword
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
HuangJunbo
antSword
Commits
9a0fbbd7
Commit
9a0fbbd7
authored
Apr 14, 2016
by
antoor
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Fix call core module
修复调用核心模块
parent
b6092dde
Changes
8
Hide whitespace changes
Inline
Side-by-side
Showing
8 changed files
with
660 additions
and
462 deletions
+660
-462
app.entry.jsx
source/app.entry.jsx
+1
-3
index.jsx
source/modules/database/asp/index.jsx
+42
-26
index.jsx
source/modules/database/custom/index.jsx
+40
-26
index.jsx
source/modules/database/php/index.jsx
+48
-36
files.jsx
source/modules/filemanager/files.jsx
+18
-0
folder.jsx
source/modules/filemanager/folder.jsx
+13
-2
index.jsx
source/modules/filemanager/index.jsx
+320
-210
index.jsx
source/modules/terminal/index.jsx
+178
-159
No files found.
source/app.entry.jsx
View file @
9a0fbbd7
...
@@ -33,9 +33,7 @@ const antSword = window.antSword = {
...
@@ -33,9 +33,7 @@ const antSword = window.antSword = {
};
};
// 加载模板代码
// 加载模板代码
[
'php'
,
'asp'
,
'aspx'
,
'custom'
].
map
((
_
)
=>
{
antSword
[
'core'
]
=
require
(
'./core/index'
);
antSword
[
'core'
][
_
]
=
require
(
`./core/
${
_
}
/index`
);
});
// 加载显示语言
// 加载显示语言
let
_lang
=
localStorage
.
getItem
(
'language'
)
||
navigator
.
language
;
let
_lang
=
localStorage
.
getItem
(
'language'
)
||
navigator
.
language
;
...
...
source/modules/database/asp/index.jsx
View file @
9a0fbbd7
//
//
// 数据库驱动::ASP
// 数据库驱动::ASP
// 支持数据库:access,sqlserver,mysql
// 支持数据库:access,sqlserver,mysql
//
//
class
ASP
{
class
ASP
{
...
@@ -9,9 +9,9 @@ class ASP {
...
@@ -9,9 +9,9 @@ class ASP {
this
.
opt
=
opt
;
this
.
opt
=
opt
;
this
.
core
=
this
.
opt
.
core
;
this
.
core
=
this
.
opt
.
core
;
this
.
manager
=
this
.
opt
.
super
;
this
.
manager
=
this
.
opt
.
super
;
//
//
// * 数据库驱动列表
// * 数据库驱动列表
//
//
this
.
conns
=
{
this
.
conns
=
{
'dsn'
:
'Dsn=DsnName;'
,
'dsn'
:
'Dsn=DsnName;'
,
'mysql'
:
'Driver={MySQL};Server=localhost;database=mysql;UID=root;PWD='
,
'mysql'
:
'Driver={MySQL};Server=localhost;database=mysql;UID=root;PWD='
,
...
@@ -254,11 +254,15 @@ class ASP {
...
@@ -254,11 +254,15 @@ class ASP {
_id
:
this
.
manager
.
opt
[
'_id'
],
_id
:
this
.
manager
.
opt
[
'_id'
],
id
:
id
id
:
id
});
});
this
.
core
[
`database_
${
conf
[
'type'
]}
`
].
show_databases
(
{
this
.
core
.
request
(
conn
:
conf
[
'conn'
],
this
.
core
[
`database_
${
conf
[
'type'
]}
`
].
show_databases
(
dbname
:
[
'access'
,
'microsoft_jet_oledb_4_0'
].
indexOf
(
conf
[
'type'
])
>
-
1
?
conf
[
'conn'
].
match
(
/
[\w]
+.mdb$/
)
:
'database'
{
},
(
ret
)
=>
{
conn
:
conf
[
'conn'
],
dbname
:
[
'access'
,
'microsoft_jet_oledb_4_0'
].
indexOf
(
conf
[
'type'
])
>
-
1
?
conf
[
'conn'
].
match
(
/
[\w]
+.mdb$/
)
:
'database'
})
).
then
((
res
)
=>
{
let
ret
=
res
[
'text'
];
const
arr
=
ret
.
split
(
'
\
t'
);
const
arr
=
ret
.
split
(
'
\
t'
);
if
(
arr
.
length
===
1
&&
ret
===
''
)
{
if
(
arr
.
length
===
1
&&
ret
===
''
)
{
toastr
.
warning
(
'执行完毕,没有结果返回'
)
toastr
.
warning
(
'执行完毕,没有结果返回'
)
...
@@ -279,7 +283,7 @@ class ASP {
...
@@ -279,7 +283,7 @@ class ASP {
this
.
manager
.
list
.
imgs
[
1
]);
this
.
manager
.
list
.
imgs
[
1
]);
});
});
this
.
manager
.
list
.
layout
.
progressOff
();
this
.
manager
.
list
.
layout
.
progressOff
();
}
,
(
err
)
=>
{
}
).
catch
(
(
err
)
=>
{
toastr
.
error
(
'获取数据库列表失败!'
+
err
[
'status'
]
||
JSON
.
stringify
(
err
),
'ERROR'
);
toastr
.
error
(
'获取数据库列表失败!'
+
err
[
'status'
]
||
JSON
.
stringify
(
err
),
'ERROR'
);
this
.
manager
.
list
.
layout
.
progressOff
();
this
.
manager
.
list
.
layout
.
progressOff
();
});
});
...
@@ -293,11 +297,15 @@ class ASP {
...
@@ -293,11 +297,15 @@ class ASP {
_id
:
this
.
manager
.
opt
[
'_id'
],
_id
:
this
.
manager
.
opt
[
'_id'
],
id
:
id
id
:
id
});
});
this
.
core
[
`database_
${
conf
[
'type'
]}
`
].
show_tables
(
{
this
.
core
.
request
(
conn
:
conf
[
'conn'
],
this
.
core
[
`database_
${
conf
[
'type'
]}
`
].
show_tables
(
dbname
:
db
{
},
(
ret
)
=>
{
conn
:
conf
[
'conn'
],
dbname
:
db
})
).
then
((
res
)
=>
{
let
ret
=
res
[
'text'
];
const
arr
=
ret
.
split
(
'
\
t'
);
const
arr
=
ret
.
split
(
'
\
t'
);
const
_db
=
new
Buffer
(
db
).
toString
(
'base64'
);
const
_db
=
new
Buffer
(
db
).
toString
(
'base64'
);
// 删除子节点
// 删除子节点
...
@@ -328,11 +336,15 @@ class ASP {
...
@@ -328,11 +336,15 @@ class ASP {
_id
:
this
.
manager
.
opt
[
'_id'
],
_id
:
this
.
manager
.
opt
[
'_id'
],
id
:
id
id
:
id
});
});
this
.
core
[
`database_
${
conf
[
'type'
]}
`
].
show_columns
(
{
this
.
core
.
request
(
conn
:
conf
[
'conn'
],
this
.
core
[
`database_
${
conf
[
'type'
]}
`
].
show_columns
(
table
:
conf
[
'type'
]
===
'oracle'
?
`SELECT * FROM (SELECT A.*,ROWNUM N FROM
${
table
}
A) WHERE N=1`
:
`SELECT TOP 1 * FROM
${
table
}
`
{
},
(
ret
)
=>
{
conn
:
conf
[
'conn'
],
table
:
conf
[
'type'
]
===
'oracle'
?
`SELECT * FROM (SELECT A.*,ROWNUM N FROM
${
table
}
A) WHERE N=1`
:
`SELECT TOP 1 * FROM
${
table
}
`
})
).
then
((
res
)
=>
{
let
ret
=
res
[
'text'
];
const
arr
=
ret
.
split
(
'
\
t'
);
const
arr
=
ret
.
split
(
'
\
t'
);
const
_db
=
new
Buffer
(
db
).
toString
(
'base64'
);
const
_db
=
new
Buffer
(
db
).
toString
(
'base64'
);
const
_table
=
new
Buffer
(
table
).
toString
(
'base64'
);
const
_table
=
new
Buffer
(
table
).
toString
(
'base64'
);
...
@@ -363,14 +375,18 @@ class ASP {
...
@@ -363,14 +375,18 @@ class ASP {
// 执行SQL
// 执行SQL
execSQL
(
sql
)
{
execSQL
(
sql
)
{
this
.
manager
.
query
.
layout
.
progressOn
();
this
.
manager
.
query
.
layout
.
progressOn
();
this
.
core
[
`database_
${
this
.
dbconf
[
'type'
]}
`
].
query
({
conn
:
this
.
dbconf
[
'conn'
],
this
.
core
.
request
(
sql
:
sql
this
.
core
[
`database_
${
this
.
dbconf
[
'type'
]}
`
].
query
({
},
(
ret
)
=>
{
conn
:
this
.
dbconf
[
'conn'
],
sql
:
sql
})
).
then
((
res
)
=>
{
let
ret
=
res
[
'text'
];
// 更新执行结果
// 更新执行结果
this
.
updateResult
(
ret
);
this
.
updateResult
(
ret
);
this
.
manager
.
query
.
layout
.
progressOff
();
this
.
manager
.
query
.
layout
.
progressOff
();
}
,
(
err
)
=>
{
}
).
catch
(
(
err
)
=>
{
console
.
error
(
err
);
console
.
error
(
err
);
});
});
}
}
...
@@ -455,4 +471,4 @@ class ASP {
...
@@ -455,4 +471,4 @@ class ASP {
}
}
module
.
exports
=
ASP
;
module
.
exports
=
ASP
;
\ No newline at end of file
source/modules/database/custom/index.jsx
View file @
9a0fbbd7
...
@@ -250,12 +250,14 @@ class ASP {
...
@@ -250,12 +250,14 @@ class ASP {
_id
:
this
.
manager
.
opt
[
'_id'
],
_id
:
this
.
manager
.
opt
[
'_id'
],
id
:
id
id
:
id
});
});
this
.
core
[
`database_
${
conf
[
'type'
]}
`
].
show_databases
(
this
.
core
.
request
(
{
this
.
core
[
`database_
${
conf
[
'type'
]}
`
].
show_databases
({
conn
:
conf
[
'conn'
],
conn
:
conf
[
'conn'
],
encode
:
this
.
manager
.
opt
.
encode
,
encode
:
this
.
manager
.
opt
.
encode
,
db
:
[
'access'
,
'microsoft_jet_oledb_4_0'
].
indexOf
(
conf
[
'type'
])
>
-
1
?
conf
[
'conn'
].
match
(
/
[\w]
+.mdb$/
)
:
'database'
db
:
[
'access'
,
'microsoft_jet_oledb_4_0'
].
indexOf
(
conf
[
'type'
])
>
-
1
?
conf
[
'conn'
].
match
(
/
[\w]
+.mdb$/
)
:
'database'
},
(
ret
)
=>
{
})
).
then
((
res
)
=>
{
let
ret
=
res
[
'text'
];
const
arr
=
ret
.
split
(
'
\
t'
);
const
arr
=
ret
.
split
(
'
\
t'
);
if
(
arr
.
length
===
1
&&
ret
===
''
)
{
if
(
arr
.
length
===
1
&&
ret
===
''
)
{
toastr
.
warning
(
'执行完毕,没有结果返回'
)
toastr
.
warning
(
'执行完毕,没有结果返回'
)
...
@@ -276,7 +278,7 @@ class ASP {
...
@@ -276,7 +278,7 @@ class ASP {
this
.
manager
.
list
.
imgs
[
1
]);
this
.
manager
.
list
.
imgs
[
1
]);
});
});
this
.
manager
.
list
.
layout
.
progressOff
();
this
.
manager
.
list
.
layout
.
progressOff
();
}
,
(
err
)
=>
{
}
).
catch
(
(
err
)
=>
{
toastr
.
error
(
'获取数据库列表失败!'
+
err
[
'status'
]
||
JSON
.
stringify
(
err
),
'ERROR'
);
toastr
.
error
(
'获取数据库列表失败!'
+
err
[
'status'
]
||
JSON
.
stringify
(
err
),
'ERROR'
);
this
.
manager
.
list
.
layout
.
progressOff
();
this
.
manager
.
list
.
layout
.
progressOff
();
});
});
...
@@ -290,12 +292,16 @@ class ASP {
...
@@ -290,12 +292,16 @@ class ASP {
_id
:
this
.
manager
.
opt
[
'_id'
],
_id
:
this
.
manager
.
opt
[
'_id'
],
id
:
id
id
:
id
});
});
this
.
core
[
`database_
${
conf
[
'type'
]}
`
].
show_tables
(
{
this
.
core
.
request
(
conn
:
conf
[
'conn'
],
this
.
core
[
`database_
${
conf
[
'type'
]}
`
].
show_tables
(
encode
:
this
.
manager
.
opt
.
encode
,
{
db
:
db
conn
:
conf
[
'conn'
],
},
(
ret
)
=>
{
encode
:
this
.
manager
.
opt
.
encode
,
db
:
db
})
).
then
((
res
)
=>
{
let
ret
=
res
[
'text'
];
const
arr
=
ret
.
split
(
'
\
t'
);
const
arr
=
ret
.
split
(
'
\
t'
);
const
_db
=
new
Buffer
(
db
).
toString
(
'base64'
);
const
_db
=
new
Buffer
(
db
).
toString
(
'base64'
);
// 删除子节点
// 删除子节点
...
@@ -326,13 +332,17 @@ class ASP {
...
@@ -326,13 +332,17 @@ class ASP {
_id
:
this
.
manager
.
opt
[
'_id'
],
_id
:
this
.
manager
.
opt
[
'_id'
],
id
:
id
id
:
id
});
});
this
.
core
[
`database_
${
conf
[
'type'
]}
`
].
show_columns
(
{
this
.
core
.
request
(
conn
:
conf
[
'conn'
],
this
.
core
[
`database_
${
conf
[
'type'
]}
`
].
show_columns
(
encode
:
this
.
manager
.
opt
.
encode
,
{
db
:
db
,
conn
:
conf
[
'conn'
],
table
:
table
encode
:
this
.
manager
.
opt
.
encode
,
},
(
ret
)
=>
{
db
:
db
,
table
:
table
})
).
then
((
res
)
=>
{
let
ret
=
res
[
'text'
];
const
arr
=
ret
.
split
(
'
\
t'
);
const
arr
=
ret
.
split
(
'
\
t'
);
const
_db
=
new
Buffer
(
db
).
toString
(
'base64'
);
const
_db
=
new
Buffer
(
db
).
toString
(
'base64'
);
const
_table
=
new
Buffer
(
table
).
toString
(
'base64'
);
const
_table
=
new
Buffer
(
table
).
toString
(
'base64'
);
...
@@ -363,15 +373,19 @@ class ASP {
...
@@ -363,15 +373,19 @@ class ASP {
// 执行SQL
// 执行SQL
execSQL
(
sql
)
{
execSQL
(
sql
)
{
this
.
manager
.
query
.
layout
.
progressOn
();
this
.
manager
.
query
.
layout
.
progressOn
();
this
.
core
[
`database_
${
this
.
dbconf
[
'type'
]}
`
].
query
({
conn
:
this
.
dbconf
[
'conn'
],
this
.
core
.
request
(
encode
:
this
.
manager
.
opt
.
encode
,
this
.
core
[
`database_
${
this
.
dbconf
[
'type'
]}
`
].
query
({
sql
:
sql
conn
:
this
.
dbconf
[
'conn'
],
},
(
ret
)
=>
{
encode
:
this
.
manager
.
opt
.
encode
,
sql
:
sql
})
).
then
((
res
)
=>
{
let
ret
=
res
[
'text'
];
// 更新执行结果
// 更新执行结果
this
.
updateResult
(
ret
);
this
.
updateResult
(
ret
);
this
.
manager
.
query
.
layout
.
progressOff
();
this
.
manager
.
query
.
layout
.
progressOff
();
}
,
(
err
)
=>
{
}
).
catch
(
(
err
)
=>
{
console
.
error
(
err
);
console
.
error
(
err
);
});
});
}
}
...
...
source/modules/database/php/index.jsx
View file @
9a0fbbd7
//
//
// 数据库驱动::PHP
// 数据库驱动::PHP
// 支持数据库:mysql,mssql,oracle,informix
// 支持数据库:mysql,mssql,oracle,informix
//
//
const
LANG
=
antSword
[
'language'
][
'database'
];
const
LANG
=
antSword
[
'language'
][
'database'
];
const
LANG_T
=
antSword
[
'language'
][
'toastr'
];
const
LANG_T
=
antSword
[
'language'
][
'toastr'
];
...
@@ -271,12 +271,14 @@ class PHP {
...
@@ -271,12 +271,14 @@ class PHP {
_id
:
this
.
manager
.
opt
[
'_id'
],
_id
:
this
.
manager
.
opt
[
'_id'
],
id
:
id
id
:
id
});
});
this
.
core
[
`database_
${
conf
[
'type'
]}
`
].
show_databases
(
this
.
core
.
request
(
{
this
.
core
[
`database_
${
conf
[
'type'
]}
`
].
show_databases
({
host
:
conf
[
'host'
],
host
:
conf
[
'host'
],
user
:
conf
[
'user'
],
user
:
conf
[
'user'
],
passwd
:
conf
[
'passwd'
]
passwd
:
conf
[
'passwd'
]
},
(
ret
)
=>
{
})
).
then
((
res
)
=>
{
let
ret
=
res
[
'text'
];
const
arr
=
ret
.
split
(
'
\
t'
);
const
arr
=
ret
.
split
(
'
\
t'
);
if
(
arr
.
length
===
1
&&
ret
===
''
)
{
if
(
arr
.
length
===
1
&&
ret
===
''
)
{
toastr
.
warning
(
LANG
[
'result'
][
'warning'
],
LANG_T
[
'warning'
]);
toastr
.
warning
(
LANG
[
'result'
][
'warning'
],
LANG_T
[
'warning'
]);
...
@@ -297,7 +299,7 @@ class PHP {
...
@@ -297,7 +299,7 @@ class PHP {
this
.
manager
.
list
.
imgs
[
1
]);
this
.
manager
.
list
.
imgs
[
1
]);
});
});
this
.
manager
.
list
.
layout
.
progressOff
();
this
.
manager
.
list
.
layout
.
progressOff
();
}
,
(
err
)
=>
{
}
).
catch
(
(
err
)
=>
{
toastr
.
error
(
LANG
[
'result'
][
'error'
][
'database'
](
err
[
'status'
]
||
JSON
.
stringify
(
err
)),
LANG_T
[
'error'
]);
toastr
.
error
(
LANG
[
'result'
][
'error'
][
'database'
](
err
[
'status'
]
||
JSON
.
stringify
(
err
)),
LANG_T
[
'error'
]);
this
.
manager
.
list
.
layout
.
progressOff
();
this
.
manager
.
list
.
layout
.
progressOff
();
});
});
...
@@ -311,13 +313,16 @@ class PHP {
...
@@ -311,13 +313,16 @@ class PHP {
_id
:
this
.
manager
.
opt
[
'_id'
],
_id
:
this
.
manager
.
opt
[
'_id'
],
id
:
id
id
:
id
});
});
this
.
core
[
`database_
${
conf
[
'type'
]}
`
].
show_tables
(
{
this
.
core
.
request
(
host
:
conf
[
'host'
],
this
.
core
[
`database_
${
conf
[
'type'
]}
`
].
show_tables
({
user
:
conf
[
'user'
],
host
:
conf
[
'host'
],
passwd
:
conf
[
'passwd'
],
user
:
conf
[
'user'
],
db
:
db
passwd
:
conf
[
'passwd'
],
},
(
ret
)
=>
{
db
:
db
})
).
then
((
res
)
=>
{
let
ret
=
res
[
'text'
];
const
arr
=
ret
.
split
(
'
\
t'
);
const
arr
=
ret
.
split
(
'
\
t'
);
const
_db
=
new
Buffer
(
db
).
toString
(
'base64'
);
const
_db
=
new
Buffer
(
db
).
toString
(
'base64'
);
// 删除子节点
// 删除子节点
...
@@ -337,7 +342,7 @@ class PHP {
...
@@ -337,7 +342,7 @@ class PHP {
);
);
});
});
this
.
manager
.
list
.
layout
.
progressOff
();
this
.
manager
.
list
.
layout
.
progressOff
();
}
,
(
err
)
=>
{
}
).
catch
(
(
err
)
=>
{
toastr
.
error
(
LANG
[
'result'
][
'error'
][
'table'
](
err
[
'status'
]
||
JSON
.
stringify
(
err
)),
LANG_T
[
'error'
]);
toastr
.
error
(
LANG
[
'result'
][
'error'
][
'table'
](
err
[
'status'
]
||
JSON
.
stringify
(
err
)),
LANG_T
[
'error'
]);
this
.
manager
.
list
.
layout
.
progressOff
();
this
.
manager
.
list
.
layout
.
progressOff
();
});
});
...
@@ -351,14 +356,17 @@ class PHP {
...
@@ -351,14 +356,17 @@ class PHP {
_id
:
this
.
manager
.
opt
[
'_id'
],
_id
:
this
.
manager
.
opt
[
'_id'
],
id
:
id
id
:
id
});
});
this
.
core
[
`database_
${
conf
[
'type'
]}
`
].
show_columns
(
{
this
.
core
.
request
(
host
:
conf
[
'host'
],
this
.
core
[
`database_
${
conf
[
'type'
]}
`
].
show_columns
({
user
:
conf
[
'user'
],
host
:
conf
[
'host'
],
passwd
:
conf
[
'passwd'
],
user
:
conf
[
'user'
],
db
:
db
,
passwd
:
conf
[
'passwd'
],
table
:
table
db
:
db
,
},
(
ret
)
=>
{
table
:
table
})
).
then
((
res
)
=>
{
let
ret
=
res
[
'text'
];
const
arr
=
ret
.
split
(
'
\
t'
);
const
arr
=
ret
.
split
(
'
\
t'
);
const
_db
=
new
Buffer
(
db
).
toString
(
'base64'
);
const
_db
=
new
Buffer
(
db
).
toString
(
'base64'
);
const
_table
=
new
Buffer
(
table
).
toString
(
'base64'
);
const
_table
=
new
Buffer
(
table
).
toString
(
'base64'
);
...
@@ -380,7 +388,7 @@ class PHP {
...
@@ -380,7 +388,7 @@ class PHP {
// 更新编辑器SQL语句
// 更新编辑器SQL语句
this
.
manager
.
query
.
editor
.
session
.
setValue
(
`SELECT * FROM \`
${
table
}
\` ORDER BY 1 DESC LIMIT 0,20;`
);
this
.
manager
.
query
.
editor
.
session
.
setValue
(
`SELECT * FROM \`
${
table
}
\` ORDER BY 1 DESC LIMIT 0,20;`
);
this
.
manager
.
list
.
layout
.
progressOff
();
this
.
manager
.
list
.
layout
.
progressOff
();
}
,
(
err
)
=>
{
}
).
catch
(
(
err
)
=>
{
toastr
.
error
(
LANG
[
'result'
][
'error'
][
'column'
](
err
[
'status'
]
||
JSON
.
stringify
(
err
)),
LANG_T
[
'error'
]);
toastr
.
error
(
LANG
[
'result'
][
'error'
][
'column'
](
err
[
'status'
]
||
JSON
.
stringify
(
err
)),
LANG_T
[
'error'
]);
this
.
manager
.
list
.
layout
.
progressOff
();
this
.
manager
.
list
.
layout
.
progressOff
();
});
});
...
@@ -389,18 +397,22 @@ class PHP {
...
@@ -389,18 +397,22 @@ class PHP {
// 执行SQL
// 执行SQL
execSQL
(
sql
)
{
execSQL
(
sql
)
{
this
.
manager
.
query
.
layout
.
progressOn
();
this
.
manager
.
query
.
layout
.
progressOn
();
this
.
core
[
`database_
${
this
.
dbconf
[
'type'
]}
`
].
query
({
host
:
this
.
dbconf
[
'host'
],
this
.
core
.
request
(
user
:
this
.
dbconf
[
'user'
],
this
.
core
[
`database_
${
this
.
dbconf
[
'type'
]}
`
].
query
({
passwd
:
this
.
dbconf
[
'passwd'
],
host
:
this
.
dbconf
[
'host'
],
db
:
this
.
dbconf
[
'database'
],
user
:
this
.
dbconf
[
'user'
],
sql
:
sql
,
passwd
:
this
.
dbconf
[
'passwd'
],
encode
:
this
.
dbconf
[
'encode'
]
||
'utf8'
db
:
this
.
dbconf
[
'database'
],
},
(
ret
)
=>
{
sql
:
sql
,
encode
:
this
.
dbconf
[
'encode'
]
||
'utf8'
})
).
then
((
res
)
=>
{
let
ret
=
res
[
'text'
];
// 更新执行结果
// 更新执行结果
this
.
updateResult
(
ret
);
this
.
updateResult
(
ret
);
this
.
manager
.
query
.
layout
.
progressOff
();
this
.
manager
.
query
.
layout
.
progressOff
();
}
,
(
err
)
=>
{
}
).
catch
(
(
err
)
=>
{
toastr
.
error
(
LANG
[
'result'
][
'error'
][
'query'
](
err
[
'status'
]
||
JSON
.
stringify
(
err
)),
LANG_T
[
'error'
]);
toastr
.
error
(
LANG
[
'result'
][
'error'
][
'query'
](
err
[
'status'
]
||
JSON
.
stringify
(
err
)),
LANG_T
[
'error'
]);
this
.
manager
.
query
.
layout
.
progressOff
();
this
.
manager
.
query
.
layout
.
progressOff
();
});
});
...
@@ -484,4 +496,4 @@ class PHP {
...
@@ -484,4 +496,4 @@ class PHP {
}
}
module
.
exports
=
PHP
;
module
.
exports
=
PHP
;
\ No newline at end of file
source/modules/filemanager/files.jsx
View file @
9a0fbbd7
...
@@ -194,6 +194,7 @@ class Files {
...
@@ -194,6 +194,7 @@ class Files {
grid
.
setInitWidths
(
"40,*,150,100,100"
);
grid
.
setInitWidths
(
"40,*,150,100,100"
);
grid
.
setColAlign
(
"center,left,left,right,center"
);
grid
.
setColAlign
(
"center,left,left,right,center"
);
grid
.
enableMultiselect
(
true
);
grid
.
enableMultiselect
(
true
);
grid
.
enableDragAndDrop
(
true
);
// grid.enableMultiline(true);
// grid.enableMultiline(true);
// grid右键
// grid右键
...
@@ -368,6 +369,23 @@ class Files {
...
@@ -368,6 +369,23 @@ class Files {
// 剪贴板
// 剪贴板
this
.
Clipboard
=
{};
this
.
Clipboard
=
{};
// 文件拖拽上传
$
(
this
.
cell
.
cell
).
on
({
dragleave
:
(
e
)
=>
{
e
.
preventDefault
()
},
drop
:
(
e
)
=>
{
e
.
preventDefault
();
let
filePaths
=
[];
let
files
=
e
.
originalEvent
[
'dataTransfer'
][
'files'
]
||
{};
for
(
let
i
=
0
;
i
<
files
.
length
;
i
++
)
{
let
f
=
files
.
item
(
i
);
filePaths
.
push
(
f
[
'path'
]);
}
this
.
manager
.
uploadFile
(
filePaths
);
},
dragenter
:
(
e
)
=>
{
e
.
preventDefault
()
},
dragover
:
(
e
)
=>
{
e
.
preventDefault
()
}
});
}
}
// 刷新当前目录
// 刷新当前目录
...
...
source/modules/filemanager/folder.jsx
View file @
9a0fbbd7
...
@@ -11,7 +11,6 @@ class Folder {
...
@@ -11,7 +11,6 @@ class Folder {
// 1.cell: 左侧layout.cell对象
// 1.cell: 左侧layout.cell对象
constructor
(
cell
,
manager
)
{
constructor
(
cell
,
manager
)
{
cell
.
setWidth
(
250
);
cell
.
setWidth
(
250
);
cell
.
setText
(
`<i class="fa fa-folder-o"></i>
${
LANG
[
'title'
]}
`
);
// 创建tree
// 创建tree
let
tree
=
cell
.
attachTree
();
let
tree
=
cell
.
attachTree
();
// tree事件
// tree事件
...
@@ -23,6 +22,7 @@ class Folder {
...
@@ -23,6 +22,7 @@ class Folder {
this
.
cell
=
cell
;
this
.
cell
=
cell
;
this
.
cache
=
{};
this
.
cache
=
{};
this
.
manager
=
manager
;
this
.
manager
=
manager
;
this
.
setTitle
(
0
);
}
}
...
@@ -44,12 +44,15 @@ class Folder {
...
@@ -44,12 +44,15 @@ class Folder {
self
.
cache
[
curPath
]
=
0
;
self
.
cache
[
curPath
]
=
0
;
});
});
// 2. 解析当前子目录
// 2. 解析当前子目录
let
folderNum
=
0
;
files
.
map
((
f
)
=>
{
files
.
map
((
f
)
=>
{
let
_
=
f
[
'name'
];
let
_
=
f
[
'name'
];
if
(
!
_
.
endsWith
(
'/'
)
||
[
'./'
,
'../'
].
indexOf
(
_
)
!==
-
1
)
{
return
};
if
(
!
_
.
endsWith
(
'/'
)
||
[
'./'
,
'../'
].
indexOf
(
_
)
!==
-
1
)
{
return
};
self
.
cache
[
`
${
curPath
}${
_
}
`
]
=
0
;
self
.
cache
[
`
${
curPath
}${
_
}
`
]
=
0
;
folderNum
++
;
});
});
// 设置标题
this
.
setTitle
(
folderNum
);
// 3. 解析缓存为树形菜单虚拟对象
// 3. 解析缓存为树形菜单虚拟对象
// /var/www/html 根据/分割为数组,循环,相加,增加到虚拟缓存
// /var/www/html 根据/分割为数组,循环,相加,增加到虚拟缓存
...
@@ -100,6 +103,14 @@ class Folder {
...
@@ -100,6 +103,14 @@ class Folder {
this
.
cell
.
progressOff
();
this
.
cell
.
progressOff
();
}
}
/**
* 设置标题
* @param {Number} num 当前目录数
*/
setTitle
(
num
)
{
this
.
cell
.
setText
(
`<i class="fa fa-folder-o"></i>
${
LANG
[
'title'
]}
(
${
num
}
)`
);
}
}
}
export
default
Folder
;
export
default
Folder
;
source/modules/filemanager/index.jsx
View file @
9a0fbbd7
//
/**
// 文件管理模块
* 文件管理模板
//
* 更新:2016/04/13
* 作者:蚁逅 <https://github.com/antoor>
*/
'use strict'
;
import
Files
from
'./files'
;
import
Files
from
'./files'
;
import
Tasks
from
'./tasks'
;
import
Tasks
from
'./tasks'
;
...
@@ -25,13 +28,15 @@ class FileManager {
...
@@ -25,13 +28,15 @@ class FileManager {
tabbar
.
addTab
(
tabbar
.
addTab
(
`tab_filemanager_
${
hash
}
`
,
`tab_filemanager_
${
hash
}
`
,
// `<i class="fa fa-folder-o"></i> ${LANG['title']} \/\/ ${opts['ip']}`,
`<i class="fa fa-folder-o"></i>
${
opts
[
'ip'
]}
`
,
`<i class="fa fa-folder-o"></i>
${
opts
[
'ip'
]}
`
,
null
,
null
,
true
,
true
null
,
null
,
true
,
true
);
);
// 创建框架
// 创建框架
const
cell
=
tabbar
.
cells
(
`tab_filemanager_
${
hash
}
`
);
const
cell
=
tabbar
.
cells
(
`tab_filemanager_
${
hash
}
`
);
// 增加到全局变量方便调试
antSword
[
'modules'
][
'filemanager'
]
=
antSword
[
'modules'
][
'filemanager'
]
||
{};
antSword
[
'modules'
][
'filemanager'
][
hash
]
=
this
;
this
.
isWin
=
true
;
this
.
isWin
=
true
;
this
.
path
=
'/'
;
this
.
path
=
'/'
;
...
@@ -51,14 +56,24 @@ class FileManager {
...
@@ -51,14 +56,24 @@ class FileManager {
this
.
initUI
(
cache_info
);
this
.
initUI
(
cache_info
);
}
else
{
}
else
{
this
.
cell
.
progressOn
();
this
.
cell
.
progressOn
();
this
.
core
.
base
.
info
((
ret
)
=>
{
this
.
core
.
request
(
this
.
initUI
(
ret
);
this
.
core
.
base
.
info
()
).
then
((
ret
)
=>
{
this
.
initUI
(
ret
[
'text'
]);
this
.
cell
.
progressOff
();
this
.
cell
.
progressOff
();
}
,
(
err
)
=>
{
}
).
catch
(
(
err
)
=>
{
this
.
cell
.
progressOff
();
this
.
cell
.
progressOff
();
this
.
cell
.
close
();
this
.
cell
.
close
();
toastr
.
error
((
typeof
(
err
)
===
'object'
)
?
JSON
.
stringify
(
err
)
:
String
(
err
),
LANG_T
[
'error'
]);
toastr
.
error
((
typeof
(
err
)
===
'object'
)
?
JSON
.
stringify
(
err
)
:
String
(
err
),
LANG_T
[
'error'
]);
});
});
// this.core.base.info((ret) => {
// this.initUI(ret);
// this.cell.progressOff();
// }, (err) => {
// this.cell.progressOff();
// this.cell.close();
// toastr.error((typeof(err) === 'object') ? JSON.stringify(err) : String(err), LANG_T['error']);
// });
}
}
}
}
...
@@ -131,9 +146,12 @@ class FileManager {
...
@@ -131,9 +146,12 @@ class FileManager {
return
callback
(
JSON
.
parse
(
cache
));
return
callback
(
JSON
.
parse
(
cache
));
};
};
this
.
core
.
filemanager
.
dir
({
this
.
core
.
request
(
path
:
path
this
.
core
.
filemanager
.
dir
({
},
(
ret
)
=>
{
path
:
path
})
).
then
((
res
)
=>
{
let
ret
=
res
[
'text'
];
// 判断是否出错
// 判断是否出错
if
(
ret
.
startsWith
(
'ERROR://'
))
{
if
(
ret
.
startsWith
(
'ERROR://'
))
{
callback
([]);
callback
([]);
...
@@ -167,9 +185,49 @@ class FileManager {
...
@@ -167,9 +185,49 @@ class FileManager {
// 增加缓存
// 增加缓存
// self.cache[path] = data;
// self.cache[path] = data;
this
.
cache
.
set
(
cache_tag
,
JSON
.
stringify
(
data
));
this
.
cache
.
set
(
cache_tag
,
JSON
.
stringify
(
data
));
}
,
(
err
)
=>
{
}
).
catch
(
(
err
)
=>
{
toastr
.
error
((
err
instanceof
Object
)
?
JSON
.
stringify
(
err
)
:
String
(
err
),
LANG_T
[
'error'
]);
toastr
.
error
((
err
instanceof
Object
)
?
JSON
.
stringify
(
err
)
:
String
(
err
),
LANG_T
[
'error'
]);
});
})
// this.core.filemanager.dir({
// path: path
// }, (ret) => {
// // 判断是否出错
// if (ret.startsWith('ERROR://')) {
// callback([]);
// return toastr.error(ret.substr(9), LANG_T['error']);
// };
// let tmp = ret.split('\n');
//
// tmp.sort();
//
// let folders = [];
// let files = [];
//
// tmp.map( (t) => {
// let _ = t.split('\t');
// let d = {
// name: _[0],
// time: _[1],
// size: _[2],
// attr: _[3]
// }
// if (_[0].endsWith('/')) {
// folders.push(d);
// }else{
// files.push(d);
// }
// } );
//
// let data = folders.concat(files);
// callback(data);
//
// // 增加缓存
// // self.cache[path] = data;
// this.cache.set(cache_tag, JSON.stringify(data));
// }, (err) => {
// toastr.error((err instanceof Object) ? JSON.stringify(err) : String(err), LANG_T['error']);
// });
}
}
// 更改目录,返回最终绝对路径
// 更改目录,返回最终绝对路径
...
@@ -225,9 +283,12 @@ class FileManager {
...
@@ -225,9 +283,12 @@ class FileManager {
((
p
)
=>
{
((
p
)
=>
{
const
path
=
this
.
path
+
p
;
const
path
=
this
.
path
+
p
;
this
.
files
.
cell
.
progressOn
();
this
.
files
.
cell
.
progressOn
();
this
.
core
.
filemanager
.
delete
({
this
.
core
.
request
(
path
:
path
this
.
core
.
filemanager
.
delete
({
},
(
ret
)
=>
{
path
:
path
})
).
then
((
res
)
=>
{
let
ret
=
res
[
'text'
];
this
.
files
.
cell
.
progressOff
();
this
.
files
.
cell
.
progressOff
();
if
(
ret
===
'1'
)
{
if
(
ret
===
'1'
)
{
toastr
.
success
(
LANG
[
'delete'
][
'success'
](
path
),
LANG_T
[
'success'
]);
toastr
.
success
(
LANG
[
'delete'
][
'success'
](
path
),
LANG_T
[
'success'
]);
...
@@ -235,10 +296,24 @@ class FileManager {
...
@@ -235,10 +296,24 @@ class FileManager {
}
else
{
}
else
{
toastr
.
error
(
LANG
[
'delete'
][
'error'
](
path
,
ret
===
'0'
?
false
:
ret
),
LANG_T
[
'error'
]);
toastr
.
error
(
LANG
[
'delete'
][
'error'
](
path
,
ret
===
'0'
?
false
:
ret
),
LANG_T
[
'error'
]);
}
}
}
,
(
err
)
=>
{
}
).
catch
(
(
err
)
=>
{
this
.
files
.
cell
.
progressOff
();
this
.
files
.
cell
.
progressOff
();
toastr
.
error
(
LANG
[
'delete'
][
'error'
](
path
,
err
),
LANG_T
[
'error'
]);
toastr
.
error
(
LANG
[
'delete'
][
'error'
](
path
,
err
),
LANG_T
[
'error'
]);
})
});
// this.core.filemanager.delete({
// path: path
// }, (ret) => {
// this.files.cell.progressOff();
// if (ret === '1') {
// toastr.success(LANG['delete']['success'](path), LANG_T['success']);
// this.files.refreshPath();
// }else{
// toastr.error(LANG['delete']['error'](path, ret === '0' ? false : ret), LANG_T['error']);
// }
// }, (err) => {
// this.files.cell.progressOff();
// toastr.error(LANG['delete']['error'](path, err), LANG_T['error']);
// })
})(
p
);
})(
p
);
});
});
}
}
...
@@ -254,10 +329,13 @@ class FileManager {
...
@@ -254,10 +329,13 @@ class FileManager {
const
target
=
this
.
path
+
name
;
const
target
=
this
.
path
+
name
;
this
.
files
.
cell
.
progressOn
();
this
.
files
.
cell
.
progressOn
();
this
.
core
.
filemanager
.
copy
({
this
.
core
.
request
(
path
:
source
,
this
.
core
.
filemanager
.
copy
({
target
:
target
path
:
source
,
},
(
ret
)
=>
{
target
:
target
})
).
then
((
res
)
=>
{
let
ret
=
res
[
'text'
];
this
.
files
.
cell
.
progressOff
();
this
.
files
.
cell
.
progressOff
();
if
(
ret
===
'1'
)
{
if
(
ret
===
'1'
)
{
// 刷新目录
// 刷新目录
...
@@ -268,7 +346,7 @@ class FileManager {
...
@@ -268,7 +346,7 @@ class FileManager {
}
else
{
}
else
{
toastr
.
error
(
LANG
[
'paste'
][
'error'
](
name
,
ret
===
'0'
?
false
:
ret
),
LANG_T
[
'error'
]);
toastr
.
error
(
LANG
[
'paste'
][
'error'
](
name
,
ret
===
'0'
?
false
:
ret
),
LANG_T
[
'error'
]);
}
}
}
,
(
err
)
=>
{
}
).
catch
(
(
err
)
=>
{
toastr
.
error
(
LANG
[
'paste'
][
'error'
](
name
,
err
),
LANG_T
[
'error'
]);
toastr
.
error
(
LANG
[
'paste'
][
'error'
](
name
,
err
),
LANG_T
[
'error'
]);
});
});
}
}
...
@@ -281,10 +359,13 @@ class FileManager {
...
@@ -281,10 +359,13 @@ class FileManager {
title
:
`<i class="fa fa-fa fa-font"></i>
${
LANG
[
'rename'
][
'title'
]}
(
${
antSword
.
noxss
(
name
)}
)`
title
:
`<i class="fa fa-fa fa-font"></i>
${
LANG
[
'rename'
][
'title'
]}
(
${
antSword
.
noxss
(
name
)}
)`
},
(
value
,
index
,
elem
)
=>
{
},
(
value
,
index
,
elem
)
=>
{
this
.
files
.
cell
.
progressOn
();
this
.
files
.
cell
.
progressOn
();
this
.
core
.
filemanager
.
rename
({
this
.
core
.
request
(
path
:
this
.
path
+
name
,
this
.
core
.
filemanager
.
rename
({
name
:
this
.
path
+
value
+
((
isDir
&&
!
value
.
endsWith
(
'/'
))
?
'/'
:
''
)
path
:
this
.
path
+
name
,
},
(
ret
)
=>
{
name
:
this
.
path
+
value
+
((
isDir
&&
!
value
.
endsWith
(
'/'
))
?
'/'
:
''
)
})
).
then
((
res
)
=>
{
let
ret
=
res
[
'text'
];
this
.
files
.
cell
.
progressOff
();
this
.
files
.
cell
.
progressOff
();
if
(
ret
===
'1'
)
{
if
(
ret
===
'1'
)
{
this
.
files
.
refreshPath
();
this
.
files
.
refreshPath
();
...
@@ -292,7 +373,7 @@ class FileManager {
...
@@ -292,7 +373,7 @@ class FileManager {
}
else
{
}
else
{
toastr
.
error
(
LANG
[
'rename'
][
'error'
](
ret
===
'0'
?
false
:
ret
),
LANG_T
[
'error'
]);
toastr
.
error
(
LANG
[
'rename'
][
'error'
](
ret
===
'0'
?
false
:
ret
),
LANG_T
[
'error'
]);
}
}
}
,
(
err
)
=>
{
}
).
catch
(
(
err
)
=>
{
toastr
.
error
(
LANG
[
'rename'
][
'error'
](
err
),
LANG_T
[
'error'
]);
toastr
.
error
(
LANG
[
'rename'
][
'error'
](
err
),
LANG_T
[
'error'
]);
});
});
layer
.
close
(
index
);
layer
.
close
(
index
);
...
@@ -306,9 +387,12 @@ class FileManager {
...
@@ -306,9 +387,12 @@ class FileManager {
title
:
`<i class="fa fa-folder"></i>
${
LANG
[
'createFolder'
][
'title'
]}
`
title
:
`<i class="fa fa-folder"></i>
${
LANG
[
'createFolder'
][
'title'
]}
`
},
(
value
,
i
,
e
)
=>
{
},
(
value
,
i
,
e
)
=>
{
this
.
files
.
cell
.
progressOn
();
this
.
files
.
cell
.
progressOn
();
this
.
core
.
filemanager
.
mkdir
({
this
.
core
.
request
(
path
:
this
.
path
+
value
this
.
core
.
filemanager
.
mkdir
({
},
(
ret
)
=>
{
path
:
this
.
path
+
value
})
).
then
((
res
)
=>
{
let
ret
=
res
[
'text'
];
this
.
files
.
cell
.
progressOff
();
this
.
files
.
cell
.
progressOff
();
if
(
ret
===
'1'
)
{
if
(
ret
===
'1'
)
{
this
.
files
.
refreshPath
();
this
.
files
.
refreshPath
();
...
@@ -316,7 +400,7 @@ class FileManager {
...
@@ -316,7 +400,7 @@ class FileManager {
}
else
{
}
else
{
toastr
.
error
(
LANG
[
'createFolder'
][
'error'
](
value
,
ret
===
'0'
?
false
:
ret
),
LANG_T
[
'error'
]);
toastr
.
error
(
LANG
[
'createFolder'
][
'error'
](
value
,
ret
===
'0'
?
false
:
ret
),
LANG_T
[
'error'
]);
}
}
}
,
(
err
)
=>
{
}
).
catch
(
(
err
)
=>
{
toastr
.
error
(
LANG
[
'createFolder'
][
'error'
](
value
,
err
),
LANG_T
[
'error'
]);
toastr
.
error
(
LANG
[
'createFolder'
][
'error'
](
value
,
err
),
LANG_T
[
'error'
]);
});
});
layer
.
close
(
i
);
layer
.
close
(
i
);
...
@@ -330,10 +414,15 @@ class FileManager {
...
@@ -330,10 +414,15 @@ class FileManager {
title
:
`<i class="fa fa-file"></i>
${
LANG
[
'createFile'
][
'title'
]}
`
title
:
`<i class="fa fa-file"></i>
${
LANG
[
'createFile'
][
'title'
]}
`
},
(
value
,
i
,
e
)
=>
{
},
(
value
,
i
,
e
)
=>
{
this
.
files
.
cell
.
progressOn
();
this
.
files
.
cell
.
progressOn
();
this
.
core
.
filemanager
.
create_file
({
path
:
this
.
path
+
value
,
// 发起http请求
content
:
'
\
0'
this
.
core
.
request
(
},
(
ret
)
=>
{
this
.
core
.
filemanager
.
create_file
({
path
:
this
.
path
+
value
,
content
:
'Halo ANT!'
})
).
then
((
res
)
=>
{
let
ret
=
res
[
'text'
];
this
.
files
.
cell
.
progressOff
();
this
.
files
.
cell
.
progressOff
();
if
(
ret
===
'1'
)
{
if
(
ret
===
'1'
)
{
this
.
files
.
refreshPath
();
this
.
files
.
refreshPath
();
...
@@ -341,7 +430,7 @@ class FileManager {
...
@@ -341,7 +430,7 @@ class FileManager {
}
else
{
}
else
{
toastr
.
error
(
LANG
[
'createFile'
][
'error'
](
value
,
ret
===
'0'
?
false
:
ret
),
LANG_T
[
'error'
]);
toastr
.
error
(
LANG
[
'createFile'
][
'error'
](
value
,
ret
===
'0'
?
false
:
ret
),
LANG_T
[
'error'
]);
}
}
}
,
(
err
)
=>
{
}
).
catch
(
(
err
)
=>
{
toastr
.
error
(
LANG
[
'createFile'
][
'error'
](
value
,
err
),
LANG_T
[
'error'
]);
toastr
.
error
(
LANG
[
'createFile'
][
'error'
](
value
,
err
),
LANG_T
[
'error'
]);
});
});
layer
.
close
(
i
);
layer
.
close
(
i
);
...
@@ -356,10 +445,15 @@ class FileManager {
...
@@ -356,10 +445,15 @@ class FileManager {
content
:
`<input type="text" class="layui-layer-input" onClick="laydate({istime: true, format: 'YYYY-MM-DD hh:mm:ss'});" value="
${
oldtime
}
">`
content
:
`<input type="text" class="layui-layer-input" onClick="laydate({istime: true, format: 'YYYY-MM-DD hh:mm:ss'});" value="
${
oldtime
}
">`
},
(
value
,
i
,
e
)
=>
{
},
(
value
,
i
,
e
)
=>
{
this
.
files
.
cell
.
progressOn
();
this
.
files
.
cell
.
progressOn
();
this
.
core
.
filemanager
.
retime
({
path
:
this
.
path
+
name
,
// http request
time
:
value
this
.
core
.
request
(
},
(
ret
)
=>
{
this
.
core
.
filemanager
.
retime
({
path
:
this
.
path
+
name
,
time
:
value
})
).
then
((
res
)
=>
{
let
ret
=
res
[
'text'
];
this
.
files
.
cell
.
progressOff
();
this
.
files
.
cell
.
progressOff
();
if
(
ret
===
'1'
)
{
if
(
ret
===
'1'
)
{
this
.
files
.
refreshPath
();
this
.
files
.
refreshPath
();
...
@@ -367,7 +461,7 @@ class FileManager {
...
@@ -367,7 +461,7 @@ class FileManager {
}
else
{
}
else
{
toastr
.
error
(
LANG
[
'retime'
][
'error'
](
name
,
ret
===
'0'
?
false
:
ret
),
LANG_T
[
'error'
]);
toastr
.
error
(
LANG
[
'retime'
][
'error'
](
name
,
ret
===
'0'
?
false
:
ret
),
LANG_T
[
'error'
]);
}
}
}
,
(
err
)
=>
{
}
).
catch
(
(
err
)
=>
{
toastr
.
error
(
LANG
[
'retime'
][
'error'
](
name
,
err
),
LANG_T
[
'error'
]);
toastr
.
error
(
LANG
[
'retime'
][
'error'
](
name
,
err
),
LANG_T
[
'error'
]);
});
});
layer
.
close
(
i
);
layer
.
close
(
i
);
...
@@ -384,16 +478,18 @@ class FileManager {
...
@@ -384,16 +478,18 @@ class FileManager {
win
.
cell
.
lastChild
[
'style'
][
'textAlign'
]
=
'center'
;
win
.
cell
.
lastChild
[
'style'
][
'textAlign'
]
=
'center'
;
let
data
=
'data:image/png;base64,'
;
let
data
=
'data:image/png;base64,'
;
let
buff
=
''
;
let
buff
=
''
;
this
.
core
.
filemanager
.
download_file
({
path
:
path
this
.
core
.
request
(
},
(
ret
,
buff
)
=>
{
this
.
core
.
filemanager
.
download_file
()
let
imgData
=
new
Buffer
(
buff
).
toString
(
'base64'
);
,
(
chunk
)
=>
{
buff
+=
chunk
;
let
imgData
=
data
+
new
Buffer
(
buff
).
toString
(
'base64'
);
}
).
then
((
res
)
=>
{
let
imgData
=
new
Buffer
(
res
[
'buff'
]).
toString
(
'base64'
);
win
.
attachHTMLString
(
`<img src="data:/image/png;base64,
${
imgData
}
"/>`
);
win
.
attachHTMLString
(
`<img src="data:/image/png;base64,
${
imgData
}
"/>`
);
}
,
(
err
)
=>
{
}
).
catch
(
(
err
)
=>
{
},
(
chunk
)
=>
{
buff
+=
chunk
;
let
imgData
=
data
+
new
Buffer
(
buff
).
toString
(
'base64'
);
});
});
}
}
...
@@ -408,41 +504,39 @@ class FileManager {
...
@@ -408,41 +504,39 @@ class FileManager {
},
(
filePath
)
=>
{
},
(
filePath
)
=>
{
if
(
!
filePath
)
{
return
task
.
end
(
LANG
[
'download'
][
'task'
][
'cancel'
])
};
if
(
!
filePath
)
{
return
task
.
end
(
LANG
[
'download'
][
'task'
][
'cancel'
])
};
task
.
update
(
LANG
[
'download'
][
'task'
][
'start'
]);
task
.
update
(
LANG
[
'download'
][
'task'
][
'start'
]);
// setTimeout(() => {
let
down_size
=
0
;
let
down_size
=
0
;
// 删除旧文件(如果存在
this
.
core
.
filemanager
.
download_file
({
if
(
fs
.
existsSync
(
filePath
))
{
fs
.
unlinkSync
(
filePath
);
}
this
.
core
.
download
(
filePath
,
this
.
core
.
filemanager
.
download_file
({
path
:
path
path
:
path
},
(
ret
,
buff
)
=>
{
})
// 保存文件
,
(
_size
)
=>
{
// fs.writeFileSync(filePath+'_bak', new global.Buffer(buff));
// 检测文件大小是否一致
if
(
buff
.
length
===
size
)
{
task
.
success
(
LANG
[
'download'
][
'task'
][
'success'
]);
toastr
.
success
(
LANG
[
'download'
][
'success'
](
name
),
LANG_T
[
'success'
]);
}
else
if
(
buff
.
length
===
21
)
{
task
.
failed
(
buff
.
toString
());
}
else
{
// task.failed(`FileSize(${buff.length} != ${size}`);
task
.
failed
(
LANG
[
'download'
][
'task'
][
'error'
](
`SizeErr:
${
buff
.
length
}
!=
${
size
}
`
))
}
},
(
err
)
=>
{
task
.
failed
(
LANG
[
'download'
][
'task'
][
'error'
](
err
));
toastr
.
error
(
LANG
[
'download'
][
'error'
](
name
,
err
),
LANG_T
[
'error'
]);
},
(
chunk
)
=>
{
// 写入文件
fs
.
writeFileSync
(
filePath
,
new
global
.
Buffer
(
chunk
),
{
flag
:
'a'
});
// 计算进度百分比
// 计算进度百分比
down_size
+=
chunk
.
length
;
down_size
+=
_size
;
let
down_progress
=
parseInt
(
parseFloat
(
down_size
/
size
).
toFixed
(
2
)
*
100
);
let
down_progress
=
parseInt
(
parseFloat
(
down_size
/
size
).
toFixed
(
2
)
*
100
);
if
(
!
(
down_progress
%
5
))
{
if
(
!
(
down_progress
%
5
))
{
task
.
update
(
down_progress
+
'%'
);
task
.
update
(
down_progress
+
'%'
);
};
};
// task.update(`${parseFloat(down_size/size).toFixed(0) * 100} %`);
}
});
).
then
((
_size
)
=>
{
// }, 200);
if
(
_size
===
size
)
{
task
.
success
(
LANG
[
'download'
][
'task'
][
'success'
]);
toastr
.
success
(
LANG
[
'download'
][
'success'
](
name
),
LANG_T
[
'success'
]);
// }else if (_size === 21) {
// task.failed('len=' + _size);
}
else
{
throw
Error
(
`SizeErr:
${
_size
}
!=
${
size
}
`
);
// task.failed(LANG['download']['task']['error']())
}
}).
catch
((
err
)
=>
{
task
.
failed
(
LANG
[
'download'
][
'task'
][
'error'
](
err
));
toastr
.
error
(
LANG
[
'download'
][
'error'
](
name
,
err
),
LANG_T
[
'error'
]);
});
});
});
}
}
...
@@ -472,19 +566,24 @@ class FileManager {
...
@@ -472,19 +566,24 @@ class FileManager {
};
};
const
task
=
this
.
tasks
.
new
(
LANG
[
'wget'
][
'task'
][
'name'
],
`
${
url
}
->
${
path
}
`
);
const
task
=
this
.
tasks
.
new
(
LANG
[
'wget'
][
'task'
][
'name'
],
`
${
url
}
->
${
path
}
`
);
task
.
update
(
LANG
[
'wget'
][
'task'
][
'start'
]);
task
.
update
(
LANG
[
'wget'
][
'task'
][
'start'
]);
this
.
core
.
filemanager
.
wget
({
url
:
url
,
// http request
path
:
path
this
.
core
.
request
(
},
(
ret
)
=>
{
this
.
core
.
filemanager
.
wget
({
// 下载成功?当前目录?刷新:删除缓存
url
:
url
,
if
(
ret
===
'1'
)
{
path
:
path
task
.
success
(
LANG
[
'wget'
][
'task'
][
'success'
]);
})
let
_
=
path
.
substr
(
0
,
path
.
lastIndexOf
(
'/'
)
+
1
);
).
then
((
res
)
=>
{
this
.
files
.
refreshPath
((
_
===
self
.
path
)
?
false
:
_
);
let
ret
=
res
[
'text'
];
}
else
{
// 下载成功?当前目录?刷新:删除缓存
task
.
failed
(
LANG
[
'wget'
][
'task'
][
'failed'
](
ret
));
if
(
ret
===
'1'
)
{
}
task
.
success
(
LANG
[
'wget'
][
'task'
][
'success'
]);
},
(
err
)
=>
{
let
_
=
path
.
substr
(
0
,
path
.
lastIndexOf
(
'/'
)
+
1
);
this
.
files
.
refreshPath
((
_
===
self
.
path
)
?
false
:
_
);
}
else
{
task
.
failed
(
LANG
[
'wget'
][
'task'
][
'failed'
](
ret
));
}
}).
catch
((
err
)
=>
{
task
.
failed
(
LANG
[
'wget'
][
'task'
][
'error'
](
err
));
task
.
failed
(
LANG
[
'wget'
][
'task'
][
'error'
](
err
));
});
});
layer
.
close
(
i
);
layer
.
close
(
i
);
...
@@ -493,83 +592,109 @@ class FileManager {
...
@@ -493,83 +592,109 @@ class FileManager {
$
(
`#layui-layer
${
_index
}
`
).
css
(
'width'
,
'400px'
);
$
(
`#layui-layer
${
_index
}
`
).
css
(
'width'
,
'400px'
);
}
}
// 上传文件
/**
uploadFile
()
{
* 上传文件
const
path
=
this
.
path
;
* @param {Array} _filePaths 要上传的本地文件路径(可选,如未指定,则调用文件选择框
* @return {None} [description]
*/
uploadFile
(
_filePaths
)
{
// 任务列表
let
tasks
=
{};
let
tasks
=
{};
const
upload
=
(
filePaths
)
=>
{
// 上传路径
if
(
!
filePaths
[
0
])
{
let
path
=
this
.
path
;
return
false
;
new
Promise
((
res
,
rej
)
=>
{
};
// 获取要上传的文件列表
const
filePath
=
filePaths
[
0
];
if
(
Array
.
isArray
(
_filePaths
)
&&
_filePaths
.
length
>
0
)
{
return
res
(
_filePaths
);
let
i
=
0
;
let
buff
=
[];
// 数据分段上传,一次上传512kb=1024*512
let
split
=
1024
*
512
;
const
task
=
tasks
[
filePath
];
// 获取文件名
const
fileName
=
filePath
.
substr
(
filePath
.
lastIndexOf
(
'/'
)
+
1
);
let
fileBuff
;
// 读取文件buffer
try
{
fileBuff
=
fs
.
readFileSync
(
filePath
);
}
catch
(
e
)
{
return
task
.
failed
(
e
);
}
}
dialog
.
showOpenDialog
({
while
(
true
)
{
properties
:
[
'openFile'
,
'multiSelections'
]
const
_
=
fileBuff
.
slice
(
i
,
i
+
split
);
},
(
_filePaths
)
=>
{
i
+=
split
;
if
(
!
_filePaths
)
{
return
};
if
(
_
.
length
===
0
)
{
break
};
return
res
(
_filePaths
);
buff
.
push
(
_
);
})
}
}).
then
((
filePaths
)
=>
{
// 初始化任务
const
all_num
=
buff
.
length
;
filePaths
.
map
((
f
)
=>
{
const
upload_func
=
(
arr
)
=>
{
const
fileName
=
f
.
substr
(
f
.
lastIndexOf
(
'/'
)
+
1
);
if
(
!
arr
[
0
])
{
tasks
[
f
]
=
this
.
tasks
.
new
(
LANG
[
'upload'
][
'task'
][
'name'
],
`
${
fileName
}
=>
${
path
}
`
,
'Waiting for uploading..'
);
// 上传完毕
});
task
.
success
(
'100%'
);
return
filePaths
;
// 刷新目录
}).
then
((
filePaths
)
=>
{
toastr
.
success
(
LANG
[
'upload'
][
'success'
](
fileName
),
LANG_T
[
'success'
]);
// 文件上传(逐个队列上传
// 刷新目录缓存
const
upload
=
()
=>
{
this
.
files
.
refreshPath
(
path
===
this
.
path
?
''
:
path
);
new
Promise
((
res
,
rej
)
=>
{
return
upload
(
filePaths
);
// 获取单个上传文件
};
let
filePath
=
filePaths
.
shift
();
// 更新进度条
if
(
filePath
)
{
task
.
update
(
`
${
parseInt
((
all_num
-
arr
.
length
)
/
all_num
*
100
)}
%`
);
res
(
filePath
);
// 开始上传分段数据
}
this
.
core
.
filemanager
.
upload_file
({
}).
then
((
filePath
)
=>
{
path
:
path
+
fileName
,
// 上传单个
content
:
arr
[
0
]
let
buffIndex
=
0
;
},
(
ret
)
=>
{
let
buff
=
[];
if
(
ret
===
'1'
)
{
// 分段上传大小,默认1M
// 继续上传
let
dataSplit
=
1024
*
1024
;
arr
.
shift
();
let
task
=
tasks
[
filePath
];
upload_func
(
arr
);
// 获取文件名
}
else
{
let
fileName
=
filePath
.
substr
(
filePath
.
lastIndexOf
(
'/'
)
+
1
);
task
.
failed
(
LANG
[
'upload'
][
'task'
][
'failed'
](
ret
));
// 读取文件buff
toastr
.
error
(
LANG
[
'upload'
][
'error'
](
fileName
,
ret
===
'0'
?
''
:
'<br/>'
+
ret
),
LANG_T
[
'error'
]);
let
fileBuff
;
try
{
fileBuff
=
fs
.
readFileSync
(
filePath
);
}
catch
(
e
)
{
return
task
.
failed
(
e
);
}
// 文件数据分段
let
buffLength
=
fileBuff
.
length
;
while
(
buffIndex
<=
buffLength
)
{
let
buffSplit
=
fileBuff
.
slice
(
buffIndex
,
buffIndex
+
dataSplit
);
buffIndex
+=
dataSplit
;
buff
.
push
(
buffSplit
);
}
// 开始上传
const
uploadBuffFunc
=
(
_buff
)
=>
{
new
Promise
((
res
,
rej
)
=>
{
let
_b
=
_buff
.
shift
();
if
(
_b
)
{
res
(
_b
);
}
else
{
// 上传完毕
task
.
success
(
'100%'
);
toastr
.
success
(
LANG
[
'upload'
][
'success'
](
fileName
),
LANG_T
[
'success'
]);
// 刷新缓存
this
.
files
.
refreshPath
(
path
===
this
.
path
?
''
:
path
);
// 继续上传
return
upload
();
}
}).
then
((
b
)
=>
{
// 更新进度条
task
.
update
(
`
${
parseInt
((
buffLength
-
_buff
.
length
)
/
buffLength
*
100
)}
%`
);
this
.
core
.
request
(
this
.
core
.
filemanager
.
upload_file
({
path
:
path
+
fileName
,
content
:
b
})
).
then
((
res
)
=>
{
let
ret
=
res
[
'text'
];
if
(
ret
===
'1'
)
{
return
uploadBuffFunc
(
_buff
);
}
task
.
failed
(
LANG
[
'upload'
][
'task'
][
'failed'
](
ret
));
toastr
.
error
(
LANG
[
'upload'
][
'error'
](
fileName
,
ret
===
'0'
?
''
:
`<br/>
${
ret
}
`
),
LANG_T
[
'error'
]);
}).
catch
((
err
)
=>
{
task
.
failed
(
LANG
[
'upload'
][
'task'
][
'error'
](
err
));
toastr
.
error
(
LANG
[
'upload'
][
'error'
](
fileName
,
err
),
LANG_T
[
'error'
]);
});
})
}
}
},
(
err
)
=>
{
uploadBuffFunc
(
buff
);
task
.
failed
(
LANG
[
'upload'
][
'task'
][
'error'
](
err
));
toastr
.
error
(
LANG
[
'upload'
][
'error'
](
fileName
,
err
),
LANG_T
[
'error'
]);
});
});
}
};
upload
();
upload_func
(
buff
);
filePaths
.
shift
();
}
dialog
.
showOpenDialog
({
properties
:
[
'openFile'
,
'multiSelections'
]
},
(
filePaths
)
=>
{
if
(
!
filePaths
)
{
return
};
// 逐个文件上传
filePaths
.
map
((
_
)
=>
{
const
fileName
=
_
.
substr
(
_
.
lastIndexOf
(
'/'
)
+
1
);
tasks
[
_
]
=
this
.
tasks
.
new
(
LANG
[
'upload'
][
'task'
][
'name'
],
`
${
fileName
}
=>
${
path
}
`
,
'准备上传..'
);
});
upload
(
filePaths
);
});
});
}
}
...
@@ -590,34 +715,13 @@ class FileManager {
...
@@ -590,34 +715,13 @@ class FileManager {
// 检测文件后缀
// 检测文件后缀
let
ext
=
name
.
substr
(
name
.
lastIndexOf
(
'.'
)
+
1
);
let
ext
=
name
.
substr
(
name
.
lastIndexOf
(
'.'
)
+
1
);
let
ext_dict
=
{
let
ext_dict
=
{
'php'
:
'php'
,
'php'
:
'php'
,
'c'
:
'c_cpp'
,
'cpp'
:
'c_cpp'
,
'h'
:
'c_cpp'
,
'c'
:
'c_cpp'
,
'coffee'
:
'coffee'
,
'cfm'
:
'coldfusion'
,
'css'
:
'css'
,
'cpp'
:
'c_cpp'
,
'go'
:
'golang'
,
'html'
:
'html'
,
'ini'
:
'ini'
,
'conf'
:
'ini'
,
'h'
:
'c_cpp'
,
'jade'
:
'jade'
,
'java'
:
'java'
,
'js'
:
'javascript'
,
'json'
:
'json'
,
'coffee'
:
'coffee'
,
'jsp'
:
'jsp'
,
'jsx'
:
'jsx'
,
'less'
:
'less'
,
'lua'
:
'lua'
,
'md'
:
'markdown'
,
'cfm'
:
'coldfusion'
,
'sql'
:
'sql'
,
'pl'
:
'perl'
,
'py'
:
'python'
,
'rb'
:
'ruby'
,
'css'
:
'css'
,
'sh'
:
'sh'
,
'txt'
:
'text'
,
'xml'
:
'xml'
// 'ejs': 'ejs',
'go'
:
'golang'
,
'html'
:
'html'
,
'ini'
:
'ini'
,
'conf'
:
'ini'
,
'jade'
:
'jade'
,
'java'
:
'java'
,
'js'
:
'javascript'
,
'json'
:
'json'
,
'jsp'
:
'jsp'
,
'jsx'
:
'jsx'
,
'less'
:
'less'
,
'lua'
:
'lua'
,
'md'
:
'markdown'
,
'sql'
:
'sql'
,
'pl'
:
'perl'
,
'py'
:
'python'
,
'rb'
:
'ruby'
,
'sh'
:
'sh'
,
'txt'
:
'text'
,
'xml'
:
'xml'
}
}
if
(
!
(
ext
in
ext_dict
))
{
ext
=
'txt'
};
if
(
!
(
ext
in
ext_dict
))
{
ext
=
'txt'
};
// 创建窗口工具栏
// 创建窗口工具栏
...
@@ -665,21 +769,24 @@ class FileManager {
...
@@ -665,21 +769,24 @@ class FileManager {
if
(
id
===
'save'
)
{
if
(
id
===
'save'
)
{
// 保存代码
// 保存代码
win
.
progressOn
();
win
.
progressOn
();
// self.ajax(
self
.
core
.
request
(
self
.
core
.
filemanager
.
create_file
({
self
.
core
.
filemanager
.
create_file
({
path
:
path
,
path
:
path
,
content
:
editor
.
session
.
getValue
()
||
'
\
0'
content
:
editor
.
session
.
getValue
()
||
'Halo ANT!'
},
(
ret
)
=>
{
})
win
.
progressOff
();
).
then
((
res
)
=>
{
if
(
ret
===
'1'
)
{
let
ret
=
res
[
'text'
];
toastr
.
success
(
LANG
[
'editor'
][
'success'
](
path
),
LANG_T
[
'success'
]);
win
.
progressOff
();
// 刷新目录(显示更改时间、大小等)
if
(
ret
===
'1'
)
{
self
.
files
.
refreshPath
();
toastr
.
success
(
LANG
[
'editor'
][
'success'
](
path
),
LANG_T
[
'success'
]);
}
else
{
// 刷新目录(显示更改时间、大小等)
toastr
.
error
(
LANG
[
'editor'
][
'error'
](
path
,
ret
===
'0'
?
''
:
'<br/>'
+
ret
),
LANG_T
[
'error'
]);
self
.
files
.
refreshPath
();
}
}
else
{
toastr
.
error
(
LANG
[
'editor'
][
'error'
](
path
,
ret
===
'0'
?
''
:
'<br/>'
+
ret
),
LANG_T
[
'error'
]);
}
}
)
}).
catch
((
err
)
=>
{
});
}
else
if
(
id
.
startsWith
(
'mode_'
))
{
}
else
if
(
id
.
startsWith
(
'mode_'
))
{
let
mode
=
id
.
split
(
'_'
)[
1
];
let
mode
=
id
.
split
(
'_'
)[
1
];
editor
.
session
.
setMode
(
`ace/mode/
${
mode
}
`
);
editor
.
session
.
setMode
(
`ace/mode/
${
mode
}
`
);
...
@@ -692,9 +799,12 @@ class FileManager {
...
@@ -692,9 +799,12 @@ class FileManager {
});
});
// 获取文件代码
// 获取文件代码
this
.
core
.
filemanager
.
read_file
({
this
.
core
.
request
(
path
:
path
this
.
core
.
filemanager
.
read_file
({
},
(
ret
)
=>
{
path
:
path
})
).
then
((
res
)
=>
{
let
ret
=
res
[
'text'
];
codes
=
ret
;
codes
=
ret
;
win
.
progressOff
();
win
.
progressOff
();
...
@@ -732,7 +842,7 @@ class FileManager {
...
@@ -732,7 +842,7 @@ class FileManager {
clearInterval
(
inter
);
clearInterval
(
inter
);
return
true
;
return
true
;
});
});
}
,
(
err
)
=>
{
}
).
catch
(
(
err
)
=>
{
toastr
.
error
(
LANG
[
'editor'
][
'loadErr'
](
err
),
LANG_T
[
'error'
]);
toastr
.
error
(
LANG
[
'editor'
][
'loadErr'
](
err
),
LANG_T
[
'error'
]);
win
.
close
();
win
.
close
();
});
});
...
@@ -761,4 +871,4 @@ class FileManager {
...
@@ -761,4 +871,4 @@ class FileManager {
}
}
export
default
FileManager
;
export
default
FileManager
;
\ No newline at end of file
source/modules/terminal/index.jsx
View file @
9a0fbbd7
//
/**
// 虚拟终端模块
* 虚拟终端模块
//
* 更新:2016/04/13
* 作者:蚁逅 <https://github.com/antoor>
*/
// import React from 'react';
// import ReactDOM from 'react-dom';
const
LANG_T
=
antSword
[
'language'
][
'toastr'
];
const
LANG
=
antSword
[
'language'
][
'terminal'
];
const
LANG
=
antSword
[
'language'
][
'terminal'
];
// const ipcRenderer = antSword['ipcRendere
r'];
const
LANG_T
=
antSword
[
'language'
][
'toast
r'
];
class
Terminal
{
class
Terminal
{
constructor
(
opts
)
{
constructor
(
opts
)
{
const
tabbar
=
antSword
[
'tabbar'
];
// 生存一个随机ID,用于标识多个窗口dom
const
hash
=
String
(
Math
.
random
()).
substr
(
2
,
10
);
const
hash
=
String
(
Math
.
random
()).
substr
(
2
,
10
);
// 初始化UI::tabbar
const
tabbar
=
antSword
[
'tabbar'
];
tabbar
.
addTab
(
tabbar
.
addTab
(
`tab_terminal_
${
hash
}
`
,
`tab_terminal_
${
hash
}
`
,
// `<i class="fa fa-terminal"></i> ${LANG['title']} \/\/ ${opts['ip']}`,
`<i class="fa fa-terminal"></i>
${
opts
[
'ip'
]}
`
,
`<i class="fa fa-terminal"></i>
${
opts
[
'ip'
]}
`
,
null
,
null
,
true
,
true
null
,
null
,
true
,
true
);
);
tabbar
.
attachEvent
(
'onTabClick'
,
(
id
,
lid
)
=>
{
tabbar
.
attachEvent
(
'onTabClick'
,
(
id
,
lid
)
=>
{
if
(
id
===
`tab_terminal_
${
hash
}
`
)
{
if
(
id
!==
`tab_terminal_
${
hash
}
`
)
{
return
};
this
.
term
?
this
.
term
.
focus
()
:
0
;
this
.
term
?
this
.
term
.
focus
()
:
0
;
};
});
});
// 初始化UI::cell
const
cell
=
tabbar
.
cells
(
`tab_terminal_
${
hash
}
`
);
const
cell
=
tabbar
.
cells
(
`tab_terminal_
${
hash
}
`
);
// ReactDOM.render(
// <div id={`div_terminal_${hash}`} style={{
// height: '100%',
// margin: '0',
// padding: '0px 5px 1px 5px',
// overflow: 'scroll'
// }} />
// , cell.cell
// );
cell
.
attachHTMLString
(
`
cell
.
attachHTMLString
(
`
<div id="div_terminal_
${
hash
}
" style="height:100%;margin:0;padding:0 5px 1px 5px;overflow:scroll"></div>
<div
id="div_terminal_
${
hash
}
"
style="height:100%;margin:0;padding:0 5px 1px 5px;overflow:scroll"
></div>
`
);
`
);
this
.
path
=
''
;
this
.
path
=
''
;
...
@@ -48,160 +40,187 @@ class Terminal {
...
@@ -48,160 +40,187 @@ class Terminal {
this
.
cell
=
cell
;
this
.
cell
=
cell
;
this
.
isWin
=
true
;
this
.
isWin
=
true
;
this
.
core
=
new
antSword
[
'core'
][
opts
[
'type'
]](
opts
);
this
.
core
=
new
antSword
[
'core'
][
opts
[
'type'
]](
opts
);
this
.
cache
=
new
antSword
[
'CacheManager'
](
this
.
opts
[
'_id'
]);
this
.
cache
=
new
antSword
[
'CacheManager'
](
this
.
opts
[
'_id'
]);
// this.initTerminal($(`#div_terminal_${hash}`));
// 获取缓存::info
this
const
dom
=
$
(
`#div_terminal_
${
hash
}
`
);
.
getInformation
()
const
cache_info
=
this
.
cache
.
get
(
'info'
);
.
then
((
ret
)
=>
{
if
(
cache_info
)
{
this
.
initTerminal
(
ret
[
'info'
],
ret
[
'dom'
]);
this
.
initTerminal
(
cache_info
,
dom
);
})
}
else
{
.
catch
((
err
)
=>
{
this
.
cell
.
progressOn
();
this
.
core
.
base
.
info
((
ret
)
=>
{
this
.
cell
.
progressOff
();
// 判断获取数据是否正确
// let info = ret.split('\t');
// if (info.length !== 4) {
// toastr.error('Loading infomations failed!', LANG_T['error']);
// return this.cell.close();
// };
// 更新缓存
this
.
cache
.
set
(
'info'
,
ret
);
// ipcRenderer.sendSync('cache-add', {
// id: this.opts['id'],
// tag: 'info',
// cache: ret
// });
// 初始化终端
this
.
initTerminal
(
ret
,
dom
);
},
(
err
)
=>
{
toastr
.
error
((
typeof
(
err
)
===
'object'
)
?
JSON
.
stringify
(
err
)
:
String
(
err
),
LANG_T
[
'error'
]);
toastr
.
error
((
typeof
(
err
)
===
'object'
)
?
JSON
.
stringify
(
err
)
:
String
(
err
),
LANG_T
[
'error'
]);
this
.
cell
.
progressOff
();
this
.
cell
.
progressOff
();
this
.
cell
.
close
();
this
.
cell
.
close
();
})
}
/**
* 获取目标信息
* @return {Promise} 返回一个Promise操作对象//{dom,info}
*/
getInformation
()
{
return
new
Promise
((
ret
,
rej
)
=>
{
// 获取DOM
const
dom
=
$
(
`#div_terminal_
${
this
.
hash
}
`
);
// 获取缓存
let
infoCache
=
this
.
cache
.
get
(
'info'
);
// 如果有缓存?初始化终端:获取信息&&保存缓存&&初始化终端
if
(
infoCache
)
{
return
ret
({
dom
:
dom
,
info
:
infoCache
});
}
// 开始获取信息
this
.
cell
.
progressOn
();
this
.
core
.
request
(
this
.
core
.
base
.
info
()
).
then
((
_ret
)
=>
{
this
.
cell
.
progressOff
();
this
.
cache
.
set
(
'info'
,
_ret
[
'text'
]);
return
ret
({
dom
:
dom
,
info
:
_ret
[
'text'
]
});
}).
catch
((
e
)
=>
{
rej
(
e
);
});
});
}
}
);
}
}
// 初始化终端
/**
* 初始化终端
* @param {String} ret 目标信息
* @param {Object} dom 要操作的dom元素
* @return {None} [description]
*/
initTerminal
(
ret
,
dom
)
{
initTerminal
(
ret
,
dom
)
{
// this.cell.progressOn();
let
info
=
ret
.
split
(
'
\
t'
);
// // 获取缓存info
let
infoUser
,
infoPath
,
infoDrive
,
infoSystem
;
// const _info = ipcRenderer.sendSync('cache-get', {
let
banner
=
`[[b;cyan;](*)
${
LANG
[
'banner'
][
'title'
]}
]`
;
// id: this.opts['id'],
// tag: 'info'
// 判断数据是否正确
// });
if
(
info
.
length
===
4
)
{
// this.core.base.info((ret) => {
infoPath
=
info
[
0
];
// this.cell.progressOff();
infoDrive
=
info
[
1
];
let
info
=
ret
.
split
(
'
\
t'
);
infoSystem
=
info
[
2
];
let
info_user
;
infoUser
=
info
[
3
];
let
info_path
;
}
else
if
(
info
.
length
===
2
)
{
let
info_drive
;
infoPath
=
info
[
0
];
let
info_system
;
infoDrive
=
info
[
1
];
// 解析banner
}
else
{
let
banner
=
`[[b;cyan;](*)
${
LANG
[
'banner'
][
'title'
]}
]`
;
toastr
.
error
(
'Loading infomations failed!<br/>'
+
ret
,
LANG_T
[
'error'
]);
// 判断获取数据是否正确
this
.
cache
.
del
(
'info'
);
if
(
info
.
length
===
4
)
{
return
this
.
cell
.
close
();
info_user
=
info
[
3
];
}
info_path
=
info
[
0
];
info_drive
=
info
[
1
];
// 转换路径特殊字符
info_system
=
info
[
2
];
infoPath
=
infoPath
.
replace
(
/
\\
/g
,
'/'
).
replace
(
/
\.
$/
,
''
);
}
else
if
(
info
.
length
===
2
)
{
info_path
=
info
[
0
];
// 判断是否为!win
info_drive
=
info
[
1
];
this
.
isWin
=
!
(
infoPath
.
substr
(
0
,
1
)
===
'/'
)
}
else
{
this
.
path
=
infoPath
;
toastr
.
error
(
'Loading infomations failed!<br/>'
+
ret
,
LANG_T
[
'error'
]);
this
.
cache
.
del
(
'info'
);
// 组合banner
return
this
.
cell
.
close
();
banner
+=
`\n[[b;#99A50D;]
${
LANG
[
'banner'
][
'path'
]}
]: [[;#C3C3C3;]
${
infoPath
}
]`
;
};
banner
+=
`\n[[b;#99A50D;]
${
LANG
[
'banner'
][
'drive'
]}
]: [[;#C3C3C3;]
${
infoDrive
}
]`
;
info_path
=
info_path
.
replace
(
/
\\
/g
,
'/'
).
replace
(
/
\.
$/
,
''
);
if
(
info
.
length
===
4
)
{
// 判断是否为linux
banner
+=
`\n[[b;#99A50D;]
${
LANG
[
'banner'
][
'system'
]}
]: [[;#C3C3C3;]
${
infoSystem
}
]`
;
if
(
info_path
.
substr
(
0
,
1
)
===
'/'
)
{
banner
+=
`\n[[b;#99A50D;]
${
LANG
[
'banner'
][
'user'
]}
]: [[;#C3C3C3;]
${
infoUser
}
]`
;
this
.
isWin
=
false
;
}
// 初始化终端
this
.
term
=
dom
.
terminal
(
(
cmd
,
term
)
=>
{
if
(
!
cmd
)
{
return
false
};
// 如果为exit||quit则关闭窗口
if
(
cmd
===
'exit'
||
cmd
===
'quit'
)
{
return
this
.
cell
.
close
()
};
term
.
pause
();
// 是否有缓存
let
cacheTag
=
'command-'
+
new
Buffer
(
this
.
path
+
cmd
).
toString
(
'base64'
);
let
cacheCmd
;
if
(
cacheCmd
=
this
.
cache
.
get
(
cacheTag
))
{
term
.
echo
(
antSword
.
noxss
(
cacheCmd
)
);
return
term
.
resume
();
};
};
this
.
path
=
info_path
;
banner
+=
`\n[[b;#99A50D;]
${
LANG
[
'banner'
][
'path'
]}
]: [[;#C3C3C3;]
${
info_path
}
]`
;
// 开始执行命令
banner
+=
`\n[[b;#99A50D;]
${
LANG
[
'banner'
][
'drive'
]}
]: [[;#C3C3C3;]
${
info_drive
}
]`
;
this
.
core
.
request
(
if
(
info
.
length
===
4
)
{
banner
+=
`\n[[b;#99A50D;]
${
LANG
[
'banner'
][
'system'
]}
]: [[;#C3C3C3;]
${
info_system
}
]`
;
banner
+=
`\n[[b;#99A50D;]
${
LANG
[
'banner'
][
'user'
]}
]: [[;#C3C3C3;]
${
info_user
}
]`
;
}
// 初始化终端
this
.
term
=
dom
.
terminal
(
(
cmd
,
term
)
=>
{
if
(
!
cmd
)
{
return
false
};
// 如果为exit||quit则关闭窗口
if
(
cmd
===
'exit'
||
cmd
===
'quit'
)
{
return
this
.
cell
.
close
()
};
term
.
pause
();
// 是否有缓存
let
cache_tag
=
'command-'
+
new
Buffer
(
this
.
path
+
cmd
).
toString
(
'base64'
);
let
cache_cmd
;
if
(
cache_cmd
=
this
.
cache
.
get
(
cache_tag
))
{
term
.
echo
(
antSword
.
noxss
(
cache_cmd
));
return
term
.
resume
();
};
this
.
core
.
command
.
exec
({
this
.
core
.
command
.
exec
({
cmd
:
this
.
parseCmd
(
cmd
,
this
.
path
),
cmd
:
this
.
parseCmd
(
cmd
,
this
.
path
),
bin
:
this
.
isWin
?
'cmd'
:
'/bin/sh'
bin
:
this
.
isWin
?
'cmd'
:
'/bin/sh'
},
(
_
)
=>
{
})
// 解析出命令执行路径
).
then
((
ret
)
=>
{
const
index_s
=
_
.
indexOf
(
'[S]'
);
let
_
=
ret
[
'text'
];
const
index_e
=
_
.
lastIndexOf
(
'[E]'
);
// 解析出命令执行路径
let
_path
=
_
.
substr
(
index_s
+
3
,
index_e
-
index_s
-
3
);
const
indexS
=
_
.
indexOf
(
'[S]'
);
const
indexE
=
_
.
lastIndexOf
(
'[E]'
);
let
_path
=
_
.
substr
(
indexS
+
3
,
indexE
-
indexS
-
3
);
// let _sindex = _.indexOf('[S]') + 3;
// let _eindex = _.indexOf('[E]');
let
output
=
_
.
replace
(
`[S]
${
_path
}
[E]`
,
''
);
// let _path = _.substr(_sindex, _eindex - _sindex);
_path
=
_path
.
replace
(
/
\n
/g
,
''
).
replace
(
/
\r
/g
,
''
);
let
output
=
_
.
replace
(
`[S]
${
_path
}
[E]`
,
''
);
_path
=
_path
.
replace
(
/
\n
/g
,
''
).
replace
(
/
\r
/g
,
''
);
this
.
path
=
_path
||
this
.
path
;
term
.
set_prompt
(
this
.
parsePrompt
(
infoUser
));
this
.
path
=
_path
||
this
.
path
;
term
.
set_prompt
(
this
.
parsePrompt
(
info_user
));
// 去除换行符
[
// let output = _.substr(0, _sindex - 3).replace(/\n$/, '');
/
\n\n
$/
,
/^
\n\n
/
,
/
\r\r
$/
,
// 去除换行符
/^
\r\r
/
,
/
\r\n
$/
,
/^
\r\n
/
,
[
/
\n\n
$/
,
/^
\n\n
/
,
/
\r\r
$/
,
/^
\r\r
/
,
/
\r\n
$/
,
/^
\r\n
/
,
/
\n\r
$/
,
/^
\n\r
/
,
/
\r
$/
,
/^
\r
/
,
/
\n
$/
,
/^
\n
/
].
map
((
_
)
=>
{
/
\n\r
$/
,
/^
\n\r
/
,
/
\r
$/
,
output
=
output
.
replace
(
_
,
''
);
/^
\r
/
,
/
\n
$/
,
/^
\n
/
});
].
map
((
_
)
=>
{
// output = output.replace(/\n$/, '').replace(/^\n/, '').replace(/^\r/, '').replace(/\r$/, '').;
output
=
output
.
replace
(
_
,
''
);
if
(
output
.
length
>
0
)
{
});
term
.
echo
(
antSword
.
noxss
(
output
));
if
(
output
.
length
>
0
)
{
// 保存最大100kb数据
term
.
echo
(
if
(
output
.
length
<
(
1024
*
1024
))
{
antSword
.
noxss
(
output
)
this
.
cache
.
set
(
cache_tag
,
output
);
);
};
// 保存最大100kb数据
};
if
(
output
.
length
<
(
1024
*
1024
))
{
term
.
resume
();
this
.
cache
.
set
(
cacheTag
,
output
);
},
(
_
)
=>
{
};
term
.
error
(
'ERR: '
+
(
_
instanceof
Object
)
?
JSON
.
stringify
(
_
)
:
String
(
_
));
};
term
.
resume
();
term
.
resume
();
}
}).
catch
((
e
)
=>
{
)
term
.
error
(
'ERR: '
+
(
_
instanceof
Object
)
?
JSON
.
stringify
(
_
)
:
String
(
_
));
},
{
term
.
resume
();
greetings
:
banner
,
name
:
`terminal_
${
this
.
hash
}
`
,
prompt
:
this
.
parsePrompt
(
info_user
),
exit
:
false
});
});
// }, (err) => {
},
{
// toastr.error(err, LANG_T['error']);
greetings
:
banner
,
// this.cell.progressOff();
name
:
`terminal_
${
this
.
hash
}
`
,
// this.cell.close();
prompt
:
this
.
parsePrompt
(
infoUser
),
// });
exit
:
false
});
}
}
// 生成CMD代码
/**
* 根据执行命令&&路径生成最终command
* @param {String} cmd 要执行的命令
* @param {String} path 当前路径
* @return {String} 最终执行命令
*/
parseCmd
(
cmd
,
path
)
{
parseCmd
(
cmd
,
path
)
{
path
=
path
.
replace
(
/
\\\\
/g
,
'
\
\'
).replace(/"/g, '
\\
"').replace(/
\\
/g, '
\\\\
');
path
=
path
.
replace
(
/
\\\\
/g
,
'
\
\'
).replace(/"/g, '
\\
"').replace(/
\\
/g, '
\\\\
');
return this.isWin ? `cd /d "
$
{
path
}
"&${cmd}&echo [S]&cd&echo [E]` : `cd "
$
{
path
}
";${cmd};echo [S];pwd;echo [E]`;
return (this.isWin
? `cd /d "
$
{
path
}
"&${cmd}&echo [S]&cd&echo [E]`
: `cd "
$
{
path
}
";${cmd};echo [S];pwd;echo [E]`
);
}
}
// 生成路径提示
/**
* 生成路径提示符
* @param {String} user 当前用户名
* @return {String} term输出字符串
*/
parsePrompt(user) {
parsePrompt(user) {
let ret = this.isWin ? '[[b;white;]' + this.path.replace(/
\
//g, '
\\
') + '> ]' : (user ? ('([[b;#E80000;]' + user + ']:[[;#0F93D2;]') : '[[;0F93D2;]') + this.path + ']) $ ';
return antSword.noxss(this.isWin
return antSword.noxss(ret);
? `[[b;white;]${this.path.replace(/
\
//g, '
\\
')}> ]`
: (user ? `([[b;#E80000;]${user}]:[[;#0F93D2;]` : '[[;0F93D2;]') + this.path + ']) $ '
);
}
}
}
}
export default Terminal;
export default Terminal;
\ No newline at end of file
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment