1
0

EnvIndicator.vue 2.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105
  1. <script setup lang="ts">
  2. import { useSettingsStore } from '@/pinia'
  3. import { CloseOutlined, DashboardOutlined, DatabaseOutlined } from '@ant-design/icons-vue'
  4. import { storeToRefs } from 'pinia'
  5. import { useRouter } from 'vue-router'
  6. const settingsStore = useSettingsStore()
  7. const { environment } = storeToRefs(settingsStore)
  8. const router = useRouter()
  9. async function clear_env() {
  10. await router.push('/dashboard')
  11. settingsStore.clear_environment()
  12. }
  13. const is_local = computed(() => {
  14. return environment.value.id === 0
  15. })
  16. const node_id = computed(() => environment.value.id)
  17. watch(node_id, async () => {
  18. await router.push('/dashboard')
  19. location.reload()
  20. })
  21. const { server_name } = storeToRefs(useSettingsStore())
  22. </script>
  23. <template>
  24. <div class="indicator">
  25. <div class="container">
  26. <DatabaseOutlined />
  27. <span
  28. v-if="is_local"
  29. class="env-name"
  30. >
  31. {{ server_name || $gettext('Local') }}
  32. </span>
  33. <span
  34. v-else
  35. class="env-name"
  36. >
  37. {{ environment.name }}
  38. </span>
  39. <ATag @click="clear_env">
  40. <DashboardOutlined v-if="is_local" />
  41. <CloseOutlined v-else />
  42. </ATag>
  43. </div>
  44. </div>
  45. </template>
  46. <style scoped lang="less">
  47. .ant-layout-sider-collapsed {
  48. .ant-tag, .env-name {
  49. display: none;
  50. }
  51. .indicator {
  52. .container {
  53. justify-content: center;
  54. }
  55. }
  56. }
  57. .indicator {
  58. padding: 20px 20px 16px 20px;
  59. .container {
  60. border-radius: 16px;
  61. border: 1px solid #91d5ff;
  62. background: #e6f7ff;
  63. padding: 5px 15px;
  64. color: #096dd9;
  65. display: flex;
  66. align-items: center;
  67. justify-content: space-between;
  68. .env-name {
  69. max-width: 85px;
  70. text-overflow: ellipsis;
  71. white-space: nowrap;
  72. line-height: 1em;
  73. overflow: hidden;
  74. }
  75. .ant-tag {
  76. cursor: pointer;
  77. margin-right: 0;
  78. padding: 0 5px;
  79. }
  80. }
  81. }
  82. .dark {
  83. .container {
  84. border: 1px solid #545454;
  85. background: transparent;
  86. color: #bebebe;
  87. }
  88. }
  89. </style>