Skip to content
项目
群组
代码片段
帮助
正在加载...
帮助
提交反馈
为 GitLab 提交贡献
登录
切换导航
iBiz-Vue-R7-Res
项目
项目
详情
动态
版本
周期分析
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
统计图
议题
0
议题
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
CI / CD
CI / CD
流水线
作业
计划
统计图
Wiki
Wiki
代码片段
代码片段
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
统计图
创建新议题
作业
提交
议题看板
打开侧边栏
iBiz-R7前端标准模板
iBiz-Vue-R7-Res
提交
a7cae7ca
提交
a7cae7ca
编写于
5月 10, 2022
作者:
Mosher
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
update:更新支持预定义代码表服务缓存
上级
a34f407b
变更
1
隐藏空白字符变更
内嵌
并排
正在显示
1 个修改的文件
包含
83 行增加
和
92 行删除
+83
-92
codelist-service.ts
src/codelist/codelist-service.ts
+83
-92
未找到文件。
src/codelist/codelist-service.ts
浏览文件 @
a7cae7ca
...
...
@@ -39,7 +39,7 @@ export default class CodeListService {
* @type {Map<string,any>}
* @memberof CodeListService
*/
public
static
codelistCache
:
Map
<
string
,
any
>
=
new
Map
();
public
static
codelistCache
:
Map
<
string
,
any
>
=
new
Map
();
/**
* 动态代码表缓存(已完成)
...
...
@@ -47,7 +47,7 @@ export default class CodeListService {
* @type {Map<string,any>}
* @memberof CodeListService
*/
public
static
codelistCached
:
Map
<
string
,
any
>
=
new
Map
();
public
static
codelistCached
:
Map
<
string
,
any
>
=
new
Map
();
/**
* 数据服务基类
...
...
@@ -55,7 +55,7 @@ export default class CodeListService {
* @type {Minorentity}
* @memberof CodeListService
*/
public
entityService
:
EntityService
=
new
EntityService
();
public
entityService
:
EntityService
=
new
EntityService
();
/**
* 获取代码表服务
...
...
@@ -79,15 +79,15 @@ export default class CodeListService {
* @returns {Promise<any[]>}
* @memberof CodeListService
*/
public
async
getDataItems
(
codelist
:
any
,
context
?:
any
,
data
?:
any
,
isloading
?:
boolean
)
{
let
dataItems
:
Array
<
any
>
=
[];
try
{
if
(
codelist
.
tag
&&
Object
.
is
(
codelist
.
type
,
"STATIC"
))
{
public
async
getDataItems
(
codelist
:
any
,
context
?:
any
,
data
?:
any
,
isloading
?:
boolean
)
{
let
dataItems
:
Array
<
any
>
=
[];
try
{
if
(
codelist
.
tag
&&
Object
.
is
(
codelist
.
type
,
"STATIC"
))
{
dataItems
=
await
this
.
getStaticItems
(
codelist
.
tag
);
}
else
{
dataItems
=
await
this
.
getItems
(
codelist
.
tag
,
codelist
.
context
,
codelist
.
viewparam
,
codelist
.
isloading
);
}
else
{
dataItems
=
await
this
.
getItems
(
codelist
.
tag
,
codelist
.
context
,
codelist
.
viewparam
,
codelist
.
isloading
);
}
}
catch
(
error
)
{
}
catch
(
error
)
{
console
.
warn
(
"代码表加载异常"
+
error
);
}
return
dataItems
;
...
...
@@ -100,8 +100,8 @@ export default class CodeListService {
* @returns {Promise<any[]>}
* @memberof CodeListService
*/
public
getStaticItems
(
tag
:
string
):
Promise
<
any
[]
>
{
return
new
Promise
((
resolve
:
any
,
reject
:
any
)
=>
{
public
getStaticItems
(
tag
:
string
):
Promise
<
any
[]
>
{
return
new
Promise
((
resolve
:
any
,
reject
:
any
)
=>
{
const
codelist
=
this
.
$store
.
getters
.
getCodeList
(
tag
);
if
(
codelist
)
{
let
items
:
Array
<
any
>
=
[...
JSON
.
parse
(
JSON
.
stringify
(
codelist
.
items
))];
...
...
@@ -117,33 +117,17 @@ export default class CodeListService {
* @returns {Promise<any[]>}
* @memberof CodeListService
*/
public
getPredefinedItems
(
tag
:
string
,
data
?:
any
,
isloading
?:
boolean
):
Promise
<
any
[]
>
{
return
new
Promise
((
resolve
:
any
,
reject
:
any
)
=>
{
if
(
CodeListService
.
codelistCached
.
get
(
`
${
tag
}
`
)){
let
items
:
any
=
CodeListService
.
codelistCached
.
get
(
`
${
tag
}
`
).
items
;
if
(
items
.
length
>
0
)
resolve
(
items
);
}
const
callback
:
Function
=
(
tag
:
string
,
promise
:
Promise
<
any
>
)
=>
{
promise
.
then
((
res
:
any
)
=>
{
let
result
:
any
=
res
.
data
;
if
(
result
.
items
&&
result
.
items
.
length
>
0
){
CodeListService
.
codelistCached
.
set
(
`
${
tag
}
`
,{
items
:
result
.
items
});
return
resolve
(
result
.
items
);
}
else
{
return
resolve
([]);
}
}).
catch
((
result
:
any
)
=>
{
return
reject
(
result
);
})
}
// 加载中,UI又需要数据,解决连续加载同一代码表问题
if
(
CodeListService
.
codelistCache
.
get
(
`
${
tag
}
`
)){
callback
(
tag
,
CodeListService
.
codelistCache
.
get
(
`
${
tag
}
`
));
}
else
{
let
result
:
Promise
<
any
>
=
this
.
entityService
.
getPredefinedCodelist
(
tag
);
CodeListService
.
codelistCache
.
set
(
`
${
tag
}
`
,
result
);
callback
(
tag
,
result
);
}
public
getPredefinedItems
(
tag
:
string
,
data
?:
any
,
isloading
?:
boolean
):
Promise
<
any
[]
>
{
return
new
Promise
((
resolve
:
any
,
reject
:
any
)
=>
{
this
.
entityService
.
getPredefinedCodelist
(
tag
).
then
((
response
:
any
)
=>
{
if
(
response
&&
response
.
status
===
200
&&
response
.
data
&&
response
.
data
.
items
)
{
resolve
(
response
.
data
.
items
);
}
else
{
resolve
([]);
}
}).
catch
((
error
:
any
)
=>
{
resolve
([]);
});
})
}
...
...
@@ -155,70 +139,77 @@ export default class CodeListService {
* @returns {Promise<any[]>}
* @memberof CodeListService
*/
public
getItems
(
tag
:
string
,
context
:
any
=
{},
data
?:
any
,
isloading
?:
boolean
):
Promise
<
any
[]
>
{
public
getItems
(
tag
:
string
,
context
:
any
=
{},
data
?:
any
,
isloading
?:
boolean
):
Promise
<
any
[]
>
{
let
_this
:
any
=
this
;
if
(
context
&&
context
.
srfsessionid
)
{
if
(
context
&&
context
.
srfsessionid
)
{
delete
context
.
srfsessionid
;
}
return
new
Promise
((
resolve
:
any
,
reject
:
any
)
=>
{
this
.
getService
(
tag
).
then
((
codelist
:
any
)
=>
{
if
(
Object
.
is
(
codelist
.
predefinedType
,
"RUNTIME"
)){
this
.
getPredefinedItems
(
tag
).
then
((
res
:
any
)
=>
{
resolve
(
res
);
})
return
;
}
let
isEnableCache
:
boolean
=
codelist
.
isEnableCache
;
let
cacheTimeout
:
any
=
codelist
.
cacheTimeout
;
// 启用缓存
if
(
isEnableCache
){
const
callback
:
Function
=
(
context
:
any
=
{},
data
:
any
=
{},
tag
:
string
,
promise
:
Promise
<
any
>
)
=>
{
const
callbackKey
:
string
=
`
${
JSON
.
stringify
(
context
)}
-
${
JSON
.
stringify
(
data
)}
-
${
tag
}
`
;
promise
.
then
((
result
:
any
)
=>
{
if
(
result
.
length
>
0
){
CodeListService
.
codelistCached
.
set
(
callbackKey
,{
items
:
result
});
CodeListService
.
codelistCache
.
delete
(
callbackKey
);
return
resolve
(
result
);
}
else
{
return
resolve
([]);
}
}).
catch
((
result
:
any
)
=>
{
return
reject
(
result
);
})
}
// 加载完成,从本地缓存获取
const
key
:
string
=
`
${
JSON
.
stringify
(
context
)}
-
${
JSON
.
stringify
(
data
)}
-
${
tag
}
`
;
if
(
CodeListService
.
codelistCached
.
get
(
key
)){
let
items
:
any
=
CodeListService
.
codelistCached
.
get
(
key
).
items
;
if
(
items
.
length
>
0
){
if
(
new
Date
().
getTime
()
<=
codelist
.
getExpirationTime
()){
return
resolve
(
items
);
}
return
new
Promise
((
resolve
:
any
,
reject
:
any
)
=>
{
this
.
getService
(
tag
).
then
((
codelist
:
any
)
=>
{
let
isEnableCache
:
boolean
=
codelist
.
isEnableCache
;
let
cacheTimeout
:
any
=
codelist
.
cacheTimeout
;
// 启用缓存
if
(
isEnableCache
)
{
const
callback
:
Function
=
(
context
:
any
=
{},
data
:
any
=
{},
tag
:
string
,
promise
:
Promise
<
any
>
)
=>
{
const
callbackKey
:
string
=
`
${
JSON
.
stringify
(
context
)}
-
${
JSON
.
stringify
(
data
)}
-
${
tag
}
`
;
promise
.
then
((
result
:
any
)
=>
{
if
(
result
.
length
>
0
)
{
CodeListService
.
codelistCached
.
set
(
callbackKey
,
{
items
:
result
});
CodeListService
.
codelistCache
.
delete
(
callbackKey
);
return
resolve
(
result
);
}
else
{
return
resolve
([]);
}
}).
catch
((
result
:
any
)
=>
{
return
reject
(
result
);
})
}
// 加载完成,从本地缓存获取
const
key
:
string
=
`
${
JSON
.
stringify
(
context
)}
-
${
JSON
.
stringify
(
data
)}
-
${
tag
}
`
;
if
(
CodeListService
.
codelistCached
.
get
(
key
))
{
let
items
:
any
=
CodeListService
.
codelistCached
.
get
(
key
).
items
;
if
(
items
.
length
>
0
)
{
if
(
new
Date
().
getTime
()
<=
codelist
.
getExpirationTime
())
{
return
resolve
(
items
);
}
}
if
(
codelist
)
{
// 加载中,UI又需要数据,解决连续加载同一代码表问题
if
(
CodeListService
.
codelistCache
.
get
(
key
)){
callback
(
context
,
data
,
tag
,
CodeListService
.
codelistCache
.
get
(
key
));
}
else
{
let
result
:
Promise
<
any
>
=
codelist
.
getItems
(
context
,
data
,
isloading
);
CodeListService
.
codelistCache
.
set
(
key
,
result
);
codelist
.
setExpirationTime
(
new
Date
().
getTime
()
+
cacheTimeout
);
callback
(
context
,
data
,
tag
,
result
);
}
if
(
codelist
)
{
// 加载中,UI又需要数据,解决连续加载同一代码表问题
if
(
CodeListService
.
codelistCache
.
get
(
key
))
{
callback
(
context
,
data
,
tag
,
CodeListService
.
codelistCache
.
get
(
key
));
}
else
{
let
result
:
Promise
<
any
>
;
if
(
Object
.
is
(
codelist
.
predefinedType
,
"RUNTIME"
))
{
result
=
this
.
getPredefinedItems
(
tag
);
}
else
{
result
=
codelist
.
getItems
(
context
,
data
,
isloading
);
}
CodeListService
.
codelistCache
.
set
(
key
,
result
);
codelist
.
setExpirationTime
(
new
Date
().
getTime
()
+
cacheTimeout
);
callback
(
context
,
data
,
tag
,
result
);
}
}
else
{
if
(
codelist
)
{
codelist
.
getItems
(
context
,
data
,
isloading
).
then
((
result
:
any
)
=>
{
}
}
else
{
if
(
codelist
)
{
if
(
Object
.
is
(
codelist
.
predefinedType
,
"RUNTIME"
))
{
this
.
getPredefinedItems
(
tag
).
then
((
res
:
any
)
=>
{
resolve
(
res
);
}).
catch
((
error
:
any
)
=>
{
Promise
.
reject
([]);
})
}
else
{
codelist
.
getItems
(
context
,
data
,
isloading
).
then
((
result
:
any
)
=>
{
resolve
(
result
);
}).
catch
((
error
:
any
)
=>
{
}).
catch
((
error
:
any
)
=>
{
Promise
.
reject
([]);
})
}
else
{
return
Promise
.
reject
([]);
}
}
}
else
{
return
Promise
.
reject
([]);
}
}).
catch
((
error
:
any
)
=>
{
}
}).
catch
((
error
:
any
)
=>
{
console
.
warn
(
"获取代码表异常"
);
return
Promise
.
reject
([]);
})
...
...
编辑
预览
Markdown
格式
0%
请重试
or
添加新附件
添加附件
取消
您添加了
0
人
到此讨论。请谨慎行事。
先完成此消息的编辑!
取消
想要评论请
注册
或
登录