Skip to content
Toggle navigation
Projects
Groups
Snippets
Help
gh
/
data-view
This project
Loading...
Sign in
Toggle navigation
Go to a project
Project
Repository
Issues
0
Merge Requests
0
Pipelines
Wiki
Settings
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Commit f85df08a
authored
Jul 28, 2022
by
王志慧
Browse Files
Options
Browse Files
Tag
Download
Email Patches
Plain Diff
commit:定时器优化
1 parent
4ab02ebe
Show whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
43 additions
and
11 deletions
src/components/Marquees.vue
src/components/PieChart.vue
src/main.js
src/utils/dep.js
src/components/Marquees.vue
View file @
f85df08
...
...
@@ -57,18 +57,18 @@ export default {
},
computedValue
()
{
const
{
marqueeBox
}
=
this
.
$refs
console
.
log
(
this
.
text
)
//
console.log(this.text)
this
.
boxWidth
=
marqueeBox
.
offsetWidth
// 盒子宽度
this
.
valueWidth
=
this
.
text
.
visualLength
(
this
.
fontSize
)
// 内容文本宽度
const
{
boxWidth
,
valueWidth
}
=
this
console
.
log
(
valueWidth
,
boxWidth
)
//
console.log(valueWidth, boxWidth)
if
(
valueWidth
<
boxWidth
)
{
this
.
$set
(
this
,
'speed'
,
0
)
}
else
{
this
.
$set
(
this
,
'speed'
,
this
.
scrollamount
)
}
this
.
key
=
new
Date
().
getTime
()
console
.
log
(
valueWidth
>
boxWidth
,
this
.
speed
,
this
.
scrollamount
)
//
console.log(valueWidth > boxWidth, this.speed, this.scrollamount)
}
}
}
...
...
src/components/PieChart.vue
View file @
f85df08
...
...
@@ -51,7 +51,6 @@ export default {
return
{
option
:
''
,
echartsPie
:
''
,
mTime
:
''
,
viewData
:
[],
text
:
''
,
subtext
:
''
,
...
...
@@ -76,6 +75,7 @@ export default {
},
mounted
()
{
console
.
log
(
this
.
dep
)
// this.initData()
// this.draw()
},
...
...
@@ -93,7 +93,7 @@ export default {
})
},
draw
()
{
if
(
this
.
mTime
)
clearInterval
(
this
.
mTime
)
this
.
dep
.
remove
(
this
.
id
)
this
.
echartsPie
=
echarts
.
init
(
document
.
getElementById
(
this
.
id
))
window
.
addEventListener
(
'resize'
,
()
=>
{
this
.
echartsPie
.
resize
()
...
...
@@ -142,11 +142,11 @@ export default {
// this.setAnamiteText()
this
.
echartsPie
.
setOption
(
this
.
option
)
this
.
pieActive
()
this
.
mTime
=
setInterval
(
this
.
pieActive
,
15000
)
this
.
dep
.
addSub
({
id
:
this
.
id
,
fn
:
this
.
pieActive
})
this
.
dep
.
notify
()
// 鼠标划出
this
.
echartsPie
.
on
(
'mouseout'
,
()
=>
{
if
(
this
.
mTime
)
clearInterval
(
this
.
mTime
)
this
.
mTime
=
setInterval
(
this
.
pieActive
,
15000
)
this
.
dep
.
addSub
({
id
:
this
.
id
,
fn
:
this
.
pieActive
})
})
this
.
echartsPie
.
on
(
'mouseover'
,
data
=>
{
this
.
mainValue
=
data
.
data
.
value
...
...
@@ -154,7 +154,8 @@ export default {
this
.
descColor
=
data
.
color
this
.
setAnamiteText
()
// 停止定时器,清除之前的高亮
clearInterval
(
this
.
mTime
)
// clearInterval(this.mTime)
this
.
dep
.
remove
(
this
.
id
)
this
.
currentIndex
=
data
.
dataIndex
this
.
highlightPie
()
this
.
emitEvent
(
data
.
data
)
...
...
src/main.js
View file @
f85df08
...
...
@@ -20,6 +20,7 @@ import { fetchConfig, cfg } from '@/config'
import
'@/assets/css/index.scss'
import
'./utils/util'
import
'components'
import
Dep
from
'./utils/dep'
Vue
.
prototype
.
to
=
function
(
name
,
params
)
{
if
(
name
===
-
1
)
{
router
.
go
(
-
1
)
...
...
@@ -29,11 +30,10 @@ Vue.prototype.to = function (name, params) {
}
// 移动端适配 rem
// import 'lib-flexible/flexible.js'
Vue
.
prototype
.
dep
=
new
Dep
()
Vue
.
config
.
productionTip
=
false
const
isMock
=
[
'prod'
,
'production'
].
includes
(
process
.
env
.
NODE_ENV
)
fetchConfig
(
!
isMock
).
then
(
res
=>
{
console
.
log
(
res
)
// 从配置服务器获取动态配置
// 设置 js中可以访问 $cdn
Vue
.
use
(
cfg
)
...
...
src/utils/dep.js
0 → 100644
View file @
f85df08
export
default
class
Dep
{
constructor
()
{
this
.
subs
=
[]
// 此数组用来收集订阅
this
.
mTime
=
''
}
//事件收集
addSub
(
data
)
{
let
isAdd
=
true
this
.
subs
.
forEach
(
sub
=>
{
if
(
sub
.
id
==
data
.
id
)
{
isAdd
=
false
sub
.
fn
=
data
.
fn
}
})
if
(
isAdd
)
this
.
subs
.
push
(
data
)
}
remove
(
id
)
{
this
.
subs
.
forEach
(
sub
=>
{
if
(
sub
.
id
==
id
)
sub
.
fn
=
''
})
}
//事件触发
notify
()
{
if
(
this
.
mTime
)
clearInterval
(
this
.
mTime
)
this
.
mTime
=
setInterval
(()
=>
{
this
.
subs
.
forEach
(
sub
=>
{
sub
.
fn
&&
sub
.
fn
()
})
},
15000
)
}
}
Write
Preview
Markdown
is supported
Attach a file
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 post a comment