Commit fd623b70 authored by Medicean's avatar Medicean

Merge branch 'db_editconf' into db_exec_dml

parents ef6c9d13 5dc51f42
......@@ -41,6 +41,7 @@ class Database {
.on('shell-clear', this.clearShell.bind(this))
.on('shell-findOne', this.findOneShell.bind(this))
.on('shell-addDataConf', this.addDataConf.bind(this))
.on('shell-editDataConf', this.editDataConf.bind(this))
.on('shell-delDataConf', this.delDataConf.bind(this))
.on('shell-getDataConf', this.getDataConf.bind(this))
.on('shell-renameCategory', this.renameShellCategory.bind(this));
......@@ -261,6 +262,34 @@ class Database {
});
}
/**
* 修改数据库配置
* @param {Object} event ipcMain对象
* @param {Object} opts 配置(_id,id,data
*/
editDataConf(event, opts) {
logger.info('editDataConf', opts);
// 1. 获取原配置列表
this.cursor.findOne({
_id: opts['_id']
}, (err, ret) => {
let confs = ret['database'] || {};
// 添加到配置
confs[opts['id']] = opts['data'];
// 更新数据库
this.cursor.update({
_id: opts['_id']
}, {
$set: {
database: confs,
utime: +new Date
}
}, (_err, _ret) => {
event.returnValue = opts['id'];
});
});
}
/**
* 删除数据库配置
* @param {Object} event ipcMain对象
......
......@@ -6,4 +6,4 @@ jdbc:sqlserver://127.0.0.1:1433;databaseName=test;user=sa;password=123456
</X>
*/
module.exports = require('default');
\ No newline at end of file
module.exports = require('./default');
\ No newline at end of file
......@@ -338,9 +338,11 @@ module.exports = {
title: 'Config list',
add: 'Add',
del: 'Del',
edit: 'Edit',
menu: {
add: 'Add conf',
del: 'Del conf'
del: 'Del conf',
edit: 'Edit conf'
}
},
query: {
......@@ -364,8 +366,10 @@ module.exports = {
title: 'Add conf',
toolbar: {
add: 'Add',
clear: 'Clear'
clear: 'Clear',
edit: 'Edit'
},
conn: 'Connection String',
type: 'Database type',
encode: 'Database encode',
host: 'Host',
......
......@@ -339,9 +339,11 @@ module.exports = {
title: '配置列表',
add: '添加',
del: '删除',
edit: '编辑',
menu: {
add: '添加配置',
del: '删除配置'
del: '删除配置',
edit: '编辑配置'
}
},
query: {
......@@ -365,8 +367,10 @@ module.exports = {
title: '添加配置',
toolbar: {
add: '添加',
clear: '清空'
clear: '清空',
edit: '编辑'
},
conn: '连接字符串',
type: '数据库类型',
encode: '数据库编码',
host: '数据库地址',
......
......@@ -3,6 +3,9 @@
// 支持数据库:access,sqlserver,mysql
//
const LANG = antSword['language']['database'];
const LANG_T = antSword['language']['toastr'];
class ASP {
constructor(opt) {
......@@ -91,13 +94,19 @@ class ASP {
this.tree.callEvent('onClick', [id]);
bmenu([
{
text: '添加配置',
text: LANG['list']['menu']['add'],
icon: 'fa fa-plus-circle',
action: this.addConf.bind(this)
}, {
divider: true
}, {
text: '删除配置',
text: LANG['list']['menu']['edit'],
icon: 'fa fa-edit',
action: this.editConf.bind(this)
}, {
divider: true
}, {
text: LANG['list']['menu']['del'],
icon: 'fa fa-remove',
action: this.delConf.bind(this)
}
......@@ -140,7 +149,7 @@ class ASP {
const hash = (+new Date * Math.random()).toString(16).substr(2, 8);
// 创建窗口
const win = this.manager.win.createWindow(hash, 0, 0, 450, 300);
win.setText('添加配置');
win.setText(LANG['form']['title']);
win.centerOnScreen();
win.button('minmax').hide();
win.setModal(true);
......@@ -151,21 +160,21 @@ class ASP {
id: 'add',
type: 'button',
icon: 'plus-circle',
text: '添加'
text: LANG['form']['toolbar']['add']
}, {
type: 'separator'
}, {
id: 'clear',
type: 'button',
icon: 'remove',
text: '清空'
text: LANG['form']['toolbar']['clear']
}]);
// form
const form = win.attachForm([
{ type: 'settings', position: 'label-left', labelWidth: 80, inputWidth: 280 },
{ type: 'block', inputWidth: 'auto', offsetTop: 12, list: [
{ type: 'combo', label: '数据库类型', readonly: true, name: 'type', options: (() => {
{ type: 'combo', label: LANG['form']['type'], readonly: true, name: 'type', options: (() => {
let ret = [];
for (let _ in this.conns) {
ret.push({
......@@ -175,7 +184,7 @@ class ASP {
}
return ret;
})() },
{ type: 'input', label: '连接字符串', name: 'conn', required: true, value: 'Dsn=DsnName;', rows: 9 }
{ type: 'input', label: LANG['form']['conn'], name: 'conn', required: true, value: 'Dsn=DsnName;', rows: 9 }
]}
], true);
......@@ -194,8 +203,8 @@ class ASP {
break;
case 'add':
if (!form.validate()) {
return '填写完整!';
// return toastr.warning(LANG['list']['add']['warning'], LANG_T['warning']);
// return '填写完整!';
return toastr.warning(LANG['form']['warning'], LANG_T['warning']);
};
// 解析数据
let data = form.getValues();
......@@ -205,7 +214,7 @@ class ASP {
data: data
});
win.close();
toastr.success('添加配置成功!');
toastr.success(LANG['form']['success'], LANG_T['success']);
this.tree.insertNewItem(0,
`conn::${id}`,
// `${data['type']}:\/\/${data['user']}@${data['host']}`,
......@@ -220,12 +229,97 @@ class ASP {
});
}
// 修改配置
editConf() {
const id = this.tree.getSelected().split('::')[1];
// 获取配置
const conf = antSword['ipcRenderer'].sendSync('shell-getDataConf', {
_id: this.manager.opt['_id'],
id: id
});
const hash = (+new Date * Math.random()).toString(16).substr(2, 8);
// 创建窗口
const win = this.manager.win.createWindow(hash, 0, 0, 450, 300);
win.setText(LANG['form']['title']);
win.centerOnScreen();
win.button('minmax').hide();
win.setModal(true);
win.denyResize();
// 工具栏
const toolbar = win.attachToolbar();
toolbar.loadStruct([{
id: 'edit',
type: 'button',
icon: 'edit',
text: LANG['form']['toolbar']['edit']
}, {
type: 'separator'
}, {
id: 'clear',
type: 'button',
icon: 'remove',
text: LANG['form']['toolbar']['clear']
}]);
// form
const form = win.attachForm([
{ type: 'settings', position: 'label-left', labelWidth: 80, inputWidth: 280 },
{ type: 'block', inputWidth: 'auto', offsetTop: 12, list: [
{ type: 'combo', label: LANG['form']['type'], readonly: true, name: 'type', options: (() => {
let ret = [];
for (let _ in this.conns) {
ret.push({
text: _.toUpperCase(),
value: _,
selected: conf['type'] === _
});
}
return ret;
})() },
{ type: 'input', label: LANG['form']['conn'], name: 'conn', required: true, value: conf['conn'], rows: 9 }
]}
], true);
form.attachEvent('onChange', (_, id) => {
if (_ !== 'type') { return };
form.setFormData({
conn: this.conns[id]
});
});
// 工具栏点击事件
toolbar.attachEvent('onClick', (id) => {
switch(id) {
case 'clear':
form.clear();
break;
case 'edit':
if (!form.validate()) {
return toastr.warning(LANG['form']['warning'], LANG_T['warning']);
};
// 解析数据
let data = form.getValues();
// 验证是否连接成功(获取数据库列表)
const id = antSword['ipcRenderer'].sendSync('shell-editDataConf', {
_id: this.manager.opt['_id'],
id: this.tree.getSelected().split('::')[1],
data: data
});
win.close();
toastr.success(LANG['form']['success'], LANG_T['success']);
// 刷新 UI
this.parse();
break;
}
});
}
// 删除配置
delConf() {
const id = this.tree.getSelected().split('::')[1];
layer.confirm('确定删除此配置吗?', {
layer.confirm(LANG['form']['del']['confirm'], {
icon: 2, shift: 6,
title: '删除配置'
title: LANG['form']['del']['title']
}, (_) => {
layer.close(_);
const ret = antSword['ipcRenderer'].sendSync('shell-delDataConf', {
......@@ -233,7 +327,7 @@ class ASP {
id: id
});
if (ret === 1) {
toastr.success('删除配置成功!');
toastr.success(LANG['form']['del']['success'], LANG_T['success']);
this.tree.deleteItem(`conn::${id}`);
// 禁用按钮
this.disableToolbar();
......@@ -241,7 +335,7 @@ class ASP {
// ['edit', 'del'].map(this.toolbar::this.toolbar.disableItem);
// this.parse();
}else{
toastr.error('删除配置失败!<br/>' + ret);
toastr.error(LANG['form']['del']['error'](ret), LANG_T['error']);
}
});
}
......@@ -265,7 +359,7 @@ class ASP {
let ret = res['text'];
const arr = ret.split('\t');
if (arr.length === 1 && ret === '') {
toastr.warning('执行完毕,没有结果返回')
toastr.warning(LANG['result']['warning'], LANG_T['warning']);
return this.manager.list.layout.progressOff();
};
// 删除子节点
......@@ -284,7 +378,7 @@ class ASP {
});
this.manager.list.layout.progressOff();
}).catch((err) => {
toastr.error('获取数据库列表失败!' + err['status'] || JSON.stringify(err), 'ERROR');
toastr.error(LANG['result']['error']['database'](err['status'] || JSON.stringify(err)), LANG_T['error']);
this.manager.list.layout.progressOff();
});
}
......@@ -325,6 +419,9 @@ class ASP {
);
});
this.manager.list.layout.progressOff();
}).catch((err) => {
toastr.error(LANG['result']['error']['table'](err['status'] || JSON.stringify(err)), LANG_T['error']);
this.manager.list.layout.progressOff();
});
}
......@@ -369,6 +466,9 @@ class ASP {
? `SELECT * FROM (SELECT A.*,ROWNUM N FROM ${table} A ORDER BY 1 DESC) WHERE N>0 AND N<=20`
: `SELECT TOP 20 * FROM ${table} ORDER BY 1 DESC;`);
this.manager.list.layout.progressOff();
}).catch((err) => {
toastr.error(LANG['result']['error']['column'](err['status'] || JSON.stringify(err)), LANG_T['error']);
this.manager.list.layout.progressOff();
});
}
......@@ -387,7 +487,8 @@ class ASP {
this.updateResult(ret);
this.manager.query.layout.progressOff();
}).catch((err) => {
console.error(err);
toastr.error(LANG['result']['error']['query'](err['status'] || JSON.stringify(err)), LANG_T['error']);
this.manager.query.layout.progressOff();
});
}
......@@ -402,12 +503,12 @@ class ASP {
// console.log(_arr, arr);
// 2.判断数据
if (arr.length < 2) {
return console.log('数据不正确');
return toastr.error(LANG['result']['error']['parse'], LANG_T['error']);
};
// 3.行头
let header_arr = arr[0].split('\t|\t');
if (header_arr.length === 1) {
return toastr.warning('没有查询结果');
return toastr.warning(LANG['result']['error']['noresult'], LANG_T['warning']);
};
if (header_arr[header_arr.length - 1] === '\r') {
header_arr.pop();
......@@ -446,11 +547,13 @@ class ASP {
// 禁用toolbar按钮
disableToolbar() {
this.manager.list.toolbar.disableItem('del');
this.manager.list.toolbar.disableItem('edit');
}
// 启用toolbar按钮
enableToolbar() {
this.manager.list.toolbar.enableItem('del');
this.manager.list.toolbar.enableItem('edit');
}
// 禁用SQL编辑框
......
//
// 数据库驱动::ASP
// 支持数据库:access,sqlserver,mysql
// 数据库驱动::CUSTOM
// 支持数据库: Any
//
class ASP {
const LANG = antSword['language']['database'];
const LANG_T = antSword['language']['toastr'];
class CUSTOM {
constructor(opt) {
this.opt = opt;
......@@ -87,13 +90,19 @@ class ASP {
this.tree.callEvent('onClick', [id]);
bmenu([
{
text: '添加配置',
text: LANG['list']['menu']['add'],
icon: 'fa fa-plus-circle',
action: this.addConf.bind(this)
}, {
divider: true
}, {
text: '删除配置',
text: LANG['list']['menu']['edit'],
icon: 'fa fa-edit',
action: this.editConf.bind(this)
}, {
divider: true
}, {
text: LANG['list']['menu']['del'],
icon: 'fa fa-remove',
action: this.delConf.bind(this)
}
......@@ -136,7 +145,7 @@ class ASP {
const hash = (+new Date * Math.random()).toString(16).substr(2, 8);
// 创建窗口
const win = this.manager.win.createWindow(hash, 0, 0, 450, 300);
win.setText('添加配置');
win.setText(LANG['form']['title']);
win.centerOnScreen();
win.button('minmax').hide();
win.setModal(true);
......@@ -147,21 +156,21 @@ class ASP {
id: 'add',
type: 'button',
icon: 'plus-circle',
text: '添加'
text: LANG['form']['toolbar']['add']
}, {
type: 'separator'
}, {
id: 'clear',
type: 'button',
icon: 'remove',
text: '清空'
text: LANG['form']['toolbar']['clear']
}]);
// form
const form = win.attachForm([
{ type: 'settings', position: 'label-left', labelWidth: 80, inputWidth: 280 },
{ type: 'block', inputWidth: 'auto', offsetTop: 12, list: [
{ type: 'combo', label: '数据库类型', readonly: true, name: 'type', options: (() => {
{ type: 'combo', label: LANG['form']['type'], readonly: true, name: 'type', options: (() => {
let ret = [];
for (let _ in this.conns) {
ret.push({
......@@ -171,7 +180,7 @@ class ASP {
}
return ret;
})() },
{ type: 'input', label: '连接字符串', name: 'conn', required: true, value: 'com.mysql.jdbc.Driver\r\njdbc:mysql://localhost/test?user=root&password=123456', rows: 9 }
{ type: 'input', label: LANG['form']['conn'], name: 'conn', required: true, value: 'com.mysql.jdbc.Driver\r\njdbc:mysql://localhost/test?user=root&password=123456', rows: 9 }
]}
], true);
......@@ -190,8 +199,8 @@ class ASP {
break;
case 'add':
if (!form.validate()) {
return '填写完整!';
// return toastr.warning(LANG['list']['add']['warning'], LANG_T['warning']);
// return '填写完整!';
return toastr.warning(LANG['form']['warning'], LANG_T['warning']);
};
// 解析数据
let data = form.getValues();
......@@ -201,7 +210,7 @@ class ASP {
data: data
});
win.close();
toastr.success('添加配置成功!');
toastr.success(LANG['form']['success'], LANG_T['success']);
this.tree.insertNewItem(0,
`conn::${id}`,
// `${data['type']}:\/\/${data['user']}@${data['host']}`,
......@@ -216,12 +225,98 @@ class ASP {
});
}
// 修改配置
editConf() {
const id = this.tree.getSelected().split('::')[1];
// 获取配置
const conf = antSword['ipcRenderer'].sendSync('shell-getDataConf', {
_id: this.manager.opt['_id'],
id: id
});
const hash = (+new Date * Math.random()).toString(16).substr(2, 8);
// 创建窗口
const win = this.manager.win.createWindow(hash, 0, 0, 450, 300);
win.setText(LANG['form']['title']);
win.centerOnScreen();
win.button('minmax').hide();
win.setModal(true);
win.denyResize();
// 工具栏
const toolbar = win.attachToolbar();
toolbar.loadStruct([{
id: 'edit',
type: 'button',
icon: 'edit',
text: LANG['form']['toolbar']['edit']
}, {
type: 'separator'
}, {
id: 'clear',
type: 'button',
icon: 'remove',
text: LANG['form']['toolbar']['clear']
}]);
// form
const form = win.attachForm([
{ type: 'settings', position: 'label-left', labelWidth: 80, inputWidth: 280 },
{ type: 'block', inputWidth: 'auto', offsetTop: 12, list: [
{ type: 'combo', label: LANG['form']['type'], readonly: true, name: 'type', options: (() => {
let ret = [];
for (let _ in this.conns) {
ret.push({
text: _.toUpperCase(),
value: _,
selected: conf['type'] === _
});
}
return ret;
})() },
{ type: 'input', label: LANG['form']['conn'], name: 'conn', required: true, value: conf['conn'], rows: 9 }
]}
], true);
form.attachEvent('onChange', (_, id) => {
if (_ !== 'type') { return };
form.setFormData({
conn: this.conns[id]
});
});
// 工具栏点击事件
toolbar.attachEvent('onClick', (id) => {
switch(id) {
case 'clear':
form.clear();
break;
case 'edit':
if (!form.validate()) {
// return '填写完整!';
return toastr.warning(LANG['form']['warning'], LANG_T['warning']);
};
// 解析数据
let data = form.getValues();
// 验证是否连接成功(获取数据库列表)
const id = antSword['ipcRenderer'].sendSync('shell-editDataConf', {
_id: this.manager.opt['_id'],
id: this.tree.getSelected().split('::')[1],
data: data
});
win.close();
toastr.success(LANG['form']['success'], LANG_T['success']);
// 刷新 UI
this.parse();
break;
}
});
}
// 删除配置
delConf() {
const id = this.tree.getSelected().split('::')[1];
layer.confirm('确定删除此配置吗?', {
layer.confirm(LANG['form']['del']['confirm'], {
icon: 2, shift: 6,
title: '删除配置'
title: LANG['form']['del']['title']
}, (_) => {
layer.close(_);
const ret = antSword['ipcRenderer'].sendSync('shell-delDataConf', {
......@@ -229,7 +324,7 @@ class ASP {
id: id
});
if (ret === 1) {
toastr.success('删除配置成功!');
toastr.success(LANG['form']['del']['success'], LANG_T['success']);
this.tree.deleteItem(`conn::${id}`);
// 禁用按钮
this.disableToolbar();
......@@ -237,7 +332,7 @@ class ASP {
// ['edit', 'del'].map(this.toolbar::this.toolbar.disableItem);
// this.parse();
}else{
toastr.error('删除配置失败!<br/>' + ret);
toastr.error(LANG['form']['del']['error'](ret), LANG_T['error']);
}
});
}
......@@ -260,7 +355,7 @@ class ASP {
let ret = res['text'];
const arr = ret.split('\t');
if (arr.length === 1 && ret === '') {
toastr.warning('执行完毕,没有结果返回')
toastr.warning(LANG['result']['warning'], LANG_T['warning'])
return this.manager.list.layout.progressOff();
};
// 删除子节点
......@@ -279,7 +374,7 @@ class ASP {
});
this.manager.list.layout.progressOff();
}).catch((err) => {
toastr.error('获取数据库列表失败!' + err['status'] || JSON.stringify(err), 'ERROR');
toastr.error(LANG['result']['error']['database'](err['status'] || JSON.stringify(err)), LANG_T['error']);
this.manager.list.layout.progressOff();
});
}
......@@ -321,6 +416,9 @@ class ASP {
);
});
this.manager.list.layout.progressOff();
}).catch((err) => {
toastr.error(LANG['result']['error']['table'](err['status'] || JSON.stringify(err)), LANG_T['error']);
this.manager.list.layout.progressOff();
});
}
......@@ -367,6 +465,9 @@ class ASP {
? `SELECT * FROM (SELECT A.*,ROWNUM N FROM ${db}.${table} A ORDER BY 1 DESC) WHERE N>0 AND N<=20`
: `SELECT * FROM ${db}.${table} ORDER BY 1 DESC LIMIT 0,20;`);
this.manager.list.layout.progressOff();
}).catch((err) => {
toastr.error(LANG['result']['error']['column'](err['status'] || JSON.stringify(err)), LANG_T['error']);
this.manager.list.layout.progressOff();
});
}
......@@ -386,7 +487,8 @@ class ASP {
this.updateResult(ret);
this.manager.query.layout.progressOff();
}).catch((err) => {
console.error(err);
toastr.error(LANG['result']['error']['query'](err['status'] || JSON.stringify(err)), LANG_T['error']);
this.manager.query.layout.progressOff();
});
}
......@@ -401,12 +503,12 @@ class ASP {
// console.log(_arr, arr);
// 2.判断数据
if (arr.length < 2) {
return console.log('数据不正确');
return toastr.error(LANG['result']['error']['parse'], LANG_T['error']);
};
// 3.行头
let header_arr = arr[0].split('\t|\t');
if (header_arr.length === 1) {
return toastr.warning('没有查询结果');
return toastr.warning(LANG['result']['error']['noresult'], LANG_T['warning']);
};
if (header_arr[header_arr.length - 1] === '\r') {
header_arr.pop();
......@@ -445,11 +547,13 @@ class ASP {
// 禁用toolbar按钮
disableToolbar() {
this.manager.list.toolbar.disableItem('del');
this.manager.list.toolbar.disableItem('edit');
}
// 启用toolbar按钮
enableToolbar() {
this.manager.list.toolbar.enableItem('del');
this.manager.list.toolbar.enableItem('edit');
}
// 禁用SQL编辑框
......@@ -470,4 +574,4 @@ class ASP {
}
module.exports = ASP;
module.exports = CUSTOM;
......@@ -65,8 +65,8 @@ class Database {
const toolbar = layout.attachToolbar();
toolbar.loadStruct([
{ id: 'add', text: LANG['list']['add'], icon: 'plus-circle', type: 'button' },
// { type: 'separator' },
// { id: 'edit', text: '编辑', icon: 'edit', type: 'button', disabled: true },
{ type: 'separator' },
{ id: 'edit', text: LANG['list']['edit'], icon: 'edit', type: 'button', disabled: true },
{ type: 'separator' },
{ id: 'del', text: LANG['list']['del'], icon: 'trash-o', type: 'button', disabled: true }
]);
......@@ -78,9 +78,9 @@ class Database {
case 'del':
this.drive.delConf();
break;
// case 'edit':
// this.drive.editConf();
// break;
case 'edit':
this.drive.editConf();
break;
}
});
return {
......
......@@ -87,6 +87,12 @@ class PHP {
action: this.addConf.bind(this)
}, {
divider: true
}, {
text: LANG['list']['menu']['edit'],
icon: 'fa fa-edit',
action: this.editConf.bind(this)
}, {
divider: true
}, {
text: LANG['list']['menu']['del'],
icon: 'fa fa-remove',
......@@ -254,6 +260,138 @@ class PHP {
});
}
// 编辑配置
editConf(){
const id = this.tree.getSelected().split('::')[1];
// 获取配置
const conf = antSword['ipcRenderer'].sendSync('shell-getDataConf', {
_id: this.manager.opt['_id'],
id: id
});
const hash = (+new Date * Math.random()).toString(16).substr(2, 8);
// 创建窗口
const win = this.manager.win.createWindow(hash, 0, 0, 450, 300);
win.setText(LANG['form']['title']);
win.centerOnScreen();
win.button('minmax').hide();
win.setModal(true);
win.denyResize();
// 工具栏
const toolbar = win.attachToolbar();
toolbar.loadStruct([{
id: 'edit',
type: 'button',
icon: 'edit',
text: LANG['form']['toolbar']['edit']
}, {
type: 'separator'
}, {
id: 'clear',
type: 'button',
icon: 'remove',
text: LANG['form']['toolbar']['clear']
}]);
// form
const form = win.attachForm([
{ type: 'settings', position: 'label-left', labelWidth: 90, inputWidth: 250 },
{ type: 'block', inputWidth: 'auto', offsetTop: 12, list: [
{ type: 'combo', label: LANG['form']['type'], readonly: true, name: 'type', options: [
{ text: 'MYSQL', value: 'mysql', selected: conf['type'] === 'mysql', list: [
{ type: 'settings', position: 'label-left', offsetLeft: 70, labelWidth: 90, inputWidth: 150 },
{ type: 'label', label: LANG['form']['encode'] },
{ type: 'combo', label: '', name: 'encode', options: (() => {
let ret = [];
['utf8', 'big5', 'dec8', 'cp850', 'hp8', 'koi8r', 'latin1', 'latin2', 'ascii', 'euckr', 'gb2312', 'gbk'].map((_) => {
ret.push({
text: _,
value: _,
selected: conf['encode'] === _
});
})
return ret;
})() }
] },
{ text: 'MYSQLI', value: 'mysqli', selected: conf['type'] === 'mysqli', list: [
{ type: 'settings', position: 'label-left', offsetLeft: 70, labelWidth: 90, inputWidth: 150 },
{ type: 'label', label: LANG['form']['encode'] },
{ type: 'combo', label: '', name: 'encode', options: (() => {
let ret = [];
['utf8', 'big5', 'dec8', 'cp850', 'hp8', 'koi8r', 'latin1', 'latin2', 'ascii', 'euckr', 'gb2312', 'gbk'].map((_) => {
ret.push({
text: _,
value: _,
selected: conf['encode'] === _
});
})
return ret;
})() }
] },
{ text: 'MSSQL', value: 'mssql', selected: conf['type'] === 'mssql' },
{ text: 'ORACLE', value: 'oracle', selected: conf['type'] === 'oracle' },
{ text: 'INFORMIX', value: 'informix', selected: conf['type'] === 'informix' }
] },
{ type: 'input', label: LANG['form']['host'], name: 'host', required: true, value: conf['host'] },
{ type: 'input', label: LANG['form']['user'], name: 'user', required: true, value: conf['user'] },
{ type: 'input', label: LANG['form']['passwd'], name: 'passwd', value: conf['passwd'] }
]}
], true);
form.attachEvent('onChange', (_, id) => {
if (_ !== 'type') { return };
switch(id) {
case 'mysql':
case 'mysqli':
form.setFormData({
user: conf['user'],
passwd: conf['passwd']
});
break;
case 'mssql':
form.setFormData({
user: conf['user'],
passwd: conf['passwd']
});
break;
default:
form.setFormData({
user: conf['user'],
passwd: conf['passwd']
});
}
});
// 工具栏点击事件
toolbar.attachEvent('onClick', (id) => {
switch(id) {
case 'clear':
form.clear();
break;
case 'edit':
if (!form.validate()) {
return toastr.warning(LANG['form']['warning'], LANG_T['warning']);
};
// 解析数据
let data = form.getValues();
// 验证是否连接成功(获取数据库列表)
const id = antSword['ipcRenderer'].sendSync('shell-editDataConf', {
_id: this.manager.opt['_id'],
id: this.tree.getSelected().split('::')[1],
data: data
});
win.close();
toastr.success(LANG['form']['success'], LANG_T['success']);
// 刷新 UI
this.parse();
break;
}
});
}
// 删除配置
delConf() {
const id = this.tree.getSelected().split('::')[1];
......@@ -488,11 +626,13 @@ class PHP {
// 禁用toolbar按钮
disableToolbar() {
this.manager.list.toolbar.disableItem('del');
this.manager.list.toolbar.disableItem('edit');
}
// 启用toolbar按钮
enableToolbar() {
this.manager.list.toolbar.enableItem('del');
this.manager.list.toolbar.enableItem('edit');
}
// 禁用SQL编辑框
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment