Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
B
bi
Project
Project
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
张苑
bi
Commits
297e8233
Commit
297e8233
authored
Sep 22, 2021
by
莫坚培
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
feat: 组件轮询逻辑优化
parent
83c64a2c
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
89 additions
and
35 deletions
+89
-35
dashboard.js
js/dashboard.js
+70
-27
tokenSetting.js
js/tokenSetting.js
+19
-8
No files found.
js/dashboard.js
View file @
297e8233
...
...
@@ -25,12 +25,14 @@ var Controls = {}
var
Common
=
{}
var
time
=
5000
let
requestDataPool
=
[]
// 各个组件实时刷新的请求数据,放到一个集合里,原来的多个组件请求合并成一个请求发送
let
dataPoolRequestingFlag
=
false
// requestDataPool请求中标志,正在请求时不进行下一波轮询,前一波请求完成才执行下一波
let
requestLoop_timer
=
null
// 轮询定时器
let
requestLoop_dataPool
=
[]
// 各个组件实时刷新的请求数据,放到一个集合里,原来的多个组件请求合并成一个请求发送
let
requestLoop_stopFlag
=
false
// requestLoop_dataPool请求中标志,正在请求时不进行下一波轮询,前一波请求完成才执行下一波
let
requestLoop_time
=
5000
// 轮询间隔时间
let
requestLoop_groupSliceNum
=
10
// 请求池requestLoop_dataPool分组,每组多少个
// 添加定时器
var
timer1
=
null
var
timer8
=
null
var
app
=
{
msg
:
function
(
message
,
style
)
{
var
css
=
{
...
...
@@ -292,7 +294,9 @@ function nodeCLick(e, treeId, treeNode, type) {
$
(
'#right-wrap'
).
css
(
'background-image'
,
''
)
// 清除定时器
clearInterval
(
timer1
)
clearInterval
(
requestLoop_timer
)
timer1
=
null
requestLoop_timer
=
null
let
postData
=
{
appId
,
panelId
:
treeNode
.
id
,
...
...
@@ -843,8 +847,10 @@ function initCanvas() {
LineChartDataFun
(
'tool'
)
},
20
)
clearInterval
(
timer1
)
// setTimer()
refreshDataLoop
()
setTimer
()
// 开始轮询
clearInterval
(
requestLoop_timer
)
startRequestLoop
(
requestLoop_time
)
// wrap.style.background = Common.BackColor
...
...
@@ -856,7 +862,7 @@ function setTimer() {
if
(
item
.
ControlType
===
'staticimage'
||
item
.
ControlType
===
'image'
)
{
renderImage
(
index
)
}
if
(
item
.
ControlType
===
'datatextblock'
&&
S
==
1
)
{
if
(
item
.
ControlType
===
'datatextblock'
)
{
renderDataText
(
index
)
}
if
(
item
.
ControlType
===
'dynamictext'
)
{
...
...
@@ -913,42 +919,74 @@ function setTimer() {
}
// 轮询数据,用新逻辑,合并各组件的请求数据,做合并请求,例如,300个组件,分成6个请求,每个请求包含50个组件的数据
function
refreshDataLoop
()
{
requestDataPool
=
handleControlListInArray
()
let
dataPoolList
=
sliceRequestDataPool
(
10
)
timer1
=
setInterval
(
async
()
=>
{
if
(
dataPoolRequestingFlag
)
{
function
startRequestLoop
()
{
console
.
log
(
'requestLoop_dataPool'
,
requestLoop_dataPool
)
requestLoop_dataPool
=
collectRequestLoopData
()
console
.
log
(
'Controls.dataPoolMap'
,
Controls
.
dataPoolMap
)
let
dataPoolList
=
sliceRequestLoopData
(
requestLoop_groupSliceNum
)
requestLoop_timer
=
setInterval
(
async
()
=>
{
if
(
requestLoop_stopFlag
)
{
return
}
for
(
let
i
=
0
,
len
=
dataPoolList
.
length
;
i
<
len
;
i
++
)
{
dataPoolRequesting
Flag
=
true
// 进入循环即表示已经开始请求
await
send
DataPoolRequest
(
dataPoolList
[
i
],
i
,
len
)
requestLoop_stop
Flag
=
true
// 进入循环即表示已经开始请求
await
send
RequestLoopData
(
dataPoolList
[
i
],
i
,
len
)
}
},
time
)
},
requestLoop_
time
)
}
// 发起request
D
ataPool的合并请求
function
send
DataPoolRequest
(
list
,
i
,
len
)
{
// 发起request
Loop_d
ataPool的合并请求
function
send
RequestLoopData
(
list
,
i
,
len
)
{
return
new
Promise
((
resolve
,
reject
)
=>
{
request
.
post
(
`/bi/
${
appId
}
/variables/real-time/data/mergeReq`
,
list
)
.
then
(
res
=>
{
if
(
i
===
len
-
1
)
{
dataPoolRequestingFlag
=
false
if
(
i
===
len
-
1
)
{
requestLoop_stopFlag
=
false
}
if
(
res
.
data
.
data
&&
Object
.
prototype
.
toString
.
call
(
res
.
data
.
data
)
===
'[object Object]'
)
{
Object
.
keys
(
res
.
data
.
data
).
forEach
(
key
=>
{
renderRequestLoopData
(
Controls
.
dataPoolMap
[
key
])
})
}
resolve
(
res
)
})
.
catch
(
err
=>
{
if
(
i
===
len
-
1
)
{
dataPoolRequesting
Flag
=
false
if
(
i
===
len
-
1
)
{
requestLoop_stop
Flag
=
false
}
reject
(
err
)
})
})
}
// 对轮询获得的数据进行渲染
function
renderRequestLoopData
(
data
)
{
console
.
log
(
98741
,
Object
.
prototype
.
toString
.
call
(
data
))
if
(
Object
.
prototype
.
toString
.
call
(
data
)
!==
'[object Object]'
)
{
return
}
Object
.
keys
(
data
).
forEach
(
key
=>
{
renderRequestLoopData_item
(
Controls
.
dataPoolMap
[
key
])
})
}
// 分类渲染
function
renderRequestLoopData_item
(
obj
)
{
switch
(
obj
.
ControlType
)
{
case
'datatextblock'
:
renderDatatextblock
(
obj
)
break
}
}
function
renderDatatextblock
(
obj
)
{
}
// 整合所有组件的请求数据,放到一个数组里
function
handleControlListInArray
()
{
function
collectRequestLoopData
()
{
let
resList
=
[]
Controls
.
dataPoolMap
=
{}
Controls
.
ControlList
.
forEach
((
item
,
index
)
=>
{
switch
(
item
.
ControlType
)
{
case
'datatextblock'
:
// 数值显示
...
...
@@ -962,13 +1000,14 @@ function handleControlListInArray() {
variableCode
:
item
.
CheckData
.
name
}
})
Controls
.
dataPoolMap
[
`
${
index
}
-
${
item
.
CheckData
.
name
}
`
]
=
item
break
case
'commonlamp'
:
// 矩形状态灯
case
'image'
:
// 动态图片
case
'dynamictext'
:
// 动态文本
case
'ellipselamp'
:
// 圆形状态灯
item
.
DataList
.
forEach
((
dlItem
,
dlIndex
)
=>
{
if
(
dlItem
.
variable
!==
'选择'
&&
dlItem
.
CheckData
)
{
if
(
dlItem
.
variable
!==
'选择'
&&
dlItem
.
CheckData
)
{
resList
.
push
({
urlType
:
'status'
,
assemblyKey
:
`
${
index
}
-
${
dlIndex
}
-
${
dlItem
.
CheckData
.
name
}
`
,
...
...
@@ -978,7 +1017,8 @@ function handleControlListInArray() {
variableCode
:
dlItem
.
CheckData
.
name
}
})
}
Controls
.
dataPoolMap
[
`
${
index
}
-
${
dlIndex
}
-
${
dlItem
.
CheckData
.
name
}
`
]
=
item
}
})
break
case
'piechart'
:
...
...
@@ -999,6 +1039,7 @@ function handleControlListInArray() {
assemblyKey
:
`
${
index
}
-
${
item
.
Name
}
`
,
pieChartOrPanel
})
Controls
.
dataPoolMap
[
`
${
index
}
-
${
item
.
Name
}
`
]
=
pieItem
}
}
})
...
...
@@ -1017,6 +1058,7 @@ function handleControlListInArray() {
variableCode
:
VariableCheckDataObj
.
name
}]
})
Controls
.
dataPoolMap
[
`
${
index
}
-
${
item
.
Name
}
`
]
=
dashItem
}
}
})
...
...
@@ -1047,6 +1089,7 @@ function handleControlListInArray() {
variableCode
:
vc
.
name
}
})
Controls
.
dataPoolMap
[
`
${
index
}
-
${
variableIndex
}
-
${
item
.
Name
}
`
]
=
pieItem
})
}
}
...
...
@@ -1056,12 +1099,12 @@ function handleControlListInArray() {
return
resList
}
// 对request
D
ataPool进行分组
function
sliceRequest
DataPool
(
num
)
{
// 对request
Loop_d
ataPool进行分组
function
sliceRequest
LoopData
(
num
)
{
let
list
=
[]
let
groupNum
=
Math
.
ceil
(
request
D
ataPool
.
length
/
num
)
let
groupNum
=
Math
.
ceil
(
request
Loop_d
ataPool
.
length
/
num
)
for
(
let
i
=
0
;
i
<
groupNum
;
i
++
)
{
list
.
push
(
request
D
ataPool
.
slice
(
i
*
num
,
(
i
+
1
)
*
num
))
list
.
push
(
request
Loop_d
ataPool
.
slice
(
i
*
num
,
(
i
+
1
)
*
num
))
}
return
list
}
...
...
js/tokenSetting.js
View file @
297e8233
...
...
@@ -3,12 +3,24 @@
* @description: 文件描述
* @Date: 2021-09-16 18:33:55
* @LastEditors: 莫靓仔
* @LastEditTime: 2021-09-
17 10:30:21
* @LastEditTime: 2021-09-
22 15:36:48
*/
window
.
devToken
=
'f35ae2b4-f88c-4cae-9428-c45216e13257'
// window.devToken = 'cca20c8c-507b-43e0-8ca6-3571ae779698'
let
setObj
=
{
// 厂家大佬
set1
:
{
devToken
:
'f35ae2b4-f88c-4cae-9428-c45216e13257'
,
devAppId
:
'innerTestPlatformId'
,
devTenantId
:
'innerTestPlatformId'
},
// test-123
set2
:
{
devToken
:
'cca20c8c-507b-43e0-8ca6-3571ae779698'
,
devAppId
:
'TEST123_o582'
,
devTenantId
:
'TEST123_o582'
}
}
window
.
devAppId
=
'innerTestPlatformId'
// window.devAppId = 'TEST123_o582'
window
.
devTenantId
=
'innerTestPlatformId'
\ No newline at end of file
let
defaultObj
=
'set1'
window
.
devToken
=
setObj
[
defaultObj
].
devToken
window
.
devAppId
=
setObj
[
defaultObj
].
devAppId
window
.
devTenantId
=
setObj
[
defaultObj
].
devTenantId
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment