parent
c498b03f1e
commit
32c64a5399
@ -1,6 +1,6 @@
|
|||||||
{
|
{
|
||||||
"/js/vue/Authentication/app.js": "/js/vue/Authentication/app.js?id=584db8725dd8389d6625",
|
"/js/vue/Authentication/app.js": "/js/vue/Authentication/app.js?id=ada36e14123738cce4a1",
|
||||||
"/js/vue/Home/app.js": "/js/vue/Home/app.js?id=2c594e6374c9a8a0ea78",
|
"/js/vue/Home/app.js": "/js/vue/Home/app.js?id=4389447314d810908e49",
|
||||||
"/js/vue/Modules/CRM/app.js": "/js/vue/Modules/CRM/app.js?id=0c0fad3f977417217589",
|
"/js/vue/Modules/CRM/app.js": "/js/vue/Modules/CRM/app.js?id=59997cc242d94438537d",
|
||||||
"/js/vue/User/app.js": "/js/vue/User/app.js?id=d5b0a3c5d8bd997a7f4c"
|
"/js/vue/User/app.js": "/js/vue/User/app.js?id=32e40e7920eba25a4bb2"
|
||||||
}
|
}
|
||||||
|
@ -0,0 +1,13 @@
|
|||||||
|
import axiosApi from '@Global/utils/api/factory/axios/axiosApi'
|
||||||
|
import apolloApi from '@Global/utils/api/factory/axios/axiosApi'
|
||||||
|
import apiHandler from '@Global/utils/api/apiHandler'
|
||||||
|
|
||||||
|
export const api = (url) => {
|
||||||
|
apiHandler.request(new url['type']+'Api'(url));
|
||||||
|
}
|
||||||
|
|
||||||
|
export default {
|
||||||
|
methods: {
|
||||||
|
$_api: api(url)
|
||||||
|
},
|
||||||
|
}
|
@ -0,0 +1,7 @@
|
|||||||
|
export default class apiHandler {
|
||||||
|
|
||||||
|
request(apiMethod) {
|
||||||
|
return apiMethod.Handle();
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
@ -0,0 +1,7 @@
|
|||||||
|
export default class apiFactory {
|
||||||
|
|
||||||
|
Handle() {
|
||||||
|
return this.init();
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
@ -0,0 +1,41 @@
|
|||||||
|
import apiFactory from "../apiFactory";
|
||||||
|
|
||||||
|
export default class apolloApi extends apiFactory {
|
||||||
|
|
||||||
|
constructor(urlObj) {
|
||||||
|
super();
|
||||||
|
this.staticMethods = ["query", "mutations"];
|
||||||
|
|
||||||
|
this.method = urlObj.method;
|
||||||
|
this.gql = urlObj.gql;
|
||||||
|
this.variables = urlObj.variables;
|
||||||
|
}
|
||||||
|
|
||||||
|
init() {
|
||||||
|
if (this.checkMethod()) {
|
||||||
|
return this[this.method]();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
checkMethod() {
|
||||||
|
return this.staticMethods.includes(this.method);
|
||||||
|
}
|
||||||
|
|
||||||
|
query() {
|
||||||
|
const query = this.gql;
|
||||||
|
const variables = this.variables;
|
||||||
|
return apollo.query({
|
||||||
|
query,
|
||||||
|
variables
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
mutate() {
|
||||||
|
const mutation = this.gql;
|
||||||
|
const variables = this.variables;
|
||||||
|
return apollo.mutate({
|
||||||
|
mutation,
|
||||||
|
variables
|
||||||
|
});
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,47 @@
|
|||||||
|
import apiFactory from "../apiFactory";
|
||||||
|
import axios from "axios";
|
||||||
|
|
||||||
|
export default class axiosApi extends apiFactory {
|
||||||
|
|
||||||
|
constructor(urlObj) {
|
||||||
|
super();
|
||||||
|
this.staticMethods = ["get", "post", "put", "delete"];
|
||||||
|
|
||||||
|
this.method = urlObj.method;
|
||||||
|
this.url = urlObj.url;
|
||||||
|
this.data = urlObj.data;
|
||||||
|
}
|
||||||
|
|
||||||
|
init() {
|
||||||
|
if (this.checkMethod()) {
|
||||||
|
return this[this.method]();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
checkMethod() {
|
||||||
|
return this.staticMethods.includes(this.method);
|
||||||
|
}
|
||||||
|
|
||||||
|
get() {
|
||||||
|
const params = this.data;
|
||||||
|
return axios.get(this.url, {
|
||||||
|
params
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
post() {
|
||||||
|
return axios.post(this.url, this.data);
|
||||||
|
}
|
||||||
|
|
||||||
|
put() {
|
||||||
|
const data = this.data;
|
||||||
|
data['_method'] = 'put';
|
||||||
|
return axios.put(this.url, data);
|
||||||
|
}
|
||||||
|
|
||||||
|
delete() {
|
||||||
|
const data = this.data;
|
||||||
|
data['_method'] = 'delete';
|
||||||
|
return axios.put(this.url, data);
|
||||||
|
}
|
||||||
|
}
|
Loading…
Reference in new issue