style:首页增加定时器
Showing
2 changed files
with
65 additions
and
50 deletions
1 | <!-- | ||
2 | * @Description: | ||
3 | * @Autor: renchao | ||
4 | * @LastEditTime: 2023-07-04 13:48:00 | ||
5 | --> | ||
1 | <template> | 6 | <template> |
2 | <!-- 登记类型总量 --> | 7 | <!-- 登记类型总量 --> |
3 | <Chart :cdata="cdata" /> | 8 | <Chart :cdata="cdata" /> |
4 | </template> | 9 | </template> |
5 | 10 | ||
6 | <script> | 11 | <script> |
7 | import Chart from "./Chart"; | 12 | import Chart from "./Chart"; |
8 | import work from "@/api/work"; | 13 | import work from "@/api/work"; |
9 | export default { | 14 | export default { |
10 | data () { | 15 | data () { |
11 | return { | 16 | return { |
12 | cdata: { | 17 | cdata: { |
13 | category: [], | 18 | timer: null, |
14 | lineData: [], | 19 | category: [], |
15 | }, | 20 | lineData: [], |
16 | }; | 21 | }, |
17 | }, | 22 | }; |
18 | components: { | 23 | }, |
19 | Chart, | 24 | components: { |
20 | }, | 25 | Chart, |
21 | mounted () { | 26 | }, |
22 | this.getDjlxtotal(); | 27 | mounted () { |
23 | }, | 28 | this.getDjlxtotal() |
24 | methods: { | 29 | this.timer = setInterval(() => { |
25 | getDjlxtotal () { | 30 | this.getDjlxtotal() |
26 | return new Promise(async (resolve) => { | 31 | }, 10000) // 10s |
32 | }, | ||
33 | methods: { | ||
34 | getDjlxtotal () { | ||
35 | return new Promise(async (resolve) => { | ||
27 | try { | 36 | try { |
28 | let p = { | 37 | let p = { |
29 | DJLX: "", | 38 | DJLX: "", |
30 | QLLX: "", | 39 | QLLX: "", |
31 | XZQDM: "", | 40 | XZQDM: "", |
32 | }; | 41 | }; |
33 | let res = await work.getDjlxtotal(p); | 42 | let res = await work.getDjlxtotal(p); |
34 | res.result.map((item) => { | 43 | res.result.map((item) => { |
35 | return ( | 44 | return ( |
36 | this.cdata.category.push(item.AREACODE), | 45 | this.cdata.category.push(item.AREACODE), |
37 | this.cdata.lineData.push(item.ywtotal) | 46 | this.cdata.lineData.push(item.ywtotal) |
38 | ); | 47 | ); |
39 | }); | 48 | }); |
40 | } catch (error) { | 49 | } catch (error) { |
41 | this.$refs.msg.messageShow(); | 50 | this.$refs.msg.messageShow(); |
42 | } | 51 | } |
43 | }); | 52 | }); |
53 | } | ||
54 | }, | ||
55 | destroyed () { | ||
56 | clearInterval(this.timer) | ||
44 | } | 57 | } |
45 | } | 58 | }; |
46 | }; | ||
47 | </script> | 59 | </script> |
48 | <style lang="scss" scoped> | 60 | <style lang="scss" scoped> |
49 | </style> | 61 | </style> | ... | ... |
1 | <!-- | 1 | <!-- |
2 | * @Author: xiaomiao 1158771342@qq.com | 2 | * @Author: xiaomiao 1158771342@qq.com |
3 | * @Date: 2023-03-09 15:24:53 | 3 | * @Date: 2023-03-09 15:24:53 |
4 | * @LastEditors: xiaomiao 1158771342@qq.com | 4 | * @LastEditors: Please set LastEditors |
5 | * @LastEditTime: 2023-03-16 15:58:03 | 5 | * @LastEditTime: 2023-07-04 13:45:56 |
6 | * @FilePath: \上报\bdcjg-web\src\components\Echart\Rose\index.vue | 6 | * @FilePath: \上报\bdcjg-web\src\components\Echart\Rose\index.vue |
7 | * @Description: 这是默认设置,请设置`customMade`, 打开koroFileHeader查看配置 进行设置: https://github.com/OBKoro1/koro1FileHeader/wiki/%E9%85%8D%E7%BD%AE | 7 | * @Description: 这是默认设置,请设置`customMade`, 打开koroFileHeader查看配置 进行设置: https://github.com/OBKoro1/koro1FileHeader/wiki/%E9%85%8D%E7%BD%AE |
8 | --> | 8 | --> |
... | @@ -18,6 +18,7 @@ | ... | @@ -18,6 +18,7 @@ |
18 | export default { | 18 | export default { |
19 | data () { | 19 | data () { |
20 | return { | 20 | return { |
21 | timer: null, | ||
21 | cdata: [], | 22 | cdata: [], |
22 | getdata: [], | 23 | getdata: [], |
23 | }; | 24 | }; |
... | @@ -25,13 +26,17 @@ | ... | @@ -25,13 +26,17 @@ |
25 | components: { | 26 | components: { |
26 | Chart, | 27 | Chart, |
27 | }, | 28 | }, |
29 | created () { | ||
30 | this.addhousetotal() | ||
31 | this.timer = setInterval(() => { | ||
32 | this.addhousetotal() | ||
33 | }, 10000) // 10s | ||
34 | }, | ||
28 | mounted () { | 35 | mounted () { |
29 | this.addhousetotal(); | ||
30 | window.addEventListener("resize", () => { | 36 | window.addEventListener("resize", () => { |
31 | this.cdata = []; | 37 | this.cdata = []; |
32 | this.addhousetotal(); | 38 | this.addhousetotal(); |
33 | }); | 39 | }); |
34 | |||
35 | }, | 40 | }, |
36 | methods: { | 41 | methods: { |
37 | async addhousetotal () { | 42 | async addhousetotal () { |
... | @@ -53,12 +58,9 @@ | ... | @@ -53,12 +58,9 @@ |
53 | console.log("error", error); | 58 | console.log("error", error); |
54 | } | 59 | } |
55 | } | 60 | } |
56 | |||
57 | |||
58 | }, | 61 | }, |
59 | // 处理数据方法 | 62 | // 处理数据方法 |
60 | setadat (delarr) { | 63 | setadat (delarr) { |
61 | |||
62 | this.cdata = delarr.splice(0, 6); | 64 | this.cdata = delarr.splice(0, 6); |
63 | let sum = 0 | 65 | let sum = 0 |
64 | for (var i = 0; i < delarr.length; i++) { | 66 | for (var i = 0; i < delarr.length; i++) { |
... | @@ -73,9 +75,10 @@ | ... | @@ -73,9 +75,10 @@ |
73 | }, | 75 | }, |
74 | // 排序方法 | 76 | // 排序方法 |
75 | up (x, y) { return y.value - x.value } | 77 | up (x, y) { return y.value - x.value } |
76 | 78 | }, | |
79 | destroyed () { | ||
80 | clearInterval(this.timer) | ||
77 | } | 81 | } |
78 | }; | 82 | } |
79 | </script> | 83 | </script> |
80 | 84 | ||
81 | <style lang="scss" scoped></style> | ... | ... |
-
Please register or sign in to post a comment