index.vue 3.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122
  1. <template>
  2. <div>
  3. <page-header :title="headerTitle" :tabs="cloudEnvOptions" :current-tab.sync="cloudEnv" />
  4. <page-body needMarginBottom>
  5. <component :is="component" :type="type" ref="formRef" />
  6. </page-body>
  7. <page-footer>
  8. <template v-slot:right>
  9. <a-button type="primary" class="mr-2" @click="submit" :loading="loading">{{ $t('common.create') }}</a-button>
  10. <a-button @click="cancel">{{$t('network.text_31')}}</a-button>
  11. </template>
  12. </page-footer>
  13. </div>
  14. </template>
  15. <script>
  16. import IDC from './form/IDC'
  17. import Public from './form/Public'
  18. import Private from './form/Private'
  19. import { getCloudEnvOptions } from '@/utils/common/hypervisor'
  20. export default {
  21. name: 'LbCreate',
  22. components: {
  23. IDC,
  24. Public,
  25. Private,
  26. },
  27. data () {
  28. const cloudEnvOptions = getCloudEnvOptions('compute_engine_brands', true)
  29. const queryType = this.$route.query.type
  30. let cloudEnv = queryType === 'idc' ? 'onpremise' : this.$route.query.type
  31. let routerQuery = this.$route.query.type
  32. if (!cloudEnvOptions.find(val => val.key === cloudEnv)) {
  33. cloudEnv = cloudEnvOptions[0].key
  34. routerQuery = cloudEnv === 'onpremise' ? 'idc' : cloudEnv
  35. }
  36. return {
  37. loading: false,
  38. cloudEnvOptions,
  39. cloudEnv,
  40. routerQuery,
  41. }
  42. },
  43. computed: {
  44. type () {
  45. const { type = 'idc' } = this.$route.query
  46. switch (type) {
  47. case 'private':
  48. return 'private'
  49. case 'public':
  50. return 'public'
  51. default:
  52. return 'idc'
  53. }
  54. },
  55. component () {
  56. const { type = 'idc' } = this.$route.query
  57. switch (type) {
  58. case 'private':
  59. return 'Private'
  60. case 'public':
  61. return 'Public'
  62. default:
  63. return 'IDC'
  64. }
  65. },
  66. headerTitle () {
  67. const res = this.$t('network.text_137')
  68. return this.$t('compute.text_1161', [res])
  69. },
  70. },
  71. watch: {
  72. cloudEnv (val) {
  73. this.$nextTick(() => {
  74. const query = this.getQuery(this.$router.history.current.query)
  75. const path = this.$router.history.current.path
  76. const newQuery = JSON.parse(JSON.stringify(query))
  77. newQuery.type = val === 'onpremise' ? 'idc' : val
  78. this.$router.push({ path, query: newQuery })
  79. })
  80. },
  81. },
  82. created () {
  83. if (this.routerQuery !== this.$route.query.type) {
  84. this.$router.push({
  85. path: this.$router.history.current.path,
  86. query: {
  87. type: this.routerQuery,
  88. },
  89. })
  90. }
  91. },
  92. beforeDestroy () {
  93. window.removeEventListener('popstate', this.popstate)
  94. },
  95. methods: {
  96. getQuery (query) {
  97. if (query.sence === 'image') {
  98. return { type: query.type }
  99. }
  100. return query
  101. },
  102. async submit () {
  103. this.loading = true
  104. try {
  105. const data = await this.$refs.formRef.submit()
  106. await new this.$Manager('loadbalancers').create({ data })
  107. this.loading = false
  108. this.$message.success(this.$t('network.text_290'))
  109. this.cancel()
  110. } catch (error) {
  111. this.loading = false
  112. throw error
  113. }
  114. },
  115. cancel () {
  116. this.$router.push('/lb')
  117. },
  118. },
  119. }
  120. </script>