1
0

Environments.vue 3.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102
  1. <script setup lang="ts">
  2. import {useSettingsStore} from '@/pinia'
  3. import {useGettext} from 'vue3-gettext'
  4. import {computed, ref} from 'vue'
  5. import environment from '@/api/environment'
  6. import Icon, {LinkOutlined, SendOutlined, ThunderboltOutlined} from '@ant-design/icons-vue'
  7. import logo from '@/assets/img/logo.png'
  8. import pulse from '@/assets/svg/pulse.svg'
  9. import cpu from '@/assets/svg/cpu.svg'
  10. import memory from '@/assets/svg/memory.svg'
  11. import {formatDateTime} from '@/lib/helper'
  12. const settingsStore = useSettingsStore()
  13. const {$gettext} = useGettext()
  14. const data = ref([])
  15. environment.get_list().then(r => {
  16. data.value = r.data
  17. })
  18. export interface Node {
  19. id: number
  20. name: string
  21. token: string
  22. }
  23. const {environment: env} = settingsStore
  24. function link_start(node: Node) {
  25. env.id = node.id
  26. env.name = node.name
  27. }
  28. const visible = computed(() => {
  29. if (env.id > 0) {
  30. return false
  31. } else {
  32. return data.value?.length
  33. }
  34. })
  35. </script>
  36. <template>
  37. <a-card class="env-list-card" :title="$gettext('Environments')" v-if="visible">
  38. <a-list item-layout="horizontal" :data-source="data">
  39. <template #renderItem="{ item }">
  40. <a-list-item>
  41. <template #actions>
  42. <a-button type="primary" @click="link_start(item)" :disabled="env.id===item.id" ghost>
  43. <send-outlined/>
  44. {{ env.id !== item.id ? $gettext('Link Start') : $gettext('Connected') }}
  45. </a-button>
  46. </template>
  47. <a-list-item-meta>
  48. <template #title>
  49. {{ item.name }}
  50. <a-tag color="blue" v-if="item.status">{{ $gettext('Online') }}</a-tag>
  51. <a-tag color="error" v-else>{{ $gettext('Offline') }}</a-tag>
  52. <div class="runtime-meta">
  53. <span><Icon :component="pulse"/> {{ formatDateTime(item.response_at) }}</span>
  54. <span><thunderbolt-outlined/>{{ item.version }}</span>
  55. <span><link-outlined/>{{ item.url }}</span>
  56. </div>
  57. </template>
  58. <template #avatar>
  59. <a-avatar :src="logo"/>
  60. </template>
  61. <template #description>
  62. <div class="runtime-meta">
  63. <span><Icon :component="cpu"/> {{ item.cpu_num }} CPU</span>
  64. <span><Icon :component="memory"/> {{ item.memory_total }}</span>
  65. </div>
  66. </template>
  67. </a-list-item-meta>
  68. </a-list-item>
  69. </template>
  70. </a-list>
  71. </a-card>
  72. </template>
  73. <style scoped lang="less">
  74. .env-list-card {
  75. margin-top: 16px;
  76. .runtime-meta {
  77. display: inline-flex;
  78. margin-left: 8px;
  79. span {
  80. font-weight: 400;
  81. font-size: 13px;
  82. margin-right: 16px;
  83. color: #9b9b9b;
  84. &.anticon {
  85. margin-right: 4px;
  86. }
  87. }
  88. }
  89. }
  90. </style>