common.js 3.2 KB

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