Skip to content
项目
群组
代码片段
帮助
当前项目
正在载入...
登录 / 注册
切换导航面板
A
app-manage-console
项目
项目
详情
活动
周期分析
仓库
仓库
文件
提交
分支
标签
贡献者
图表
比较
统计图
议题
0
议题
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
CI / CD
CI / CD
流水线
作业
日程
统计图
Wiki
Wiki
代码片段
代码片段
成员
成员
折叠边栏
关闭边栏
活动
图像
聊天
创建新问题
作业
提交
问题看板
Open sidebar
ReactNative
app-manage-console
Commits
009a684a
提交
009a684a
authored
3月 02, 2018
作者:
vipcxj
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
资源查询rest api重构
上级
86053616
隐藏空白字符变更
内嵌
并排
正在显示
1 个修改的文件
包含
90 行增加
和
33 行删除
+90
-33
resource.js
src/services/resource.js
+90
-33
没有找到文件。
src/services/resource.js
浏览文件 @
009a684a
import
{
castArray
}
from
'lodash'
;
import
post
from
'../utils/post'
;
import
config
from
'../utils/config'
;
import
request
from
'../utils/request'
;
...
...
@@ -61,6 +60,92 @@ export class Operations {
};
}
export
class
Query
{
constructor
()
{
this
.
pageSize
=
-
1
;
}
setAfter
=
(
after
)
=>
{
this
.
after
=
after
;
};
setOrder
=
()
=>
{
const
argn
=
arguments
.
length
;
if
(
argn
>
0
)
{
this
.
orders
=
[];
let
lastOrder
;
for
(
let
i
=
0
;
i
<
argn
;
++
i
)
{
if
(
lastOrder
!==
undefined
&&
(
typeof
arguments
[
i
]
===
'boolean'
))
{
this
.
orders
.
push
({
target
:
lastOrder
,
asc
:
arguments
[
i
],
});
lastOrder
=
undefined
;
}
else
if
(
lastOrder
!==
undefined
)
{
this
.
orders
.
push
({
target
:
lastOrder
,
asc
:
true
,
});
lastOrder
=
arguments
[
i
];
}
else
{
lastOrder
=
arguments
[
i
];
}
}
if
(
lastOrder
!==
undefined
)
{
this
.
orders
.
push
({
target
:
lastOrder
,
asc
:
true
,
});
}
}
};
setPageSize
=
(
size
)
=>
{
this
.
pageSize
=
size
>=
0
?
size
:
-
1
;
};
setCondition
=
(
condition
)
=>
{
this
.
condition
=
condition
;
};
setStores
=
(...
stores
)
=>
{
this
.
stores
=
stores
;
};
static
tag
=
(...
tags
)
=>
{
if
(
tags
.
length
===
0
)
{
throw
new
Error
(
'At least one tag!'
);
}
if
(
tags
.
length
===
1
)
{
return
{
type
:
'tag'
,
value
:
tags
[
0
],
};
}
else
{
return
Query
.
and
(...
tags
.
map
(
tag
=>
Query
.
tag
(
tag
)));
}
};
static
usage
=
(...
usage
)
=>
{
if
(
usage
.
length
===
0
)
{
throw
new
Error
(
'At least one usage!'
);
}
if
(
usage
.
length
===
1
)
{
return
{
type
:
'usage'
,
value
:
usage
[
0
],
};
}
else
{
return
Query
.
and
(...
usage
.
map
(
tag
=>
Query
.
usage
(
tag
)));
}
};
static
and
=
(...
conditions
)
=>
{
return
{
type
:
'and'
,
conditions
,
};
};
static
or
=
(...
conditions
)
=>
{
return
{
type
:
'or'
,
conditions
,
};
};
}
export
const
createOperations
=
()
=>
{
return
new
Operations
();
};
...
...
@@ -69,38 +154,10 @@ export async function editResource(uri, operations) {
return
post
(
`
${
config
.
apiContextPath
}
/api/resource/user/
${
encodeURIComponent
(
uri
)}
/meta`
,
{
operations
:
operations
.
operations
});
}
export
async
function
getResourceInfo
(
uri
)
{
return
request
(
`
${
config
.
apiContextPath
}
/api/resource/user/
${
encodeURIComponent
(
uri
)}
/meta`
);
}
export
async
function
queryResourceByUsage
(
usage
,
pst
=
-
1
,
psz
=
-
1
)
{
return
request
(
`
${
config
.
apiContextPath
}
/api/resource/user/query`
,
{
usage
,
pst
,
psz
});
export
async
function
queryResource
(
query
)
{
return
post
(
`
${
config
.
apiContextPath
}
/api/resource/user/query`
,
query
);
}
export
async
function
queryResourceByUsageStartWith
(
usage
,
pst
=
-
1
,
psz
=
-
1
)
{
return
request
(
`
${
config
.
apiContextPath
}
/api/resource/user/query`
,
{
usage
,
startWith
:
true
,
pst
,
psz
});
}
export
async
function
queryResourceByAllTags
(
tags
,
pst
=
-
1
,
psz
=
-
1
)
{
return
request
(
`
${
config
.
apiContextPath
}
/api/resource/user/query`
,
{
tags
:
castArray
(
tags
),
pst
,
psz
});
}
export
async
function
queryResourceByAnyTags
(
tags
,
pst
=
-
1
,
psz
=
-
1
)
{
return
request
(
`
${
config
.
apiContextPath
}
/api/resource/user/query`
,
{
tags
:
castArray
(
tags
),
andOr
:
'or'
,
pst
,
psz
});
}
export
async
function
queryResourceByUsageAndAllTags
(
usage
,
tags
,
pst
=
-
1
,
psz
=
-
1
)
{
return
request
(
`
${
config
.
apiContextPath
}
/api/resource/user/query`
,
{
usage
,
tags
:
castArray
(
tags
),
pst
,
psz
});
}
export
async
function
queryResourceByUsageAndAnyTags
(
usage
,
tags
,
pst
=
-
1
,
psz
=
-
1
)
{
return
request
(
`
${
config
.
apiContextPath
}
/api/resource/user/query`
,
{
usage
,
tags
:
castArray
(
tags
),
andOr
:
'or'
,
pst
,
psz
});
}
export
async
function
queryResourceByUsageStartWithAndAllTags
(
usage
,
tags
,
pst
=
-
1
,
psz
=
-
1
)
{
return
request
(
`
${
config
.
apiContextPath
}
/api/resource/user/query`
,
{
usage
,
startWith
:
true
,
tags
:
castArray
(
tags
),
pst
,
psz
});
}
export
async
function
queryResourceByUsageStartWithAndAnyTags
(
usage
,
tags
,
pst
=
-
1
,
psz
=
-
1
)
{
return
request
(
`
${
config
.
apiContextPath
}
/api/resource/user/query`
,
{
usage
,
startWith
:
true
,
tags
:
castArray
(
tags
),
andOr
:
'or'
,
pst
,
psz
});
export
async
function
getResourceInfo
(
uri
)
{
return
request
(
`
${
config
.
apiContextPath
}
/api/resource/user/
${
encodeURIComponent
(
uri
)}
/meta`
);
}
编写
预览
Markdown
格式
0%
重试
或
添加新文件
添加附件
取消
您添加了
0
人
到此讨论。请谨慎行事。
请先完成此评论的编辑!
取消
请
注册
或者
登录
后发表评论