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
979da3c1
Commit
979da3c1
authored
Jun 22, 2016
by
antoor
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Reconstruction of optimized code
重构优化代码
parent
9d61cf82
Changes
10
Show whitespace changes
Inline
Side-by-side
Showing
10 changed files
with
723 additions
and
792 deletions
+723
-792
category.js
source/modules/shellmanager/category.js
+0
-142
index.js
source/modules/shellmanager/category/index.js
+39
-0
sidebar.js
source/modules/shellmanager/category/sidebar.js
+52
-0
toolbar.js
source/modules/shellmanager/category/toolbar.js
+183
-0
data.js
source/modules/shellmanager/data.js
+47
-0
index.js
source/modules/shellmanager/index.js
+37
-416
list.js
source/modules/shellmanager/list.js
+0
-234
contextmenu.js
source/modules/shellmanager/list/contextmenu.js
+236
-0
grid.js
source/modules/shellmanager/list/grid.js
+94
-0
index.js
source/modules/shellmanager/list/index.js
+35
-0
No files found.
source/modules/shellmanager/category.js
deleted
100644 → 0
View file @
9d61cf82
/**
* 右侧目录管理模块
*/
'use strict'
;
const
LANG_T
=
antSword
[
'language'
][
'toastr'
];
const
LANG
=
antSword
[
'language'
][
'shellmanager'
];
class
Category
{
constructor
(
cell
,
manager
)
{
// cell.setText(`<i class="fa fa-folder"></i> ${LANG['category']['title']}`);
cell
.
setWidth
(
222
);
cell
.
fixSize
(
1
,
0
);
// 初始化toolbar
const
toolbar
=
cell
.
attachToolbar
();
toolbar
.
loadStruct
([
{
id
:
'add'
,
type
:
'button'
,
text
:
`<i class="fa fa-plus-circle"></i>
${
LANG
[
'category'
][
'toolbar'
][
'add'
]}
`
},
{
type
:
'separator'
},
{
id
:
'rename'
,
type
:
'button'
,
text
:
`<i class="fa fa-font"></i>
${
LANG
[
'category'
][
'toolbar'
][
'rename'
]}
`
,
disabled
:
true
},
{
type
:
'separator'
},
{
id
:
'del'
,
type
:
'button'
,
text
:
`<i class="fa fa-trash"></i>
${
LANG
[
'category'
][
'toolbar'
][
'del'
]}
`
,
disabled
:
true
}
]);
// toolbar点击
toolbar
.
attachEvent
(
'onClick'
,
(
id
)
=>
{
switch
(
id
)
{
case
'add'
:
// 添加分类
layer
.
prompt
({
title
:
`<i class="fa fa-plus-circle"></i>
${
LANG
[
'category'
][
'add'
][
'title'
]}
`
,
value
:
new
Date
().
format
(
'yyyyMMdd'
)
},
(
value
,
index
,
ele
)
=>
{
layer
.
close
(
index
);
sidebar
.
callEvent
(
'onSelect'
,
[
value
]);
});
break
;
case
'rename'
:
// 重命名分类
const
_category
=
sidebar
.
getActiveItem
();
layer
.
prompt
({
title
:
`<i class="fa fa-font"></i>
${
LANG
[
'category'
][
'rename'
][
'title'
]}
`
,
value
:
_category
},
(
value
,
index
,
ele
)
=>
{
// 禁止的分类名
if
(
value
===
'default'
)
{
return
toastr
.
warning
(
LANG
[
'category'
][
'rename'
][
'disable'
],
LANG_T
[
'warning'
]);
};
// 判断分类是否存在
if
(
sidebar
.
items
(
value
))
{
return
toastr
.
warning
(
LANG
[
'category'
][
'rename'
][
'exists'
],
LANG_T
[
'warning'
]);
};
layer
.
close
(
index
);
// 更新数据库
const
ret
=
antSword
[
'ipcRenderer'
].
sendSync
(
'shell-renameCategory'
,
{
oldName
:
_category
,
newName
:
value
});
if
(
typeof
ret
===
'number'
)
{
// 更新成功
toastr
.
success
(
LANG
[
'category'
][
'rename'
][
'success'
],
LANG_T
[
'success'
]);
// 删除旧分类
sidebar
.
items
(
_category
).
remove
();
// 添加新分类
sidebar
.
addItem
({
id
:
value
,
bubble
:
ret
,
text
:
`<i class="fa fa-folder-o"></i>
${
value
}
`
});
// 跳转分类
setTimeout
(()
=>
{
sidebar
.
items
(
value
).
setActive
();
},
233
);
}
else
{
toastr
.
error
(
LANG
[
'category'
][
'rename'
][
'error'
],
LANG_T
[
'error'
]);
}
});
break
;
case
'del'
:
// 删除分类
const
category
=
sidebar
.
getActiveItem
();
layer
.
confirm
(
LANG
[
'category'
][
'del'
][
'confirm'
],
{
icon
:
2
,
shift
:
6
,
// skin: 'layui-layer-molv',
title
:
`<i class="fa fa-trash"></i>
${
LANG
[
'category'
][
'del'
][
'title'
]}
`
,
},
(
_
)
=>
{
layer
.
close
(
_
);
// 1. 删除分类数据
const
ret
=
antSword
[
'ipcRenderer'
].
sendSync
(
'shell-clear'
,
category
);
if
(
typeof
(
ret
)
===
'number'
)
{
toastr
.
success
(
LANG
[
'category'
][
'del'
][
'success'
](
category
),
LANG_T
[
'success'
]);
// 2. 跳转到默认分类
sidebar
.
callEvent
(
'onSelect'
,
[
'default'
]);
// 3. 删除侧边栏
sidebar
.
items
(
category
).
remove
();
setTimeout
(
this
.
updateTitle
.
bind
(
this
),
100
);
}
else
{
return
toastr
.
error
(
LANG
[
'category'
][
'del'
][
'error'
](
category
,
ret
.
toString
()),
LANG_T
[
'error'
]);
}
});
break
;
}
});
// 初始化sidebar
const
sidebar
=
cell
.
attachSidebar
({
template
:
'text'
,
width
:
222
});
// 默认分类
sidebar
.
addItem
({
id
:
'default'
,
bubble
:
0
,
selected
:
true
,
text
:
`<i class="fa fa-folder-o"></i>
${
LANG
[
'category'
][
'default'
]}
</i>`
});
// sidebar点击事件
sidebar
.
attachEvent
(
'onSelect'
,
(
id
)
=>
{
// 更改删除按钮状态
toolbar
[(
id
===
'default'
)
?
'disableItem'
:
'enableItem'
](
'del'
);
toolbar
[(
id
===
'default'
)
?
'disableItem'
:
'enableItem'
](
'rename'
);
manager
.
loadData
({
category
:
id
});
});
this
.
cell
=
cell
;
this
.
toolbar
=
toolbar
;
this
.
sidebar
=
sidebar
;
}
// 更新标题
updateTitle
()
{
const
num
=
this
.
sidebar
.
getAllItems
().
length
;
this
.
cell
.
setText
(
`<i class="fa fa-folder"></i>
${
LANG
[
'category'
][
'title'
]}
(
${
num
}
)`
);
}
}
module
.
exports
=
Category
;
source/modules/shellmanager/category/index.js
0 → 100644
View file @
979da3c1
/**
* shellmanager::category
*/
const
LANG
=
antSword
[
'language'
][
'shellmanager'
][
'category'
];
const
Toolbar
=
require
(
'./toolbar'
);
const
Sidebar
=
require
(
'./sidebar'
);
class
Category
{
/**
* 初始化函数
* @param {Object} cell dhtmlx.cell对象
* @param {Object} top 顶层对象
* @return {[type]} [description]
*/
constructor
(
cell
,
top
)
{
this
.
top
=
top
;
// 设置cell样式
cell
.
setWidth
(
222
);
cell
.
fixSize
(
1
,
0
);
this
.
cell
=
cell
;
this
.
toolbar
=
new
Toolbar
(
cell
,
this
);
this
.
sidebar
=
new
Sidebar
(
cell
,
this
);
this
.
updateHeader
();
}
/**
* 更新标题
* @return {[type]} [description]
*/
updateHeader
()
{
const
num
=
this
.
sidebar
.
getAllItems
().
length
;
this
.
cell
.
setText
(
`<i class="fa fa-folder"></i>
${
LANG
[
'title'
]}
(
${
num
}
)`
);
}
}
module
.
exports
=
Category
;
source/modules/shellmanager/category/sidebar.js
0 → 100644
View file @
979da3c1
/**
* 分类侧边栏
*/
const
LANG
=
antSword
[
'language'
][
'shellmanager'
][
'category'
];
class
Sidebar
{
/**
* 初始化函数
* @param {object} cell dhtmlx.cell对象
* @param {object} top 父层category对象
* @return {[type]} [description]
*/
constructor
(
cell
,
top
)
{
this
.
top
=
top
;
const
sidebar
=
cell
.
attachSidebar
({
template
:
'text'
,
width
:
222
});
// 默认分类
sidebar
.
addItem
({
id
:
'default'
,
bubble
:
0
,
// selected: true,
text
:
`<i class="fa fa-folder-o"></i>
${
LANG
[
'default'
]}
</i>`
});
// sidebar点击事件
sidebar
.
attachEvent
(
'onSelect'
,
this
.
_onSelect
.
bind
(
this
));
return
sidebar
;
}
/**
* 点击事件
* @param {number} id [description]
* @return {[type]} [description]
*/
_onSelect
(
id
)
{
// 更新工具栏按钮状态
[
'del'
,
'rename'
].
map
((
_
)
=>
{
this
.
top
.
toolbar
[
id
===
'default'
?
'disableItem'
:
'enableItem'
](
_
)
});
// 重新加载数据
this
.
top
.
top
.
reloadData
({
category
:
id
});
}
}
module
.
exports
=
Sidebar
;
source/modules/shellmanager/category/toolbar.js
0 → 100644
View file @
979da3c1
/**
* 工具栏
*/
const
LANG
=
antSword
[
'language'
][
'shellmanager'
][
'category'
];
const
LANG_T
=
antSword
[
'language'
][
'toastr'
];
class
Toolbar
{
/**
* 初始化函数
* @param {Object} cell dhtmlx.cell对象
* @param {Object} top 顶层父对象
* @return {[type]} [description]
*/
constructor
(
cell
,
top
)
{
this
.
top
=
top
;
const
toolbar
=
cell
.
attachToolbar
();
this
.
parseToolbar
(
toolbar
);
toolbar
.
attachEvent
(
'onClick'
,
this
.
_onClick
.
bind
(
this
));
return
toolbar
;
}
/**
* 解析工具栏按钮
* @param {object} toolbar
* @return {[type]} [description]
*/
parseToolbar
(
toolbar
)
{
let
_tbObj
=
[];
[
// id&&lang, icon, disabled
[
'add'
,
'plus-circle'
],
false
,
[
'rename'
,
'font'
,
true
],
false
,
[
'del'
,
'trash'
,
true
]
].
map
((
_
)
=>
{
// 分隔符
if
(
!
_
)
{
return
_tbObj
.
push
({
type
:
'separator'
})
}
let
_tb
=
{
id
:
_
[
0
],
type
:
'button'
,
text
:
`<i class="fa fa-
${
_
[
1
]}
"></i>
${
LANG
[
'toolbar'
][
_
[
0
]]}
`
}
// 禁用
if
(
_
[
2
])
{
_tb
[
'disabled'
]
=
true
;
}
_tbObj
.
push
(
_tb
);
});
toolbar
.
loadStruct
(
_tbObj
);
}
/**
* 工具栏点击事件
* @param {[type]} id [description]
* @return {[type]} [description]
*/
_onClick
(
id
)
{
switch
(
id
)
{
case
'add'
:
this
.
_addCategory
();
break
;
case
'del'
:
this
.
_delCategory
();
break
;
case
'rename'
:
this
.
_renameCategory
();
break
;
}
}
/**
* 删除分类(会同时删除该分类下的所有数据
* @return {[type]} [description]
*/
_delCategory
()
{
// 获取当前选择的分类
const
category
=
this
.
top
.
sidebar
.
getActiveItem
();
// 删除提示框
layer
.
confirm
(
LANG
[
'del'
][
'confirm'
],
{
icon
:
2
,
shift
:
6
,
title
:
`<i class="fa fa-trash"></i>
${
LANG
[
'del'
][
'title'
]}
`
},
(
_
)
=>
{
layer
.
close
(
_
);
// 1. 删除分类数据
const
ret
=
antSword
[
'ipcRenderer'
].
sendSync
(
'shell-clear'
,
category
);
if
(
typeof
(
ret
)
===
'number'
)
{
toastr
.
success
(
LANG
[
'del'
][
'success'
](
category
),
LANG_T
[
'success'
]);
// 2. 跳转到默认分类
this
.
top
.
sidebar
.
callEvent
(
'onSelect'
,
[
'default'
]);
// 3. 删除侧边栏
this
.
top
.
sidebar
.
items
(
category
).
remove
();
// 4. 更新侧边栏标题
setTimeout
(
this
.
top
.
updateHeader
.
bind
(
this
.
top
),
200
);
}
else
{
return
toastr
.
error
(
LANG
[
'del'
][
'error'
](
category
,
ret
.
toString
()),
LANG_T
[
'error'
]);
}
}
);
}
/**
* 添加分类
* @return {[type]} [description]
*/
_addCategory
()
{
this
.
categoryForm
(
`<i class="fa fa-plus-circle"></i>
${
LANG
[
'add'
][
'title'
]}
`
).
then
((
v
)
=>
{
this
.
top
.
sidebar
.
callEvent
(
'onSelect'
,
[
v
]);
})
}
/**
* 重命名分类
* @return {[type]} [description]
*/
_renameCategory
()
{
const
_category
=
this
.
top
.
sidebar
.
getActiveItem
();
this
.
categoryForm
(
`<i class="fa fa-font"></i>
${
LANG
[
'rename'
][
'title'
]}
`
,
_category
).
then
((
v
)
=>
{
// 禁止的分类名
if
(
v
===
'default'
)
{
return
toastr
.
warning
(
LANG
[
'rename'
][
'disable'
],
LANG_T
[
'warning'
]);
};
// 判断分类是否存在
if
(
this
.
top
.
sidebar
.
items
(
v
))
{
return
toastr
.
warning
(
LANG
[
'rename'
][
'exists'
],
LANG_T
[
'warning'
]);
};
// 更新数据库
const
ret
=
antSword
[
'ipcRenderer'
].
sendSync
(
'shell-renameCategory'
,
{
oldName
:
_category
,
newName
:
v
});
if
(
typeof
ret
===
'number'
)
{
// 更新成功
toastr
.
success
(
LANG
[
'rename'
][
'success'
],
LANG_T
[
'success'
]);
// 删除旧分类
this
.
top
.
sidebar
.
items
(
_category
).
remove
();
// 添加新分类
this
.
top
.
sidebar
.
addItem
({
id
:
v
,
bubble
:
ret
,
text
:
`<i class="fa fa-folder-o"></i>
${
v
}
`
});
// 跳转分类
setTimeout
(()
=>
{
this
.
top
.
sidebar
.
items
(
v
).
setActive
();
},
233
);
}
else
{
toastr
.
error
(
LANG
[
'rename'
][
'error'
],
LANG_T
[
'error'
]);
}
})
}
/**
* 分类表单
* @param {string} title 标题
* @param {string} value 默认值
* @return {[type]} [description]
*/
categoryForm
(
title
,
value
=
new
Date
().
format
(
'yyyyMMdd'
))
{
return
new
Promise
((
res
,
rej
)
=>
{
layer
.
prompt
({
title
:
title
,
value
:
value
},
(
val
,
idx
,
ele
)
=>
{
layer
.
close
(
idx
);
return
res
(
val
);
});
})
}
}
module
.
exports
=
Toolbar
;
source/modules/shellmanager/data.js
0 → 100644
View file @
979da3c1
/**
* shell数据操作模块
*/
module
.
exports
=
{
/**
* 获取Shell数据
* @param {Object} arg 查询参数
* @return {[type]} [description]
*/
get
:
(
arg
=
{})
=>
{
const
ret
=
antSword
[
'ipcRenderer'
].
sendSync
(
'shell-find'
,
arg
);
// 解析数据
let
data
=
[];
let
category
=
{};
ret
.
map
((
_
)
=>
{
let
_c
=
_
[
'category'
]
||
'default'
;
category
[
_c
]
=
category
[
_c
]
||
0
;
category
[
_c
]
++
;
if
((
arg
instanceof
Object
)
&&
arg
[
'category'
]
&&
arg
[
'category'
]
!==
_
[
'category'
])
{
return
;
};
if
(
!
arg
&&
_
[
'category'
]
!==
'default'
)
{
return
;
};
data
.
push
({
id
:
_
[
'_id'
],
data
:
[
_
[
'url'
],
_
[
'ip'
],
_
[
'addr'
],
new
Date
(
_
[
'ctime'
]).
format
(
'yyyy/MM/dd hh:mm:ss'
),
new
Date
(
_
[
'utime'
]).
format
(
'yyyy/MM/dd hh:mm:ss'
)
]
});
});
// 如果分类没数据
if
((
arg
instanceof
Object
)
&&
arg
[
'category'
]
&&
!
category
[
arg
[
'category'
]])
{
category
[
arg
[
'category'
]]
=
0
;
};
if
(
typeof
(
category
[
'default'
])
===
'object'
)
{
category
[
'default'
]
=
0
;
};
return
{
data
:
data
,
category
:
category
}
}
}
source/modules/shellmanager/index.js
View file @
979da3c1
/**
* Shell管理模块
* Shell数据管理模块
* 重构:2016/06/20
*/
'use strict'
;
// import List from './list';
// import Category from './category';
// import ENCODES from '../../base/encodes';
const
List
=
require
(
'./list'
);
const
Category
=
require
(
'./category'
);
const
ENCODES
=
require
(
'../../base/encodes'
);
const
LANG_T
=
antSword
[
'language'
][
'toastr'
];
const
LANG
=
antSword
[
'language'
][
'shellmanager'
];
const
Data
=
require
(
'./data'
);
const
List
=
require
(
'./list/'
);
const
Category
=
require
(
'./category/'
);
class
ShellManager
{
constructor
()
{
// 初始化tabbar
const
tabbar
=
antSword
[
'tabbar'
];
tabbar
.
addTab
(
'tab_shellmanager'
,
// `<i class="fa fa-list-ul"></i> ${LANG['title']}`,
'<i class="fa fa-th-large"></i>'
,
null
,
null
,
true
,
false
)
);
const
cell
=
tabbar
.
cells
(
'tab_shellmanager'
);
const
layout
=
cell
.
attachLayout
(
'2U'
);
// 初始化左侧::列表管理
// 初始化左侧栏:数据
this
.
list
=
new
List
(
layout
.
cells
(
'a'
),
this
);
// 初始化右侧::目录管理
// 初始化右侧栏:目录
this
.
category
=
new
Category
(
layout
.
cells
(
'b'
),
this
);
this
.
cell
=
cell
;
this
.
win
=
new
dhtmlXWindows
();
this
.
win
.
attachViewportTo
(
cell
.
cell
);
// 监听菜单栏消息
antSword
[
'menubar'
].
reg
(
'shell-add'
,
this
.
addData
.
bind
(
this
));
this
.
loadData
();
}
// 清空缓存
clearCache
(
id
)
{
layer
.
confirm
(
LANG
[
'list'
][
'clearCache'
][
'confirm'
],
{
icon
:
2
,
shift
:
6
,
title
:
`<i class="fa fa-trash"></i>
${
LANG
[
'list'
][
'clearCache'
][
'title'
]}
`
},
(
_
)
=>
{
layer
.
close
(
_
);
const
ret
=
antSword
[
'ipcRenderer'
].
sendSync
(
'cache-clear'
,
{
id
:
id
});
if
(
ret
===
true
)
{
toastr
.
success
(
LANG
[
'list'
][
'clearCache'
][
'success'
],
LANG_T
[
'success'
]);
}
else
{
toastr
.
error
(
LANG
[
'list'
][
'clearCache'
][
'error'
](
ret
[
'errno'
]
===
-
2
?
'Not cache file.'
:
ret
[
'errno'
]),
LANG_T
[
'error'
]);
}
});
}
// 清空所有缓存
clearAllCache
()
{
layer
.
confirm
(
LANG
[
'list'
][
'clearAllCache'
][
'confirm'
],
{
icon
:
2
,
shift
:
6
,
title
:
`<i class="fa fa-trash"></i>
${
LANG
[
'list'
][
'clearAllCache'
][
'title'
]}
`
},
(
_
)
=>
{
layer
.
close
(
_
);
const
ret
=
antSword
[
'ipcRenderer'
].
sendSync
(
'cache-clearAll'
);
if
(
ret
===
true
)
{
toastr
.
success
(
LANG
[
'list'
][
'clearAllCache'
][
'success'
],
LANG_T
[
'success'
]);
}
else
{
toastr
.
error
(
LANG
[
'list'
][
'clearAllCache'
][
'error'
](
ret
),
LANG_T
[
'error'
]);
}
});
}
// 添加数据
addData
()
{
// 判断当前tab是否在主页
if
(
antSword
[
'tabbar'
].
getActiveTab
()
!==
'tab_shellmanager'
)
{
this
.
cell
.
setActive
()
};
// 初始化窗口
const
win
=
this
.
createWin
({
title
:
LANG
[
'list'
][
'add'
][
'title'
],
width
:
450
,
height
:
350
});
win
.
denyResize
();
// 工具栏
const
toolbar
=
win
.
attachToolbar
();
toolbar
.
loadStruct
([{
id
:
'add'
,
type
:
'button'
,
icon
:
'plus-circle'
,
text
:
LANG
[
'list'
][
'add'
][
'toolbar'
][
'add'
]
},
{
type
:
'separator'
},
{
id
:
'clear'
,
type
:
'button'
,
icon
:
'remove'
,
text
:
LANG
[
'list'
][
'add'
][
'toolbar'
][
'clear'
]
}]);
// 表单对象
const
form
=
win
.
attachForm
([
{
type
:
'settings'
,
position
:
'label-left'
,
labelWidth
:
80
,
inputWidth
:
250
},
{
type
:
'block'
,
inputWidth
:
'auto'
,
offsetTop
:
12
,
list
:
[
{
type
:
'input'
,
label
:
LANG
[
'list'
][
'add'
][
'form'
][
'url'
],
name
:
'url'
,
required
:
true
},
{
type
:
'input'
,
label
:
LANG
[
'list'
][
'add'
][
'form'
][
'pwd'
],
name
:
'pwd'
,
required
:
true
},
{
type
:
'combo'
,
label
:
LANG
[
'list'
][
'add'
][
'form'
][
'encode'
],
readonly
:
true
,
name
:
'encode'
,
options
:
(()
=>
{
let
ret
=
[];
ENCODES
.
map
((
_
)
=>
{
ret
.
push
({
text
:
_
,
value
:
_
,
selected
:
_
===
'UTF8'
});
});
return
ret
;
})()
},
{
type
:
'combo'
,
label
:
LANG
[
'list'
][
'add'
][
'form'
][
'type'
],
name
:
'type'
,
readonly
:
true
,
options
:
(()
=>
{
let
ret
=
[];
for
(
let
c
in
antSword
[
'core'
])
{
let
encoders
=
antSword
[
'core'
][
c
].
prototype
.
encoders
;
ret
.
push
({
text
:
c
.
toUpperCase
(),
value
:
c
,
selected
:
c
===
'php'
,
list
:
((
c
)
=>
{
let
_
=
[
{
type
:
'settings'
,
position
:
'label-right'
,
offsetLeft
:
60
,
labelWidth
:
100
},
{
type
:
'label'
,
label
:
LANG
[
'list'
][
'add'
][
'form'
][
'encoder'
]
},
{
type
:
'radio'
,
name
:
`encoder_
${
c
}
`
,
value
:
'default'
,
label
:
'default'
,
checked
:
true
}
];
encoders
.
map
((
e
)
=>
{
_
.
push
({
type
:
'radio'
,
name
:
`encoder_
${
c
}
`
,
value
:
e
,
label
:
e
})
});
return
_
;
})(
c
)
});
}
return
ret
;
})()
}
]}
],
true
);
// toolbar点击
toolbar
.
attachEvent
(
'onClick'
,
(
id
)
=>
{
switch
(
id
)
{
case
'add'
:
// 添加数据
// 判断表单数据
if
(
!
form
.
validate
())
{
return
toastr
.
warning
(
LANG
[
'list'
][
'add'
][
'warning'
],
LANG_T
[
'warning'
]);
};
// 解析数据
let
data
=
form
.
getValues
();
win
.
progressOn
();
// 获取编码器
data
[
'encoder'
]
=
data
[
`encoder_
${
data
[
'type'
]}
`
]
?
data
[
`encoder_
${
data
[
'type'
]}
`
]
:
''
;
// 获取分类
data
[
'category'
]
=
this
.
category
[
'sidebar'
].
getActiveItem
()
||
'default'
;
const
ret
=
antSword
[
'ipcRenderer'
].
sendSync
(
'shell-add'
,
data
);
// 更新UI
win
.
progressOff
();
if
(
ret
instanceof
Object
)
{
win
.
close
();
toastr
.
success
(
LANG
[
'list'
][
'add'
][
'success'
],
LANG_T
[
'success'
]);
this
.
loadData
({
category
:
data
[
'category'
]
});
}
else
{
toastr
.
error
(
LANG
[
'list'
][
'add'
][
'error'
](
ret
.
toString
()),
LANG_T
[
'error'
]);
}
break
;
case
'clear'
:
// 清空表单
form
.
clear
();
break
;
}
});
this
.
reloadData
();
}
// 编辑数据
editData
(
sid
)
{
// 获取数据
// const data = antSword['ipcRenderer'].sendSync('shell-find', {
// _id: sid
// })[0];
const
data
=
antSword
[
'ipcRenderer'
].
sendSync
(
'shell-findOne'
,
sid
);
// 初始化窗口
const
win
=
this
.
createWin
({
title
:
LANG
[
'list'
][
'edit'
][
'title'
](
data
[
'url'
]),
width
:
450
,
height
:
350
});
win
.
setModal
(
true
);
win
.
denyResize
();
// 工具栏
const
toolbar
=
win
.
attachToolbar
();
toolbar
.
loadStruct
([{
id
:
'save'
,
type
:
'button'
,
icon
:
'save'
,
text
:
LANG
[
'list'
][
'edit'
][
'toolbar'
][
'save'
]
},
{
type
:
'separator'
},
{
id
:
'clear'
,
type
:
'button'
,
icon
:
'remove'
,
text
:
LANG
[
'list'
][
'edit'
][
'toolbar'
][
'clear'
]
}]);
// 表单对象
const
form
=
win
.
attachForm
([
{
type
:
'settings'
,
position
:
'label-left'
,
labelWidth
:
80
,
inputWidth
:
250
},
{
type
:
'block'
,
inputWidth
:
'auto'
,
offsetTop
:
12
,
list
:
[
{
type
:
'input'
,
label
:
LANG
[
'list'
][
'edit'
][
'form'
][
'url'
],
name
:
'url'
,
required
:
true
,
value
:
data
[
'url'
]
},
{
type
:
'password'
,
label
:
LANG
[
'list'
][
'edit'
][
'form'
][
'pwd'
],
name
:
'pwd'
,
required
:
true
,
value
:
data
[
'pwd'
]
},
{
type
:
'combo'
,
label
:
LANG
[
'list'
][
'edit'
][
'form'
][
'encode'
],
readonly
:
true
,
name
:
'encode'
,
options
:
(()
=>
{
let
ret
=
[];
ENCODES
.
map
((
_
)
=>
{
ret
.
push
({
text
:
_
,
value
:
_
,
selected
:
_
===
data
[
'encode'
]
});
});
return
ret
;
})()
},
{
type
:
'combo'
,
label
:
LANG
[
'list'
][
'edit'
][
'form'
][
'type'
],
name
:
'type'
,
readonly
:
true
,
options
:
(()
=>
{
let
ret
=
[];
for
(
let
c
in
antSword
[
'core'
])
{
let
encoders
=
antSword
[
'core'
][
c
].
prototype
.
encoders
;
ret
.
push
({
text
:
c
.
toUpperCase
(),
value
:
c
,
selected
:
data
[
'type'
]
===
c
,
list
:
((
c
)
=>
{
let
_
=
[
{
type
:
'settings'
,
position
:
'label-right'
,
offsetLeft
:
60
,
labelWidth
:
100
},
{
type
:
'label'
,
label
:
LANG
[
'list'
][
'add'
][
'form'
][
'encoder'
]
},
{
type
:
'radio'
,
name
:
`encoder_
${
c
}
`
,
value
:
'default'
,
label
:
'default'
,
checked
:
(
data
[
'encoder'
]
===
'default'
)
||
(
c
!==
data
[
'type'
])
||
(
!
encoders
.
indexOf
(
data
[
'encoder'
]))
}
];
encoders
.
map
((
e
)
=>
{
_
.
push
({
type
:
'radio'
,
name
:
`encoder_
${
c
}
`
,
value
:
e
,
label
:
e
,
checked
:
data
[
'encoder'
]
===
e
})
});
return
_
;
})(
c
)
});
}
return
ret
;
})()
}
]}
],
true
);
// toolbar点击
toolbar
.
attachEvent
(
'onClick'
,
(
id
)
=>
{
switch
(
id
)
{
case
'save'
:
// 添加数据
// 判断表单数据
if
(
!
form
.
validate
())
{
return
toastr
.
warning
(
LANG
[
'list'
][
'edit'
][
'warning'
],
LANG_T
[
'warning'
]);
};
// 解析数据
let
data
=
form
.
getValues
();
data
[
'_id'
]
=
sid
;
win
.
progressOn
();
// 获取编码器
data
[
'encoder'
]
=
data
[
`encoder_
${
data
[
'type'
]}
`
]
?
data
[
`encoder_
${
data
[
'type'
]}
`
]
:
''
;
// 获取分类
data
[
'category'
]
=
this
.
category
[
'sidebar'
].
getActiveItem
()
||
'default'
;
const
ret
=
antSword
[
'ipcRenderer'
].
sendSync
(
'shell-edit'
,
data
);
// 更新UI
win
.
progressOff
();
if
(
typeof
(
ret
)
===
'number'
)
{
win
.
close
();
toastr
.
success
(
LANG
[
'list'
][
'edit'
][
'success'
],
LANG_T
[
'success'
]);
this
.
loadData
({
category
:
data
[
'category'
]
});
}
else
{
toastr
.
error
(
LANG
[
'list'
][
'edit'
][
'error'
](
ret
.
toString
()),
LANG_T
[
'error'
]);
}
break
;
case
'clear'
:
// 清空表单
form
.
clear
();
break
;
}
});
}
// 删除数据
delData
(
ids
)
{
layer
.
confirm
(
LANG
[
'list'
][
'del'
][
'confirm'
](
ids
.
length
),
{
icon
:
2
,
shift
:
6
,
title
:
`<i class="fa fa-trash"></i>
${
LANG
[
'list'
][
'del'
][
'title'
]}
`
},
(
_
)
=>
{
layer
.
close
(
_
);
const
ret
=
antSword
[
'ipcRenderer'
].
sendSync
(
'shell-del'
,
ids
);
if
(
typeof
(
ret
)
===
'number'
)
{
toastr
.
success
(
LANG
[
'list'
][
'del'
][
'success'
](
ret
),
LANG_T
[
'success'
]);
// 更新UI
this
.
loadData
({
category
:
this
.
category
[
'sidebar'
].
getActiveItem
()
||
'default'
});
}
else
{
toastr
.
error
(
LANG
[
'list'
][
'del'
][
'error'
](
ret
.
toString
()),
LANG_T
[
'error'
]);
}
});
}
// 搜索数据
searchData
()
{
// 判断当前tab是否在主页
if
(
antSword
[
'tabbar'
].
getActiveTab
()
!==
'tab_shellmanager'
)
{
this
.
cell
.
setActive
()
};
const
category
=
this
.
category
[
'sidebar'
].
getActiveItem
()
||
'default'
;
// 初始化窗口
const
win
=
this
.
createWin
({
title
:
'搜索数据 //'
+
category
,
width
:
450
,
height
:
350
});
}
// 加载数据
loadData
(
arg
)
{
// 获取当前分类
// const _category = this.category.sidebar.getActiveItem() || 'default';
// 根据分类查询数据
const
ret
=
antSword
[
'ipcRenderer'
].
sendSync
(
'shell-find'
,
arg
||
{});
let
category
=
{};
// 解析数据
let
data
=
[];
ret
.
map
((
_
)
=>
{
category
[
_
[
'category'
]
||
'default'
]
=
category
[
_
[
'category'
]
||
'default'
]
||
0
;
category
[
_
[
'category'
]
||
'default'
]
++
;
if
((
arg
instanceof
Object
)
&&
arg
[
'category'
]
&&
arg
[
'category'
]
!==
_
[
'category'
])
{
return
;
};
if
(
!
arg
&&
_
[
'category'
]
!==
'default'
)
{
return
;
};
data
.
push
({
id
:
_
[
'_id'
],
// pwd: _['pwd'],
// type: _['type'],
// encode: _['encode'] || 'utf8',
// encoder: _['encoder'] || 'default',
data
:
[
_
[
'url'
],
_
[
'ip'
],
_
[
'addr'
],
new
Date
(
_
[
'ctime'
]).
format
(
'yyyy/MM/dd hh:mm:ss'
),
new
Date
(
_
[
'utime'
]).
format
(
'yyyy/MM/dd hh:mm:ss'
)
]
});
});
// 刷新UI::左侧数据
/**
* 重新加载shell数据
* @param {object} arg = {} 查询参数
* @return {[type]} [description]
*/
reloadData
(
arg
=
{})
{
const
_data
=
Data
.
get
(
arg
);
// 刷新UI::数据
this
.
list
.
grid
.
clearAll
();
this
.
list
.
grid
.
parse
({
'rows'
:
data
'rows'
:
_data
[
'data'
]
},
'json'
);
// 刷新UI::右侧目录
if
((
arg
instanceof
Object
)
&&
arg
[
'category'
]
&&
!
category
[
arg
[
'category'
]])
{
category
[
arg
[
'category'
]]
=
0
;
};
if
(
typeof
(
category
[
'default'
])
===
'object'
)
{
category
[
'default'
]
=
0
;
};
// 1. 判断目录是否存在?更新目录bubble:添加目录
for
(
let
c
in
category
)
{
// 添加category
if
(
!
this
.
category
[
'sidebar'
].
items
(
c
))
{
// 刷新UI::分类
for
(
let
_
in
_data
[
'category'
])
{
// 目录存在,则更新bubble
if
(
!!
this
.
category
[
'sidebar'
].
items
(
_
))
{
this
.
category
[
'sidebar'
].
items
(
_
).
setBubble
(
_data
[
'category'
][
_
]);
continue
;
}
// 目录不存在,则添加
this
.
category
[
'sidebar'
].
addItem
({
id
:
c
,
bubble
:
category
[
c
],
// selected: true,
text
:
`<i class="fa fa-folder-o"></i>
${
c
}
`
id
:
_
,
bubble
:
_data
[
'category'
][
_
],
text
:
`<i class="fa fa-folder-o"></i>
${
_
}
`
});
}
else
{
this
.
category
[
'sidebar'
].
items
(
c
).
setBubble
(
category
[
c
]);
}
}
// 2. 选中默认分类
this
.
category
[
'sidebar'
].
items
((
arg
||
{})[
'category'
]
||
'default'
).
setActive
();
// 3. 更新标题
this
.
list
.
updateTitle
(
data
.
length
);
this
.
category
.
updateTitle
();
// 加载分类数据
this
.
category
.
sidebar
.
items
(
arg
[
'category'
]
||
'default'
).
setActive
(
true
);
// 更新标题
this
.
category
.
updateHeader
();
this
.
list
.
updateHeader
(
_data
[
'data'
].
length
);
}
// 创建窗口
createWin
(
opts
)
{
let
_id
=
String
(
Math
.
random
()).
substr
(
5
,
10
);
// 默认配置
let
opt
=
$
.
extend
({
title
:
'Window:'
+
_id
,
width
:
550
,
height
:
450
},
opts
);
// 创建窗口
let
_win
=
this
.
win
.
createWindow
(
_id
,
0
,
0
,
opt
[
'width'
],
opt
[
'height'
]);
_win
.
setText
(
opt
[
'title'
]);
_win
.
centerOnScreen
();
_win
.
button
(
'minmax'
).
show
();
_win
.
button
(
'minmax'
).
enable
();
// 返回窗口对象
return
_win
;
}
}
// export default ShellManager;
module
.
exports
=
ShellManager
;
source/modules/shellmanager/list.js
deleted
100644 → 0
View file @
9d61cf82
/**
* 左侧shell数据管理模块
*/
const
path
=
require
(
'path'
);
const
Terminal
=
require
(
'../terminal/'
);
const
Database
=
require
(
'../database/'
);
const
FileManager
=
require
(
'../filemanager/'
);
const
LANG_T
=
antSword
[
'language'
][
'toastr'
];
const
LANG
=
antSword
[
'language'
][
'shellmanager'
];
class
List
{
constructor
(
cell
,
manager
)
{
// cell.hideHeader();
// cell.setText(`<i class="fa fa-list-ul"></i> ${LANG['list']['title']}`);
// 删除折叠按钮
document
.
getElementsByClassName
(
'dhxlayout_arrow dhxlayout_arrow_va'
)[
0
].
remove
();
// 初始化工具栏
// const toolbar = cell.attachToolbar();
// toolbar.loadStruct([
// { id: 'add', type: 'button', text: `<i class="fa fa-plus-circle"></i> ${LANG.list.toolbar['add']}` },
// { type: 'separator' },
// { id: 'edit', type: 'button', text: `<i class="fa fa-edit"></i> ${LANG.list.toolbar['edit']}` }
// ]);
// 初始化数据表格
const
grid
=
cell
.
attachGrid
();
grid
.
setHeader
(
`
${
LANG
[
'list'
][
'grid'
][
'url'
]}
,
${
LANG
[
'list'
][
'grid'
][
'ip'
]}
,
${
LANG
[
'list'
][
'grid'
][
'addr'
]}
,
${
LANG
[
'list'
][
'grid'
][
'ctime'
]}
,
${
LANG
[
'list'
][
'grid'
][
'utime'
]}
`
);
grid
.
setColTypes
(
"ro,ro,ro,ro,ro"
);
grid
.
setColSorting
(
'str,str,str,str,str'
);
grid
.
setInitWidths
(
"200,120,*,140,140"
);
grid
.
setColAlign
(
"left,left,left,center,center"
);
grid
.
enableMultiselect
(
true
);
// 右键
grid
.
attachEvent
(
'onRightClick'
,
(
id
,
lid
,
event
)
=>
{
// 获取选中ID列表
let
ids
=
(
grid
.
getSelectedId
()
||
''
).
split
(
','
);
// 如果没有选中?则选中右键对应选项
if
(
ids
.
length
===
1
)
{
grid
.
selectRowById
(
id
);
ids
=
[
id
];
}
// 获取选择数据信息
let
infos
=
[];
if
(
ids
.
length
>=
1
)
{
infos
=
antSword
[
'ipcRenderer'
].
sendSync
(
'shell-find'
,
{
_id
:
{
$in
:
ids
}
}
)
}
// 获取选中的单条数据
let
info
=
infos
[
0
];
// let info = {};
// if (id && ids.length === 1) {
// info = antSword['ipcRenderer'].sendSync('shell-findOne', id);
// };
bmenu
([
{
text
:
LANG
[
'contextmenu'
][
'terminal'
],
icon
:
'fa fa-terminal'
,
disabled
:
!
id
||
ids
.
length
!==
1
,
action
:
()
=>
{
new
Terminal
(
info
);
}
},
{
text
:
LANG
[
'contextmenu'
][
'filemanager'
],
icon
:
'fa fa-folder-o'
,
disabled
:
!
id
||
ids
.
length
!==
1
,
action
:
()
=>
{
new
FileManager
(
info
);
}
},
{
text
:
LANG
[
'contextmenu'
][
'database'
],
icon
:
'fa fa-database'
,
disabled
:
!
id
||
ids
.
length
!==
1
,
action
:
()
=>
{
new
Database
(
info
);
}
},
{
divider
:
true
},
// 加载插件列表
{
text
:
LANG
[
'contextmenu'
][
'plugin'
],
icon
:
'fa fa-folder-o'
,
disabled
:
!
id
,
subMenu
:
(()
=>
{
// 1. 遍历插件分类信息
let
plugins
=
{
default
:
[]
};
for
(
let
_
in
antSword
[
'plugins'
])
{
let
p
=
antSword
[
'plugins'
][
_
];
plugins
[
p
[
'info'
][
'category'
]
||
'default'
]
=
plugins
[
p
[
'info'
][
'category'
]
||
'default'
]
||
[];
plugins
[
p
[
'info'
][
'category'
]
||
'default'
].
push
(
p
);
}
// 2. 解析分类数据
let
pluginItems
=
[];
for
(
let
_
in
plugins
)
{
// 0x01 添加分类目录
pluginItems
.
push
({
text
:
antSword
.
noxss
(
_
===
'default'
?
LANG
[
'contextmenu'
][
'pluginDefault'
]
:
_
),
icon
:
'fa fa-folder-open-o'
,
disabled
:
plugins
[
_
].
length
===
0
,
subMenu
:
((
plugs
)
=>
{
let
plugItems
=
[];
// 0x02 添加目录数据
plugs
.
map
((
p
)
=>
{
plugItems
.
push
({
text
:
antSword
.
noxss
(
p
[
'info'
][
'name'
]),
icon
:
`fa fa-
${
p
[
'info'
][
'icon'
]
||
'puzzle-piece'
}
`
,
disabled
:
ids
.
length
>
1
?
(()
=>
{
let
ret
=
false
;
// 判断脚本是否支持,不支持则禁止
if
(
p
[
'info'
][
'scripts'
]
&&
p
[
'info'
][
'scripts'
].
length
>
0
)
{
infos
.
map
((
_info
)
=>
{
if
(
p
[
'info'
][
'scripts'
].
indexOf
(
_info
[
'type'
])
===
-
1
)
{
// 如果检测到不支持的脚本,则禁止
ret
=
true
;
}
});
}
// 判断是否支持多目标执行
return
ret
||
!
p
[
'info'
][
'multiple'
];
})()
:
info
&&
(
p
[
'info'
][
'scripts'
]
||
[]).
indexOf
(
info
[
'type'
])
===
-
1
,
action
:
((
plug
)
=>
()
=>
{
// 如果没有加载到内存,则加载
if
(
!
antSword
[
'plugins'
][
plug
[
'_id'
]][
'module'
])
{
antSword
[
'plugins'
][
plug
[
'_id'
]][
'module'
]
=
require
(
path
.
join
(
plug
[
'path'
],
plug
[
'info'
][
'main'
]
||
'index.js'
)
);
}
// 执行插件
new
antSword
[
'plugins'
][
plug
[
'_id'
]][
'module'
](
infos
.
length
===
1
&&
!
plug
[
'info'
][
'multiple'
]
?
info
:
infos
);
})(
p
)
})
});
return
plugItems
;
})(
plugins
[
_
])
})
}
return
pluginItems
;
})()
},
{
// text: LANG['contextmenu']['pluginManager'],
// icon: 'fa fa-th-large',
// action: antSword['menubar'].run.bind(antSword['menubar'], 'plugin-local')
// }, {
text
:
LANG
[
'contextmenu'
][
'pluginStore'
],
icon
:
'fa fa-cart-arrow-down'
,
action
:
antSword
[
'menubar'
].
run
.
bind
(
antSword
[
'menubar'
],
'plugin-store'
)
},
{
divider
:
true
},
{
text
:
LANG
[
'contextmenu'
][
'add'
],
icon
:
'fa fa-plus-circle'
,
action
:
manager
.
addData
.
bind
(
manager
)
},
{
text
:
LANG
[
'contextmenu'
][
'edit'
],
icon
:
'fa fa-edit'
,
disabled
:
!
id
||
ids
.
length
!==
1
,
action
:
()
=>
{
manager
.
editData
(
id
);
}
},
{
text
:
LANG
[
'contextmenu'
][
'delete'
],
icon
:
'fa fa-remove'
,
disabled
:
!
id
,
action
:
()
=>
{
manager
.
delData
(
ids
);
}
},
{
divider
:
true
},
{
text
:
LANG
[
'contextmenu'
][
'move'
],
icon
:
'fa fa-share-square'
,
disabled
:
!
id
,
subMenu
:
(()
=>
{
const
items
=
manager
.
category
.
sidebar
.
getAllItems
();
const
category
=
manager
.
category
.
sidebar
.
getActiveItem
();
let
ret
=
[];
items
.
map
((
_
)
=>
{
ret
.
push
({
text
:
_
===
'default'
?
LANG
[
'category'
][
'default'
]
:
_
,
icon
:
'fa fa-folder-o'
,
disabled
:
category
===
_
,
action
:
((
c
)
=>
{
return
()
=>
{
const
ret
=
antSword
[
'ipcRenderer'
].
sendSync
(
'shell-move'
,
{
ids
:
ids
,
category
:
c
});
if
(
typeof
(
ret
)
===
'number'
)
{
toastr
.
success
(
LANG
[
'list'
][
'move'
][
'success'
](
ret
),
LANG_T
[
'success'
]);
manager
.
loadData
();
manager
.
category
.
sidebar
.
callEvent
(
'onSelect'
,
[
c
]);
}
else
{
toastr
.
error
(
LANG
[
'list'
][
'move'
][
'error'
](
ret
),
LANG_T
[
'error'
]);
}
}
})(
_
)
});
});
return
ret
;
})()
},
{
text
:
LANG
[
'contextmenu'
][
'search'
],
icon
:
'fa fa-search'
,
action
:
manager
.
searchData
.
bind
(
manager
),
disabled
:
true
},
{
divider
:
true
},
{
text
:
LANG
[
'contextmenu'
][
'clearCache'
],
icon
:
'fa fa-trash-o'
,
disabled
:
!
id
,
action
:
()
=>
{
manager
.
clearCache
(
id
);
}
},
{
text
:
LANG
[
'contextmenu'
][
'clearAllCache'
],
icon
:
'fa fa-trash'
,
action
:
manager
.
clearAllCache
.
bind
(
manager
)
}
],
event
);
return
true
;
});
// 双击
grid
.
attachEvent
(
'onRowDblClicked'
,
(
id
)
=>
{
const
info
=
antSword
[
'ipcRenderer'
].
sendSync
(
'shell-findOne'
,
id
);
new
FileManager
(
info
);
});
// 隐藏右键菜单
grid
.
attachEvent
(
'onRowSelect'
,
bmenu
.
hide
);
$
(
'.objbox'
).
on
(
'click'
,
bmenu
.
hide
);
$
(
'.objbox'
).
on
(
'contextmenu'
,
(
e
)
=>
{
(
e
.
target
.
nodeName
===
'DIV'
&&
grid
.
callEvent
instanceof
Function
)
?
grid
.
callEvent
(
'onRightClick'
,
[
grid
.
getSelectedRowId
(),
''
,
e
])
:
0
;
});
grid
.
init
();
// 变量赋值
this
.
grid
=
grid
;
this
.
cell
=
cell
;
this
.
toolbar
=
toolbar
;
}
// 更新标题
updateTitle
(
num
)
{
this
.
cell
.
setText
(
`<i class="fa fa-list-ul"></i>
${
LANG
[
'list'
][
'title'
]}
(
${
num
}
)`
);
}
}
// export default List;
module
.
exports
=
List
;
source/modules/shellmanager/list/contextmenu.js
0 → 100644
View file @
979da3c1
/**
* 右键菜单
*/
const
DATA
=
require
(
'../data'
);
const
LANG
=
antSword
[
'language'
][
'shellmanager'
][
'contextmenu'
];
class
ContextMenu
{
/**
* 初始化函数
* @param {array} data 选中的数据
* @param {object} event 右键事件对象
* @return {[type]} [description]
*/
constructor
(
data
,
event
,
id
,
ids
)
{
let
selectedData
=
!
id
||
ids
.
length
!==
1
;
let
selectedMultiData
=
!
id
;
// 解析菜单事件
let
menuItems
=
[];
[
// text, icon, disabled, action, submenu
[
'terminal'
,
'terminal'
,
selectedData
],
[
'filemanager'
,
'folder-o'
,
selectedData
],
[
'database'
,
'database'
,
selectedData
],
false
,
[
'plugin'
,
'folder-o'
,
selectedMultiData
,
null
,
this
.
parsePlugContextMenu
(
data
)],
[
'pluginStore'
,
'cart-arrow-down'
,
false
,
antSword
[
'menubar'
].
run
.
bind
(
antSword
[
'menubar'
],
'plugin-store'
)
],
false
,
[
'add'
,
'plus-circle'
,
false
,
this
.
addData
.
bind
(
this
)],
[
'edit'
,
'edit'
,
selectedData
,
this
.
editData
.
bind
(
this
,
id
)],
[
'delete'
,
'remove'
,
selectedMultiData
,
this
.
delData
.
bind
(
this
,
ids
)],
false
,
[
'move'
,
'share-square'
,
selectedMultiData
],
[
'search'
,
'search'
,
true
],
false
,
[
'clearCache'
,
'trash-o'
,
selectedMultiData
,
this
.
clearCache
.
bind
(
this
,
ids
)],
[
'clearAllCache'
,
'trash'
,
false
,
this
.
clearAllCache
.
bind
(
this
)]
].
map
((
menu
)
=>
{
// 分隔符号
if
(
!
menu
)
{
return
menuItems
.
push
({
divider
:
true
})
}
let
menuObj
=
{
text
:
LANG
[
menu
[
0
]],
icon
:
`fa fa-
${
menu
[
1
]}
`
,
disabled
:
menu
[
2
]
}
// 点击事件
if
(
menu
[
3
]
instanceof
Function
)
{
menuObj
[
'action'
]
=
menu
[
3
];
}
// 子菜单
if
(
Array
.
isArray
(
menu
[
4
]))
{
menuObj
[
'subMenu'
]
=
menu
[
4
];
}
menuItems
.
push
(
menuObj
);
});
// 弹出菜单
bmenu
(
menuItems
,
event
);
//
// { divider: true },
// { text: LANG['add'], icon: 'fa fa-plus-circle', action: this.addData.bind(this) },
// {
// text: LANG['edit'], icon: 'fa fa-edit', disabled: selectedData,
// action: this.editData.bind(this, id)
// }, {
// text: LANG['delete'], icon: 'fa fa-remove', disabled: selectedMultiData,
// action: this.delData.bind(this, ids)
// }, {
// divider: true
// }, { text: LANG['move'], icon: 'fa fa-share-square', disabled: selectedMultiData }, //subMenu: (() => {
// // const items = manager.category.sidebar.getAllItems();
// // const category = manager.category.sidebar.getActiveItem();
// // let ret = [];
// // items.map((_) => {
// // ret.push({
// // text: _ === 'default' ? LANG['category']['default'] : _,
// // icon: 'fa fa-folder-o',
// // disabled: category === _,
// // action: ((c) => {
// // return () => {
// // const ret = antSword['ipcRenderer'].sendSync('shell-move', {
// // ids: ids,
// // category: c
// // });
// // if (typeof(ret) === 'number') {
// // toastr.success(LANG['list']['move']['success'](ret), LANG_T['success']);
// // manager.loadData();
// // manager.category.sidebar.callEvent('onSelect', [c]);
// // }else{
// // toastr.error(LANG['list']['move']['error'](ret), LANG_T['error']);
// // }
// // }
// // })(_)
// // });
// // });
// // return ret;
// // })() },
// {
// text: LANG['search'], icon: 'fa fa-search', action: this.searchData.bind(this), disabled: true
// }, {
// divider: true
// }, {
// text: LANG['clearCache'], icon: 'fa fa-trash-o',
// disabled: selectedMultiData, action: this.clearCache.bind(this, ids)
// }, {
// text: LANG['clearAllCache'], icon: 'fa fa-trash', action: this.clearAllCache.bind(this)
// }
// ], event);
}
/**
* 把插件列表解析成右键菜单所需要的数据
* @return {array} [description]
*/
parsePlugContextMenu
(
data
)
{
let
info
=
data
[
0
];
let
infos
=
data
;
// 1. 遍历插件分类信息
let
plugins
=
{
default
:
[]
};
for
(
let
_
in
antSword
[
'plugins'
])
{
let
p
=
antSword
[
'plugins'
][
_
];
let
c
=
p
[
'info'
][
'category'
]
||
'default'
;
plugins
[
c
]
=
plugins
[
c
]
||
[];
plugins
[
c
].
push
(
p
);
}
// 2. 解析分类数据
let
pluginItems
=
[];
for
(
let
_
in
plugins
)
{
// 0x01 添加分类目录
pluginItems
.
push
({
text
:
antSword
.
noxss
(
_
===
'default'
?
LANG
[
'pluginDefault'
]
:
_
),
icon
:
'fa fa-folder-open-o'
,
disabled
:
plugins
[
_
].
length
===
0
,
subMenu
:
((
plugs
)
=>
{
let
plugItems
=
[];
// 0x02 添加目录数据
plugs
.
map
((
p
)
=>
{
plugItems
.
push
({
text
:
antSword
.
noxss
(
p
[
'info'
][
'name'
]),
icon
:
`fa fa-
${
p
[
'info'
][
'icon'
]
||
'puzzle-piece'
}
`
,
disabled
:
infos
.
length
>
1
?
(()
=>
{
let
ret
=
false
;
// 判断脚本是否支持,不支持则禁止
if
(
p
[
'info'
][
'scripts'
]
&&
p
[
'info'
][
'scripts'
].
length
>
0
)
{
infos
.
map
((
_info
)
=>
{
if
(
p
[
'info'
][
'scripts'
].
indexOf
(
_info
[
'type'
])
===
-
1
)
{
// 如果检测到不支持的脚本,则禁止
ret
=
true
;
}
});
}
// 判断是否支持多目标执行
return
ret
||
!
p
[
'info'
][
'multiple'
];
})()
:
info
&&
(
p
[
'info'
][
'scripts'
]
||
[]).
indexOf
(
info
[
'type'
])
===
-
1
,
action
:
((
plug
)
=>
()
=>
{
// 如果没有加载到内存,则加载
if
(
!
antSword
[
'plugins'
][
plug
[
'_id'
]][
'module'
])
{
antSword
[
'plugins'
][
plug
[
'_id'
]][
'module'
]
=
require
(
path
.
join
(
plug
[
'path'
],
plug
[
'info'
][
'main'
]
||
'index.js'
)
);
}
// 执行插件
new
antSword
[
'plugins'
][
plug
[
'_id'
]][
'module'
](
infos
.
length
===
1
&&
!
plug
[
'info'
][
'multiple'
]
?
info
:
infos
);
})(
p
)
})
});
return
plugItems
;
})(
plugins
[
_
])
})
}
return
pluginItems
;
}
/**
* 添加数据
*/
addData
()
{
}
/**
* 编辑数据
* @param {number} id [description]
* @return {[type]} [description]
*/
editData
(
id
)
{
}
/**
* 删除数据
* @param {array} ids [description]
* @return {[type]} [description]
*/
delData
(
ids
)
{
}
/**
* 搜索数据
* @return {[type]} [description]
*/
searchData
()
{
}
/**
* 清空缓存
* @param {array} ids [description]
* @return {[type]} [description]
*/
clearCache
(
ids
)
{
}
/**
* 清空所有缓存
* @return {[type]} [description]
*/
clearAllCache
()
{
}
}
module
.
exports
=
ContextMenu
;
source/modules/shellmanager/list/grid.js
0 → 100644
View file @
979da3c1
/**
* 数据表格模块
*/
const
LANG
=
antSword
[
'language'
][
'shellmanager'
][
'list'
][
'grid'
];
const
ContextMenu
=
require
(
'./contextmenu'
);
class
Grid
{
/**
* 初始化函数
* @param {object} cell dhtmlx.cell对象
* @param {object} top 父层list对象
* @return {[type]} [description]
*/
constructor
(
cell
,
top
)
{
// 初始化grid
const
grid
=
cell
.
attachGrid
();
// 设置grid头
grid
.
setHeader
(
`
${
LANG
[
'url'
]}
,
${
LANG
[
'ip'
]}
,
${
LANG
[
'addr'
]}
,
${
LANG
[
'ctime'
]}
,
${
LANG
[
'utime'
]}
`
);
grid
.
setColTypes
(
"ro,ro,ro,ro,ro"
);
grid
.
setColSorting
(
'str,str,str,str,str'
);
grid
.
setInitWidths
(
"200,120,*,140,140"
);
grid
.
setColAlign
(
"left,left,left,center,center"
);
grid
.
enableMultiselect
(
true
);
// 隐藏右键菜单
grid
.
attachEvent
(
'onRowSelect'
,
bmenu
.
hide
);
$
(
'.objbox'
)
.
on
(
'click'
,
bmenu
.
hide
)
.
on
(
'contextmenu'
,
(
e
)
=>
{
if
(
e
.
target
.
nodeName
===
'DIV'
&&
grid
.
callEvent
instanceof
Function
)
{
grid
.
callEvent
(
'onRightClick'
,
[
grid
.
getSelectedRowId
(),
''
,
e
]);
}
});
// 监听事件
grid
.
attachEvent
(
'onRightClick'
,
this
.
_onRightClick
);
grid
.
attachEvent
(
'onRowDblClicked'
,
this
.
_onRowDblClicked
);
grid
.
init
();
return
grid
;
}
/**
* 右键事件
* @param {number} id 选择ID
* @param {number} lid 上一ID
* @param {object} event [description]
* @return {[type]} [description]
*/
_onRightClick
(
id
,
lid
,
event
)
{
// 解析出选中的数据信息
let
ids
=
(
this
.
getSelectedId
()
||
''
).
split
(
','
);
// 如果没有选中?则选中右键对应选项
if
(
ids
.
length
===
1
)
{
this
.
selectRowById
(
id
);
ids
=
[
id
];
}
// 获取选择数据信息
let
infos
=
[];
if
(
ids
.
length
>=
1
)
{
infos
=
antSword
[
'ipcRenderer'
].
sendSync
(
'shell-find'
,
{
_id
:
{
$in
:
ids
}
}
)
}
// 获取选中的单条数据
let
info
=
infos
[
0
];
// 弹出右键菜单
new
ContextMenu
(
infos
,
event
,
id
,
ids
);
return
true
;
}
/**
* 双击事件
* @param {[type]} id [description]
* @param {[type]} event [description]
* @return {[type]} [description]
*/
_onRowDblClicked
(
id
,
event
)
{
}
}
module
.
exports
=
Grid
;
source/modules/shellmanager/list/index.js
0 → 100644
View file @
979da3c1
/**
* 左侧数据列表模块
*/
const
Grid
=
require
(
'./grid'
);
// const LANG_T = antSword['language']['toastr'];
const
LANG
=
antSword
[
'language'
][
'shellmanager'
][
'list'
];
class
List
{
/**
* 初始化函数
* @param {Object} cell dhtmlx cell-object
* @param {Object} top shell-manager obj
* @return {[type]} [description]
*/
constructor
(
cell
,
top
)
{
// 删除折叠按钮
document
.
getElementsByClassName
(
'dhxlayout_arrow dhxlayout_arrow_va'
)[
0
].
remove
();
this
.
cell
=
cell
;
this
.
grid
=
new
Grid
(
cell
,
this
);
this
.
updateHeader
();
}
/**
* 更新标题
* @param {number} num 数据总数
* @return {[type]} [description]
*/
updateHeader
(
num
=
0
)
{
this
.
cell
.
setText
(
`<i class="fa fa-list-ul"></i>
${
LANG
[
'title'
]}
(
${
num
}
)`
);
}
}
module
.
exports
=
List
;
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