index.vue 18 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577
  1. <template>
  2. <div>
  3. <page-header :title="$t('network.text_724')" :tabs="cloudEnvOptions" :current-tab.sync="cloudEnv" />
  4. <page-body needMarginBottom>
  5. <a-form
  6. :form="form.fc"
  7. hideRequiredMark>
  8. <a-form-item :label="$t('network.text_205', [$t('dictionary.project')])" v-bind="formItemLayout">
  9. <domain-project :fc="form.fc" :form-layout="formItemLayout" :decorators="{ project: decorators.project, domain: decorators.domain }" @update:domain="domainChange" />
  10. </a-form-item>
  11. <area-selects
  12. class="mb-0"
  13. ref="areaSelects"
  14. :wrapperCol="formItemLayout.wrapperCol"
  15. :labelCol="formItemLayout.labelCol"
  16. :names="areaselectsName"
  17. :cloudregionParams="regionParams"
  18. :providerParams="cloudProviderParams"
  19. :isRequired="true"
  20. :region.sync="regionList"
  21. filterBrandResource="network_manage"
  22. @change="cloudregionChange" />
  23. <a-form-item :label="$t('network.text_21')" v-bind="formItemLayout">
  24. <a-input v-decorator="decorators.name" :placeholder="$t('network.text_44')" />
  25. </a-form-item>
  26. <a-form-item :label="$t('common.description')" v-bind="formItemLayout">
  27. <a-textarea :auto-size="{ minRows: 1, maxRows: 3 }" v-decorator="decorators.description" :placeholder="$t('common_367')" />
  28. </a-form-item>
  29. <a-form-item :label="$t('network.text_743')" v-bind="formItemLayout" v-if="showBgpTypes">
  30. <a-select v-decorator="decorators.bgp_type" @change="handleBgpTypeChange">
  31. <a-select-option v-for="item in bgpTypeOptions" :value="item" :key="item">{{ item === '' ? $t('network.text_749') : BGP_TYPES_MAP[item] ? BGP_TYPES_MAP[item].label : item }}</a-select-option>
  32. </a-select>
  33. </a-form-item>
  34. <template v-if="showIpSubnet">
  35. <ip-subnet
  36. :label="$t('network.text_211')"
  37. :isRequired="true"
  38. :labelCol="formItemLayout.labelCol"
  39. :wrapperCol="formItemLayout.wrapperCol"
  40. :decorator="decorators"
  41. :vpcParams="vpcParams"
  42. :networkParams="networkParams"
  43. :vpcResourceMapper="vpcResourceMapper"
  44. :showIpConfig="cloudEnv !== 'public'"
  45. :helplink="{ipSubnetHelp: $t('network.eip.tip'), ipSubnetHref: '/network/create'}" />
  46. </template>
  47. <template v-if="cloudEnv !== 'private' || isHCSO || isHCS">
  48. <a-form-item :label="$t('network.text_192')" v-bind="formItemLayout">
  49. <a-radio-group v-decorator="decorators.charge_type" @change="chargeTypeChange">
  50. <a-radio-button v-for="item in chargeTypeOptions" :value="item.value" :key="item.value">
  51. {{item.label}}
  52. </a-radio-button>
  53. </a-radio-group>
  54. </a-form-item>
  55. <a-form-item :label="$t('network.text_484')" v-bind="formItemLayout">
  56. <div class="d-flex align-items-center">
  57. <a-tooltip placement="top" :title="$t('network.eip.text_725', [maxBandwidth])">
  58. <a-input-number
  59. style="width: 120px"
  60. :min="1"
  61. :max="maxBandwidth"
  62. :step="cloudEnv === 'onpremise' ? 1 : 50"
  63. :formatter="format"
  64. :parse="format"
  65. v-decorator="decorators.bandwidth" />
  66. </a-tooltip>
  67. <span class="ml-2">Mbps</span>
  68. </div>
  69. </a-form-item>
  70. </template>
  71. <a-form-item :label="$t('compute.text_15')" v-bind="formItemLayout" v-if="cloudEnv === 'public' || isHCSO || isHCS" key="manager">
  72. <base-select
  73. :remote="true"
  74. v-decorator="decorators.manager"
  75. resource="cloudproviders"
  76. :params="providerParams"
  77. :mapper="providerMapper"
  78. :remote-fn="q => ({ filter: `name.contains(${q})` })"
  79. @update:item="providerChange"
  80. :isDefaultSelect="true"
  81. :select-props="{ placeholder: $t('compute.text_1387') }"
  82. style="width: 320px" />
  83. </a-form-item>
  84. <a-form-item :label="$t('common.text00012')" class="mb-0" v-bind="formItemLayout">
  85. <tag
  86. v-decorator="decorators.__meta__" :allowNoValue="false" />
  87. </a-form-item>
  88. </a-form>
  89. </page-body>
  90. <bottom-bar
  91. :isHCSO="isHCSO || isHCS"
  92. :current-cloudregion="selectedRegionItem"
  93. :size="bandwidth"
  94. :bgp-type="bgp_type"
  95. :cloudAccountId="cloudAccountId" />
  96. </div>
  97. </template>
  98. <script>
  99. import * as R from 'ramda'
  100. import { mapGetters } from 'vuex'
  101. import IpSubnet from '@Network/sections/IpSubnet'
  102. import AreaSelects from '@/sections/AreaSelects'
  103. import DomainProject from '@/sections/DomainProject'
  104. import validateForm, { isRequired } from '@/utils/validate'
  105. import { getCloudEnvOptions } from '@/utils/common/hypervisor'
  106. import Tag from '@/sections/Tag'
  107. import { BGP_TYPES, BGP_TYPES_MAP } from '@/constants/network'
  108. import { HYPERVISORS_MAP } from '../../../../../src/constants'
  109. import BottomBar from './components/BottomBar'
  110. export default {
  111. name: 'EipCreate',
  112. components: {
  113. AreaSelects,
  114. DomainProject,
  115. IpSubnet,
  116. BottomBar,
  117. Tag,
  118. },
  119. data () {
  120. const cloudEnvOptions = getCloudEnvOptions('network_manage_brands', true)
  121. const queryType = this.$route.query.type
  122. let cloudEnv = queryType === 'idc' ? 'onpremise' : this.$route.query.type
  123. let routerQuery = this.$route.query.type
  124. if (!cloudEnvOptions.find(val => val.key === cloudEnv)) {
  125. cloudEnv = cloudEnvOptions[0].key
  126. routerQuery = cloudEnv === 'onpremise' ? 'idc' : cloudEnv
  127. }
  128. return {
  129. BGP_TYPES_MAP,
  130. loading: false,
  131. inputIpType: 'random',
  132. cloudEnvOptions,
  133. cloudEnv,
  134. routerQuery,
  135. form: {
  136. fc: this.$form.createForm(this, {
  137. onValuesChange: (props, values) => {
  138. if (values.cloudregion) {
  139. this.selectedRegionItem = this.regionList[values.cloudregion]
  140. }
  141. if (values.bandwidth) {
  142. this.bandwidth = values.bandwidth
  143. }
  144. },
  145. }),
  146. },
  147. decorators: {
  148. domain: [
  149. 'domain',
  150. {
  151. rules: [
  152. { validator: isRequired(), message: this.$t('rules.domain'), trigger: 'change' },
  153. ],
  154. },
  155. ],
  156. project: [
  157. 'project',
  158. {
  159. rules: [
  160. { validator: isRequired(), message: this.$t('dictionary.project'), trigger: 'change' },
  161. ],
  162. },
  163. ],
  164. manager: [
  165. 'manager',
  166. {
  167. rules: [
  168. { required: true, message: this.$t('network.text_215') },
  169. ],
  170. },
  171. ],
  172. vpc: [
  173. 'vpc',
  174. {
  175. rules: [
  176. { required: true, message: this.$t('network.text_212') },
  177. ],
  178. },
  179. ],
  180. network: [
  181. 'network',
  182. {
  183. rules: [
  184. { required: true, message: this.$t('network.text_212') },
  185. ],
  186. },
  187. ],
  188. ip_addr: [
  189. 'ip_addr',
  190. {
  191. validateFirst: true,
  192. rules: [
  193. { required: true, message: this.$t('network.text_217') },
  194. { validator: this.$validate('IPv4') },
  195. ],
  196. },
  197. ],
  198. bandwidth: [
  199. 'bandwidth',
  200. {
  201. initialValue: 30,
  202. },
  203. ],
  204. name: [
  205. 'name',
  206. {
  207. validateFirst: true,
  208. rules: [
  209. { required: true, message: this.$t('network.text_218') },
  210. { validator: this.$validate('serverName') },
  211. ],
  212. },
  213. ],
  214. description: ['description'],
  215. charge_type: [
  216. 'charge_type',
  217. ],
  218. bgp_type: [
  219. 'bgp_type',
  220. ],
  221. __meta__: [
  222. '__meta__',
  223. {
  224. rules: [
  225. { validator: validateForm('tagName') },
  226. ],
  227. },
  228. ],
  229. },
  230. formItemLayout: {
  231. wrapperCol: {
  232. md: { span: 17 },
  233. xl: { span: 19 },
  234. xxl: { span: 21 },
  235. },
  236. labelCol: {
  237. md: { span: 7 },
  238. xl: { span: 5 },
  239. xxl: { span: 3 },
  240. },
  241. },
  242. manager: '',
  243. cloudAccountId: '',
  244. selectedRegionItem: {},
  245. showBandwidth: true,
  246. charge_type: cloudEnv === 'onpremise' ? 'bandwidth' : 'traffic',
  247. providerC: '',
  248. domain_id: 'default',
  249. regionList: {},
  250. bandwidth: cloudEnv !== 'private' ? 30 : 0,
  251. bgpTypeOptions: [],
  252. bgp_type: undefined,
  253. }
  254. },
  255. computed: {
  256. ...mapGetters(['isAdminMode', 'scope', 'userInfo']),
  257. sliderMarks () {
  258. let ret = { [this.maxBandwidth / 2]: `${this.maxBandwidth / 2}Mbps` }
  259. ret = { ...ret, ...{ 1: '1Mbps', [this.maxBandwidth]: `${this.maxBandwidth}Mbps` } }
  260. return ret
  261. },
  262. isOnpremise () {
  263. return this.cloudEnv === 'onpremise'
  264. },
  265. isHCSO () {
  266. if (this.selectedRegionItem) {
  267. return this.selectedRegionItem.provider === HYPERVISORS_MAP.hcso.provider
  268. }
  269. return false
  270. },
  271. isHCS () {
  272. if (this.selectedRegionItem) {
  273. return this.selectedRegionItem.provider === HYPERVISORS_MAP.hcs.provider
  274. }
  275. return false
  276. },
  277. isAliyun () {
  278. if (this.selectedRegionItem) {
  279. return this.selectedRegionItem.provider === HYPERVISORS_MAP.aliyun.provider
  280. }
  281. return false
  282. },
  283. providerParams () {
  284. const params = {
  285. enabled: 1,
  286. details: true,
  287. read_only: false,
  288. public_cloud: !this.isHCSO && !this.isHCS,
  289. scope: this.$store.getters.scope,
  290. usable: true,
  291. }
  292. if (this.isAdminMode) {
  293. params.project_domain_id = this.domain_id
  294. }
  295. if (!R.isEmpty(this.selectedRegionItem)) {
  296. params.cloudregion_id = this.selectedRegionItem.id
  297. }
  298. return params
  299. },
  300. showBgpTypes () {
  301. if (!this.bgpTypeOptions || this.bgpTypeOptions.length === 0) {
  302. return false
  303. }
  304. if (this.bgpTypeOptions.length === 1 && this.bgpTypeOptions[0] === '') {
  305. return false
  306. }
  307. return this.isOnpremise || this.isAliyun
  308. },
  309. regionParams () {
  310. let params = {
  311. cloud_env: this.cloudEnv,
  312. }
  313. if (this.cloudEnv === 'onpremise') {
  314. params = {
  315. ...params,
  316. usable: true,
  317. show_emulated: true,
  318. scope: this.$store.getters.scope,
  319. }
  320. }
  321. if (this.isAdminMode) {
  322. params.project_domain = this.domain_id
  323. delete params.scope
  324. }
  325. return params
  326. },
  327. networkParams () {
  328. const ret = {
  329. limit: 0,
  330. scope: this.scope,
  331. bgp_type: this.bgp_type,
  332. }
  333. if (this.manager) {
  334. ret.manager = this.manager
  335. return ret
  336. }
  337. if (this.cloudEnv === 'onpremise' && !R.isEmpty(this.selectedRegionItem)) {
  338. ret.server_type = 'eip'
  339. ret.cloudregion_id = this.selectedRegionItem.id
  340. return ret
  341. }
  342. return ret
  343. },
  344. vpcParams () {
  345. const params = {
  346. scope: this.scope,
  347. cloudregion_id: this.selectedRegionItem.id,
  348. }
  349. if (this.selectedRegionItem.provider === 'HCS') {
  350. params['@external_access_mode'] = 'eip'
  351. params.show_emulated = true
  352. }
  353. if (this.isAdminMode) {
  354. params.project_domain = this.domain_id
  355. delete params.scope
  356. }
  357. return params
  358. },
  359. chargeTypeOptions () {
  360. const arr = [
  361. { label: this.$t('network.text_194'), value: 'bandwidth' },
  362. { label: this.$t('network.text_193'), value: 'traffic' },
  363. ]
  364. if (this.cloudEnv === 'onpremise') {
  365. return [arr[0]]
  366. }
  367. if (!this.showBandwidth) {
  368. arr.shift()
  369. }
  370. return arr
  371. },
  372. maxBandwidth () {
  373. if (this.cloudEnv === 'onpremise') {
  374. return 10000
  375. }
  376. let maxBandwidth = 200
  377. if (!R.isEmpty(this.selectedRegionItem)) {
  378. if (this.charge_type === 'bandwidth') {
  379. if (this.selectedRegionItem.provider === 'Huawei') {
  380. maxBandwidth = 2000
  381. } else if (this.selectedRegionItem.provider === 'Aliyun') {
  382. maxBandwidth = 500
  383. }
  384. } else {
  385. if (this.selectedRegionItem.provider === 'Huawei') {
  386. maxBandwidth = 300
  387. } else {
  388. maxBandwidth = 200
  389. }
  390. }
  391. }
  392. return maxBandwidth
  393. },
  394. updateProviderParams: {
  395. get () {
  396. return this.providerParams
  397. },
  398. set (newValue) {
  399. this.providerParams = newValue
  400. },
  401. },
  402. areaselectsName () {
  403. if (this.cloudEnv === 'private' || this.cloudEnv === 'onpremise') {
  404. return ['cloudregion']
  405. }
  406. return ['provider', 'cloudregion']
  407. },
  408. showIpSubnet () {
  409. if (this.selectedRegionItem.provider === HYPERVISORS_MAP.hcso.provider) return false
  410. if (this.selectedRegionItem.provider === HYPERVISORS_MAP.hcs.provider) return true
  411. if (this.providerC === 'zstack' || this.providerC === 'openstack') return true
  412. if (this.cloudEnv === 'onpremise' && this.selectedRegionItem && this.selectedRegionItem.id) return true
  413. if (this.cloudEnv === 'private' && this.selectedRegionItem && this.selectedRegionItem.id) return true
  414. return false
  415. },
  416. cloudProviderParams () {
  417. const param = {
  418. scope: this.scope,
  419. cloudEnv: this.cloudEnv,
  420. }
  421. if (this.isAdminMode) {
  422. param.project_domain_id = this.domain_id
  423. delete param.scope
  424. }
  425. return param
  426. },
  427. bgpTypeParams () {
  428. return {
  429. usable: true,
  430. limit: 0,
  431. scope: this.scope,
  432. server_type: 'eip',
  433. field: 'bgp_type',
  434. }
  435. },
  436. },
  437. watch: {
  438. cloudEnv (newValue) {
  439. if (R.has('public_cloud', this.updateProviderParams)) {
  440. Reflect.deleteProperty(this.updateProviderParams, 'public_cloud')
  441. } else {
  442. Reflect.deleteProperty(this.updateProviderParams, 'private_cloud')
  443. }
  444. const platform = newValue + '_cloud'
  445. this.updateProviderParams = {
  446. ...this.updateProviderParams,
  447. [platform]: true,
  448. }
  449. this.$refs.areaSelects.fetchs(this.areaselectsName)
  450. this.form.fc.resetFields(['manager'])
  451. this.manager = ''
  452. this.providerC = ''
  453. this.charge_type = newValue === 'onpremise' ? 'bandwidth' : 'traffic'
  454. this.$nextTick(() => {
  455. this.form.fc.getFieldDecorator('charge_type', { initialValue: newValue === 'onpremise' ? 'bandwidth' : 'traffic' })
  456. })
  457. this.bandwidth = newValue === 'private' && !this.isHCSO && !this.isHCS ? 0 : 30
  458. },
  459. isAliyun (newValue) {
  460. if (newValue) {
  461. this.bgpTypeOptions = BGP_TYPES.map(item => item.value)
  462. this.$nextTick(() => {
  463. this.form.fc.setFieldsValue({ bgp_type: 'BGP' })
  464. })
  465. } else {
  466. this.fetchBgpType()
  467. }
  468. },
  469. },
  470. provide () {
  471. return {
  472. form: this.form,
  473. cloudEnv: this.cloudEnv,
  474. }
  475. },
  476. created () {
  477. this.fetchBgpType()
  478. this.$nextTick(() => {
  479. this.form.fc.getFieldDecorator('charge_type', { initialValue: this.cloudEnv === 'onpremise' ? 'bandwidth' : 'traffic' })
  480. })
  481. },
  482. methods: {
  483. fetchBgpType () {
  484. if (this.isAliyun) {
  485. return
  486. }
  487. new this.$Manager('networks/distinct-field').list({
  488. params: {
  489. usable: true,
  490. limit: 0,
  491. field: 'bgp_type',
  492. scope: this.$store.getters.scope,
  493. server_type: 'eip',
  494. },
  495. }).then(({ data }) => {
  496. this.bgpTypeOptions = data.bgp_type
  497. })
  498. },
  499. handleBgpTypeChange (value) {
  500. this.bgp_type = value
  501. },
  502. format (val) {
  503. if (this.cloudEnv === 'onpremise') return val
  504. return +val || 1
  505. },
  506. vpcResourceMapper (data) {
  507. if (this.cloudEnv === 'onpremise') {
  508. data = data.filter(item => item.id === 'default')
  509. return data
  510. }
  511. return data
  512. },
  513. domainChange (item) {
  514. if (R.type(item) === 'Object') {
  515. this.domain_id = item.key
  516. } else {
  517. this.domain_id = item
  518. }
  519. if (this.isAdminMode) {
  520. this.updateProviderParams = {
  521. ...this.updateProviderParams,
  522. project_domain: this.domain_id,
  523. }
  524. delete this.updateProviderParams.scope
  525. } else {
  526. this.updateProviderParams = {
  527. ...this.updateProviderParams,
  528. scope: this.$store.getters.scope,
  529. }
  530. }
  531. },
  532. cloudregionChange (data) {
  533. if (!R.isNil(data.cloudregion) && !R.isEmpty(data.cloudregion)) {
  534. this.updateProviderParams = {
  535. ...this.updateProviderParams,
  536. cloudregion_id: data.cloudregion.id,
  537. }
  538. }
  539. },
  540. providerMapper (data) {
  541. data = data.filter(item => item.status === 'connected' && item.enabled)
  542. return data
  543. },
  544. providerChange (e) {
  545. if (e) {
  546. this.manager = e.id
  547. if (e.provider.toLowerCase() === 'azure') {
  548. this.form.fc.setFieldsValue({ bandwidth: 0 })
  549. } else {
  550. this.form.fc.setFieldsValue({ bandwidth: 30 })
  551. }
  552. this.hiddenBrandwidthHandle(e.provider)
  553. this.providerC = e.provider.toLowerCase()
  554. this.cloudAccountId = e.cloudaccount_id || ''
  555. } else {
  556. this.cloudAccountId = ''
  557. }
  558. },
  559. chargeTypeChange (e) {
  560. this.charge_type = e.target.value
  561. },
  562. hiddenBrandwidthHandle (selectedProvider) {
  563. const providers = ['Azure', 'Aws', 'Google']
  564. if (providers.some(v => v === selectedProvider)) {
  565. this.form.fc.setFieldsValue({ bandwidth: 1 })
  566. this.showBandwidth = false
  567. } else {
  568. this.form.fc.setFieldsValue({ bandwidth: 30 })
  569. this.showBandwidth = true
  570. }
  571. },
  572. },
  573. }
  574. </script>