2 changed files with 66 additions and 45 deletions
@ -0,0 +1,63 @@ |
|||||
|
<template> |
||||
|
<div class="bg-white border-b p-5 flex flex-row flex-wrap"> |
||||
|
<div class="p-1 grow" style="min-width:33.33%;" v-for="(status,index) in statuses" :key="index"> |
||||
|
<div class="py-1 px-2 rounded border"> |
||||
|
{{ status.name }} : |
||||
|
<template v-if="isBoolean(status.value)"> |
||||
|
<BulbOutlined class="align-text-bottom" :class="{'text-green-400':status.value}"/> |
||||
|
</template> |
||||
|
<span v-else>{{ status.value }}</span> |
||||
|
</div> |
||||
|
</div> |
||||
|
</div> |
||||
|
</template> |
||||
|
<script setup> |
||||
|
import ApiClient from '@/utils/ApiClient'; |
||||
|
import { BulbOutlined } from '@ant-design/icons-vue' |
||||
|
import { onUnmounted, watch, ref } from 'vue'; |
||||
|
/** @var {Object} */ |
||||
|
const props = defineProps({ |
||||
|
serviceKey : String, |
||||
|
}); |
||||
|
/** @var {Array} */ |
||||
|
const statuses = ref([]); |
||||
|
/** @var {Integer} */ |
||||
|
let statusRefreshTimer = null; |
||||
|
// watch service key |
||||
|
watch(() => props.serviceKey, handleServiceKeyChange); |
||||
|
// on unmounted |
||||
|
onUnmounted(() => { |
||||
|
if ( null !== statusRefreshTimer ) { |
||||
|
clearTimeout(statusRefreshTimer); |
||||
|
statusRefreshTimer = false; |
||||
|
} |
||||
|
}); |
||||
|
|
||||
|
// handle |
||||
|
async function handleServiceKeyChange() { |
||||
|
if ( null !== statusRefreshTimer ) { |
||||
|
clearTimeout(statusRefreshTimer); |
||||
|
statusRefreshTimer = null; |
||||
|
} |
||||
|
if ( null === props.serviceKey ) { |
||||
|
return ; |
||||
|
} |
||||
|
await refreshServiceStatusList(); |
||||
|
} |
||||
|
|
||||
|
// refresh service status list |
||||
|
async function refreshServiceStatusList() { |
||||
|
try { |
||||
|
let client = ApiClient.getClient(); |
||||
|
statuses.value = await client.call('service-config/service-status-list', {serviceKey:props.serviceKey}); |
||||
|
if ( false !== statusRefreshTimer ) { |
||||
|
statusRefreshTimer = setTimeout(refreshServiceStatusList, 1000); |
||||
|
} |
||||
|
} catch ( e ) {/** nothing to do here */} |
||||
|
} |
||||
|
|
||||
|
// is boolean |
||||
|
function isBoolean( value ) { |
||||
|
return 'boolean' === typeof(value); |
||||
|
} |
||||
|
</script> |
Write
Preview
Loading…
Cancel
Save
Reference in new issue