quickapi.index.js Maven / Gradle / Ivy
let app = angular.module("app",[]);
app.factory('formInterceptor', function ($q, $rootScope) {
return {
request: function (config) {
$rootScope.isLoading = true;
return config;
},
requestError: function (err) {
console.log(err);
$rootScope.isLoading = false;
},
response: function (res) {
$rootScope.isLoading = false;
return res;
},
responseError: function (err) {
$rootScope.isLoading = false;
return $q.reject(err);
}
}
});
app.config(function ($httpProvider) {
$httpProvider.interceptors.push('formInterceptor');
});
app.filter('trustAsHtml', function ($sce) {
return function (value) {
return $sce.trustAsHtml(value);
};
});
app.directive('entityTable',function(){
return {
restrict: 'AE',
replace: true,
templateUrl:"directive/entityTable.html",
scope:{
"entity":"=entity"
},
link:function($scope,$elem,$attr){
}
}
});
app.controller("indexController",function($scope,$rootScope,$http,$httpParamSerializer,$location,$anchorScroll){
$scope.apiDocument = null;
$http.get("api.json").then(function(response){
$scope.apiDocument = response.data;
//处理历史变更记录
for(let i=0;i<$scope.apiDocument.apiHistoryList.length;i++){
let addList = $scope.apiDocument.apiHistoryList[i].addList;
let modifyList = $scope.apiDocument.apiHistoryList[i].modifyList;
for(let i=0;i<$scope.apiDocument.apiControllerList.length;i++){
let apiList = $scope.apiDocument.apiControllerList[i].apiList;
for(let j=0;j=0||api.url.indexOf($scope.searchText)>=0){
return true;
}
return false;
};
//显示API详情
$scope.currentAPI = null;
$scope.setCurrentAPI = function(api){
$scope.currentEntity = null;
$scope.view = "api";
$scope.currentAPI = api;
$scope.response = null;
$scope.request = {};
let apiParameters = $scope.currentAPI.apiParameters;
for(let i=0;i=0){
let fd = new FormData();
for(let prop in $scope.request){
if(null!=document.getElementById(prop)){
fd.append(prop,document.getElementById(prop).files[0]);
}else{
fd.append(prop,$scope.request[prop]);
}
}
operation.data = fd;
}else if($scope.currentAPI.contentType.indexOf("application/json")>=0){
operation.data = $scope.request[$scope.currentAPI.apiParameters[0].name];
}else{
operation.data = $httpParamSerializer($scope.request);
}
}else{
operation.params = $scope.request;
}
operation.headers = {"Content-Type":$scope.currentAPI.contentType};
if($scope.currentAPI.contentType.indexOf("multipart/form-data")>=0){
operation.headers = {"Content-Type":undefined};
}
for(let prop in $rootScope.headers){
operation.headers[prop] = $rootScope.headers[prop];
}
$scope.loading = true;
$http(operation).then(function(response){
$scope.response = response;
$scope.responseJSON = JSON.stringify(response.data,null,4);
},function(error){
$scope.response = error;
$scope.responseJSON = JSON.stringify(error.data,null,4);
}).finally(function(){
$scope.loading = false;
localStorage.setItem($scope.currentAPI.url,JSON.stringify($scope.request));
if($scope.lastUsed.length>5){
$scope.lastUsed.shift();
}
//判断是否有重复
let exist = false;
for(let i=0;i<$scope.lastUsed.length;i++){
if($scope.lastUsed[i].url==$scope.currentAPI.url){
exist = true;
break;
}
}
if(!exist){
$scope.lastUsed.unshift($scope.currentAPI);
$scope.saveToLocalStorage("lastUsed",$scope.lastUsed);
}
});
};
});
© 2015 - 2024 Weber Informatics LLC | Privacy Policy