Commit 9a0fbbd7 authored by antoor's avatar antoor

Fix call core module

修复调用核心模块
parent b6092dde
...@@ -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;
......
// //
// 数据库驱动::ASP // 数据库驱动::ASP
// 支持数据库:access,sqlserver,mysql // 支持数据库:access,sqlserver,mysql
// //
class ASP { class ASP {
...@@ -9,9 +9,9 @@ class ASP { ...@@ -9,9 +9,9 @@ class ASP {
this.opt = opt; this.opt = opt;
this.core = this.opt.core; this.core = this.opt.core;
this.manager = this.opt.super; this.manager = this.opt.super;
// //
// * 数据库驱动列表 // * 数据库驱动列表
// //
this.conns = { this.conns = {
'dsn': 'Dsn=DsnName;', 'dsn': 'Dsn=DsnName;',
'mysql': 'Driver={MySQL};Server=localhost;database=mysql;UID=root;PWD=', 'mysql': 'Driver={MySQL};Server=localhost;database=mysql;UID=root;PWD=',
...@@ -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[`database_${conf['type']}`].show_databases(
{ this.core.request(
conn: conf['conn'], this.core[`database_${conf['type']}`].show_databases(
dbname: ['access', 'microsoft_jet_oledb_4_0'].indexOf(conf['type']) > -1 ? conf['conn'].match(/[\w]+.mdb$/) : 'database' {
}, (ret) => { conn: conf['conn'],
dbname: ['access', 'microsoft_jet_oledb_4_0'].indexOf(conf['type']) > -1 ? conf['conn'].match(/[\w]+.mdb$/) : 'database'
})
).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[`database_${conf['type']}`].show_tables(
{ this.core.request(
conn: conf['conn'], this.core[`database_${conf['type']}`].show_tables(
dbname: db {
}, (ret) => { conn: conf['conn'],
dbname: db
})
).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[`database_${conf['type']}`].show_columns(
{ this.core.request(
conn: conf['conn'], this.core[`database_${conf['type']}`].show_columns(
table: conf['type'] === 'oracle' ? `SELECT * FROM (SELECT A.*,ROWNUM N FROM ${table} A) WHERE N=1` : `SELECT TOP 1 * FROM ${table}` {
}, (ret) => { conn: conf['conn'],
table: conf['type'] === 'oracle' ? `SELECT * FROM (SELECT A.*,ROWNUM N FROM ${table} A) WHERE N=1` : `SELECT TOP 1 * FROM ${table}`
})
).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[`database_${this.dbconf['type']}`].query({
conn: this.dbconf['conn'], this.core.request(
sql: sql this.core[`database_${this.dbconf['type']}`].query({
}, (ret) => { conn: this.dbconf['conn'],
sql: sql
})
).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);
}); });
} }
...@@ -455,4 +471,4 @@ class ASP { ...@@ -455,4 +471,4 @@ class ASP {
} }
module.exports = ASP; module.exports = ASP;
\ No newline at end of file
...@@ -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[`database_${conf['type']}`].show_tables(
{ this.core.request(
conn: conf['conn'], this.core[`database_${conf['type']}`].show_tables(
encode: this.manager.opt.encode, {
db: db conn: conf['conn'],
}, (ret) => { encode: this.manager.opt.encode,
db: db
})
).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[`database_${conf['type']}`].show_columns(
{ this.core.request(
conn: conf['conn'], this.core[`database_${conf['type']}`].show_columns(
encode: this.manager.opt.encode, {
db: db, conn: conf['conn'],
table: table encode: this.manager.opt.encode,
}, (ret) => { db: db,
table: table
})
).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[`database_${this.dbconf['type']}`].query({
conn: this.dbconf['conn'], this.core.request(
encode: this.manager.opt.encode, this.core[`database_${this.dbconf['type']}`].query({
sql: sql conn: this.dbconf['conn'],
}, (ret) => { encode: this.manager.opt.encode,
sql: sql
})
).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);
}); });
} }
......
// //
// 数据库驱动::PHP // 数据库驱动::PHP
// 支持数据库:mysql,mssql,oracle,informix // 支持数据库:mysql,mssql,oracle,informix
// //
const LANG = antSword['language']['database']; const LANG = antSword['language']['database'];
const LANG_T = antSword['language']['toastr']; const LANG_T = antSword['language']['toastr'];
...@@ -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(
host: conf['host'], this.core[`database_${conf['type']}`].show_tables({
user: conf['user'], host: conf['host'],
passwd: conf['passwd'], user: conf['user'],
db: db passwd: conf['passwd'],
}, (ret) => { db: db
})
).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(
host: conf['host'], this.core[`database_${conf['type']}`].show_columns({
user: conf['user'], host: conf['host'],
passwd: conf['passwd'], user: conf['user'],
db: db, passwd: conf['passwd'],
table: table db: db,
}, (ret) => { table: table
})
).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,18 +397,22 @@ class PHP { ...@@ -389,18 +397,22 @@ class PHP {
// 执行SQL // 执行SQL
execSQL(sql) { execSQL(sql) {
this.manager.query.layout.progressOn(); this.manager.query.layout.progressOn();
this.core[`database_${this.dbconf['type']}`].query({
host: this.dbconf['host'], this.core.request(
user: this.dbconf['user'], this.core[`database_${this.dbconf['type']}`].query({
passwd: this.dbconf['passwd'], host: this.dbconf['host'],
db: this.dbconf['database'], user: this.dbconf['user'],
sql: sql, passwd: this.dbconf['passwd'],
encode: this.dbconf['encode'] || 'utf8' db: this.dbconf['database'],
}, (ret) => { sql: sql,
encode: this.dbconf['encode'] || 'utf8'
})
).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();
}); });
...@@ -484,4 +496,4 @@ class PHP { ...@@ -484,4 +496,4 @@ class PHP {
} }
module.exports = PHP; module.exports = PHP;
\ No newline at end of file
...@@ -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() }
});
} }
// 刷新当前目录 // 刷新当前目录
......
...@@ -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;
This diff is collapsed.
This diff is collapsed.
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