| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122 |
- <template>
- <div>
- <page-header :title="headerTitle" :tabs="cloudEnvOptions" :current-tab.sync="cloudEnv" />
- <page-body needMarginBottom>
- <component :is="component" :type="type" ref="formRef" />
- </page-body>
- <page-footer>
- <template v-slot:right>
- <a-button type="primary" class="mr-2" @click="submit" :loading="loading">{{ $t('common.create') }}</a-button>
- <a-button @click="cancel">{{$t('network.text_31')}}</a-button>
- </template>
- </page-footer>
- </div>
- </template>
- <script>
- import IDC from './form/IDC'
- import Public from './form/Public'
- import Private from './form/Private'
- import { getCloudEnvOptions } from '@/utils/common/hypervisor'
- export default {
- name: 'LbCreate',
- components: {
- IDC,
- Public,
- Private,
- },
- data () {
- const cloudEnvOptions = getCloudEnvOptions('compute_engine_brands', true)
- const queryType = this.$route.query.type
- let cloudEnv = queryType === 'idc' ? 'onpremise' : this.$route.query.type
- let routerQuery = this.$route.query.type
- if (!cloudEnvOptions.find(val => val.key === cloudEnv)) {
- cloudEnv = cloudEnvOptions[0].key
- routerQuery = cloudEnv === 'onpremise' ? 'idc' : cloudEnv
- }
- return {
- loading: false,
- cloudEnvOptions,
- cloudEnv,
- routerQuery,
- }
- },
- computed: {
- type () {
- const { type = 'idc' } = this.$route.query
- switch (type) {
- case 'private':
- return 'private'
- case 'public':
- return 'public'
- default:
- return 'idc'
- }
- },
- component () {
- const { type = 'idc' } = this.$route.query
- switch (type) {
- case 'private':
- return 'Private'
- case 'public':
- return 'Public'
- default:
- return 'IDC'
- }
- },
- headerTitle () {
- const res = this.$t('network.text_137')
- return this.$t('compute.text_1161', [res])
- },
- },
- watch: {
- cloudEnv (val) {
- this.$nextTick(() => {
- const query = this.getQuery(this.$router.history.current.query)
- const path = this.$router.history.current.path
- const newQuery = JSON.parse(JSON.stringify(query))
- newQuery.type = val === 'onpremise' ? 'idc' : val
- this.$router.push({ path, query: newQuery })
- })
- },
- },
- created () {
- if (this.routerQuery !== this.$route.query.type) {
- this.$router.push({
- path: this.$router.history.current.path,
- query: {
- type: this.routerQuery,
- },
- })
- }
- },
- beforeDestroy () {
- window.removeEventListener('popstate', this.popstate)
- },
- methods: {
- getQuery (query) {
- if (query.sence === 'image') {
- return { type: query.type }
- }
- return query
- },
- async submit () {
- this.loading = true
- try {
- const data = await this.$refs.formRef.submit()
- await new this.$Manager('loadbalancers').create({ data })
- this.loading = false
- this.$message.success(this.$t('network.text_290'))
- this.cancel()
- } catch (error) {
- this.loading = false
- throw error
- }
- },
- cancel () {
- this.$router.push('/lb')
- },
- },
- }
- </script>
|