Skip to content

Commit 08a5393

Browse files
authored
新增功能:列表清单定时刷新的设置 (#280)
1 parent 2513aab commit 08a5393

File tree

5 files changed

+154
-14
lines changed

5 files changed

+154
-14
lines changed
Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
<template>
2+
<span style="color: white;margin-left: 20px">
3+
<el-select v-model="autorefresh" @change="changeAutorefresh">
4+
<el-option v-for="(vs,index) in autorefreshs" :key="vs.value"
5+
:label="vs.label"
6+
:value="vs.value"
7+
></el-option>
8+
</el-select>
9+
</span>
10+
</template>
11+
12+
<script>
13+
/*定时刷新设置*/
14+
export default {
15+
name: "autorefresh",
16+
components: {},
17+
props: {},
18+
data () {
19+
return {
20+
autorefresh: '-1',
21+
autorefreshs:[
22+
{value:'-1',label:"手动刷新"},
23+
{value:'5',label:"5秒自动刷新"},
24+
{value:'10',label:"10秒自动刷新"},
25+
{value:'30',label:"30秒自动刷新"},
26+
]
27+
}
28+
},
29+
methods: {
30+
async changeAutorefresh(){
31+
await this.$store.dispatch("app/setAutorefresh", this.autorefresh)
32+
}
33+
},
34+
async mounted () {
35+
this.autorefresh =localStorage.getItem("autorefresh")
36+
if(!this.autorefresh || this.autorefresh === 'undefined' || this.autorefresh === ''){
37+
this.autorefresh = '-1'
38+
}
39+
await this.$store.dispatch("app/setAutorefresh", this.autorefresh)
40+
41+
},
42+
created () {
43+
44+
}
45+
}
46+
</script>
47+
48+
<style scoped>
49+
50+
</style>
51+

web/dashboard/src/business/app-layout/horizontal-layout/HorizontalHeader.vue

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
<home></home>
66
<project-switch style="margin-left: 20px"></project-switch>
77
<cluster-name></cluster-name>
8+
<AutoRefresh></AutoRefresh>
89
</div>
910
<div class="header-right">
1011
<TerminalEnter></TerminalEnter>
@@ -24,10 +25,10 @@ import Help from "@/business/app-layout/header-components/Help";
2425
import LanguageSwitch from "@/business/app-layout/header-components/LanguageSwitch"
2526
import TerminalEnter from "@/business/app-layout/header-components/TerminalEnter";
2627
import ClusterName from "@/business/app-layout/header-components/Cluster"
27-
28+
import AutoRefresh from "@/business/app-layout/header-components/AutoRefresh"
2829
export default {
2930
name: "HorizontalHeader",
30-
components: { ClusterName, TerminalEnter, LanguageSwitch, ProjectSwitch, Help, Home, UserSetting, SidebarToggleButton}
31+
components: { ClusterName, TerminalEnter, LanguageSwitch, ProjectSwitch, Help, Home, UserSetting, SidebarToggleButton,AutoRefresh}
3132
}
3233
</script>
3334

web/dashboard/src/business/dashboard/index.vue

Lines changed: 40 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -168,7 +168,8 @@ export default {
168168
},
169169
dialogMetricVisible: false,
170170
loading: false,
171-
isFullTextSearch: false
171+
isFullTextSearch: false,
172+
intervalId:null,//定时器
172173
}
173174
},
174175
methods: {
@@ -189,6 +190,7 @@ export default {
189190
this.cluster = res.data
190191
})
191192
if (checkPermissions({scope: 'cluster', apiGroup: "", resource: "nodes", verb: "list"})) {
193+
this.resources=[]
192194
listNodes(this.clusterName).then(res => {
193195
const nodes = {
194196
name: "Nodes",
@@ -315,7 +317,7 @@ export default {
315317
this.resources.push(services)
316318
})
317319
}
318-
this.search()
320+
319321
},
320322
search(resetPage) {
321323
this.loading = true
@@ -396,12 +398,48 @@ export default {
396398
//改变选项"是否全文搜索"
397399
OnIsFullTextSearchChange(val){
398400
this.isFullTextSearch=val
401+
},
402+
stopTimeTick(){
403+
if (!this.intervalId) {
404+
return;
405+
}
406+
clearInterval(this.intervalId); //清除计时器
407+
this.intervalId = null; //设置为null
408+
},
409+
startTimeTick(tick){
410+
// 计时器为空,操作
411+
this.intervalId = setInterval(() => {
412+
this.stopTimeTick()
413+
//刷新图表
414+
this.listResources();
415+
console.log(tick)
416+
this.startTimeTick(tick)
417+
},tick*1000);
399418
}
400419
},
401420
created() {
402421
this.clusterName = this.$route.query.cluster
403422
this.showMetric = checkPermissions({scope: 'cluster', apiGroup: "", resource: "nodes", verb: "list"}) && checkPermissions({scope: 'cluster', apiGroup: "metrics.k8s.io", resource: "nodes", verb: "list"})
404423
this.listResources()
424+
this.search()
425+
},
426+
watch: {
427+
/*监控自动刷新变量*/
428+
"$store.state.app.autorefresh":{
429+
handler:function(newVal,oldVal){
430+
if(!newVal || newVal=='-1' || newVal=='undefined' || newVal==''){
431+
this.stopTimeTick();
432+
} else {
433+
this.stopTimeTick();
434+
// 计时器为空,操作
435+
this.startTimeTick(parseInt(newVal));
436+
}
437+
}
438+
}
439+
},
440+
destroyed(){
441+
// 在页面销毁后,清除计时器
442+
this.stopTimeTick();
405443
}
406444
}
407445
</script>

web/dashboard/src/components/complex-table/index.vue

Lines changed: 50 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -5,27 +5,34 @@
55
</div>
66

77
<div class="complex-table__toolbar">
8-
<div>
9-
10-
<div v-if="searchConfig">
8+
<template v-if="searchConfig">
119
<el-row v-if="showFullTextSwitch">
12-
<el-col :span="12">
10+
<el-col :span="8">
1311
<div style="margin-top: 5px; float: left">
1412
<span class="spanClass">{{$t('commons.search.fullTextSearch')}}</span>
1513
<el-switch class="interval" v-model="isFullTextSearch" @change="OnIsFullTextSearchChange"/>
1614
</div>
1715
</el-col>
18-
<el-col :span="12">
16+
<el-col :span="6">
17+
<el-button size="mini" @click="search(true)"><i class="el-icon-search"/>{{this.$t('commons.button.search')}}</el-button>
18+
</el-col>
19+
<el-col :span="10">
1920
<el-input :placeholder="$t('commons.button.search')" suffix-icon="el-icon-search" clearable v-model="searchConfig.keywords" @change="search(true)">
2021
</el-input>
2122
</el-col>
2223
</el-row>
23-
<el-input v-if="!showFullTextSwitch" :placeholder="$t('commons.button.search')" suffix-icon="el-icon-search" clearable v-model="searchConfig.keywords" @change="search(true)">
24-
</el-input>
25-
</div>
24+
<el-row v-if="!showFullTextSwitch">
25+
<el-col :span="12">
26+
<el-button size="mini" @click="search(true)"><i class="el-icon-search"/>{{this.$t('commons.button.search')}}</el-button>
27+
</el-col>
28+
<el-col :span="12">
29+
<el-input :placeholder="$t('commons.button.search')" suffix-icon="el-icon-search" clearable v-model="searchConfig.keywords" @change="search(true)">
30+
</el-input>
31+
</el-col>
32+
</el-row>
33+
</template>
2634
<slot name="toolbar">
2735
</slot>
28-
</div>
2936
</div>
3037

3138
<div class="complex-table__body">
@@ -65,6 +72,7 @@ export default {
6572
return {
6673
pageShow: false,
6774
isFullTextSearch :false,//是否全文本搜索
75+
intervalId:null,//定时
6876
}
6977
},
7078
methods: {
@@ -76,8 +84,41 @@ export default {
7684
},
7785
OnIsFullTextSearchChange(val){
7886
this.$emit("update:isFullTextSearch", val)
87+
},
88+
stopTimeTick(){
89+
if (!this.intervalId) {
90+
return;
91+
}
92+
clearInterval(this.intervalId); //清除计时器
93+
this.intervalId = null; //设置为null
94+
},
95+
startTimeTick(tick){
96+
// 计时器为空,操作
97+
this.intervalId = setInterval(() => {
98+
this.stopTimeTick()
99+
this.search(true);
100+
this.startTimeTick(tick)
101+
},tick*1000);
79102
}
80103
},
104+
watch: {
105+
/*监控自动刷新变量*/
106+
"$store.state.app.autorefresh":{
107+
handler:function(newVal,oldVal){
108+
if(!newVal || newVal=='-1' || newVal=='undefined' || newVal==''){
109+
this.stopTimeTick();
110+
} else {
111+
this.stopTimeTick();
112+
// 计时器为空,操作
113+
this.startTimeTick(parseInt(newVal));
114+
}
115+
}
116+
}
117+
},
118+
destroyed(){
119+
// 在页面销毁后,清除计时器
120+
this.stopTimeTick();
121+
}
81122
}
82123
</script>
83124

web/dashboard/src/store/modules/app.js

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,9 @@ const state = {
88
sidebar: {
99
opened: get() ? !!+get() : true
1010
},
11-
device: 'desktop'
11+
device: 'desktop',
12+
/*定时刷新频率,单位为秒,-1为手动刷新*/
13+
autorefresh: '-1'
1214
}
1315

1416
const mutations = {
@@ -27,6 +29,10 @@ const mutations = {
2729
CLOSE_SIDEBAR: (state) => {
2830
set('sidebarStatus', 0)
2931
state.sidebar.opened = false
32+
},
33+
SET_AUTOREFRESH: (state, value) => {
34+
localStorage.setItem('autorefresh',value)
35+
state.autorefresh = value
3036
}
3137
}
3238

@@ -39,6 +45,9 @@ const actions = {
3945
},
4046
closeSideBar({commit}) {
4147
commit('CLOSE_SIDEBAR')
48+
},
49+
setAutorefresh({commit},value) {
50+
commit('SET_AUTOREFRESH',value)
4251
}
4352
}
4453

0 commit comments

Comments
 (0)