Skip to content
项目
群组
代码片段
帮助
正在加载...
帮助
提交反馈
为 GitLab 提交贡献
登录
切换导航
iBiz-Vue-R7-Res
项目
项目
详情
动态
版本
周期分析
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
统计图
议题
0
议题
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
CI / CD
CI / CD
流水线
作业
计划
统计图
Wiki
Wiki
代码片段
代码片段
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
统计图
创建新议题
作业
提交
议题看板
打开侧边栏
iBiz-R7前端标准模板
iBiz-Vue-R7-Res
提交
6075fdb1
提交
6075fdb1
编写于
8月 06, 2020
作者:
tony001
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
调整代码表服务和实体服务
上级
998bc6f1
变更
4
隐藏空白字符变更
内嵌
并排
正在显示
4 个修改的文件
包含
228 行增加
和
33 行删除
+228
-33
app-register.ts
src/app-register.ts
+3
-0
index.d.ts
src/index.d.ts
+3
-2
codelist-service.ts
src/service/app/codelist-service.ts
+207
-0
entity-service.ts
src/service/entity-service.ts
+15
-31
未找到文件。
src/app-register.ts
浏览文件 @
6075fdb1
...
...
@@ -12,6 +12,7 @@ import { authServiceRegister } from '@/authservice/auth-service-register';
import
{
utilServiceRegister
}
from
'@/utilservice/util-service-register'
;
import
{
entityServiceRegister
}
from
'@/service/entity-service-register'
;
import
{
counterServiceRegister
}
from
'@/counter/counter-service-register'
;
import
{
codeListRegister
}
from
'@codelist/codelist-register'
;
import
InputBox
from
'./components/input-box/input-box.vue'
import
AppKeepAlive
from
'./components/app-keep-alive/app-keep-alive.vue'
...
...
@@ -89,6 +90,8 @@ window['utilServiceRegister'] = utilServiceRegister;
window
[
'entityServiceRegister'
]
=
entityServiceRegister
;
// 全局挂载计数器服务注册中心
window
[
'counterServiceRegister'
]
=
counterServiceRegister
;
// 全局挂载代码表服务注册中心
window
[
'codeListRegister'
]
=
codeListRegister
;
export
const
AppComponents
=
{
install
(
v
:
any
,
opt
:
any
)
{
...
...
src/index.d.ts
浏览文件 @
6075fdb1
...
...
@@ -3,13 +3,14 @@ import { AuthServiceRegister } from '@/authservice/auth-service-register';
import
{
UtilServiceRegister
}
from
'@/utilservice/util-service-register'
;
import
{
EntityServiceRegister
}
from
'@/service/entity-service-register'
;
import
{
CounterServiceRegister
}
from
'@/counter/counter-service-register'
;
import
{
CodeListRegister
}
from
'@codelist/codelist-register'
;
declare
global
{
interface
Window
{
uiServiceRegister
:
UIServiceRegister
,
authServiceRegister
:
AuthServiceRegister
,
utilServiceRegister
:
UtilServiceRegister
,
entityServiceRegister
:
EntityServiceRegister
,
counterServiceRegister
:
CounterServiceRegister
counterServiceRegister
:
CounterServiceRegister
,
codeListRegister
:
CodeListRegister
}
}
\ No newline at end of file
src/service/app/codelist-service.ts
0 → 100644
浏览文件 @
6075fdb1
import
store
from
'@/store'
;
import
EntityService
from
'../entity-service'
;
/**
* 动态代码表服务类
*
* @export
* @class CodeListService
*/
export
default
class
CodeListService
{
/**
* Vue 状态管理器
*
* @private
* @type {(any | null)}
* @memberof CodeListService
*/
private
$store
:
any
;
constructor
(
opts
:
any
=
{})
{
this
.
$store
=
store
;
}
/**
* 获取状态管理器
*
* @returns {(any | null)}
* @memberof CodeListService
*/
public
getStore
():
any
{
return
this
.
$store
;
}
/**
* 动态代码表缓存(加载中)
*
* @type {Map<string,any>}
* @memberof CodeListService
*/
public
static
codelistCache
:
Map
<
string
,
any
>
=
new
Map
();
/**
* 动态代码表缓存(已完成)
*
* @type {Map<string,any>}
* @memberof CodeListService
*/
public
static
codelistCached
:
Map
<
string
,
any
>
=
new
Map
();
/**
* 数据服务基类
*
* @type {Minorentity}
* @memberof CodeListService
*/
public
entityService
:
EntityService
=
new
EntityService
();
/**
* 获取代码表服务
*
* @protected
* @param {string} name 实体名称
* @returns {Promise<any>}
* @memberof EntityService
*/
public
getService
(
name
:
string
):
Promise
<
any
>
{
return
(
window
as
any
)[
'codeListRegister'
].
getService
(
name
);
}
/**
* 获取静态代码表
*
* @param {string} tag 代码表标识
* @returns {Promise<any[]>}
* @memberof CodeListService
*/
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
))];
resolve
(
items
);
}
})
}
/**
* 获取预定义代码表
*
* @param {string} tag 代码表标识
* @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
((
result
:
any
)
=>
{
if
(
result
.
length
>
0
){
CodeListService
.
codelistCached
.
set
(
`
${
tag
}
`
,{
items
:
result
});
return
resolve
(
result
);
}
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
);
}
})
}
/**
* 获取动态代码表
*
* @param {string} tag 代码表标识
* @param {string} context
* @returns {Promise<any[]>}
* @memberof CodeListService
*/
public
getItems
(
tag
:
string
,
context
:
any
=
{},
data
?:
any
,
isloading
?:
boolean
):
Promise
<
any
[]
>
{
let
_this
:
any
=
this
;
if
(
context
&&
context
.
srfsessionid
){
delete
context
.
srfsessionid
;
}
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
){
// 加载完成,从本地缓存获取
if
(
CodeListService
.
codelistCached
.
get
(
`
${
JSON
.
stringify
(
context
)}
-
${
JSON
.
stringify
(
data
)}
-
${
tag
}
`
)){
let
items
:
any
=
CodeListService
.
codelistCached
.
get
(
`
${
JSON
.
stringify
(
context
)}
-
${
JSON
.
stringify
(
data
)}
-
${
tag
}
`
).
items
;
if
(
items
.
length
>
0
){
if
(
cacheTimeout
!==
-
1
){
if
(
new
Date
().
getTime
()
>
codelist
.
expirationTime
){
codelist
.
getItems
(
context
,
data
,
isloading
).
then
((
result
:
any
)
=>
{
CodeListService
.
codelistCached
.
set
(
`
${
JSON
.
stringify
(
context
)}
-
${
JSON
.
stringify
(
data
)}
-
${
tag
}
`
,{
items
:
result
});
codelist
.
expirationTime
=
new
Date
().
getTime
()
+
cacheTimeout
;
resolve
(
result
);
}).
catch
((
error
:
any
)
=>
{
Promise
.
reject
([]);
})
}
else
{
return
resolve
(
items
);
}
}
else
{
return
resolve
(
items
);
}
}
}
if
(
codelist
)
{
const
callback
:
Function
=
(
context
:
any
=
{},
data
:
any
=
{},
tag
:
string
,
promise
:
Promise
<
any
>
)
=>
{
promise
.
then
((
result
:
any
)
=>
{
if
(
result
.
length
>
0
){
CodeListService
.
codelistCached
.
set
(
`
${
JSON
.
stringify
(
context
)}
-
${
JSON
.
stringify
(
data
)}
-
${
tag
}
`
,{
items
:
result
});
return
resolve
(
result
);
}
else
{
return
resolve
([]);
}
}).
catch
((
result
:
any
)
=>
{
return
reject
(
result
);
})
}
// 加载中,UI又需要数据,解决连续加载同一代码表问题
if
(
CodeListService
.
codelistCache
.
get
(
`
${
JSON
.
stringify
(
context
)}
-
${
JSON
.
stringify
(
data
)}
-
${
tag
}
`
)){
callback
(
context
,
data
,
tag
,
CodeListService
.
codelistCache
.
get
(
`
${
JSON
.
stringify
(
context
)}
-
${
JSON
.
stringify
(
data
)}
-
${
tag
}
`
));
}
else
{
let
result
:
Promise
<
any
>
=
codelist
.
getItems
(
context
,
data
,
isloading
);
CodeListService
.
codelistCache
.
set
(
`
${
JSON
.
stringify
(
context
)}
-
${
JSON
.
stringify
(
data
)}
-
${
tag
}
`
,
result
);
if
(
cacheTimeout
!==
-
1
){
codelist
.
expirationTime
=
new
Date
().
getTime
()
+
cacheTimeout
;
}
callback
(
context
,
data
,
tag
,
result
);
}
}
}
else
{
if
(
codelist
)
{
codelist
.
getItems
(
context
,
data
,
isloading
).
then
((
result
:
any
)
=>
{
resolve
(
result
);
}).
catch
((
error
:
any
)
=>
{
Promise
.
reject
([]);
})
}
else
{
return
Promise
.
reject
([]);
}
}
}).
catch
((
error
:
any
)
=>
{
console
.
warn
(
"获取代码表异常"
);
return
Promise
.
reject
([]);
})
})
}
}
\ No newline at end of file
src/service/entity-service.ts
浏览文件 @
6075fdb1
import
{
Store
}
from
'vuex'
;
import
{
Http
}
from
'@/utils'
;
import
CodeListService
from
"@service/app/codelist-service"
;
...
...
@@ -10,15 +9,6 @@ import CodeListService from "@service/app/codelist-service";
*/
export
default
class
EntityService
{
/**
* Vue 状态管理器
*
* @private
* @type {(any | null)}
* @memberof EntityService
*/
private
$store
:
Store
<
any
>
|
null
=
null
;
/**
* 获取实体数据服务
*
...
...
@@ -101,21 +91,10 @@ export default class EntityService {
* @memberof EntityService
*/
constructor
(
opts
:
any
=
{})
{
this
.
$store
=
opts
.
$store
;
this
.
tempStorage
=
localStorage
;
this
.
initBasicData
();
}
/**
* 获取状态管理器
*
* @returns {(any | null)}
* @memberof EntityService
*/
public
getStore
():
Store
<
any
>
|
null
{
return
this
.
$store
;
}
/**
* 获取代码表
*
...
...
@@ -123,22 +102,16 @@ export default class EntityService {
*/
public
getCodeList
(
tag
:
string
,
codelistType
:
string
,
context
:
any
=
{},
param
:
any
=
{}){
return
new
Promise
((
resolve
:
any
,
reject
:
any
)
=>
{
let
codeListService
=
new
CodeListService
();
if
(
tag
&&
Object
.
is
(
codelistType
,
"STATIC"
)){
let
returnItems
:
Array
<
any
>
=
[];
const
codelist
=
(
this
.
getStore
()
as
Store
<
any
>
).
getters
.
getCodeList
(
tag
);
if
(
codelist
)
{
returnItems
=
[...
JSON
.
parse
(
JSON
.
stringify
(
codelist
.
items
))];
}
else
{
console
.
log
(
`----
${
tag
}
----代码表不存在`
);
}
resolve
(
returnItems
);
codeListService
.
getStaticItems
(
tag
).
then
((
items
:
any
)
=>
{
resolve
(
items
);
})
}
else
if
(
tag
&&
Object
.
is
(
codelistType
,
"DYNAMIC"
)){
let
codeListService
=
new
CodeListService
({
$store
:
this
.
$store
});
codeListService
.
getItems
(
tag
,
context
,
param
).
then
((
res
:
any
)
=>
{
resolve
(
res
);
}).
catch
((
error
:
any
)
=>
{
reject
(
`
${
tag
}
代码表不存在`
);
console
.
log
(
`----
${
tag
}
----代码表不存在`
);
});
}
})
...
...
@@ -988,4 +961,15 @@ export default class EntityService {
return
Http
.
getInstance
().
post
(
`/v7/changepwd`
,
data
,
isloading
);
}
/**
* 获取数字字典
*
* @param tag
* @param data
* @param isloading
*/
public
async
getPredefinedCodelist
(
tag
:
string
,
data
:
any
=
{},
isloading
?:
boolean
):
Promise
<
any
>
{
return
Http
.
getInstance
().
get
(
`/dictionarys/codelist/
${
tag
}
`
,
data
,
isloading
);
}
}
\ No newline at end of file
编辑
预览
Markdown
格式
0%
请重试
or
添加新附件
添加附件
取消
您添加了
0
人
到此讨论。请谨慎行事。
先完成此消息的编辑!
取消
想要评论请
注册
或
登录