Skip to content
项目
群组
代码片段
帮助
正在加载...
帮助
提交反馈
为 GitLab 提交贡献
登录
切换导航
iBiz-Vue-R7-Res
项目
项目
详情
动态
版本
周期分析
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
统计图
议题
0
议题
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
CI / CD
CI / CD
流水线
作业
计划
统计图
Wiki
Wiki
代码片段
代码片段
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
统计图
创建新议题
作业
提交
议题看板
打开侧边栏
iBiz-R7前端标准模板
iBiz-Vue-R7-Res
提交
1a9663d3
提交
1a9663d3
编写于
5月 21, 2020
作者:
tony001
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
zpc --- 基类增加代码表转换
上级
d4939698
变更
1
隐藏空白字符变更
内嵌
并排
正在显示
1 个修改的文件
包含
128 行增加
和
22 行删除
+128
-22
control-service.ts
src/widgets/control-service.ts
+128
-22
未找到文件。
src/widgets/control-service.ts
浏览文件 @
1a9663d3
import
{
Store
}
from
'vuex'
;
import
{
Util
}
from
'@/utils/util/util'
;
import
CodeListService
from
"@service/app/codelist-service"
;
/**
* 部件服务基类
...
...
@@ -26,6 +27,14 @@ export default class ControlService {
*/
public
model
:
any
|
null
=
null
;
/**
* 代码表服务对象
*
* @type {any}
* @memberof ControlService
*/
public
codeListService
:
any
;
/**
* 是否为从数据模式
*
...
...
@@ -43,6 +52,7 @@ export default class ControlService {
constructor
(
opts
:
any
=
{})
{
this
.
$store
=
opts
.
$store
;
this
.
setTempMode
();
this
.
codeListService
=
new
CodeListService
({
$store
:
opts
.
$store
});
}
/**
...
...
@@ -118,31 +128,42 @@ export default class ControlService {
* @param {*} response
* @memberof ControlService
*/
public
handleResponse
(
action
:
string
,
response
:
any
,
isCreate
:
boolean
=
false
){
public
async
handleResponse
(
action
:
string
,
response
:
any
,
isCreate
:
boolean
=
false
){
let
result
=
null
;
if
(
!
response
.
data
)
{
return
}
else
if
(
response
.
data
instanceof
Array
)
{
result
=
[];
response
.
data
.
forEach
((
item
:
any
)
=>
{
result
.
push
(
this
.
handleResponseData
(
action
,
item
,
isCreate
));
});
}
else
{
result
=
this
.
handleResponseData
(
action
,
response
.
data
,
isCreate
);
}
// response状态,头文件
if
(
response
.
headers
){
if
(
response
.
headers
[
'x-page'
]){
Object
.
assign
(
response
,{
page
:
Number
(
response
.
headers
[
'x-page'
])});
}
if
(
response
.
headers
[
'x-per-page'
]){
Object
.
assign
(
response
,{
size
:
Number
(
response
.
headers
[
'x-per-page'
])});
const
handleResult
:
any
=
(
action
:
string
,
response
:
any
,
isCreate
:
boolean
,
codelistArray
?:
any
)
=>
{
if
(
response
.
data
instanceof
Array
)
{
result
=
[];
response
.
data
.
forEach
((
item
:
any
)
=>
{
result
.
push
(
this
.
handleResponseData
(
action
,
item
,
isCreate
,
codelistArray
));
});
}
else
{
result
=
this
.
handleResponseData
(
action
,
response
.
data
,
isCreate
,
codelistArray
);
}
if
(
response
.
headers
[
'x-total'
]){
Object
.
assign
(
response
,{
total
:
Number
(
response
.
headers
[
'x-total'
])});
// response状态,头文件
if
(
response
.
headers
){
if
(
response
.
headers
[
'x-page'
]){
Object
.
assign
(
response
,{
page
:
Number
(
response
.
headers
[
'x-page'
])});
}
if
(
response
.
headers
[
'x-per-page'
]){
Object
.
assign
(
response
,{
size
:
Number
(
response
.
headers
[
'x-per-page'
])});
}
if
(
response
.
headers
[
'x-total'
]){
Object
.
assign
(
response
,{
total
:
Number
(
response
.
headers
[
'x-total'
])});
}
}
response
.
data
=
result
;
}
let
codelistModel
:
Array
<
any
>
=
this
.
handleCodelist
();
if
(
codelistModel
.
length
>
0
){
this
.
getAllCodeList
(
codelistModel
).
then
((
res
:
any
)
=>
{
handleResult
(
action
,
response
,
isCreate
,
res
);
})
}
else
{
handleResult
(
action
,
response
,
isCreate
);
}
response
.
data
=
result
;
}
/**
...
...
@@ -152,7 +173,7 @@ export default class ControlService {
* @param {*} response
* @memberof ControlService
*/
public
handleResponseData
(
action
:
string
,
data
:
any
=
{},
isCreate
?:
boolean
){
public
handleResponseData
(
action
:
string
,
data
:
any
=
{},
isCreate
?:
boolean
,
codelistArray
?:
any
){
let
model
:
any
=
this
.
getMode
();
if
(
!
model
&&
model
.
getDataItems
instanceof
Function
)
{
return
data
;
...
...
@@ -167,10 +188,13 @@ export default class ControlService {
if
((
isCreate
===
undefined
||
isCreate
===
null
)
&&
Object
.
is
(
dataitem
.
dataType
,
'GUID'
)
&&
Object
.
is
(
dataitem
.
name
,
'srfkey'
)
&&
(
val
&&
!
Object
.
is
(
val
,
''
))){
isCreate
=
true
;
}
// if((Object.is(dataitem.dataType,'DATE') || Object.is(dataitem.dataType,'DATETIME')) && !Object.is(Date.parse(val),NaN)){
// val = Util.dateFormat(new Date(val));
// }
item
[
dataitem
.
name
]
=
val
;
// 转化代码表
if
(
codelistArray
&&
dataitem
.
codelist
){
if
(
codelistArray
.
get
(
dataitem
.
codelist
.
tag
)
&&
codelistArray
.
get
(
dataitem
.
codelist
.
tag
).
get
(
val
)){
item
[
dataitem
.
name
]
=
codelistArray
.
get
(
dataitem
.
codelist
.
tag
).
get
(
val
);
}
}
});
item
.
srfuf
=
data
.
srfuf
?
data
.
srfuf
:
(
isCreate
?
"0"
:
"1"
);
return
item
;
...
...
@@ -199,4 +223,86 @@ export default class ControlService {
return
requestData
;
}
/**
* 处理代码表
*
* @memberof ControlService
*/
public
handleCodelist
(){
let
model
:
any
=
this
.
getMode
();
if
(
!
model
)
{
return
[];
}
let
dataItems
:
any
[]
=
model
.
getDataItems
();
let
codelistMap
:
Map
<
string
,
any
>
=
new
Map
();
if
(
dataItems
&&
dataItems
.
length
>
0
){
dataItems
.
forEach
((
item
:
any
)
=>
{
if
(
item
.
codelist
){
codelistMap
.
set
(
item
.
name
,
item
.
codelist
);
}
})
}
if
(
codelistMap
.
size
>
0
){
return
Array
.
from
(
codelistMap
).
map
(
item
=>
item
[
1
]);
}
else
{
return
[];
}
}
/**
* 获取所有代码表
*
* @param codelistArray 代码表模型数组
* @memberof ControlService
*/
public
getAllCodeList
(
codelistArray
:
Array
<
any
>
):
Promise
<
any
>
{
return
new
Promise
((
resolve
:
any
,
reject
:
any
)
=>
{
let
codeListMap
:
Map
<
string
,
any
>
=
new
Map
();
let
promiseArray
:
Array
<
any
>
=
[];
codelistArray
.
forEach
((
item
:
any
)
=>
{
if
(
!
codeListMap
.
get
(
item
.
tag
)){
promiseArray
.
push
(
this
.
getCodeList
(
item
));
Promise
.
all
(
promiseArray
).
then
((
result
:
any
)
=>
{
if
(
result
&&
result
.
length
>
0
){
result
.
forEach
((
codeList
:
any
)
=>
{
let
tempCodeListMap
:
Map
<
number
,
any
>
=
new
Map
();
if
(
codeList
.
length
>
0
){
codeList
.
forEach
((
codeListItem
:
any
)
=>
{
tempCodeListMap
.
set
(
codeListItem
.
value
,
codeListItem
.
text
);
})
}
codeListMap
.
set
(
item
.
tag
,
tempCodeListMap
);
})
resolve
(
codeListMap
);
}
})
}
})
})
}
/**
* 获取代码表
*
* @param codeListObject 传入代码表对象
* @memberof ControlService
*/
public
getCodeList
(
codeListObject
:
any
):
Promise
<
any
>
{
return
new
Promise
((
resolve
:
any
,
reject
:
any
)
=>
{
if
(
codeListObject
.
tag
&&
Object
.
is
(
codeListObject
.
codelistType
,
"STATIC"
)){
const
codelist
=
(
this
.
getStore
()
as
Store
<
any
>
).
getters
.
getCodeList
(
codeListObject
.
tag
);
if
(
codelist
)
{
resolve
([...
JSON
.
parse
(
JSON
.
stringify
(
codelist
.
items
))]);
}
else
{
console
.
log
(
`<#noparse>----
${
codeListObject
.
tag
}
----代码表不存在</#noparse>`
);
}
}
else
if
(
codeListObject
.
tag
&&
Object
.
is
(
codeListObject
.
codelistType
,
"DYNAMIC"
)){
this
.
codeListService
.
getItems
(
codeListObject
.
tag
).
then
((
res
:
any
)
=>
{
resolve
(
res
);
}).
catch
((
error
:
any
)
=>
{
console
.
log
(
`<#noparse>----
${
codeListObject
.
tag
}
----代码表不存在</#noparse>`
);
});
}
})
}
}
\ No newline at end of file
编辑
预览
Markdown
格式
0%
请重试
or
添加新附件
添加附件
取消
您添加了
0
人
到此讨论。请谨慎行事。
先完成此消息的编辑!
取消
想要评论请
注册
或
登录