Setwire.vue 3.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116
  1. <template>
  2. <base-dialog @cancel="cancelDialog">
  3. <div slot="header">{{$t('compute.text_843')}}</div>
  4. <div slot="body">
  5. <dialog-selected-tips :name="$t('dictionary.physicalmachine')" :count="params.data.length" :action="$t('compute.text_843')" />
  6. <dialog-table :data="params.data" :columns="params.columns.slice(0, 5)" />
  7. <a-form
  8. :form="form.fc">
  9. <a-form-item :label="$t('compute.text_844')" v-bind="formItemLayout" v-if="!selectWire">
  10. <base-select
  11. :filterable="true"
  12. v-decorator="decorators.wire"
  13. resource="wires"
  14. version="v1"
  15. :params="wireParams"
  16. :value="selectWire"
  17. :select-props="{ placeholder: $t('compute.text_845') }" />
  18. </a-form-item>
  19. <a-form-item :label="$t('compute.text_844')" v-if="!!selectWire">
  20. {{ params.data[0].wire }}
  21. </a-form-item>
  22. </a-form>
  23. </div>
  24. <div slot="footer">
  25. <a-button v-if="!selectWire" type="primary" @click="handleConfirm(true)" :loading="loading">{{ $t('dialog.ok') }}</a-button>
  26. <a-button v-if="!!selectWire" type="primary" @click="handleConfirm(false)">{{ $t('compute.text_354') }}</a-button>
  27. <a-button @click="cancelDialog">{{ $t('dialog.cancel') }}</a-button>
  28. </div>
  29. </base-dialog>
  30. </template>
  31. <script>
  32. import DialogMixin from '@/mixins/dialog'
  33. import WindowsMixin from '@/mixins/windows'
  34. export default {
  35. name: 'HostSetWireDialog',
  36. mixins: [DialogMixin, WindowsMixin],
  37. data () {
  38. return {
  39. loading: false,
  40. form: {
  41. fc: this.$form.createForm(this),
  42. },
  43. decorators: {
  44. wire: [
  45. 'wire',
  46. {
  47. rules: [
  48. { required: true },
  49. ],
  50. },
  51. ],
  52. },
  53. formItemLayout: {
  54. wrapperCol: {
  55. span: 20,
  56. },
  57. labelCol: {
  58. span: 4,
  59. },
  60. },
  61. wireParams: {
  62. host_id: this.params.data[0].hostId,
  63. },
  64. selectWire: this.params.data[0].wire_id,
  65. }
  66. },
  67. methods: {
  68. fetchHost () {
  69. return new this.$Manager('hosts').get({
  70. id: this.params.data[0].hostId,
  71. })
  72. },
  73. doUpdate (data) {
  74. return new this.$Manager('hosts').performAction({
  75. action: 'add-netif',
  76. id: this.params.data[0].hostId,
  77. data: {
  78. ...data,
  79. mac: this.params.data[0].mac,
  80. index: this.params.data[0].index,
  81. },
  82. })
  83. },
  84. async handleConfirm (add) {
  85. try {
  86. this.loading = true
  87. if (add) {
  88. const values = await this.form.fc.validateFields()
  89. await this.doUpdate(values)
  90. } else {
  91. await this.unsetWire()
  92. }
  93. this.params.callback && this.params.callback()
  94. this.cancelDialog()
  95. } catch (error) {
  96. throw error
  97. } finally {
  98. this.loading = false
  99. }
  100. },
  101. unsetWire () {
  102. console.log(this.params)
  103. new this.$Manager('wires').delete({
  104. id: this.selectWire,
  105. ctx: [['hosts', this.params.data[0].hostId]],
  106. params: {
  107. mac: this.params.data[0].mac,
  108. mac_addr: this.params.data[0].mac,
  109. },
  110. })
  111. },
  112. },
  113. }
  114. </script>