mirror of
https://gitee.com/java110/MicroCommunityWeb.git
synced 2026-06-12 10:00:56 +08:00
优化直接api 调用方式
This commit is contained in:
parent
3f2ba6b82f
commit
806bec57d6
@ -820,6 +820,89 @@
|
|||||||
}
|
}
|
||||||
});
|
});
|
||||||
},
|
},
|
||||||
|
apiPost: function (api, param, options, successCallback, errorCallback) {
|
||||||
|
vcFramework.loading('open');
|
||||||
|
Vue.http.post('/callComponent/' + api, param, options)
|
||||||
|
.then(function (res) {
|
||||||
|
try {
|
||||||
|
let _header = res.headers.map;
|
||||||
|
//console.log('res', res);
|
||||||
|
if (vcFramework.notNull(_header['location'])) {
|
||||||
|
window.location.href = _header['location'];
|
||||||
|
return;
|
||||||
|
};
|
||||||
|
successCallback(res.bodyText, res);
|
||||||
|
} catch (e) {
|
||||||
|
console.error(e);
|
||||||
|
} finally {
|
||||||
|
vcFramework.loading('close');
|
||||||
|
}
|
||||||
|
}, function (res) {
|
||||||
|
try {
|
||||||
|
if (res.status == 401) {
|
||||||
|
let _header = res.headers.map;
|
||||||
|
//console.log('res', res);
|
||||||
|
window.location.href = _header['location'];
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
if (res.status == 404) {
|
||||||
|
window.location.href = '/user.html#/login';
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
errorCallback(res.bodyText, res);
|
||||||
|
} catch (e) {
|
||||||
|
console.error(e);
|
||||||
|
} finally {
|
||||||
|
vcFramework.loading('close');
|
||||||
|
}
|
||||||
|
});
|
||||||
|
},
|
||||||
|
apiGet: function (api, param, successCallback, errorCallback) {
|
||||||
|
//加入缓存机制
|
||||||
|
var _getPath = '/' + api;
|
||||||
|
if (vcFramework.constant.GET_CACHE_URL.includes(_getPath)) {
|
||||||
|
var _cacheData = vcFramework.getData(_getPath);
|
||||||
|
//浏览器缓存中能获取到
|
||||||
|
if (_cacheData != null && _cacheData != undefined) {
|
||||||
|
successCallback(JSON.stringify(_cacheData), { status: 200 });
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
vcFramework.loading('open');
|
||||||
|
Vue.http.get('/callComponent/' + api, param)
|
||||||
|
.then(function (res) {
|
||||||
|
try {
|
||||||
|
|
||||||
|
successCallback(res.bodyText, res);
|
||||||
|
if (vcFramework.constant.GET_CACHE_URL.includes(_getPath) && res.status == 200) {
|
||||||
|
vcFramework.saveData(_getPath, JSON.parse(res.bodyText));
|
||||||
|
}
|
||||||
|
} catch (e) {
|
||||||
|
console.error(e);
|
||||||
|
} finally {
|
||||||
|
vcFramework.loading('close');
|
||||||
|
}
|
||||||
|
}, function (res) {
|
||||||
|
try {
|
||||||
|
if (res.status == 401) {
|
||||||
|
let _header = res.headers.map;
|
||||||
|
//console.log('res', res);
|
||||||
|
window.location.href = _header['location'];
|
||||||
|
return;
|
||||||
|
|
||||||
|
}
|
||||||
|
if (res.status == 404) {
|
||||||
|
window.location.href = '/user.html#/login';
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
errorCallback(res.bodyText, res);
|
||||||
|
} catch (e) {
|
||||||
|
console.error(e);
|
||||||
|
} finally {
|
||||||
|
vcFramework.loading('close');
|
||||||
|
}
|
||||||
|
});
|
||||||
|
},
|
||||||
upload: function (componentCode, componentMethod, param, options, successCallback, errorCallback) {
|
upload: function (componentCode, componentMethod, param, options, successCallback, errorCallback) {
|
||||||
vcFramework.loading('open');
|
vcFramework.loading('open');
|
||||||
Vue.http.post('/callComponent/upload/' + componentCode + "/" + componentMethod, param, options)
|
Vue.http.post('/callComponent/upload/' + componentCode + "/" + componentMethod, param, options)
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user