common.js 2.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283
  1. // 获取项目地址
  2. var $location = (window.location + '').split('/');
  3. var $basePath = $location[0] + '//' + $location[2];
  4. // 全局内容区域
  5. var $initContainer = $("#initContainer");
  6. // ******************* 插件封装 ***************************
  7. // 全局提示框
  8. function bootGrowl(data, type) {
  9. $.bootstrapGrowl(data, { // data为提示信息
  10. type: type == undefined ? 'success' : type,// type指提示类型
  11. delay: 1000,// 提示框显示时间
  12. allow_dismiss: true // 显示取消提示框
  13. });
  14. }
  15. // 跳转主页
  16. function backIndexPage() {
  17. // 加载页面
  18. $initContainer.load("/index?refresh=" + new Date().getTime());
  19. }
  20. // 美化SQL
  21. function beautifySql(){
  22. var $sql = $("#sql");
  23. var $tmp = $sql.attr('tmp');
  24. if(null == $tmp){
  25. $sql.attr('tmp', $sql.val());
  26. $sql.val(sqlFormatter.format($sql.val()));
  27. return;
  28. }
  29. $sql.val($tmp);
  30. $sql.removeAttr('tmp');
  31. }
  32. // ******************* 扩展JS表单方法 ***************************
  33. $.fn.serializeJson = function () {
  34. var o = {};
  35. var a = this.serializeArray();
  36. $.each(a, function () {
  37. if (o[this.name] !== undefined) {
  38. if (!o[this.name].push) {
  39. o[this.name] = [o[this.name]];
  40. }
  41. o[this.name].push(this.value || '');
  42. } else {
  43. o[this.name] = this.value || '';
  44. }
  45. });
  46. return o;
  47. };
  48. // 全局Ajax post
  49. function doPoster(url, params, action) {
  50. $.loadingT(true);
  51. $.post(url, params, function (data) {
  52. $.loadingT(false);
  53. // 异常请求:302
  54. if (!(data instanceof Object)) {
  55. bootGrowl("会话过期, 3秒后将访问登录主页...", "danger");
  56. setTimeout(function () {
  57. location.href = $basePath;
  58. }, 3000);
  59. } else {
  60. action(data);
  61. }
  62. }).error(function (xhr, status, info) {
  63. $.loadingT(false);
  64. bootGrowl("访问异常,请刷新或重试.", "danger");
  65. });
  66. }
  67. // ******************* 常量配置 ***************************
  68. // 连接器类型
  69. var ConnectorConstant = {
  70. "Mysql" : "/connector/page/addMysql",
  71. "Oracle" : "/connector/page/addOracle",
  72. "SqlServer" : "/connector/page/addSqlServer",
  73. "DqlMysql" : "/connector/page/addDqlMysql",
  74. "DqlOracle" : "/connector/page/addDqlOracle",
  75. "Ldap" : "/connector/page/addLdap",
  76. "Redis" : "/connector/page/addRedis"
  77. }