bmfe-vue2-base
Version:
BM 后台系统基础框架
87 lines (77 loc) • 1.61 kB
JavaScript
/**
* @Author: songqi
* @Date: 2016-06-29 22:06:00
* @Email: songqi@benmu-health.com
* @Last modified by: songqi
* @Last modified time: 2017-02-21
*/
import {
TESTPATH,
LOGINHREF,
LOGINCODE,
BASEINFOURL
} from 'Config/config';
var _ = require('lodash'),
PromiseAjax = require('BaseLibs/promiseAjax');
/**
* [pathMap 测试请求路径管理]
* @type {Object}
*/
var testPathMap = {
/**
* 通用
*/
getBaseInfo: '/test/getBaseInfo'
};
/**
* [prodPathMap 线上路径管理]
* @type {Object}
*/
var prodPathMap = {
/**
* [getBaseInfo 基础数据]
*/
getBaseInfo: BASEINFOURL
};
for (var i in testPathMap) {
testPathMap[i] = TESTPATH + testPathMap[i];
}
/**
* [assignIn 过度对接方案]
* @author songqi
* @date 2016-07-11
*/
var pathMap = _.assignIn({}, testPathMap, prodPathMap);
/**
* [paramMap 请求默认参数配置]
* @type {Object}
*/
var paramMap = {
post: {
type: 'post',
dataType: 'json',
contentType: 'application/json'
},
get: {
type: 'get',
dataType: 'json'
}
};
/**
* [errorFunction 全局错误的默认处理]
* @author songqi
* @date 2016-07-06
* @param {[Object]} resData [后端回调数据]
*/
function errorFunction(resData) {
if (resData.type !== 'abort') {
GLOBAL.globalEvent.emit('ajaxError', resData)
}else if(resData && resData.resCode === LOGINCODE){
location.href= LOGINHREF;
}
}
PromiseAjax.setConfig({
pathMap: pathMap,
paramMap: paramMap,
errorFunction: errorFunction
});