index.vue 2.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697
  1. <template>
  2. <div class="server-create-index">
  3. <page-header :title="headerTitle" :tabs="cloudEnvOptions" :current-tab.sync="cloudEnv" />
  4. <component :is="component" :type="type" :cloudEnv="cloudEnv" />
  5. </div>
  6. </template>
  7. <script>
  8. import { getCloudEnvOptions } from '@/utils/common/hypervisor'
  9. import IDC from './form/IDC'
  10. import Public from './form/Public'
  11. export default {
  12. name: 'FileSystemCreateIndex',
  13. components: {
  14. IDC,
  15. Public,
  16. },
  17. data () {
  18. const cloudEnvOptions = getCloudEnvOptions('object_storage_brands', true)
  19. const queryType = this.$route.query.type
  20. let cloudEnv = queryType === 'idc' ? 'onpremise' : this.$route.query.type
  21. let routerQuery = this.$route.query.type
  22. if (!cloudEnvOptions.find(val => val.key === cloudEnv)) {
  23. cloudEnv = cloudEnvOptions[0].key
  24. routerQuery = cloudEnv === 'onpremise' ? 'idc' : cloudEnv
  25. }
  26. return {
  27. cloudEnvOptions,
  28. cloudEnv,
  29. routerQuery,
  30. }
  31. },
  32. computed: {
  33. type () {
  34. const { type = 'idc' } = this.$route.query
  35. switch (type) {
  36. case 'public':
  37. return 'public'
  38. default:
  39. return 'idc'
  40. }
  41. },
  42. component () {
  43. const { type = 'idc' } = this.$route.query
  44. switch (type) {
  45. case 'public':
  46. return 'Public'
  47. default:
  48. return 'IDC'
  49. }
  50. },
  51. headerTitle () {
  52. return this.$t('compute.text_1161', [this.$t('dictionary.filesystem')])
  53. },
  54. },
  55. watch: {
  56. cloudEnv (val) {
  57. this.$nextTick(() => {
  58. const query = this.$router.history.current.query
  59. const path = this.$router.history.current.path
  60. const newQuery = JSON.parse(JSON.stringify(query))
  61. newQuery.type = val === 'onpremise' ? 'idc' : val
  62. this.$router.push({ path, query: newQuery })
  63. })
  64. },
  65. },
  66. created () {
  67. if (this.routerQuery !== this.$route.query.type) {
  68. this.$router.push({
  69. path: this.$router.history.current.path,
  70. query: {
  71. type: this.routerQuery,
  72. },
  73. })
  74. }
  75. },
  76. mounted () {
  77. this.detectBack() // 在用户点击 back 的时候,表单的处理方案
  78. },
  79. beforeDestroy () {
  80. window.removeEventListener('popstate', this.popstate)
  81. },
  82. methods: {
  83. detectBack () {
  84. window.addEventListener('popstate', this.popstate, false)
  85. },
  86. popstate (e) {
  87. if (e.state) {
  88. // 侦测是用户触发的后退操作, dosomething
  89. // 这里刷新当前 url
  90. window.location.reload()
  91. }
  92. },
  93. },
  94. }
  95. </script>