Skip to content
项目
群组
代码片段
帮助
当前项目
正在载入...
登录 / 注册
切换导航面板
A
app-manage-console
项目
项目
详情
活动
周期分析
仓库
仓库
文件
提交
分支
标签
贡献者
图表
比较
统计图
议题
0
议题
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
CI / CD
CI / CD
流水线
作业
日程
统计图
Wiki
Wiki
代码片段
代码片段
成员
成员
折叠边栏
关闭边栏
活动
图像
聊天
创建新问题
作业
提交
问题看板
Open sidebar
ReactNative
app-manage-console
Commits
11e3ac99
提交
11e3ac99
authored
9月 17, 2018
作者:
vipcxj
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
完善模块,数据源和接口相关api
上级
8b6f48b1
隐藏空白字符变更
内嵌
并排
正在显示
4 个修改的文件
包含
252 行增加
和
34 行删除
+252
-34
datasource.js
src/services/datasource.js
+93
-31
interfaces.js
src/services/interfaces.js
+58
-3
modules.js
src/services/modules.js
+73
-0
request.js
src/utils/request.js
+28
-0
没有找到文件。
src/services/datasource.js
浏览文件 @
11e3ac99
import
mapKeys
from
'lodash/mapKeys'
;
import
toPairs
from
'lodash/toPairs'
;
import
isUndefined
from
'lodash/isUndefined'
;
import
isString
from
'lodash/isString'
;
import
isString
from
'lodash/isString'
;
import
partial
from
'lodash/fp/partial'
;
import
partial
from
'lodash/fp/partial'
;
import
request
from
'../utils/request'
;
import
request
,
{
makeParams
}
from
'../utils/request'
;
import
post
from
'../utils/post'
;
import
post
from
'../utils/post'
;
import
{
normParams
}
from
'../utils/http-helper'
;
import
{
split
}
from
'../utils/filter'
;
import
config
from
'../utils/config'
;
import
config
from
'../utils/config'
;
import
{
getDomain
}
from
'../utils/auth'
;
const
parseFilters
=
filtersIn
=>
(
filtersIn
||
[]).
filter
(({
filter
})
=>
!!
filter
).
map
(({
key
,
filter
})
=>
[
split
(
key
,
false
).
map
(
value
=>
`f-
${
value
}
`
).
join
(
'|'
),
filter
,
]);
export
const
datasourceApi
=
(
coordinate
)
=>
{
export
const
datasourceApi
=
(
coordinate
)
=>
{
const
{
containerType
,
containerName
,
datasourceName
}
=
isString
(
coordinate
)
?
{
const
{
containerType
,
containerName
,
datasourceName
}
=
isString
(
coordinate
)
?
{
containerType
:
'global'
,
containerType
:
'global'
,
modul
eName
:
coordinate
,
datasourc
eName
:
coordinate
,
}
:
(
coordinate
||
{});
}
:
(
coordinate
||
{});
if
(
containerType
===
'global'
)
{
if
(
containerType
===
'global'
)
{
return
{
return
{
...
@@ -62,25 +53,6 @@ export const datasourceApi = (coordinate) => {
...
@@ -62,25 +53,6 @@ export const datasourceApi = (coordinate) => {
}
}
};
};
const
makeQueryParams
=
({
pst
,
psz
,
filters
=
[],
sortBys
=
[],
sortTypes
=
[],
params
=
{}
})
=>
{
let
stBy
=
sortBys
.
join
(
','
);
stBy
=
stBy
||
undefined
;
let
stType
=
sortTypes
.
join
(
','
);
stType
=
stType
||
undefined
;
return
[
...
toPairs
({
pst
,
psz
,
stBy
,
stType
}),
...
parseFilters
(
filters
),
...
normParams
(
mapKeys
(
params
,
(
v
,
k
)
=>
`p-
${
k
}
`
)),
].
filter
(
v
=>
v
&&
!
isUndefined
((
v
[
1
])));
};
const
makeParams
=
(
otherParams
,
{
filters
=
[],
sortBys
=
[],
sortTypes
=
[],
params
=
{}
})
=>
{
return
[
...
toPairs
(
otherParams
),
...
makeQueryParams
({
filters
,
sortBys
,
sortTypes
,
params
}),
].
filter
(
v
=>
v
&&
!
isUndefined
((
v
[
1
])));
};
export
async
function
calcGlobalDatasource
(
name
,
{
pst
,
psz
,
filters
=
[],
sortBys
=
[],
sortTypes
=
[],
params
=
{},
dmPath
})
{
export
async
function
calcGlobalDatasource
(
name
,
{
pst
,
psz
,
filters
=
[],
sortBys
=
[],
sortTypes
=
[],
params
=
{},
dmPath
})
{
return
request
(
`
${
config
.
apiContextPath
}
/api/datasource/
${
name
}
`
,
makeParams
({
pst
,
psz
,
dmPath
},
{
filters
,
sortBys
,
sortTypes
,
params
}));
return
request
(
`
${
config
.
apiContextPath
}
/api/datasource/
${
name
}
`
,
makeParams
({
pst
,
psz
,
dmPath
},
{
filters
,
sortBys
,
sortTypes
,
params
}));
}
}
...
@@ -253,3 +225,93 @@ export async function getModuleDatasourceMeta(mdName, dsName) {
...
@@ -253,3 +225,93 @@ export async function getModuleDatasourceMeta(mdName, dsName) {
return
request
(
`
${
config
.
apiContextPath
}
/api/module/user/
${
mdName
}
/datasource/
${
dsName
}
/meta`
);
return
request
(
`
${
config
.
apiContextPath
}
/api/module/user/
${
mdName
}
/datasource/
${
dsName
}
/meta`
);
}
}
export
class
Datasource
{
constructor
(
coordinate
,
dmPath
)
{
this
.
api
=
datasourceApi
(
coordinate
);
this
.
dmPath
=
dmPath
;
this
.
dealWithPath
=
::
this
.
dealWithPath
;
this
.
query
=
::
this
.
query
;
this
.
queryMeta
=
::
this
.
queryMeta
;
this
.
count
=
::
this
.
count
;
this
.
countMeta
=
::
this
.
countMeta
;
this
.
cursor
=
::
this
.
cursor
;
this
.
cursorMeta
=
::
this
.
cursorMeta
;
this
.
update
=
::
this
.
update
;
this
.
updateMeta
=
::
this
.
updateMeta
;
this
.
validateUpdate
=
::
this
.
validateUpdate
;
this
.
create
=
::
this
.
create
;
this
.
createMeta
=
::
this
.
createMeta
;
this
.
validateCreate
=
::
this
.
validateCreate
;
this
.
remove
=
::
this
.
remove
;
this
.
removeMeta
=
::
this
.
removeMeta
;
this
.
validateRemove
=
::
this
.
validateRemove
;
}
async
dealWithPath
()
{
if
(
this
.
dmPath
)
{
return
this
.
dmPath
;
}
else
{
const
domain
=
await
getDomain
();
return
domain
.
path
;
}
}
async
query
(
params
=
{},
pst
=
0
,
psz
=
-
1
,
{
filters
=
[],
sortBys
=
[],
sortTypes
=
[]
})
{
const
dmPath
=
await
this
.
dealWithPath
();
return
this
.
api
.
query
({
pst
,
psz
,
filters
,
sortBys
,
sortTypes
,
params
,
dmPath
});
}
async
queryMeta
(
params
=
{})
{
const
dmPath
=
await
this
.
dealWithPath
();
return
this
.
api
.
query
({
params
,
dmPath
});
}
async
count
(
params
=
{},
{
filters
=
[]
})
{
const
dmPath
=
await
this
.
dealWithPath
();
return
this
.
api
.
count
({
filters
,
params
,
dmPath
});
}
async
countMeta
(
params
=
{})
{
const
dmPath
=
await
this
.
dealWithPath
();
return
this
.
api
.
countMeta
({
params
,
dmPath
});
}
async
cursor
(
key
,
params
=
{})
{
const
dmPath
=
await
this
.
dealWithPath
();
return
this
.
api
.
cursor
(
key
,
params
,
dmPath
);
}
async
cursorMeta
(
key
,
params
=
{})
{
const
dmPath
=
await
this
.
dealWithPath
();
return
this
.
api
.
cursorMeta
(
key
,
params
,
dmPath
);
}
async
update
(
key
,
params
=
{})
{
const
dmPath
=
await
this
.
dealWithPath
();
return
this
.
api
.
update
(
key
,
params
,
dmPath
);
}
async
updateMeta
(
key
,
params
=
{})
{
const
dmPath
=
await
this
.
dealWithPath
();
return
this
.
api
.
updateMeta
(
key
,
params
,
dmPath
);
}
async
validateUpdate
(
key
,
params
=
{})
{
const
dmPath
=
await
this
.
dealWithPath
();
return
this
.
api
.
validateUpdate
(
key
,
params
,
dmPath
);
}
async
create
(
params
=
{})
{
const
dmPath
=
await
this
.
dealWithPath
();
return
this
.
api
.
create
(
params
,
dmPath
);
}
async
createMeta
(
params
=
{})
{
const
dmPath
=
await
this
.
dealWithPath
();
return
this
.
api
.
createMeta
(
params
,
dmPath
);
}
async
validateCreate
(
params
=
{})
{
const
dmPath
=
await
this
.
dealWithPath
();
return
this
.
api
.
validateCreate
(
params
,
dmPath
);
}
async
remove
(
key
,
params
=
{})
{
const
dmPath
=
await
this
.
dealWithPath
();
return
this
.
api
.
remove
(
key
,
params
,
dmPath
);
}
async
removeMeta
(
key
,
params
=
{})
{
const
dmPath
=
await
this
.
dealWithPath
();
return
this
.
api
.
removeMeta
(
key
,
params
,
dmPath
);
}
async
validateRemove
(
key
,
params
=
{})
{
const
dmPath
=
await
this
.
dealWithPath
();
return
this
.
api
.
validateRemove
(
key
,
params
,
dmPath
);
}
}
src/services/interfaces.js
浏览文件 @
11e3ac99
import
request
from
'../utils/request'
;
import
isString
from
'lodash/isString'
;
import
partial
from
'lodash/fp/partial'
;
import
request
,
{
makeParams
}
from
'../utils/request'
;
import
post
from
'../utils/post'
;
import
post
from
'../utils/post'
;
import
doDelete
from
'../utils/delete'
;
import
doDelete
from
'../utils/delete'
;
import
config
from
'../utils/config'
;
import
config
from
'../utils/config'
;
import
{
getDomain
}
from
'../utils/auth'
;
export
const
interfaceApi
=
(
coordinate
)
=>
{
const
{
containerType
,
containerName
,
interfaceName
}
=
isString
(
coordinate
)
?
{
containerType
:
'global'
,
interfaceName
:
coordinate
,
}
:
(
coordinate
||
{});
if
(
containerType
===
'global'
)
{
return
{
invoke
:
partial
(
userApi
.
invokeInterface
,
[
interfaceName
]),
validate
:
partial
(
userApi
.
validateState
,
[
interfaceName
]),
};
}
else
if
(
containerType
===
'module'
)
{
return
{
invoke
:
partial
(
userApi
.
invokeModuleInterface
,
[
containerName
,
interfaceName
]),
validate
:
partial
(
userApi
.
validateModuleInterface
,
[
containerName
,
interfaceName
]),
};
}
else
{
throw
new
Error
(
`Unsupported containerType:
${
containerType
}
`
);
}
};
export
const
userApi
=
{
export
const
userApi
=
{
async
getAllInterfaceInfoes
()
{
async
getAllInterfaceInfoes
()
{
...
@@ -10,12 +33,18 @@ export const userApi = {
...
@@ -10,12 +33,18 @@ export const userApi = {
async
getInterfaceInfo
(
name
)
{
async
getInterfaceInfo
(
name
)
{
return
request
(
`
${
config
.
apiContextPath
}
/api/interface/user/
${
encodeURIComponent
(
name
)}
/info`
);
return
request
(
`
${
config
.
apiContextPath
}
/api/interface/user/
${
encodeURIComponent
(
name
)}
/info`
);
},
},
async
validateState
(
name
,
dmPath
)
{
async
validateState
(
name
,
params
,
dmPath
)
{
return
request
(
`
${
config
.
apiContextPath
}
/api/interface/user/
${
encodeURIComponent
(
name
)}
/invoke/validateState`
,
{
dmPath
}
);
return
request
(
`
${
config
.
apiContextPath
}
/api/interface/user/
${
encodeURIComponent
(
name
)}
/invoke/validateState`
,
makeParams
({
dmPath
},
{
params
})
);
},
},
async
invokeInterface
(
name
,
params
,
dmPath
)
{
async
invokeInterface
(
name
,
params
,
dmPath
)
{
return
post
(
`
${
config
.
apiContextPath
}
/api/interface/user/
${
encodeURIComponent
(
name
)}
/invoke`
,
{
params
,
dmPath
});
return
post
(
`
${
config
.
apiContextPath
}
/api/interface/user/
${
encodeURIComponent
(
name
)}
/invoke`
,
{
params
,
dmPath
});
},
},
async
validateModuleInterface
(
mdName
,
name
,
params
,
dmPath
)
{
return
request
(
`
${
config
.
apiContextPath
}
/api/module/user/
${
encodeURIComponent
(
mdName
)}
/interface/
${
encodeURIComponent
(
name
)}
/invoke/validateState`
,
makeParams
({
dmPath
},
{
params
}));
},
async
invokeModuleInterface
(
mdName
,
name
,
params
,
dmPath
)
{
return
post
(
`
${
config
.
apiContextPath
}
/api/module/user/
${
encodeURIComponent
(
mdName
)}
/interface/
${
encodeURIComponent
(
name
)}
/invoke`
,
{
params
,
dmPath
});
},
async
getInterfaceDocument
(
name
,
dmPath
)
{
async
getInterfaceDocument
(
name
,
dmPath
)
{
return
request
(
`
${
config
.
apiContextPath
}
/api/interface/user/
${
encodeURIComponent
(
name
)}
/document`
,
{
dmPath
});
return
request
(
`
${
config
.
apiContextPath
}
/api/interface/user/
${
encodeURIComponent
(
name
)}
/document`
,
{
dmPath
});
},
},
...
@@ -53,3 +82,29 @@ export const adminApi = {
...
@@ -53,3 +82,29 @@ export const adminApi = {
return
post
(
`
${
config
.
apiContextPath
}
/api/interface/admin/
${
encodeURIComponent
(
name
)}
/document`
,
{
document
,
dmPath
});
return
post
(
`
${
config
.
apiContextPath
}
/api/interface/admin/
${
encodeURIComponent
(
name
)}
/document`
,
{
document
,
dmPath
});
},
},
};
};
export
class
Interface
{
constructor
(
coordinate
,
dmPath
)
{
this
.
api
=
interfaceApi
(
coordinate
);
this
.
dmPath
=
dmPath
;
this
.
dealWithPath
=
::
this
.
dealWithPath
;
this
.
invoke
=
::
this
.
invoke
;
this
.
validate
=
::
this
.
validate
;
}
async
dealWithPath
()
{
if
(
this
.
dmPath
)
{
return
this
.
dmPath
;
}
else
{
const
domain
=
await
getDomain
();
return
domain
.
path
;
}
}
async
invoke
(
params
=
{})
{
const
dmPath
=
await
this
.
dealWithPath
();
return
this
.
api
.
invoke
(
params
,
dmPath
);
}
async
validate
(
params
=
{})
{
const
dmPath
=
await
this
.
dealWithPath
();
return
this
.
api
.
validate
(
params
,
dmPath
);
}
}
src/services/modules.js
浏览文件 @
11e3ac99
/* eslint-disable no-underscore-dangle */
import
{
Datasource
}
from
'datasource'
;
import
request
from
'../utils/request'
;
import
request
from
'../utils/request'
;
import
post
from
'../utils/post'
;
import
post
from
'../utils/post'
;
import
config
from
'../utils/config'
;
import
config
from
'../utils/config'
;
import
{
Interface
}
from
'./interfaces'
;
export
async
function
fetchMenus
()
{
export
async
function
fetchMenus
()
{
return
request
(
`
${
config
.
apiContextPath
}
/api/configure/user/menus`
);
return
request
(
`
${
config
.
apiContextPath
}
/api/configure/user/menus`
);
...
@@ -59,3 +62,73 @@ export const userApi = {
...
@@ -59,3 +62,73 @@ export const userApi = {
return
request
(
`
${
config
.
apiContextPath
}
/api/module/user/
${
encodeURIComponent
(
name
)}
/document`
,
{
dmPath
});
return
request
(
`
${
config
.
apiContextPath
}
/api/module/user/
${
encodeURIComponent
(
name
)}
/document`
,
{
dmPath
});
},
},
};
};
export
class
Module
{
constructor
(
name
,
dmPath
)
{
this
.
name
=
name
;
this
.
dmPath
=
dmPath
;
this
.
_admin
=
false
;
}
get
admin
()
{
return
this
.
_admin
;
}
set
admin
(
admin
)
{
this
.
_admin
=
admin
;
}
get
info
()
{
if
(
this
.
admin
)
{
return
adminApi
.
getInfo
(
this
.
name
,
this
.
dmPath
);
}
else
{
return
userApi
.
getInfo
(
this
.
name
,
this
.
dmPath
);
}
}
get
layout
()
{
if
(
this
.
admin
)
{
return
adminApi
.
getLayout
(
this
.
name
,
this
.
dmPath
);
}
else
{
return
userApi
.
getLayout
(
this
.
name
,
this
.
dmPath
);
}
}
get
document
()
{
if
(
this
.
admin
)
{
return
adminApi
.
getDocument
(
this
.
name
,
this
.
dmPath
);
}
else
{
return
userApi
.
getDocument
(
this
.
name
,
this
.
dmPath
);
}
}
async
setDocument
(
doc
)
{
if
(
this
.
admin
)
{
return
adminApi
.
setDocument
(
this
.
name
,
doc
,
this
.
dmPath
);
}
throw
new
Error
(
'Set admin to true before set document.'
);
}
get
configure
()
{
if
(
this
.
admin
)
{
return
adminApi
.
getPlainConfigure
(
this
.
name
,
this
.
dmPath
);
}
else
{
return
userApi
.
getPlainConfigure
(
this
.
name
,
this
.
dmPath
);
}
}
async
setConfigure
(
conf
)
{
if
(
this
.
admin
)
{
return
adminApi
.
setConfigure
(
this
.
name
,
conf
,
this
.
dmPath
);
}
throw
new
Error
(
'Set admin to true before set configure.'
);
}
getDatasource
(
name
)
{
const
coordinate
=
{
containerType
:
'module'
,
containerName
:
this
.
name
,
datasourceName
:
name
,
};
return
new
Datasource
(
coordinate
,
this
.
dmPath
);
}
getInterface
(
name
)
{
const
coordinate
=
{
containerType
:
'module'
,
containerName
:
this
.
name
,
interfaceName
:
name
,
};
return
new
Interface
(
coordinate
,
this
.
dmPath
);
}
}
src/utils/request.js
浏览文件 @
11e3ac99
import
isNil
from
'lodash/isNil'
;
import
isNil
from
'lodash/isNil'
;
import
defaults
from
'lodash/defaults'
;
import
defaults
from
'lodash/defaults'
;
import
toPairs
from
'lodash/toPairs'
;
import
mapKeys
from
'lodash/mapKeys'
;
import
isUndefined
from
'lodash/isUndefined'
;
import
{
fetch
}
from
'./polyfill'
;
import
{
fetch
}
from
'./polyfill'
;
import
{
checkStatus
,
normParams
,
parseObject
}
from
'./http-helper'
;
import
{
checkStatus
,
normParams
,
parseObject
}
from
'./http-helper'
;
import
middleware
from
'./middleware'
;
import
middleware
from
'./middleware'
;
import
{
split
}
from
'./filter'
;
const
parseFilters
=
filtersIn
=>
(
filtersIn
||
[]).
filter
(({
filter
})
=>
!!
filter
).
map
(({
key
,
filter
})
=>
[
split
(
key
,
false
).
map
(
value
=>
`f-
${
value
}
`
).
join
(
'|'
),
filter
,
]);
const
makeQueryParams
=
({
pst
,
psz
,
filters
=
[],
sortBys
=
[],
sortTypes
=
[],
params
=
{}
})
=>
{
let
stBy
=
sortBys
.
join
(
','
);
stBy
=
stBy
||
undefined
;
let
stType
=
sortTypes
.
join
(
','
);
stType
=
stType
||
undefined
;
return
[
...
toPairs
({
pst
,
psz
,
stBy
,
stType
}),
...
parseFilters
(
filters
),
...
normParams
(
mapKeys
(
params
,
(
v
,
k
)
=>
`p-
${
k
}
`
)),
].
filter
(
v
=>
v
&&
!
isUndefined
((
v
[
1
])));
};
export
const
makeParams
=
(
otherParams
,
{
filters
=
[],
sortBys
=
[],
sortTypes
=
[],
params
=
{}
})
=>
{
return
[
...
toPairs
(
otherParams
),
...
makeQueryParams
({
filters
,
sortBys
,
sortTypes
,
params
}),
].
filter
(
v
=>
v
&&
!
isUndefined
((
v
[
1
])));
};
const
defaultOptions
=
{
const
defaultOptions
=
{
headers
:
{
Accept
:
'application/json'
},
headers
:
{
Accept
:
'application/json'
},
...
...
编写
预览
Markdown
格式
0%
重试
或
添加新文件
添加附件
取消
您添加了
0
人
到此讨论。请谨慎行事。
请先完成此评论的编辑!
取消
请
注册
或者
登录
后发表评论