From 7f467af42728849dd014f396c3e37b5a53c02612 Mon Sep 17 00:00:00 2001 From: Medicean Date: Wed, 30 Jan 2019 17:31:24 +0800 Subject: [PATCH] =?UTF-8?q?(Enhance:Module::ShellManager)=20=E6=96=B0?= =?UTF-8?q?=E5=A2=9E=E6=B5=8B=E8=AF=95=E8=BF=9E=E6=8E=A5=E5=8A=9F=E8=83=BD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- CHANGELOG.md | 1 + source/language/en.js | 3 + source/language/zh.js | 3 + source/modules/shellmanager/list/form.js | 101 +++++++++++++++++------ 4 files changed, 82 insertions(+), 26 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 25fb01af..0eb395b1 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -12,6 +12,7 @@ ### Shell 管理 +* 新增「测试连接」功能 * 其它设置增加「开启分块传输」开关,设置「最小分块」和「最大分块」。每次分块大小为[n, m]区间。 ![chunk-1.png](https://i.loli.net/2019/01/28/5c4e8868f178a.png) diff --git a/source/language/en.js b/source/language/en.js index 3c3378a8..90503e23 100644 --- a/source/language/en.js +++ b/source/language/en.js @@ -106,6 +106,7 @@ module.exports = { add: { title: 'Add shell', toolbar: { + test: 'Test Connection', add: 'Add', clear: 'Clear' }, @@ -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}`) diff --git a/source/language/zh.js b/source/language/zh.js index 190f1d82..b9871d09 100644 --- a/source/language/zh.js +++ b/source/language/zh.js @@ -107,6 +107,7 @@ module.exports = { add: { title: '添加数据', toolbar: { + test: '测试连接', add: '添加', clear: '清空' }, @@ -118,6 +119,8 @@ module.exports = { type: '连接类型', encoder: '编码器' }, + test_success: '连接成功!', + test_warning: '返回数据为空', warning: '请输入完整!', success: '添加数据成功!', error: (err) => antSword.noxss(`添加数据失败!\n${err}`) diff --git a/source/modules/shellmanager/list/form.js b/source/modules/shellmanager/list/form.js index 3e016190..89d8206f 100644 --- a/source/modules/shellmanager/list/form.js +++ b/source/modules/shellmanager/list/form.js @@ -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; + } }); } @@ -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; }