SourceTargetCheck.vue 2.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889
  1. <template>
  2. <base-dialog @cancel="cancelDialog">
  3. <div slot="header">{{action}}</div>
  4. <div slot="body">
  5. <dialog-selected-tips :name="$t('dictionary.server')" :count="params.data.length" :action="action" />
  6. <dialog-table :data="params.data" :columns="columns" />
  7. <a-form
  8. :form="form.fc"
  9. v-bind="formItemLayout">
  10. <a-form-item :label="$t('compute.text_1257')" :help="$t('compute.text_1258')">
  11. <a-switch :checkedChildren="$t('compute.text_115')" :unCheckedChildren="$t('compute.text_116')" v-decorator="decorators.open" />
  12. </a-form-item>
  13. </a-form>
  14. </div>
  15. <div slot="footer">
  16. <a-button type="primary" @click="handleConfirm" :loading="loading">{{ $t('dialog.ok') }}</a-button>
  17. <a-button @click="cancelDialog">{{ $t('dialog.cancel') }}</a-button>
  18. </div>
  19. </base-dialog>
  20. </template>
  21. <script>
  22. import DialogMixin from '@/mixins/dialog'
  23. import WindowsMixin from '@/mixins/windows'
  24. export default {
  25. name: 'VmSourceTargetCheckDialog',
  26. mixins: [DialogMixin, WindowsMixin],
  27. data () {
  28. const isAllClose = this.params.data.every((item) => { return !(item.src_ip_check && item.src_mac_check) })
  29. return {
  30. loading: false,
  31. action: this.$t('compute.text_1124'),
  32. form: {
  33. fc: this.$form.createForm(this),
  34. },
  35. decorators: {
  36. open: [
  37. 'open',
  38. {
  39. initialValue: !isAllClose,
  40. valuePropName: 'checked',
  41. },
  42. ],
  43. },
  44. formItemLayout: {
  45. wrapperCol: {
  46. span: 19,
  47. },
  48. labelCol: {
  49. span: 5,
  50. },
  51. },
  52. }
  53. },
  54. computed: {
  55. columns () {
  56. const showFields = ['name', 'ip', 'brand']
  57. return this.params.columns.filter((item) => { return showFields.includes(item.field) })
  58. },
  59. },
  60. methods: {
  61. async doSubmit () {
  62. const ids = this.params.data.map(item => item.id)
  63. const values = await this.form.fc.validateFields()
  64. const open = values.open ? 'on' : 'off'
  65. const params = { src_ip_check: open, src_mac_check: open }
  66. return this.params.onManager('batchPerformAction', {
  67. id: ids,
  68. steadyStatus: 'running',
  69. managerArgs: {
  70. action: 'modify-src-check',
  71. data: params,
  72. },
  73. })
  74. },
  75. async handleConfirm () {
  76. this.loading = true
  77. try {
  78. await this.doSubmit()
  79. this.loading = false
  80. this.cancelDialog()
  81. } catch (error) {
  82. this.loading = false
  83. }
  84. },
  85. },
  86. }
  87. </script>