Skip to content

Commit 4db95c3

Browse files
authored
[#2152] improvement(dashboard): Add session cache to support refresh page of dashboard (#2238)
### Why are the changes needed? Fix: #2152 ### Does this PR introduce _any_ user-facing change? No.
1 parent 56f4994 commit 4db95c3

File tree

3 files changed

+17
-11
lines changed

3 files changed

+17
-11
lines changed

dashboard/src/main/webapp/src/components/LayoutPage.vue

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -109,18 +109,21 @@ export default {
109109
}
110110
}
111111
112-
function handleChangeServer(key) {
112+
const handleChangeServer = (key) => {
113113
currentServerStore.currentServer = key
114114
}
115115
116116
async function getSelectCurrentServer() {
117117
const res = await getAllCoordinatorAddrees()
118118
const selectCurrentServer = res.data.data
119-
currentServerStore.currentServer = Object.keys(selectCurrentServer)[0]
119+
if (!currentServerStore.currentServer) {
120+
currentServerStore.currentServer = Object.keys(selectCurrentServer)[0]
121+
}
120122
hostNameAndPorts.length = 0
121123
Object.entries(selectCurrentServer).forEach(([key, value]) => {
122124
hostNameAndPorts.push({ value: value, label: key })
123125
})
126+
hostNameAndPorts.sort((a, b) => a.label.localeCompare(b.label))
124127
}
125128
126129
onMounted(() => {

dashboard/src/main/webapp/src/pages/CoordinatorServerPage.vue

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -123,7 +123,7 @@
123123
</template>
124124

125125
<script>
126-
import { ref, reactive, computed, onMounted } from 'vue'
126+
import { ref, reactive, computed, onMounted, watch } from 'vue'
127127
import { ElMessage } from 'element-plus'
128128
import {
129129
getCoordinatorConf,
@@ -196,11 +196,9 @@ export default {
196196
/**
197197
* The system obtains data from global variables and requests the interface to obtain new data after data changes.
198198
*/
199-
currentServerStore.$subscribe((mutable, state) => {
200-
if (state.currentServer) {
201-
getCoordinatorServerConfPage()
202-
getCoorServerInfo()
203-
}
199+
watch(() => currentServerStore.currentServer, () => {
200+
getCoordinatorServerConfPage()
201+
getCoorServerInfo()
204202
})
205203
206204
onMounted(() => {

dashboard/src/main/webapp/src/store/useCurrentServerStore.js

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -16,13 +16,18 @@
1616
*/
1717

1818
import { defineStore } from 'pinia'
19-
import { ref } from 'vue'
19+
import { ref, watch } from 'vue'
2020

2121
/**
2222
* Create a global shared repository that allows you to share state across components/pages.
2323
* @type {StoreDefinition<"overall", _ExtractStateFromSetupStore<{currentServer: Ref<UnwrapRef<string>>}>, _ExtractGettersFromSetupStore<{currentServer: Ref<UnwrapRef<string>>}>, _ExtractActionsFromSetupStore<{currentServer: Ref<UnwrapRef<string>>}>>}
2424
*/
2525
export const useCurrentServerStore = defineStore('overall', () => {
26-
const currentServer = ref('')
27-
return { currentServer }
26+
const currentServer = ref(sessionStorage.getItem('currentServer'))
27+
28+
watch(currentServer, (newVal) => {
29+
sessionStorage.setItem('currentServer', newVal)
30+
})
31+
32+
return { currentServer }
2833
})

0 commit comments

Comments
 (0)