|
@@ -1,3 +1,86 @@
|
|
|
|
+<script setup lang="ts">
|
|
|
|
+import DirectiveEditor from '@/views/domain/ngx_conf/directive/DirectiveEditor.vue'
|
|
|
|
+import LocationEditor from '@/views/domain/ngx_conf/LocationEditor.vue'
|
|
|
|
+import NgxConfigEditor from '@/views/domain/ngx_conf/NgxConfigEditor.vue'
|
|
|
|
+import {useGettext} from 'vue3-gettext'
|
|
|
|
+import domain from '@/api/domain'
|
|
|
|
+import ngx from '@/api/ngx'
|
|
|
|
+import {computed, reactive, ref} from 'vue'
|
|
|
|
+import {message} from 'ant-design-vue'
|
|
|
|
+import {useRouter} from 'vue-router'
|
|
|
|
+
|
|
|
|
+const {$gettext, interpolate} = useGettext()
|
|
|
|
+
|
|
|
|
+const config = reactive({name: ''})
|
|
|
|
+let ngx_config = reactive({
|
|
|
|
+ servers: [{
|
|
|
|
+ directives: [],
|
|
|
|
+ locations: []
|
|
|
|
+ }]
|
|
|
|
+})
|
|
|
|
+
|
|
|
|
+const error = reactive({})
|
|
|
|
+
|
|
|
|
+const current_step = ref(0)
|
|
|
|
+
|
|
|
|
+const enabled = ref(true)
|
|
|
|
+
|
|
|
|
+const auto_cert = ref(false)
|
|
|
|
+
|
|
|
|
+const update = ref(0)
|
|
|
|
+
|
|
|
|
+init()
|
|
|
|
+
|
|
|
|
+function init() {
|
|
|
|
+ domain.get_template().then(r => {
|
|
|
|
+ Object.assign(ngx_config, r.tokenized)
|
|
|
|
+ })
|
|
|
|
+}
|
|
|
|
+
|
|
|
|
+function save() {
|
|
|
|
+ ngx.build_config(ngx_config).then(r => {
|
|
|
|
+ domain.save(config.name, {content: r.content, enabled: true}).then(() => {
|
|
|
|
+ message.success($gettext('Saved successfully'))
|
|
|
|
+
|
|
|
|
+ domain.enable(config.name).then(() => {
|
|
|
|
+ message.success($gettext('Enabled successfully'))
|
|
|
|
+ current_step.value++
|
|
|
|
+ window.scroll({top: 0, left: 0, behavior: 'smooth'})
|
|
|
|
+ }).catch(r => {
|
|
|
|
+ message.error(r.message ?? $gettext('Enable failed'), 10)
|
|
|
|
+ })
|
|
|
|
+
|
|
|
|
+ }).catch(r => {
|
|
|
|
+ message.error(interpolate($gettext('Save error %{msg}'), {msg: r.message ?? ''}), 10)
|
|
|
|
+ })
|
|
|
|
+ })
|
|
|
|
+}
|
|
|
|
+
|
|
|
|
+const router = useRouter()
|
|
|
|
+
|
|
|
|
+function goto_modify() {
|
|
|
|
+ router.push('/domain/' + config.name)
|
|
|
|
+}
|
|
|
|
+
|
|
|
|
+function create_another() {
|
|
|
|
+ router.go(0)
|
|
|
|
+}
|
|
|
|
+
|
|
|
|
+const has_server_name = computed(() => {
|
|
|
|
+ const servers = ngx_config.servers
|
|
|
|
+ for (const server_key in servers) {
|
|
|
|
+ for (const k in servers[server_key].directives) {
|
|
|
|
+ const v = servers[server_key].directives[k]
|
|
|
|
+ if (v.directive === 'server_name' && v.params.trim() !== '') {
|
|
|
|
+ return true
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ return false
|
|
|
|
+})
|
|
|
|
+</script>
|
|
|
|
+
|
|
<template>
|
|
<template>
|
|
<a-card :title="$gettext('Add Site')">
|
|
<a-card :title="$gettext('Add Site')">
|
|
<div class="domain-add-container">
|
|
<div class="domain-add-container">
|
|
@@ -8,24 +91,25 @@
|
|
</a-steps>
|
|
</a-steps>
|
|
|
|
|
|
<template v-if="current_step===0">
|
|
<template v-if="current_step===0">
|
|
- <a-form-item :label="$gettext('Configuration Name')">
|
|
|
|
- <a-input v-model="config.name"/>
|
|
|
|
- </a-form-item>
|
|
|
|
|
|
+ <a-form layout="vertical">
|
|
|
|
+ <a-form-item :label="$gettext('Configuration Name')">
|
|
|
|
+ <a-input v-model:value="config.name"/>
|
|
|
|
+ </a-form-item>
|
|
|
|
+ </a-form>
|
|
|
|
|
|
- <directive-editor :ngx_directives="ngx_config.servers[0].directives"/>
|
|
|
|
|
|
|
|
|
|
+ <directive-editor :ngx_directives="ngx_config.servers[0].directives"/>
|
|
|
|
+ <br/>
|
|
<location-editor :locations="ngx_config.servers[0].locations"/>
|
|
<location-editor :locations="ngx_config.servers[0].locations"/>
|
|
-
|
|
|
|
|
|
+ <br/>
|
|
<a-alert
|
|
<a-alert
|
|
v-if="!has_server_name"
|
|
v-if="!has_server_name"
|
|
:message="$gettext('Warning')"
|
|
:message="$gettext('Warning')"
|
|
type="warning"
|
|
type="warning"
|
|
show-icon
|
|
show-icon
|
|
>
|
|
>
|
|
- <template slot="description">
|
|
|
|
- <span v-translate>
|
|
|
|
- server_name parameter is required
|
|
|
|
- </span>
|
|
|
|
|
|
+ <template #description>
|
|
|
|
+ <span v-translate>server_name parameter is required</span>
|
|
</template>
|
|
</template>
|
|
</a-alert>
|
|
</a-alert>
|
|
<br/>
|
|
<br/>
|
|
@@ -34,12 +118,14 @@
|
|
<template v-else-if="current_step===1">
|
|
<template v-else-if="current_step===1">
|
|
|
|
|
|
<ngx-config-editor
|
|
<ngx-config-editor
|
|
- ref="ngx_config"
|
|
|
|
|
|
+ ref="ngx-config-editor"
|
|
:ngx_config="ngx_config"
|
|
:ngx_config="ngx_config"
|
|
- v-model="auto_cert"
|
|
|
|
|
|
+ v-model:auto_cert="auto_cert"
|
|
:enabled="enabled"
|
|
:enabled="enabled"
|
|
/>
|
|
/>
|
|
|
|
|
|
|
|
+ <br/>
|
|
|
|
+
|
|
</template>
|
|
</template>
|
|
|
|
|
|
<a-space v-if="current_step<2">
|
|
<a-space v-if="current_step<2">
|
|
@@ -51,7 +137,6 @@
|
|
<translate>Next</translate>
|
|
<translate>Next</translate>
|
|
</a-button>
|
|
</a-button>
|
|
</a-space>
|
|
</a-space>
|
|
-
|
|
|
|
<a-result
|
|
<a-result
|
|
v-else-if="current_step===2"
|
|
v-else-if="current_step===2"
|
|
status="success"
|
|
status="success"
|
|
@@ -71,82 +156,6 @@
|
|
</a-card>
|
|
</a-card>
|
|
</template>
|
|
</template>
|
|
|
|
|
|
-<script>
|
|
|
|
-import DirectiveEditor from '@/views/domain/ngx_conf/directive/DirectiveEditor'
|
|
|
|
-import LocationEditor from '@/views/domain/ngx_conf/LocationEditor'
|
|
|
|
-import $gettext, {$interpolate} from '@/lib/translate/gettext'
|
|
|
|
-import NgxConfigEditor from '@/views/domain/ngx_conf/NgxConfigEditor'
|
|
|
|
-
|
|
|
|
-export default {
|
|
|
|
- name: 'DomainAdd',
|
|
|
|
- components: {NgxConfigEditor, LocationEditor, DirectiveEditor},
|
|
|
|
- data() {
|
|
|
|
- return {
|
|
|
|
- config: {},
|
|
|
|
- ngx_config: {
|
|
|
|
- servers: [{}]
|
|
|
|
- },
|
|
|
|
- error: {},
|
|
|
|
- current_step: 0,
|
|
|
|
- enabled: true,
|
|
|
|
- auto_cert: false
|
|
|
|
- }
|
|
|
|
- },
|
|
|
|
- created() {
|
|
|
|
- this.init()
|
|
|
|
- },
|
|
|
|
- methods: {
|
|
|
|
- init() {
|
|
|
|
- this.$api.domain.get_template().then(r => {
|
|
|
|
- this.ngx_config = r.tokenized
|
|
|
|
- })
|
|
|
|
- },
|
|
|
|
- save() {
|
|
|
|
- this.$api.ngx.build_config(this.ngx_config).then(r => {
|
|
|
|
- this.$api.domain.save(this.config.name, {content: r.content, enabled: true}).then(() => {
|
|
|
|
- this.$message.success($gettext('Saved successfully'))
|
|
|
|
-
|
|
|
|
- this.$api.domain.enable(this.config.name).then(() => {
|
|
|
|
- this.$message.success($gettext('Enabled successfully'))
|
|
|
|
- this.current_step++
|
|
|
|
- }).catch(r => {
|
|
|
|
- this.$message.error(r.message ?? $gettext('Enable failed'), 10)
|
|
|
|
- })
|
|
|
|
-
|
|
|
|
- }).catch(r => {
|
|
|
|
- this.$message.error($interpolate($gettext('Save error %{msg}'), {msg: r.message ?? ''}), 10)
|
|
|
|
- })
|
|
|
|
- })
|
|
|
|
- },
|
|
|
|
- goto_modify() {
|
|
|
|
- this.$router.push('/domain/' + this.config.name)
|
|
|
|
- },
|
|
|
|
- create_another() {
|
|
|
|
- this.current_step = 0
|
|
|
|
- this.config = {}
|
|
|
|
- this.ngx_config = {
|
|
|
|
- servers: [{}]
|
|
|
|
- }
|
|
|
|
- },
|
|
|
|
- },
|
|
|
|
- computed: {
|
|
|
|
- has_server_name() {
|
|
|
|
- const servers = this.ngx_config.servers
|
|
|
|
- for (const server_key in servers) {
|
|
|
|
- for (const k in servers[server_key].directives) {
|
|
|
|
- const v = servers[server_key].directives[k]
|
|
|
|
- if (v.directive === 'server_name' && v.params.trim() !== '') {
|
|
|
|
- return true
|
|
|
|
- }
|
|
|
|
- }
|
|
|
|
- }
|
|
|
|
-
|
|
|
|
- return false
|
|
|
|
- }
|
|
|
|
- }
|
|
|
|
-}
|
|
|
|
-</script>
|
|
|
|
-
|
|
|
|
<style lang="less" scoped>
|
|
<style lang="less" scoped>
|
|
.ant-steps {
|
|
.ant-steps {
|
|
padding: 10px 0 20px 0;
|
|
padding: 10px 0 20px 0;
|