123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168 |
- <script lang="ts" setup>
- import { HistoryOutlined, LoadingOutlined } from '@ant-design/icons-vue'
- import CodeEditor from '@/components/CodeEditor'
- import ConfigHistory from '@/components/ConfigHistory'
- import FooterToolBar from '@/components/FooterToolbar'
- import NgxConfigEditor from '@/components/NgxConfigEditor'
- import UpstreamCards from '@/components/UpstreamCards/UpstreamCards.vue'
- import { ConfigStatus } from '@/constants'
- import { useStreamEditorStore } from '../store'
- const router = useRouter()
- const { message } = App.useApp()
- const store = useStreamEditorStore()
- const { name, status, configText, filepath, saving, parseErrorStatus, parseErrorMessage, advanceMode, loading, data } = storeToRefs(store)
- const showHistory = ref(false)
- // Get upstream targets from backend API data
- const upstreamTargets = computed(() => {
- return data.value.proxy_targets || []
- })
- async function save() {
- try {
- await store.save()
- message.success($gettext('Saved successfully'))
- }
- catch {
- // do nothing
- }
- }
- </script>
- <template>
- <ASpin :spinning="loading" :indicator="LoadingOutlined">
- <ACard class="mb-4" :bordered="false">
- <template #title>
- <span style="margin-right: 10px">{{ $gettext('Edit %{n}', { n: name }) }}</span>
- <ATag
- v-if="status === ConfigStatus.Enabled"
- color="blue"
- >
- {{ $gettext('Enabled') }}
- </ATag>
- <ATag
- v-else
- color="orange"
- >
- {{ $gettext('Disabled') }}
- </ATag>
- </template>
- <template #extra>
- <ASpace>
- <AButton
- v-if="filepath"
- type="link"
- @click="showHistory = true"
- >
- <template #icon>
- <HistoryOutlined />
- </template>
- {{ $gettext('History') }}
- </AButton>
- <div class="mode-switch">
- <div class="switch">
- <ASwitch
- size="small"
- :disabled="parseErrorStatus"
- :checked="advanceMode"
- @change="store.handleModeChange"
- />
- </div>
- <template v-if="advanceMode">
- <div>{{ $gettext('Advance Mode') }}</div>
- </template>
- <template v-else>
- <div>{{ $gettext('Basic Mode') }}</div>
- </template>
- </div>
- </ASpace>
- </template>
- <div class="card-body">
- <Transition name="slide-fade">
- <div
- v-if="advanceMode"
- key="advance"
- >
- <div v-if="parseErrorStatus">
- <AAlert
- banner
- :message="$gettext('Nginx Configuration Parse Error')"
- :description="parseErrorMessage"
- type="error"
- show-icon
- />
- </div>
- <div>
- <CodeEditor
- v-model:content="configText"
- no-border-radius
- />
- </div>
- </div>
- <div
- v-else
- key="basic"
- class="domain-edit-container"
- >
- <!-- Upstream Cards Display -->
- <UpstreamCards
- :targets="upstreamTargets"
- :namespace-id="data.namespace_id"
- />
- <NgxConfigEditor
- :enabled="status === ConfigStatus.Enabled"
- context="stream"
- />
- </div>
- </Transition>
- </div>
- <ConfigHistory
- v-model:visible="showHistory"
- v-model:current-content="configText"
- :filepath="filepath"
- />
- <FooterToolBar>
- <ASpace>
- <AButton @click="router.push('/streams')">
- {{ $gettext('Back') }}
- </AButton>
- <AButton
- type="primary"
- :loading="saving"
- @click="save"
- >
- {{ $gettext('Save') }}
- </AButton>
- </ASpace>
- </FooterToolBar>
- </ACard>
- </ASpin>
- </template>
- <style scoped lang="less">
- .mode-switch {
- display: flex;
- .switch {
- display: flex;
- align-items: center;
- margin-right: 5px;
- }
- }
- .domain-edit-container {
- max-width: 800px;
- margin: 0 auto;
- }
- :deep(.tab-content) {
- padding-bottom: 24px;
- }
- </style>
|