Skip to content

Commit

Permalink
删除没用代码
Browse files Browse the repository at this point in the history
  • Loading branch information
sailengsi committed Sep 18, 2017
1 parent 0b8ea3a commit 723a0ab
Showing 1 changed file with 47 additions and 62 deletions.
109 changes: 47 additions & 62 deletions src/utils/ajax/ajax.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,83 +21,68 @@ Vue.axios.defaults.baseURL = gbs.host;
* @param {Function} fn 回调函数
* @param {boolean} tokenFlag 是否需要携带token参数,为true,不需要;false,需要。一般除了登录,都需要
*/
export default function ({
type,
path,
data,
fn,
errFn,
tokenFlag,
headers,
opts
} = {}) {
export default function({
type,
path,
data,
fn,
errFn,
tokenFlag,
headers,
opts
} = {}) {

var options = {
method : type,
url : path,
headers: headers && typeof headers === 'object' ? headers : {}
};

//检测接口权限
var api_flag = true;
if (options.url && options.url.indexOf(gbs.host) && this.$store.state.user.userinfo.access_status === 1) {
var url = options.url.replace(gbs.host, '');
var api_routers = this.$store.state.user.userinfo.api_routers;
if (!api_routers || !api_routers.constructor === Object || !api_routers[url]) {
api_flag = false;
}
}

if (api_flag === true) {
options[type === 'get' ? 'params' : 'data'] = data;
options[type === 'get' ? 'params' : 'data'] = data;

// 分发显示加载样式任务
this.$store.dispatch('show_loading');
// 分发显示加载样式任务
this.$store.dispatch('show_loading');

if (tokenFlag !== true) {
//如果你们的后台不会接受headers里面的参数,打开这个注释,即实现token通过普通参数方式传
// data.token = this.$store.state.user.userinfo.token;
if (tokenFlag !== true) {
//如果你们的后台不会接受headers里面的参数,打开这个注释,即实现token通过普通参数方式传
// data.token = this.$store.state.user.userinfo.token;

options.headers.token = this.$store.state.user.userinfo.token;
}
options.headers.token = this.$store.state.user.userinfo.token;
}

//axios内置属性均可写在这里
if (opts && typeof opts === 'object') {
for (var f in opts) {
options[f] = opts[f];
}
//axios内置属性均可写在这里
if (opts && typeof opts === 'object') {
for (var f in opts) {
options[f] = opts[f];
}
}

// console.log(options);
// console.log(options);

//发送请求
Vue.axios(options).then((res) => {
this.$store.dispatch('hide_loading');
if(res.data[gbs.api_status_key_field]===gbs.api_status_value_field){
if(gbs.api_data_field){
fn(res.data[gbs.api_data_field]);
}else{
fn(res.data);
}
}else{
if(gbs.api_custom[res.data[gbs.api_status_key_field]]){
gbs.api_custom[res.data[gbs.api_status_key_field]].call(this,res.data);
}else{
if(errFn){
errFn.call(this,res.data);
}else{
cbs.statusError.call(this, res.data);
}
//发送请求
Vue.axios(options).then((res) => {
this.$store.dispatch('hide_loading');
if (res.data[gbs.api_status_key_field] === gbs.api_status_value_field) {
if (gbs.api_data_field) {
fn(res.data[gbs.api_data_field]);
} else {
fn(res.data);
}
} else {
if (gbs.api_custom[res.data[gbs.api_status_key_field]]) {
gbs.api_custom[res.data[gbs.api_status_key_field]].call(this, res.data);
} else {
if (errFn) {
errFn.call(this, res.data);
} else {
cbs.statusError.call(this, res.data);
}
}
}).catch((err) => {
this.$store.dispatch('hide_loading');
// cbs.requestError.call(this, err);
});
} else {
this.$alert('您没用权限请求该接口!', '请求错误', {
confirmButtonText: '确定',
type : 'warning'
});
}
}
}).catch((err) => {
this.$store.dispatch('hide_loading');
// cbs.requestError.call(this, err);
});

};

0 comments on commit 723a0ab

Please sign in to comment.