7373 </sba-panel >
7474</template >
7575
76- <script >
77- import { computed } from ' vue' ;
76+ <script setup lang="ts" >
77+ import { computed , ref , watch } from ' vue' ;
7878
7979import { useApplicationStore } from ' @/composables/useApplicationStore' ;
8080import { getStatusInfo } from ' @/services/application' ;
@@ -87,57 +87,34 @@ const options = {
8787 minute: ' numeric' ,
8888 second: ' numeric' ,
8989};
90+ const { applications } = useApplicationStore ();
9091
91- export default {
92- setup () {
93- const { applications } = useApplicationStore ();
92+ const userLocale = navigator .languages
93+ ? navigator .languages [0 ]
94+ : navigator .language ;
95+ const dateTimeFormat = new Intl .DateTimeFormat (userLocale , options );
9496
95- const statusInfo = computed (() => getStatusInfo ( applications . value ));
97+ const lastUpdate = ref ( dateTimeFormat . format ( new Date () ));
9698
97- return { applications, statusInfo };
98- },
99- data () {
100- return {
101- lastUpdate: new Date (),
102- dateTimeFormat: new Intl.DateTimeFormat (this .$i18n .locale , options),
103- };
104- },
105- computed: {
106- someInstancesDown () {
107- return this .statusInfo .someDown ;
108- },
109- someInstancesUnknown () {
110- return this .statusInfo .someUnknown ;
111- },
112- notUpCount () {
113- return this .applications .reduce ((current , next ) => {
114- return (
115- current +
116- next .instances .filter (
117- (instance ) => instance .statusInfo .status !== ' UP' ,
118- ).length
119- );
120- }, 0 );
121- },
122- applicationsCount () {
123- return this .applications .length ;
124- },
125- instancesCount () {
126- return this .applications .reduce (
127- (current , next ) => current + next .instances .length ,
128- 0 ,
129- );
130- },
131- },
132- beforeMount () {
133- this .updateLastUpdateTime ();
134- },
135- methods: {
136- updateLastUpdateTime () {
137- this .lastUpdate = this .dateTimeFormat .format (new Date ());
138- },
139- },
140- };
99+ const statusInfo = computed (() => {
100+ return getStatusInfo (applications .value );
101+ });
102+
103+ watch (statusInfo , () => {
104+ lastUpdate .value = dateTimeFormat .format (new Date ());
105+ });
106+
107+ const applicationsCount = computed (() => {
108+ return applications .value .length ;
109+ });
110+
111+ const someInstancesDown = computed (() => {
112+ return statusInfo .value .someDown ;
113+ });
114+
115+ const someInstancesUnknown = computed (() => {
116+ return statusInfo .value .someUnknown ;
117+ });
141118 </script >
142119
143120<style scoped>
0 commit comments