From 3ebf571467d03d6162f7b81bb9bc4b668f0d0e3d Mon Sep 17 00:00:00 2001 From: windy <1374721899@qq.com> Date: Thu, 30 Mar 2017 15:48:31 +0800 Subject: [PATCH] ajax --- demo/version.js | 6 +- src/base/base.js | 6 +- src/core/base.js | 176 +---------------------------------------------- 3 files changed, 9 insertions(+), 179 deletions(-) diff --git a/demo/version.js b/demo/version.js index 51c96d178..5e16777ec 100644 --- a/demo/version.js +++ b/demo/version.js @@ -4,4 +4,8 @@ Demo = { BI.i18n = { "BI-Basic_OK": "确定" -}; \ No newline at end of file +}; + +BI.servletURL = "dist/"; +BI.resourceURL = "dist/resource/"; +BI.i18n = {}; \ No newline at end of file diff --git a/src/base/base.js b/src/base/base.js index 1198a5d52..49c5b2109 100644 --- a/src/base/base.js +++ b/src/base/base.js @@ -5,8 +5,4 @@ BI.Bubbles = new BI.BubblesController(); BI.Tooltips = new BI.TooltipsController(); BI.Popovers = new BI.FloatBoxController(); BI.Broadcasts = new BI.BroadcastController(); -BI.StyleLoaders = new BI.StyleLoaderManager(); - -BI.servletURL = "dist/"; -BI.resourceURL = "dist/resource/"; -BI.i18n = {}; \ No newline at end of file +BI.StyleLoaders = new BI.StyleLoaderManager(); \ No newline at end of file diff --git a/src/core/base.js b/src/core/base.js index e91ddc164..cdee5f2d5 100644 --- a/src/core/base.js +++ b/src/core/base.js @@ -1076,28 +1076,7 @@ if (!window.BI) { //encode encodeBIParam(option.data); - var async = true; - if (BI.isNotNull(option.async)) { - async = option.async; - } - - if (BI.isNull(loading)) { - loading = BI.createWidget({ - type: "bi.request_loading" - }); - } - - if (BI.isNull(timeoutToast)) { - timeoutToast = BI.createWidget({ - type: "bi.timeout_toast" - }); - timeoutToast.setCallback(function (op) { - decodeBIParam(op.data); - BI.ajax(op); - }); - } - timeoutToast.addReq(option); - + var async = option.async; option.data = BI.cjkEncodeDO(option.data); @@ -1107,68 +1086,14 @@ if (!window.BI) { type: "POST", data: option.data, async: async, - error: function () { - if (!timeoutToast.hasReq(option)) { - return; - } - timeoutToast.removeReq(option); - //失败 取消、重新加载 - loading.setCallback(function () { - decodeBIParam(option.data); - BI.ajax(option); - }); - loading.showError(); - }, + error: option.error, complete: function (res, status) { - if (!timeoutToast.hasReq(option)) { - return; - } - timeoutToast.removeReq(option); - //登录超时 - if (BI.isNotNull(res.responseText) && - res.responseText.indexOf("fs-login-content") > -1 && - res.responseText.indexOf("fs-login-input-password-confirm") === -1) { - if (BI.Popovers.isVisible(BI.LoginTimeOut.POPOVER_ID)) { - return; - } - if (BI.isNotNull(BI.Popovers.get(BI.LoginTimeOut.POPOVER_ID))) { - BI.Popovers.open(BI.LoginTimeOut.POPOVER_ID); - return; - } - var loginTimeout = BI.createWidget({ - type: "bi.login_timeout" - }); - loginTimeout.on(BI.LoginTimeOut.EVENT_LOGIN, function () { - decodeBIParam(option.data); - BI.ajax(option); - BI.Popovers.remove(BI.LoginTimeOut.POPOVER_ID); - }); - BI.Popovers.create(BI.LoginTimeOut.POPOVER_ID, loginTimeout, { - width: 600, - height: 400 - }).open(BI.LoginTimeOut.POPOVER_ID); - } else if (BI.isNotNull(res.responseText) && - res.responseText.indexOf("script") > -1 && - res.responseText.indexOf("Session Timeout...") > -1) { - //登录失效 - loading.setCallback(function () { - location.reload(); - }); - loading.showError(); - - } else if (status === "success" && BI.isFunction(option.success)) { - option.success(BI.jsonDecode(res.responseText)); - } if (BI.isFunction(option.complete)) { option.complete(BI.jsonDecode(res.responseText), status); } } }); - return function cancel() { - timeoutToast.removeReq(option); - }; - function encodeBIParam(data) { for (var key in data) { if (_.isObject(data[key])) { @@ -1188,101 +1113,6 @@ if (!window.BI) { } } } - })(), - - /** - * 异步ajax请求 - * @param {String} op op参数 - * @param {String} cmd cmd参数 - * @param {JSON} data ajax请求的参数 - * @param {Function} callback 回调函数 - * @param {Function} complete 回调 - */ - requestAsync: function (op, cmd, data, callback, complete) { - data = data || {}; - if (!BI.isKey(op)) { - op = 'fr_bi_dezi'; - } - if (op === "fr_bi_dezi" || op === "fr_bi_configure") { - data.sessionID = Data.SharingPool.get("sessionID"); - } - var url = BI.servletURL + '?op=' + op + '&cmd=' + cmd + "&_=" + Math.random(); - return (BI.ajax)({ - url: url, - type: 'POST', - data: data, - error: function () { - // BI.Msg.toast(BI.i18nText("BI-Ajax_Error")); - }, - success: function (res) { - if (BI.isFunction(callback)) { - callback(res); - } - }, - complete: function (res, status) { - if (BI.isFunction(complete)) { - complete(res); - } - } - }); - }, - - /** - * 同步ajax请求 - * @param {String} op op参数 - * @param {String} cmd cmd参数 - * @param {JSON} data ajax请求的参�? - * @returns {Object} ajax同步请求返回的JSON对象 - */ - requestSync: function (op, cmd, data) { - data = data || {}; - if (!BI.isKey(op)) { - op = 'fr_bi_dezi'; - } - if (op === "fr_bi_dezi") { - data.sessionID = Data.SharingPool.get("sessionID"); - } - var url = BI.servletURL + '?op=' + op + '&cmd=' + cmd + "&_=" + Math.random(); - var result = {}; - (BI.ajax)({ - url: url, - type: 'POST', - async: false, - data: data, - error: function () { - BI.Msg.toast(BI.i18nText("BI-Ajax_Error")); - }, - complete: function (res, status) { - if (status === 'success') { - result = res; - } - } - }); - return result; - }, - - /** - * 请求方法 - * @param cmd 命令 - * @param data 数据 - * @param extend 参数 - * @returns {*} - */ - request: function (cmd, data, extend) { - extend = extend || {}; - data = data || {}; - var op = extend.op; - if (!BI.isKey(op)) { - op = 'fr_bi_dezi'; - } - if (op === "fr_bi_dezi") { - data.sessionID = Data.SharingPool.get("sessionID"); - } - if (extend.async === true) { - BI.requestAsync(op, cmd, data, extend.complete || extend.success); - } else { - return BI.requestSync(op, cmd, data); - } - } + })() }); })(jQuery); \ No newline at end of file