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
Show 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
...
@@ -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
.
request
(
this
.
core
[
`database_
${
conf
[
'type'
]}
`
].
show_databases
(
this
.
core
[
`database_
${
conf
[
'type'
]}
`
].
show_databases
(
{
{
conn
:
conf
[
'conn'
],
conn
:
conf
[
'conn'
],
dbname
:
[
'access'
,
'microsoft_jet_oledb_4_0'
].
indexOf
(
conf
[
'type'
])
>
-
1
?
conf
[
'conn'
].
match
(
/
[\w]
+.mdb$/
)
:
'database'
dbname
:
[
'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
(
'执行完毕,没有结果返回'
)
...
@@ -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
.
request
(
this
.
core
[
`database_
${
conf
[
'type'
]}
`
].
show_tables
(
this
.
core
[
`database_
${
conf
[
'type'
]}
`
].
show_tables
(
{
{
conn
:
conf
[
'conn'
],
conn
:
conf
[
'conn'
],
dbname
:
db
dbname
:
db
},
(
ret
)
=>
{
})
).
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
.
request
(
this
.
core
[
`database_
${
conf
[
'type'
]}
`
].
show_columns
(
this
.
core
[
`database_
${
conf
[
'type'
]}
`
].
show_columns
(
{
{
conn
:
conf
[
'conn'
],
conn
:
conf
[
'conn'
],
table
:
conf
[
'type'
]
===
'oracle'
?
`SELECT * FROM (SELECT A.*,ROWNUM N FROM
${
table
}
A) WHERE N=1`
:
`SELECT TOP 1 * FROM
${
table
}
`
table
:
conf
[
'type'
]
===
'oracle'
?
`SELECT * FROM (SELECT A.*,ROWNUM N FROM
${
table
}
A) WHERE N=1`
:
`SELECT TOP 1 * FROM
${
table
}
`
},
(
ret
)
=>
{
})
).
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
.
request
(
this
.
core
[
`database_
${
this
.
dbconf
[
'type'
]}
`
].
query
({
this
.
core
[
`database_
${
this
.
dbconf
[
'type'
]}
`
].
query
({
conn
:
this
.
dbconf
[
'conn'
],
conn
:
this
.
dbconf
[
'conn'
],
sql
:
sql
sql
:
sql
},
(
ret
)
=>
{
})
).
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/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
.
request
(
this
.
core
[
`database_
${
conf
[
'type'
]}
`
].
show_tables
(
this
.
core
[
`database_
${
conf
[
'type'
]}
`
].
show_tables
(
{
{
conn
:
conf
[
'conn'
],
conn
:
conf
[
'conn'
],
encode
:
this
.
manager
.
opt
.
encode
,
encode
:
this
.
manager
.
opt
.
encode
,
db
:
db
db
:
db
},
(
ret
)
=>
{
})
).
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
.
request
(
this
.
core
[
`database_
${
conf
[
'type'
]}
`
].
show_columns
(
this
.
core
[
`database_
${
conf
[
'type'
]}
`
].
show_columns
(
{
{
conn
:
conf
[
'conn'
],
conn
:
conf
[
'conn'
],
encode
:
this
.
manager
.
opt
.
encode
,
encode
:
this
.
manager
.
opt
.
encode
,
db
:
db
,
db
:
db
,
table
:
table
table
:
table
},
(
ret
)
=>
{
})
).
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
.
request
(
this
.
core
[
`database_
${
this
.
dbconf
[
'type'
]}
`
].
query
({
this
.
core
[
`database_
${
this
.
dbconf
[
'type'
]}
`
].
query
({
conn
:
this
.
dbconf
[
'conn'
],
conn
:
this
.
dbconf
[
'conn'
],
encode
:
this
.
manager
.
opt
.
encode
,
encode
:
this
.
manager
.
opt
.
encode
,
sql
:
sql
sql
:
sql
},
(
ret
)
=>
{
})
).
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
...
@@ -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
(
this
.
core
[
`database_
${
conf
[
'type'
]}
`
].
show_tables
({
host
:
conf
[
'host'
],
host
:
conf
[
'host'
],
user
:
conf
[
'user'
],
user
:
conf
[
'user'
],
passwd
:
conf
[
'passwd'
],
passwd
:
conf
[
'passwd'
],
db
:
db
db
:
db
},
(
ret
)
=>
{
})
).
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
(
this
.
core
[
`database_
${
conf
[
'type'
]}
`
].
show_columns
({
host
:
conf
[
'host'
],
host
:
conf
[
'host'
],
user
:
conf
[
'user'
],
user
:
conf
[
'user'
],
passwd
:
conf
[
'passwd'
],
passwd
:
conf
[
'passwd'
],
db
:
db
,
db
:
db
,
table
:
table
table
:
table
},
(
ret
)
=>
{
})
).
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,6 +397,8 @@ class PHP {
...
@@ -389,6 +397,8 @@ class PHP {
// 执行SQL
// 执行SQL
execSQL
(
sql
)
{
execSQL
(
sql
)
{
this
.
manager
.
query
.
layout
.
progressOn
();
this
.
manager
.
query
.
layout
.
progressOn
();
this
.
core
.
request
(
this
.
core
[
`database_
${
this
.
dbconf
[
'type'
]}
`
].
query
({
this
.
core
[
`database_
${
this
.
dbconf
[
'type'
]}
`
].
query
({
host
:
this
.
dbconf
[
'host'
],
host
:
this
.
dbconf
[
'host'
],
user
:
this
.
dbconf
[
'user'
],
user
:
this
.
dbconf
[
'user'
],
...
@@ -396,11 +406,13 @@ class PHP {
...
@@ -396,11 +406,13 @@ class PHP {
db
:
this
.
dbconf
[
'database'
],
db
:
this
.
dbconf
[
'database'
],
sql
:
sql
,
sql
:
sql
,
encode
:
this
.
dbconf
[
'encode'
]
||
'utf8'
encode
:
this
.
dbconf
[
'encode'
]
||
'utf8'
},
(
ret
)
=>
{
})
).
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
();
});
});
...
...
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
.
request
(
this
.
core
.
filemanager
.
dir
({
this
.
core
.
filemanager
.
dir
({
path
:
path
path
:
path
},
(
ret
)
=>
{
})
).
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
.
request
(
this
.
core
.
filemanager
.
delete
({
this
.
core
.
filemanager
.
delete
({
path
:
path
path
:
path
},
(
ret
)
=>
{
})
).
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
.
request
(
this
.
core
.
filemanager
.
copy
({
this
.
core
.
filemanager
.
copy
({
path
:
source
,
path
:
source
,
target
:
target
target
:
target
},
(
ret
)
=>
{
})
).
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
.
request
(
this
.
core
.
filemanager
.
rename
({
this
.
core
.
filemanager
.
rename
({
path
:
this
.
path
+
name
,
path
:
this
.
path
+
name
,
name
:
this
.
path
+
value
+
((
isDir
&&
!
value
.
endsWith
(
'/'
))
?
'/'
:
''
)
name
:
this
.
path
+
value
+
((
isDir
&&
!
value
.
endsWith
(
'/'
))
?
'/'
:
''
)
},
(
ret
)
=>
{
})
).
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
.
request
(
this
.
core
.
filemanager
.
mkdir
({
this
.
core
.
filemanager
.
mkdir
({
path
:
this
.
path
+
value
path
:
this
.
path
+
value
},
(
ret
)
=>
{
})
).
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
();
// 发起http请求
this
.
core
.
request
(
this
.
core
.
filemanager
.
create_file
({
this
.
core
.
filemanager
.
create_file
({
path
:
this
.
path
+
value
,
path
:
this
.
path
+
value
,
content
:
'
\
0'
content
:
'Halo ANT!'
},
(
ret
)
=>
{
})
).
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
();
// http request
this
.
core
.
request
(
this
.
core
.
filemanager
.
retime
({
this
.
core
.
filemanager
.
retime
({
path
:
this
.
path
+
name
,
path
:
this
.
path
+
name
,
time
:
value
time
:
value
},
(
ret
)
=>
{
})
).
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
},
(
ret
,
buff
)
=>
{
let
imgData
=
new
Buffer
(
buff
).
toString
(
'base64'
);
win
.
attachHTMLString
(
`<img src="data:/image/png;base64,
${
imgData
}
"/>`
);
},
(
err
)
=>
{
},
(
chunk
)
=>
{
this
.
core
.
request
(
this
.
core
.
filemanager
.
download_file
()
,
(
chunk
)
=>
{
buff
+=
chunk
;
buff
+=
chunk
;
let
imgData
=
data
+
new
Buffer
(
buff
).
toString
(
'base64'
);
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
}
"/>`
);
}).
catch
((
err
)
=>
{
});
});
}
}
...
@@ -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
({
// 删除旧文件(如果存在
path
:
path
if
(
fs
.
existsSync
(
filePath
))
{
},
(
ret
,
buff
)
=>
{
fs
.
unlinkSync
(
filePath
);
// 保存文件
// 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
)
=>
{
this
.
core
.
download
(
task
.
failed
(
LANG
[
'download'
][
'task'
][
'error'
](
err
));
filePath
toastr
.
error
(
LANG
[
'download'
][
'error'
](
name
,
err
),
LANG_T
[
'error'
]);
,
this
.
core
.
filemanager
.
download_file
({
},
(
chunk
)
=>
{
path
:
path
// 写入文件
})
fs
.
writeFileSync
(
filePath
,
new
global
.
Buffer
(
chunk
),
{
,
(
_size
)
=>
{
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
)
=>
{
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'
]);
});
});
// }, 200);
});
});
}
}
...
@@ -472,10 +566,15 @@ class FileManager {
...
@@ -472,10 +566,15 @@ 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'
]);
// http request
this
.
core
.
request
(
this
.
core
.
filemanager
.
wget
({
this
.
core
.
filemanager
.
wget
({
url
:
url
,
url
:
url
,
path
:
path
path
:
path
},
(
ret
)
=>
{
})
).
then
((
res
)
=>
{
let
ret
=
res
[
'text'
];
// 下载成功?当前目录?刷新:删除缓存
// 下载成功?当前目录?刷新:删除缓存
if
(
ret
===
'1'
)
{
if
(
ret
===
'1'
)
{
task
.
success
(
LANG
[
'wget'
][
'task'
][
'success'
]);
task
.
success
(
LANG
[
'wget'
][
'task'
][
'success'
]);
...
@@ -484,7 +583,7 @@ class FileManager {
...
@@ -484,7 +583,7 @@ class FileManager {
}
else
{
}
else
{
task
.
failed
(
LANG
[
'wget'
][
'task'
][
'failed'
](
ret
));
task
.
failed
(
LANG
[
'wget'
][
'task'
][
'failed'
](
ret
));
}
}
}
,
(
err
)
=>
{
}
).
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
;
}
dialog
.
showOpenDialog
({
properties
:
[
'openFile'
,
'multiSelections'
]
},
(
_filePaths
)
=>
{
if
(
!
_filePaths
)
{
return
};
return
res
(
_filePaths
);
})
}).
then
((
filePaths
)
=>
{
// 初始化任务
filePaths
.
map
((
f
)
=>
{
const
fileName
=
f
.
substr
(
f
.
lastIndexOf
(
'/'
)
+
1
);
tasks
[
f
]
=
this
.
tasks
.
new
(
LANG
[
'upload'
][
'task'
][
'name'
],
`
${
fileName
}
=>
${
path
}
`
,
'Waiting for uploading..'
);
});
return
filePaths
;
}).
then
((
filePaths
)
=>
{
// 文件上传(逐个队列上传
const
upload
=
()
=>
{
new
Promise
((
res
,
rej
)
=>
{
// 获取单个上传文件
let
filePath
=
filePaths
.
shift
();
if
(
filePath
)
{
res
(
filePath
);
}
}).
then
((
filePath
)
=>
{
// 上传单个
let
buffIndex
=
0
;
let
buff
=
[];
let
buff
=
[];
// 数据分段上传,一次上传512kb=1024*512
// 分段上传大小,默认1M
let
split
=
1024
*
512
;
let
dataSplit
=
1024
*
1024
;
cons
t
task
=
tasks
[
filePath
];
le
t
task
=
tasks
[
filePath
];
// 获取文件名
// 获取文件名
const
fileName
=
filePath
.
substr
(
filePath
.
lastIndexOf
(
'/'
)
+
1
);
let
fileName
=
filePath
.
substr
(
filePath
.
lastIndexOf
(
'/'
)
+
1
);
// 读取文件buff
let
fileBuff
;
let
fileBuff
;
// 读取文件buffer
try
{
try
{
fileBuff
=
fs
.
readFileSync
(
filePath
);
fileBuff
=
fs
.
readFileSync
(
filePath
);
}
catch
(
e
)
{
}
catch
(
e
)
{
return
task
.
failed
(
e
);
return
task
.
failed
(
e
);
}
}
// 文件数据分段
while
(
true
)
{
let
buffLength
=
fileBuff
.
length
;
const
_
=
fileBuff
.
slice
(
i
,
i
+
split
);
while
(
buffIndex
<=
buffLength
)
{
i
+=
split
;
let
buffSplit
=
fileBuff
.
slice
(
buffIndex
,
buffIndex
+
dataSplit
);
if
(
_
.
length
===
0
)
{
break
};
buffIndex
+=
dataSplit
;
buff
.
push
(
_
);
buff
.
push
(
buffSplit
);
}
}
// 开始上传
const
all_num
=
buff
.
length
;
const
uploadBuffFunc
=
(
_buff
)
=>
{
const
upload_func
=
(
arr
)
=>
{
new
Promise
((
res
,
rej
)
=>
{
if
(
!
arr
[
0
])
{
let
_b
=
_buff
.
shift
();
if
(
_b
)
{
res
(
_b
);
}
else
{
// 上传完毕
// 上传完毕
task
.
success
(
'100%'
);
task
.
success
(
'100%'
);
// 刷新目录
toastr
.
success
(
LANG
[
'upload'
][
'success'
](
fileName
),
LANG_T
[
'success'
]);
toastr
.
success
(
LANG
[
'upload'
][
'success'
](
fileName
),
LANG_T
[
'success'
]);
// 刷新目录
缓存
// 刷新
缓存
this
.
files
.
refreshPath
(
path
===
this
.
path
?
''
:
path
);
this
.
files
.
refreshPath
(
path
===
this
.
path
?
''
:
path
);
return
upload
(
filePaths
);
// 继续上传
};
return
upload
();
}
}).
then
((
b
)
=>
{
// 更新进度条
// 更新进度条
task
.
update
(
`
${
parseInt
((
all_num
-
arr
.
length
)
/
all_num
*
100
)}
%`
);
task
.
update
(
`
${
parseInt
((
buffLength
-
_buff
.
length
)
/
buffLength
*
100
)}
%`
);
// 开始上传分段数据
this
.
core
.
request
(
this
.
core
.
filemanager
.
upload_file
({
this
.
core
.
filemanager
.
upload_file
({
path
:
path
+
fileName
,
path
:
path
+
fileName
,
content
:
arr
[
0
]
content
:
b
},
(
ret
)
=>
{
})
).
then
((
res
)
=>
{
let
ret
=
res
[
'text'
];
if
(
ret
===
'1'
)
{
if
(
ret
===
'1'
)
{
// 继续上传
return
uploadBuffFunc
(
_buff
);
arr
.
shift
();
upload_func
(
arr
);
}
else
{
task
.
failed
(
LANG
[
'upload'
][
'task'
][
'failed'
](
ret
));
toastr
.
error
(
LANG
[
'upload'
][
'error'
](
fileName
,
ret
===
'0'
?
''
:
'<br/>'
+
ret
),
LANG_T
[
'error'
]);
}
}
},
(
err
)
=>
{
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
));
task
.
failed
(
LANG
[
'upload'
][
'task'
][
'error'
](
err
));
toastr
.
error
(
LANG
[
'upload'
][
'error'
](
fileName
,
err
),
LANG_T
[
'error'
]);
toastr
.
error
(
LANG
[
'upload'
][
'error'
](
fileName
,
err
),
LANG_T
[
'error'
]);
});
});
})
}
}
uploadBuffFunc
(
buff
);
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
);
};
upload
();
});
});
}
}
...
@@ -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,11 +769,13 @@ class FileManager {
...
@@ -665,11 +769,13 @@ 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
)
=>
{
})
).
then
((
res
)
=>
{
let
ret
=
res
[
'text'
];
win
.
progressOff
();
win
.
progressOff
();
if
(
ret
===
'1'
)
{
if
(
ret
===
'1'
)
{
toastr
.
success
(
LANG
[
'editor'
][
'success'
](
path
),
LANG_T
[
'success'
]);
toastr
.
success
(
LANG
[
'editor'
][
'success'
](
path
),
LANG_T
[
'success'
]);
...
@@ -678,8 +784,9 @@ class FileManager {
...
@@ -678,8 +784,9 @@ class FileManager {
}
else
{
}
else
{
toastr
.
error
(
LANG
[
'editor'
][
'error'
](
path
,
ret
===
'0'
?
''
:
'<br/>'
+
ret
),
LANG_T
[
'error'
]);
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
.
request
(
this
.
core
.
filemanager
.
read_file
({
this
.
core
.
filemanager
.
read_file
({
path
:
path
path
:
path
},
(
ret
)
=>
{
})
).
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
();
});
});
...
...
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,84 +40,95 @@ class Terminal {
...
@@ -48,84 +40,95 @@ 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();
// // 获取缓存info
// const _info = ipcRenderer.sendSync('cache-get', {
// id: this.opts['id'],
// tag: 'info'
// });
// this.core.base.info((ret) => {
// this.cell.progressOff();
let
info
=
ret
.
split
(
'
\
t'
);
let
info
=
ret
.
split
(
'
\
t'
);
let
info_user
;
let
infoUser
,
infoPath
,
infoDrive
,
infoSystem
;
let
info_path
;
let
info_drive
;
let
info_system
;
// 解析banner
let
banner
=
`[[b;cyan;](*)
${
LANG
[
'banner'
][
'title'
]}
]`
;
let
banner
=
`[[b;cyan;](*)
${
LANG
[
'banner'
][
'title'
]}
]`
;
// 判断获取数据是否正确
// 判断数据是否正确
if
(
info
.
length
===
4
)
{
if
(
info
.
length
===
4
)
{
info_user
=
info
[
3
];
infoPath
=
info
[
0
];
info_path
=
info
[
0
];
infoDrive
=
info
[
1
];
info_drive
=
info
[
1
];
infoSystem
=
info
[
2
];
info_system
=
info
[
2
];
infoUser
=
info
[
3
];
}
else
if
(
info
.
length
===
2
)
{
}
else
if
(
info
.
length
===
2
)
{
info_p
ath
=
info
[
0
];
infoP
ath
=
info
[
0
];
info_d
rive
=
info
[
1
];
infoD
rive
=
info
[
1
];
}
else
{
}
else
{
toastr
.
error
(
'Loading infomations failed!<br/>'
+
ret
,
LANG_T
[
'error'
]);
toastr
.
error
(
'Loading infomations failed!<br/>'
+
ret
,
LANG_T
[
'error'
]);
this
.
cache
.
del
(
'info'
);
this
.
cache
.
del
(
'info'
);
return
this
.
cell
.
close
();
return
this
.
cell
.
close
();
};
}
info_path
=
info_path
.
replace
(
/
\\
/g
,
'/'
).
replace
(
/
\.
$/
,
''
);
// 判断是否为linux
// 转换路径特殊字符
if
(
info_path
.
substr
(
0
,
1
)
===
'/'
)
{
infoPath
=
infoPath
.
replace
(
/
\\
/g
,
'/'
).
replace
(
/
\.
$/
,
''
);
this
.
isWin
=
false
;
};
// 判断是否为!win
this
.
path
=
info_path
;
this
.
isWin
=
!
(
infoPath
.
substr
(
0
,
1
)
===
'/'
)
banner
+=
`\n[[b;#99A50D;]
${
LANG
[
'banner'
][
'path'
]}
]: [[;#C3C3C3;]
${
info_path
}
]`
;
this
.
path
=
infoPath
;
banner
+=
`\n[[b;#99A50D;]
${
LANG
[
'banner'
][
'drive'
]}
]: [[;#C3C3C3;]
${
info_drive
}
]`
;
// 组合banner
banner
+=
`\n[[b;#99A50D;]
${
LANG
[
'banner'
][
'path'
]}
]: [[;#C3C3C3;]
${
infoPath
}
]`
;
banner
+=
`\n[[b;#99A50D;]
${
LANG
[
'banner'
][
'drive'
]}
]: [[;#C3C3C3;]
${
infoDrive
}
]`
;
if
(
info
.
length
===
4
)
{
if
(
info
.
length
===
4
)
{
banner
+=
`\n[[b;#99A50D;]
${
LANG
[
'banner'
][
'system'
]}
]: [[;#C3C3C3;]
${
info_s
ystem
}
]`
;
banner
+=
`\n[[b;#99A50D;]
${
LANG
[
'banner'
][
'system'
]}
]: [[;#C3C3C3;]
${
infoS
ystem
}
]`
;
banner
+=
`\n[[b;#99A50D;]
${
LANG
[
'banner'
][
'user'
]}
]: [[;#C3C3C3;]
${
info_u
ser
}
]`
;
banner
+=
`\n[[b;#99A50D;]
${
LANG
[
'banner'
][
'user'
]}
]: [[;#C3C3C3;]
${
infoU
ser
}
]`
;
}
}
// 初始化终端
// 初始化终端
this
.
term
=
dom
.
terminal
(
(
cmd
,
term
)
=>
{
this
.
term
=
dom
.
terminal
(
(
cmd
,
term
)
=>
{
if
(
!
cmd
)
{
return
false
};
if
(
!
cmd
)
{
return
false
};
...
@@ -133,73 +136,89 @@ class Terminal {
...
@@ -133,73 +136,89 @@ class Terminal {
if
(
cmd
===
'exit'
||
cmd
===
'quit'
)
{
return
this
.
cell
.
close
()
};
if
(
cmd
===
'exit'
||
cmd
===
'quit'
)
{
return
this
.
cell
.
close
()
};
term
.
pause
();
term
.
pause
();
// 是否有缓存
// 是否有缓存
let
cache_tag
=
'command-'
+
new
Buffer
(
this
.
path
+
cmd
).
toString
(
'base64'
);
let
cacheTag
=
'command-'
+
new
Buffer
(
this
.
path
+
cmd
).
toString
(
'base64'
);
let
cache_cmd
;
let
cacheCmd
;
if
(
cache_cmd
=
this
.
cache
.
get
(
cache_tag
))
{
if
(
cacheCmd
=
this
.
cache
.
get
(
cacheTag
))
{
term
.
echo
(
antSword
.
noxss
(
cache_cmd
));
term
.
echo
(
antSword
.
noxss
(
cacheCmd
)
);
return
term
.
resume
();
return
term
.
resume
();
};
};
// 开始执行命令
this
.
core
.
request
(
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
)
=>
{
let
_
=
ret
[
'text'
];
// 解析出命令执行路径
// 解析出命令执行路径
const
index_s
=
_
.
indexOf
(
'[S]'
);
const
indexS
=
_
.
indexOf
(
'[S]'
);
const
index_e
=
_
.
lastIndexOf
(
'[E]'
);
const
indexE
=
_
.
lastIndexOf
(
'[E]'
);
let
_path
=
_
.
substr
(
index_s
+
3
,
index_e
-
index_s
-
3
);
let
_path
=
_
.
substr
(
indexS
+
3
,
indexE
-
indexS
-
3
);
// let _sindex = _.indexOf('[S]') + 3;
// let _eindex = _.indexOf('[E]');
// let _path = _.substr(_sindex, _eindex - _sindex);
let
output
=
_
.
replace
(
`[S]
${
_path
}
[E]`
,
''
);
let
output
=
_
.
replace
(
`[S]
${
_path
}
[E]`
,
''
);
_path
=
_path
.
replace
(
/
\n
/g
,
''
).
replace
(
/
\r
/g
,
''
);
_path
=
_path
.
replace
(
/
\n
/g
,
''
).
replace
(
/
\r
/g
,
''
);
this
.
path
=
_path
||
this
.
path
;
this
.
path
=
_path
||
this
.
path
;
term
.
set_prompt
(
this
.
parsePrompt
(
info_u
ser
));
term
.
set_prompt
(
this
.
parsePrompt
(
infoU
ser
));
// let output = _.substr(0, _sindex - 3).replace(/\n$/, '');
// 去除换行符
// 去除换行符
[
/
\n\n
$/
,
/^
\n\n
/
,
/
\r\r
$/
,
/^
\r\r
/
,
/
\r\n
$/
,
/^
\r\n
/
,
/
\n\r
$/
,
/^
\n\r
/
,
/
\r
$/
,
/^
\r
/
,
/
\n
$/
,
/^
\n
/
].
map
((
_
)
=>
{
[
/
\n\n
$/
,
/^
\n\n
/
,
/
\r\r
$/
,
/^
\r\r
/
,
/
\r\n
$/
,
/^
\r\n
/
,
/
\n\r
$/
,
/^
\n\r
/
,
/
\r
$/
,
/^
\r
/
,
/
\n
$/
,
/^
\n
/
].
map
((
_
)
=>
{
output
=
output
.
replace
(
_
,
''
);
output
=
output
.
replace
(
_
,
''
);
});
});
// output = output.replace(/\n$/, '').replace(/^\n/, '').replace(/^\r/, '').replace(/\r$/, '').;
if
(
output
.
length
>
0
)
{
if
(
output
.
length
>
0
)
{
term
.
echo
(
antSword
.
noxss
(
output
));
term
.
echo
(
antSword
.
noxss
(
output
)
);
// 保存最大100kb数据
// 保存最大100kb数据
if
(
output
.
length
<
(
1024
*
1024
))
{
if
(
output
.
length
<
(
1024
*
1024
))
{
this
.
cache
.
set
(
cache_t
ag
,
output
);
this
.
cache
.
set
(
cacheT
ag
,
output
);
};
};
};
};
term
.
resume
();
term
.
resume
();
},
(
_
)
=>
{
}).
catch
((
e
)
=>
{
term
.
error
(
'ERR: '
+
(
_
instanceof
Object
)
?
JSON
.
stringify
(
_
)
:
String
(
_
));
term
.
error
(
'ERR: '
+
(
_
instanceof
Object
)
?
JSON
.
stringify
(
_
)
:
String
(
_
));
term
.
resume
();
term
.
resume
();
}
});
)
},
{
},
{
greetings
:
banner
,
greetings
:
banner
,
name
:
`terminal_
${
this
.
hash
}
`
,
name
:
`terminal_
${
this
.
hash
}
`
,
prompt
:
this
.
parsePrompt
(
info_u
ser
),
prompt
:
this
.
parsePrompt
(
infoU
ser
),
exit
:
false
exit
:
false
});
});
// }, (err) => {
// toastr.error(err, LANG_T['error']);
// this.cell.progressOff();
// this.cell.close();
// });
}
}
// 生成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 + ']) $ '
);
}
}
}
}
...
...
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