Skip to content
项目
群组
代码片段
帮助
正在加载...
帮助
提交反馈
为 GitLab 提交贡献
登录
切换导航
I
ibizlab-generator
项目
项目
详情
动态
版本
周期分析
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
统计图
议题
0
议题
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
CI / CD
CI / CD
流水线
作业
计划
统计图
Wiki
Wiki
代码片段
代码片段
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
统计图
创建新议题
作业
提交
议题看板
打开侧边栏
ibiz4jteam
ibizlab-generator
提交
834903ef
提交
834903ef
编写于
1月 27, 2022
作者:
tony001
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
update:更新
上级
7a23c38d
变更
5
隐藏空白字符变更
内嵌
并排
正在显示
5 个修改的文件
包含
257 行增加
和
151 行删除
+257
-151
app-code-list-service-base.ts
...rc/core/service/app-service/app-code-list-service-base.ts
+210
-1
app-code-list-service.ts
...empl/r7/app_{{apps}}/src/service/app-code-list-service.ts
+46
-0
app-code-list-service.ts
...rc/service/app-code-list-service/app-code-list-service.ts
+0
-148
index.ts
...7/app_{{apps}}/src/service/app-code-list-service/index.ts
+0
-1
index.ts
...main/resources/templ/r7/app_{{apps}}/src/service/index.ts
+1
-1
未找到文件。
modules/ibizlab-generator-core/src/main/resources/templ/r7/app_{{apps}}/src/core/service/app-service/app-code-list-service-base.ts
浏览文件 @
834903ef
...
...
@@ -10,6 +10,32 @@ import { IAppCodeListService, IContext, IParam } from "@core";
*/
export
abstract
class
AppCodeListServiceBase
implements
IAppCodeListService
{
/**
* 动态代码表缓存(加载中)
*
* @type {Map<string,any>}
* @memberof AppCodeListServiceBase
*/
private
static
codelistCache
:
Map
<
string
,
any
>
=
new
Map
();
/**
* 动态代码表缓存(已完成)
*
* @type {Map<string,any>}
* @memberof AppCodeListServiceBase
*/
private
static
codelistCached
:
Map
<
string
,
any
>
=
new
Map
();
/**
* 通过代码表标识获取代码表
*
* @param {string} tag
* @memberof AppCodeListServiceBase
*/
public
getCodeListByTag
(
tag
:
string
):
any
{
return
undefined
;
}
/**
* 获取代码表项
*
...
...
@@ -18,7 +44,190 @@ export abstract class AppCodeListServiceBase implements IAppCodeListService {
* @memberof AppCodeListServiceBase
*/
public
async
getCodeListItems
({
tag
,
context
,
viewParams
}:
{
tag
:
string
,
context
:
IContext
|
undefined
,
viewParams
:
IParam
|
undefined
}):
Promise
<
any
>
{
throw
new
Error
(
"Method not implemented."
);
const
codeList
=
this
.
getCodeListByTag
(
tag
);
if
(
!
codeList
)
return
;
let
items
:
any
;
if
(
Object
.
is
(
codeList
.
codeListType
,
'STATIC'
))
{
items
=
await
this
.
getItemsWithStatic
(
codeList
);
}
else
{
if
(
codeList
.
predefinedType
)
{
items
=
await
this
.
getItemsWithPredefined
(
codeList
,
context
,
viewParams
);
}
else
{
items
=
await
this
.
getItemsWithDynamic
(
codeList
,
context
,
viewParams
);
}
}
// 处理成UI相关结构
this
.
handleItemData
(
items
);
return
items
;
}
/**
* 获取静态代码表
*
* @param {IParam} codeList
* @return {*}
* @memberof AppCodeListServiceBase
*/
public
async
getItemsWithStatic
(
codeList
:
IParam
):
Promise
<
IParam
[]
>
{
const
{
items
}
=
codeList
;
if
(
items
&&
items
.
length
>
0
)
{
return
items
;
}
else
{
return
[];
}
}
/**
* 获取动态代码表(非预置)
*
* @param {IParam} codeList 代码表
* @param {IContext} [context={}] 应用上下文
* @param {IParam} [viewParams={}] 视图参数
* @return {*}
* @memberof AppCodeListServiceBase
*/
public
getItemsWithDynamic
(
codeList
:
IParam
,
context
:
IContext
=
{},
viewParams
:
IParam
=
{})
{
return
new
Promise
((
resolve
,
reject
)
=>
{
const
{
isEnableCache
,
cacheTimeout
}
=
codeList
;
// 启用缓存并且缓存时间不等于-1
if
(
isEnableCache
&&
(
cacheTimeout
!==
-
1
))
{
const
tag
:
string
=
codeList
.
codeName
;
// 加载完成执行回调
const
callback
:
Function
=
(
tag
:
string
,
promise
:
Promise
<
IParam
[]
>
)
=>
{
promise
.
then
((
data
:
IParam
[])
=>
{
if
(
data
.
length
>
0
)
{
AppCodeListServiceBase
.
codelistCached
.
set
(
tag
,
{
data
,
expirationTime
:
new
Date
().
getTime
()
+
cacheTimeout
});
AppCodeListServiceBase
.
codelistCache
.
delete
(
tag
);
return
resolve
(
data
);
}
else
{
return
resolve
([]);
}
})
}
// 先从已缓存完成的代码表Map中获取
if
(
AppCodeListServiceBase
.
codelistCached
.
get
(
tag
))
{
let
activeCodeList
=
AppCodeListServiceBase
.
codelistCached
.
get
(
tag
);
if
(
new
Date
().
getTime
()
<=
activeCodeList
.
expirationTime
)
{
return
resolve
(
activeCodeList
.
data
);
}
}
// 加载中,UI又需要数据,解决连续加载同一代码表问题
if
(
AppCodeListServiceBase
.
codelistCache
.
get
(
tag
))
{
callback
(
tag
,
AppCodeListServiceBase
.
codelistCache
.
get
(
tag
));
}
else
{
let
result
=
this
.
getCodeListData
(
codeList
,
context
,
viewParams
);
AppCodeListServiceBase
.
codelistCache
.
set
(
tag
,
result
);
callback
(
tag
,
result
);
}
}
else
{
this
.
getCodeListData
(
codeList
,
context
,
viewParams
).
then
((
result
:
any
)
=>
{
resolve
(
result
);
})
}
})
}
/**
* 获取代码表数据(动态代码表)
*
* @param {IParam} codeList 代码表
* @param {IContext} [context={}] 应用上下文
* @param {IParam} [viewParams={}] 视图参数
* @memberof AppCodeListServiceBase
*/
public
async
getCodeListData
(
codeList
:
IParam
,
context
:
IContext
,
viewParams
:
IParam
)
{
try
{
const
{
appDataEntity
,
appDEDataSet
,
textPSAppDEField
,
valuePSAppDEField
}
=
codeList
;
if
(
!
appDataEntity
||
!
appDEDataSet
||
!
textPSAppDEField
||
!
valuePSAppDEField
)
{
console
.
error
(
"动态代码表获取数据异常[查询参数不足]"
);
}
const
dataService
=
await
App
.
getDataService
(
appDataEntity
.
toLowerCase
());
const
response
=
await
dataService
[
appDEDataSet
](
context
,
viewParams
,
false
);
const
{
status
,
data
}
=
response
;
if
(
status
==
200
)
{
const
items
:
IParam
[]
=
[];
if
(
data
&&
data
.
length
>
0
)
{
data
.
forEach
((
element
:
IParam
)
=>
{
items
.
push
({
value
:
element
[
valuePSAppDEField
],
text
:
element
[
textPSAppDEField
]
});
});
}
return
items
;
}
else
{
console
.
error
(
"动态代码表获取数据异常[网络请求异常]"
)
return
[];
}
}
catch
(
error
:
any
)
{
console
.
error
(
`动态代码表获取数据异常[
${
JSON
.
stringify
(
error
)}
]`
);
return
[];
}
}
/**
* 获取预定义代码表
*
* @param {IParam} codeList 代码表
* @param {IContext} [context={}] 应用上下文
* @param {IParam} [viewParams={}] 视图参数
* @return {*} {Promise<IParam[]>}
* @memberof AppCodeListServiceBase
*/
public
getItemsWithPredefined
(
codeList
:
IParam
,
context
:
IContext
=
{},
viewParams
:
IParam
=
{}):
Promise
<
IParam
[]
>
{
console
.
warn
(
"获取预定义代码表暂未实现"
);
return
Promise
.
resolve
([]);
}
/**
* 处理成UI相关结构
* 1.将{value: 'val',text: 'label'}处理成{value: 'val',label: 'label'}
* 2.处理代码表层级问题
*
* @param {IParam[]} items
* @memberof AppCodeListServiceBase
*/
public
handleItemData
(
items
:
IParam
[])
{
if
(
!
items
)
{
items
=
[];
}
// 将{value: 'val',text: 'label'}处理成{value: 'val',label: 'label'}
if
(
items
.
length
>
0
)
{
items
.
forEach
((
element
:
IParam
)
=>
{
Object
.
assign
(
element
,
{
label
:
element
.
text
});
});
}
// 处理代码表层级问题
const
hasChildren
:
boolean
=
items
.
some
((
item
:
any
)
=>
{
return
item
.
pvalue
;
})
if
(
hasChildren
)
{
let
list
:
IParam
[]
=
[];
items
.
forEach
((
codeItem
:
IParam
)
=>
{
if
(
!
codeItem
.
pvalue
)
{
this
.
setChildCodeItems
(
codeItem
.
value
,
items
,
codeItem
);
list
.
push
(
codeItem
);
}
})
items
=
list
;
}
}
/**
* 设置子项数据
*
* @param {string} pValue 父代码项值
* @param {IParam[]} items 代码表集合
* @param {IParam} codeItem 代码项
* @memberof AppCodeListServiceBase
*/
public
setChildCodeItems
(
pValue
:
string
,
items
:
IParam
[],
codeItem
:
IParam
)
{
items
.
forEach
((
item
:
IParam
)
=>
{
if
(
item
.
pvalue
==
pValue
)
{
this
.
setChildCodeItems
(
item
.
value
,
items
,
item
);
if
(
!
codeItem
.
children
)
{
codeItem
.
children
=
[];
}
codeItem
.
children
.
push
(
item
);
}
})
}
}
\ No newline at end of file
modules/ibizlab-generator-core/src/main/resources/templ/r7/app_{{apps}}/src/service/app-code-list-service.ts
0 → 100644
浏览文件 @
834903ef
import
{
AppCodeListConfig
}
from
"@/app/config"
;
import
{
AppCodeListServiceBase
,
IAppCodeListService
}
from
"@core"
;
/**
* 应用代码表服务
*
* @export
* @abstract
* @class AppCodeListService
* @extends AppCodeListServiceBase
* @implements {IAppCodeListService}
*/
export
class
AppCodeListService
extends
AppCodeListServiceBase
implements
IAppCodeListService
{
/**
* 唯一实例
*
* @private
* @static
* @memberof AppCodeListService
*/
private
static
readonly
instance
=
new
AppCodeListService
();
/**
* 获取唯一实例
*
* @static
* @return {*} {AppCodeListService}
* @memberof AppCodeListService
*/
public
static
getInstance
():
AppCodeListService
{
return
AppCodeListService
.
instance
;
}
/**
* 通过代码表标识获取代码表
*
* @param {string} tag
* @memberof AppCodeListService
*/
public
getCodeListByTag
(
tag
:
string
):
any
{
return
AppCodeListConfig
[
tag
];
}
}
\ No newline at end of file
modules/ibizlab-generator-core/src/main/resources/templ/r7/app_{{apps}}/src/service/app-code-list-service/app-code-list-service.ts
已删除
100644 → 0
浏览文件 @
7a23c38d
import
{
AppCodeListConfig
}
from
"@/app/config"
;
import
{
AppCodeListServiceBase
,
IAppCodeListService
,
IContext
,
IParam
}
from
"@core"
;
/**
* 应用代码表服务基类
*
* @export
* @abstract
* @class AppCodeListService
* @extends AppCodeListServiceBase
* @implements {IAppCodeListService}
*/
export
class
AppCodeListService
extends
AppCodeListServiceBase
implements
IAppCodeListService
{
/**
* 唯一实例
*
* @private
* @static
* @memberof AppCodeListService
*/
private
static
readonly
instance
=
new
AppCodeListService
();
/**
* 获取唯一实例
*
* @static
* @return {*} {AppCodeListService}
* @memberof AppCodeListService
*/
public
static
getInstance
():
AppCodeListService
{
return
AppCodeListService
.
instance
;
}
/**
* 获取代码表项
*
* @param { tag, context, viewParams }: { tag: string, context: IContext | undefined, viewParams: IParam | undefined }
* @return {*} {Promise<any>}
* @memberof AppCodeListService
*/
public
async
getCodeListItems
({
tag
,
context
,
viewParams
}:
{
tag
:
string
,
context
:
IContext
|
undefined
,
viewParams
:
IParam
|
undefined
}):
Promise
<
any
>
{
const
codeList
=
AppCodeListConfig
[
tag
];
if
(
!
codeList
)
return
;
let
items
:
any
;
if
(
Object
.
is
(
codeList
.
codeListType
,
'STATIC'
))
{
items
=
await
this
.
getItemsWithStatic
(
codeList
);
}
else
{
if
(
codeList
.
predefinedType
)
{
items
=
await
this
.
getItemsWithPredefined
(
codeList
);
}
else
{
items
=
await
this
.
getItemsWithDynamic
(
codeList
);
}
}
// 处理成UI相关结构
this
.
handleItemData
(
items
);
return
items
;
}
/**
* 获取静态代码表
*
* @param {IParam} codeList
* @return {*}
* @memberof AppCodeListService
*/
public
async
getItemsWithStatic
(
codeList
:
IParam
):
Promise
<
IParam
[]
>
{
const
{
items
}
=
codeList
;
if
(
items
&&
items
.
length
>
0
)
{
return
items
;
}
else
{
return
[];
}
}
/**
* 获取动态代码表(非预置)
*
* @param {IParam} codeList
* @return {*}
* @memberof AppCodeListService
*/
public
async
getItemsWithDynamic
(
codeList
:
IParam
):
Promise
<
IParam
[]
>
{
return
[];
}
/**
* 获取预定义代码表
*
* @param {IParam} codeList
* @return {*}
* @memberof AppCodeListService
*/
public
async
getItemsWithPredefined
(
codeList
:
IParam
):
Promise
<
IParam
[]
>
{
return
[];
}
/**
* 处理成UI相关结构
* 1.将{value: 'val',text: 'label'}处理成{value: 'val',label: 'label'}
* 2.处理代码表层级问题
*
* @param {IParam[]} items
* @memberof AppCodeListService
*/
public
handleItemData
(
items
:
IParam
[])
{
// 将{value: 'val',text: 'label'}处理成{value: 'val',label: 'label'}
if
(
items
&&
(
items
.
length
>
0
))
{
items
.
forEach
((
element
:
IParam
)
=>
{
Object
.
assign
(
element
,
{
label
:
element
.
text
});
});
}
// 处理代码表层级问题
const
hasChildren
:
boolean
=
items
.
some
((
item
:
any
)
=>
{
return
item
.
pvalue
;
})
if
(
hasChildren
)
{
let
list
:
IParam
[]
=
[];
items
.
forEach
((
codeItem
:
IParam
)
=>
{
if
(
!
codeItem
.
pvalue
)
{
this
.
setChildCodeItems
(
codeItem
.
value
,
items
,
codeItem
);
list
.
push
(
codeItem
);
}
})
items
=
list
;
}
}
/**
* 设置子项数据
*
* @param {string} pValue 父代码项值
* @param {IParam[]} items 代码表集合
* @param {IParam} codeItem 代码项
* @memberof AppCodeListService
*/
public
setChildCodeItems
(
pValue
:
string
,
items
:
IParam
[],
codeItem
:
IParam
)
{
items
.
forEach
((
item
:
IParam
)
=>
{
if
(
item
.
pvalue
==
pValue
)
{
this
.
setChildCodeItems
(
item
.
value
,
items
,
item
);
if
(
!
codeItem
.
children
)
{
codeItem
.
children
=
[];
}
codeItem
.
children
.
push
(
item
);
}
})
}
}
\ No newline at end of file
modules/ibizlab-generator-core/src/main/resources/templ/r7/app_{{apps}}/src/service/app-code-list-service/index.ts
已删除
100644 → 0
浏览文件 @
7a23c38d
export
{
AppCodeListService
}
from
'./app-code-list-service'
;
\ No newline at end of file
modules/ibizlab-generator-core/src/main/resources/templ/r7/app_{{apps}}/src/service/index.ts
浏览文件 @
834903ef
export
*
from
'./app-open-view-service'
;
export
*
from
'./app-code-list-service'
;
export
{
AppCodeListService
}
from
'./app-code-list-service'
;
export
{
AppActionService
}
from
'./app-action-service'
;
export
{
AppAuthService
}
from
'./app-auth-service'
;
export
{
AppFuncService
}
from
'./app-func-service'
;
...
...
编辑
预览
Markdown
格式
0%
请重试
or
添加新附件
添加附件
取消
您添加了
0
人
到此讨论。请谨慎行事。
先完成此消息的编辑!
取消
想要评论请
注册
或
登录