Skip to content

Commit

Permalink
(Enhance:Module::ShellManager) 新增测试连接功能
Browse files Browse the repository at this point in the history
  • Loading branch information
Medicean committed Jan 30, 2019
1 parent 9713e7e commit 7f467af
Show file tree
Hide file tree
Showing 4 changed files with 82 additions and 26 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@

### Shell 管理

* 新增「测试连接」功能
* 其它设置增加「开启分块传输」开关,设置「最小分块」和「最大分块」。每次分块大小为[n, m]区间。

![chunk-1.png](https://i.loli.net/2019/01/28/5c4e8868f178a.png)
Expand Down
3 changes: 3 additions & 0 deletions source/language/en.js
Original file line number Diff line number Diff line change
Expand Up @@ -106,6 +106,7 @@ module.exports = {
add: {
title: 'Add shell',
toolbar: {
test: 'Test Connection',
add: 'Add',
clear: 'Clear'
},
Expand All @@ -117,6 +118,8 @@ module.exports = {
type: 'Shell type',
encoder: 'Encoder'
},
test_success: 'Connection Successful!',
test_warning: 'Response is null!',
warning: 'Please enter the full!',
success: 'Add shell success!',
error: (err) => antSword.noxss(`Add shell failed!\n${err}`)
Expand Down
3 changes: 3 additions & 0 deletions source/language/zh.js
Original file line number Diff line number Diff line change
Expand Up @@ -107,6 +107,7 @@ module.exports = {
add: {
title: '添加数据',
toolbar: {
test: '测试连接',
add: '添加',
clear: '清空'
},
Expand All @@ -118,6 +119,8 @@ module.exports = {
type: '连接类型',
encoder: '编码器'
},
test_success: '连接成功!',
test_warning: '返回数据为空',
warning: '请输入完整!',
success: '添加数据成功!',
error: (err) => antSword.noxss(`添加数据失败!\n${err}`)
Expand Down
101 changes: 75 additions & 26 deletions source/modules/shellmanager/list/form.js
Original file line number Diff line number Diff line change
Expand Up @@ -27,36 +27,82 @@ class Form {

// toolbar点击事件
this.toolbar.attachEvent('onClick', (id) => {
if (id === 'clear') {
return this.baseForm.clear();
}
// 检测表单数据
if (
!this.baseForm.validate() ||
!this.httpForm.validate() ||
!this.otherForm.validate()
) {
return toastr.warning(LANG['list']['add']['warning'], LANG_T['warning']);
};
// 回调数据
if (callback) {
win.progressOn();
setTimeout(() => {
callback(this._parseFormData(
switch(id){
case 'clear':
this.baseForm.clear();
break;
case 'test':
if (
!this.baseForm.validate() ||
!this.httpForm.validate() ||
!this.otherForm.validate()
) {
return toastr.warning(LANG['list']['add']['warning'], LANG_T['warning']);
};
let opts = this._parseFormData(
this.baseForm.getValues(),
this.httpForm.getValues(),
this.otherForm.getValues()
)).then((msg) => {
// 添加/保存完毕后回调
win.close();
toastr.success(msg, LANG_T['success']);
}).catch((msg) => {
// 添加/保存错误
);
let opt = {
"url": opts.base['url'],
"pwd": opts.base['pwd'],
"type": opts.base['type'],
"encode": opts.base['encode'],
"encoder": opts.base['encoder'],
"httpConf": opts.http,
"otherConf": opts.other,
}
win.progressOn();
let core = new antSword["core"][opt['type']](opt);
core.request(
core.base.info()
)
.then((ret) => {
if(ret['text'].length > 0){
toastr.success(LANG['list']['add']['test_success'], LANG_T['success']);
}else{
toastr.warning(LANG['list']['add']['test_warning'], LANG_T['warning']);
}
win.progressOff();
})
.catch((err)=>{
toastr.error(JSON.stringify(err), LANG_T['error']);
win.progressOff();
toastr.error(msg, LANG_T['error']);
});
}, 100);
};
break;
case 'act':
// 检测表单数据
if (
!this.baseForm.validate() ||
!this.httpForm.validate() ||
!this.otherForm.validate()
) {
return toastr.warning(LANG['list']['add']['warning'], LANG_T['warning']);
};
// 回调数据
if (callback) {
win.progressOn();
setTimeout(() => {
callback(this._parseFormData(
this.baseForm.getValues(),
this.httpForm.getValues(),
this.otherForm.getValues()
)).then((msg) => {
// 添加/保存完毕后回调
win.close();
toastr.success(msg, LANG_T['success']);
}).catch((msg) => {
// 添加/保存错误
win.progressOff();
toastr.error(msg, LANG_T['error']);
});
}, 100);
};
break;
default:
break;
}
});
}

Expand Down Expand Up @@ -109,7 +155,10 @@ class Form {
type: 'button',
icon: 'remove',
text: LANG['list']['add']['toolbar']['clear']
}]);
},
{ type: 'separator' },
{ id: 'test', type: 'button', 'icon': 'spinner', text: LANG['list']['add']['toolbar']['test'] },
]);
return toolbar;
}

Expand Down

1 comment on commit 7f467af

@Medicean
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please sign in to comment.