BindServer.vue 3.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108
  1. <template>
  2. <base-dialog @cancel="cancelDialog">
  3. <div slot="header">{{params.title}}</div>
  4. <div slot="body">
  5. <dialog-selected-tips :name="$t('dictionary.ansibletemplate')" :count="params.data.length" :action="params.title" />
  6. <dialog-table :data="params.data" :columns="params.columns.slice(0, 3)" />
  7. <a-form class="mt-3" :form="form" v-bind="formItemLayout">
  8. <a-form-item :label="$t('compute.text_90')">
  9. <a-select v-decorator="decorators.server_id" mode="multiple" :loading="queryServerLoading" style="width: 100%" :placeholder="$t('compute.text_256')">
  10. <a-select-option :key="item.id" v-for="item in serverList" :value="item.id">{{item.name}}</a-select-option>
  11. </a-select>
  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 { CreateServerForm } from '@Compute/constants'
  23. import DialogMixin from '@/mixins/dialog'
  24. import WindowsMixin from '@/mixins/windows'
  25. export default {
  26. name: 'AnsibleTemplateBindServerDialog',
  27. mixins: [DialogMixin, WindowsMixin],
  28. data () {
  29. return {
  30. loading: false,
  31. form: this.$form.createForm(this),
  32. formItemLayout: {
  33. wrapperCol: { span: CreateServerForm.wrapperCol },
  34. labelCol: { span: CreateServerForm.labelCol },
  35. },
  36. serverList: [],
  37. queryServerLoading: false,
  38. }
  39. },
  40. computed: {
  41. decorators () {
  42. return {
  43. server_id: [
  44. 'server_id',
  45. {
  46. rules: [
  47. { required: true, message: this.$t('compute.text_256') },
  48. ],
  49. },
  50. ],
  51. }
  52. },
  53. },
  54. created () {
  55. this.fetchQueryServers()
  56. },
  57. methods: {
  58. async fetchQueryServers () {
  59. const manager = new this.$Manager('servers')
  60. const params = {
  61. limit: 0,
  62. usable: true,
  63. details: true,
  64. scope: this.$store.getters.scope,
  65. }
  66. this.queryServerLoading = true
  67. try {
  68. const { data } = await manager.list({ params })
  69. this.serverList = data.data
  70. } catch (err) {
  71. throw err
  72. } finally {
  73. this.queryServerLoading = false
  74. }
  75. },
  76. validateForm () {
  77. return new Promise((resolve, reject) => {
  78. this.form.validateFields((err, values) => {
  79. if (!err) {
  80. resolve(values)
  81. } else {
  82. reject(err)
  83. }
  84. })
  85. })
  86. },
  87. async handleConfirm () {
  88. const manager = new this.$Manager('devtool_templates')
  89. this.loading = true
  90. try {
  91. const values = await this.validateForm()
  92. await manager.performAction({
  93. id: this.params.data[0].id,
  94. action: 'bind',
  95. data: values,
  96. })
  97. this.cancelDialog()
  98. } catch (error) {
  99. throw error
  100. } finally {
  101. this.loading = false
  102. }
  103. },
  104. },
  105. }
  106. </script>