Skip to content

Commit 723a0ab

Browse files
committed
删除没用代码
1 parent 0b8ea3a commit 723a0ab

File tree

1 file changed

+47
-62
lines changed

1 file changed

+47
-62
lines changed

src/utils/ajax/ajax.js

Lines changed: 47 additions & 62 deletions
Original file line numberDiff line numberDiff line change
@@ -21,83 +21,68 @@ Vue.axios.defaults.baseURL = gbs.host;
2121
* @param {Function} fn 回调函数
2222
* @param {boolean} tokenFlag 是否需要携带token参数,为true,不需要;false,需要。一般除了登录,都需要
2323
*/
24-
export default function ({
25-
type,
26-
path,
27-
data,
28-
fn,
29-
errFn,
30-
tokenFlag,
31-
headers,
32-
opts
33-
} = {}) {
24+
export default function({
25+
type,
26+
path,
27+
data,
28+
fn,
29+
errFn,
30+
tokenFlag,
31+
headers,
32+
opts
33+
} = {}) {
3434

3535
var options = {
3636
method : type,
3737
url : path,
3838
headers: headers && typeof headers === 'object' ? headers : {}
3939
};
4040

41-
//检测接口权限
42-
var api_flag = true;
43-
if (options.url && options.url.indexOf(gbs.host) && this.$store.state.user.userinfo.access_status === 1) {
44-
var url = options.url.replace(gbs.host, '');
45-
var api_routers = this.$store.state.user.userinfo.api_routers;
46-
if (!api_routers || !api_routers.constructor === Object || !api_routers[url]) {
47-
api_flag = false;
48-
}
49-
}
5041

51-
if (api_flag === true) {
52-
options[type === 'get' ? 'params' : 'data'] = data;
42+
options[type === 'get' ? 'params' : 'data'] = data;
5343

54-
// 分发显示加载样式任务
55-
this.$store.dispatch('show_loading');
44+
// 分发显示加载样式任务
45+
this.$store.dispatch('show_loading');
5646

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

61-
options.headers.token = this.$store.state.user.userinfo.token;
62-
}
51+
options.headers.token = this.$store.state.user.userinfo.token;
52+
}
6353

64-
//axios内置属性均可写在这里
65-
if (opts && typeof opts === 'object') {
66-
for (var f in opts) {
67-
options[f] = opts[f];
68-
}
54+
//axios内置属性均可写在这里
55+
if (opts && typeof opts === 'object') {
56+
for (var f in opts) {
57+
options[f] = opts[f];
6958
}
59+
}
7060

71-
// console.log(options);
61+
// console.log(options);
7262

73-
//发送请求
74-
Vue.axios(options).then((res) => {
75-
this.$store.dispatch('hide_loading');
76-
if(res.data[gbs.api_status_key_field]===gbs.api_status_value_field){
77-
if(gbs.api_data_field){
78-
fn(res.data[gbs.api_data_field]);
79-
}else{
80-
fn(res.data);
81-
}
82-
}else{
83-
if(gbs.api_custom[res.data[gbs.api_status_key_field]]){
84-
gbs.api_custom[res.data[gbs.api_status_key_field]].call(this,res.data);
85-
}else{
86-
if(errFn){
87-
errFn.call(this,res.data);
88-
}else{
89-
cbs.statusError.call(this, res.data);
90-
}
63+
//发送请求
64+
Vue.axios(options).then((res) => {
65+
this.$store.dispatch('hide_loading');
66+
if (res.data[gbs.api_status_key_field] === gbs.api_status_value_field) {
67+
if (gbs.api_data_field) {
68+
fn(res.data[gbs.api_data_field]);
69+
} else {
70+
fn(res.data);
71+
}
72+
} else {
73+
if (gbs.api_custom[res.data[gbs.api_status_key_field]]) {
74+
gbs.api_custom[res.data[gbs.api_status_key_field]].call(this, res.data);
75+
} else {
76+
if (errFn) {
77+
errFn.call(this, res.data);
78+
} else {
79+
cbs.statusError.call(this, res.data);
9180
}
9281
}
93-
}).catch((err) => {
94-
this.$store.dispatch('hide_loading');
95-
// cbs.requestError.call(this, err);
96-
});
97-
} else {
98-
this.$alert('您没用权限请求该接口!', '请求错误', {
99-
confirmButtonText: '确定',
100-
type : 'warning'
101-
});
102-
}
82+
}
83+
}).catch((err) => {
84+
this.$store.dispatch('hide_loading');
85+
// cbs.requestError.call(this, err);
86+
});
87+
10388
};

0 commit comments

Comments
 (0)