Commit 281e67d7 authored by 何虹's avatar 何虹 💬

更改构造方式

parent 2a213db5
...@@ -93,10 +93,10 @@ class Root { ...@@ -93,10 +93,10 @@ class Root {
request (method, url, data, params, headers = null, config = {}) { request (method, url, data, params, headers = null, config = {}) {
this.filterEmptyValue(data) this.filterEmptyValue(data)
// 公共头设置 // 公共头设置
const aixosCtx = { method, url,...config } const aixosCtx = { method, url }
// if (config) { if (config) {
// Object.assign(aixosCtx, config) Object.assign(aixosCtx, config)
// } }
params && (aixosCtx.params = params) params && (aixosCtx.params = params)
if (aixosCtx.params && aixosCtx.params.token) delete aixosCtx.params.token if (aixosCtx.params && aixosCtx.params.token) delete aixosCtx.params.token
if (aixosCtx.params && aixosCtx.params._user_info) delete aixosCtx.params._user_info if (aixosCtx.params && aixosCtx.params._user_info) delete aixosCtx.params._user_info
......
This source diff could not be displayed because it is too large. You can view the blob instead.
import Root from './root'
import Billflow from './packages/modules/billflow'
import WebChartConfig from './packages/modules/webChartConfig'
import Restful from './packages/modules/restful'
import System from './packages/modules/system'
import WebQueryClient from './packages/modules/webQueryClient'
import Ref from './packages/modules/ref'
const root = new Root()
const restful = new Restful(root)
const webQueryClient = new WebQueryClient(root)
const billflow = new Billflow(root)
const system = new System(root, restful)
const webChartConfig = new WebChartConfig(root)
const ref = new Ref(root)
const list = [webQueryClient, billflow, system, webChartConfig, restful, ref]
const api = {
}
list.forEach(item => {
api[item.moduleName] = item
})
const root_prototype = root.__proto__
const root_prototype_keys = Object.getOwnPropertyNames(root_prototype)
root_prototype_keys.forEach(k => {
if (k !== 'constructor') {
api[`${k}`] = root_prototype[k]
}
})
api.init=function(axios){
root.axios=axios
}
export default api
import Root from './root'
import Billflow from './packages/modules/billflow'
import WebChartConfig from './packages/modules/webChartConfig'
import Restful from './packages/modules/restful'
import System from './packages/modules/system'
import WebQueryClient from './packages/modules/webQueryClient'
import Ref from './packages/modules/ref'
class HttpClient {
constructor(axios){
const root = new Root(axios)
const restful = new Restful(root)
const webQueryClient = new WebQueryClient(root)
const billflow = new Billflow(root)
const system = new System(root, restful)
const webChartConfig = new WebChartConfig(root)
const ref = new Ref(root)
const list = [webQueryClient, billflow, system, webChartConfig, restful, ref]
const api = {
}
list.forEach(item => {
api[item.moduleName] = item
})
const root_prototype = root.__proto__
const root_prototype_keys = Object.getOwnPropertyNames(root_prototype)
root_prototype_keys.forEach(k => {
if (k !== 'constructor') {
api[`${k}`] = root_prototype[k]
}
})
}
}
export default HttpClient
...@@ -6,24 +6,29 @@ import Restful from './packages/modules/restful' ...@@ -6,24 +6,29 @@ import Restful from './packages/modules/restful'
import System from './packages/modules/system' import System from './packages/modules/system'
import WebQueryClient from './packages/modules/webQueryClient' import WebQueryClient from './packages/modules/webQueryClient'
import Ref from './packages/modules/ref' import Ref from './packages/modules/ref'
const root = new Root() class HttpClient {
const restful = new Restful(root) constructor(axios){
const webQueryClient = new WebQueryClient(root) const root = new Root(axios)
const billflow = new Billflow(root) const restful = new Restful(root)
const system = new System(root, restful) const webQueryClient = new WebQueryClient(root)
const webChartConfig = new WebChartConfig(root) const billflow = new Billflow(root)
const ref = new Ref(root) const system = new System(root, restful)
const list = [webQueryClient, billflow, system, webChartConfig, restful, ref] const webChartConfig = new WebChartConfig(root)
const api = { const ref = new Ref(root)
} const list = [webQueryClient, billflow, system, webChartConfig, restful, ref]
list.forEach(item => { const api = {
}
list.forEach(item => {
api[item.moduleName] = item api[item.moduleName] = item
}) })
const root_prototype = root.__proto__ const root_prototype = root.__proto__
const root_prototype_keys = Object.getOwnPropertyNames(root_prototype) const root_prototype_keys = Object.getOwnPropertyNames(root_prototype)
root_prototype_keys.forEach(k => { root_prototype_keys.forEach(k => {
if (k !== 'constructor') { if (k !== 'constructor') {
api[`${k}`] = root_prototype[k] api[`${k}`] = root_prototype[k]
} }
}) })
export default api }
}
export default HttpClient
import axios from 'axios' import axios from 'axios'
class Root { class Root {
constructor(_axios) {
this.axios = _axios || axios
}
filterEmptyValue (obj) { filterEmptyValue (obj) {
if (!obj) return if (!obj) return
const emptyValues = [null, undefined, 'null', 'undefined', NaN] const emptyValues = [null, undefined, 'null', 'undefined', NaN]
...@@ -39,7 +42,7 @@ class Root { ...@@ -39,7 +42,7 @@ class Root {
if (aixosCtx.params && aixosCtx.params._user_info) delete aixosCtx.params._user_info if (aixosCtx.params && aixosCtx.params._user_info) delete aixosCtx.params._user_info
data && (aixosCtx.data = data) data && (aixosCtx.data = data)
headers && (aixosCtx.headers = headers) headers && (aixosCtx.headers = headers)
const result = axios(aixosCtx) const result = this.axios(aixosCtx)
return result return result
} }
} }
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment