create.vue 6.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206
  1. <template>
  2. <base-dialog @cancel="cancelDialog">
  3. <div slot="header">{{ $t('common.create') }}</div>
  4. <div slot="body">
  5. <a-form
  6. :form="form.fc"
  7. v-bind="formItemLayout">
  8. <a-form-item :label="$t('compute.pci.dev_type')">
  9. <a-input v-decorator="decorators.dev_type" :placeholder="$t('compute.pci.dev_type.placeholder')" />
  10. </a-form-item>
  11. <a-form-item :label="$t('compute.pci.model')">
  12. <a-input v-decorator="decorators.model" :placeholder="$t('compute.pci.model.placeholder')" />
  13. </a-form-item>
  14. <a-form-item :label="$t('compute.pci.vendor_id')">
  15. <template #extra v-if="showDocsLink()">
  16. {{ $t('compute.pci.vendor_id.extra') }}<help-link v-if="vendorAndDeviceLink" :href="vendorAndDeviceLink">{{ $t('compute.pci.document') }}</help-link>
  17. </template>
  18. <a-input v-decorator="decorators.vendor_id" :placeholder="$t('compute.pci.vendor_id.placeholder')" />
  19. </a-form-item>
  20. <a-form-item :label="$t('compute.pci.device_id')">
  21. <template #extra v-if="showDocsLink()">
  22. {{ $t('compute.pci.device_id.extra') }}<help-link v-if="vendorAndDeviceLink" :href="vendorAndDeviceLink">{{ $t('compute.pci.document') }}</help-link>
  23. </template>
  24. <a-input v-decorator="decorators.device_id" :placeholder="$t('compute.pci.device_id.placeholder')" />
  25. </a-form-item>
  26. <a-form-item :label="$t('compute.pci.disable_auto_detect')">
  27. <a-switch v-decorator="decorators.disable_auto_detect" :checked-children="$t('table.title.on')" :un-checked-children="$t('table.title.off')" />
  28. </a-form-item>
  29. <a-form-item v-if="!form.fd.disable_auto_detect" :label="$t('compute.pci.host')" :extra="$t('compute.pci.host.extra')">
  30. <list-select
  31. v-decorator="decorators.hosts"
  32. :list-props="resourceProps"
  33. :formatter="v => v.name"
  34. :multiple="true"
  35. :placeholder="$t('compute.pci.host.placeholder')"
  36. :dialog-params="{ title: $t('compute.text_111'), width: 1060 }" />
  37. </a-form-item>
  38. <a-form-item :label="$t('compute.pci.hot_pluggable')" :extra="$t('compute.pci.hot_pluggable.tips')">
  39. <!-- <span slot="label">
  40. {{ $t('compute.pci.hot_pluggable') }}&nbsp;
  41. <a-tooltip :title="$t('compute.pci.hot_pluggable.tips')">
  42. <a-icon type="question-circle-o" />
  43. </a-tooltip>
  44. </span> -->
  45. <a-switch v-decorator="decorators.hot_pluggable" :checked-children="$t('table.title.on')" :un-checked-children="$t('table.title.off')" />
  46. </a-form-item>
  47. </a-form>
  48. </div>
  49. <div slot="footer">
  50. <a-button type="primary" @click="handleConfirm" :loading="loading">{{ $t('dialog.ok') }}</a-button>
  51. <a-button @click="cancelDialog">{{ $t('dialog.cancel') }}</a-button>
  52. </div>
  53. </base-dialog>
  54. </template>
  55. <script>
  56. import DialogMixin from '@/mixins/dialog'
  57. import WindowsMixin from '@/mixins/windows'
  58. import { typeClouds } from '@/utils/common/hypervisor'
  59. import { DOCS_MAP, showDocsLink } from '@/constants/docs'
  60. import ListSelect from '@/sections/ListSelect'
  61. import ResourcePropsMixin from '../mixins/resourceProps'
  62. export default {
  63. name: 'PciCreateDialog',
  64. components: {
  65. ListSelect,
  66. },
  67. mixins: [DialogMixin, WindowsMixin, ResourcePropsMixin],
  68. data () {
  69. return {
  70. showDocsLink,
  71. loading: false,
  72. form: {
  73. fc: this.$form.createForm(this, {
  74. onValuesChange: (props, values) => {
  75. Object.keys(values).forEach((key) => {
  76. this.form.fd[key] = values[key]
  77. })
  78. },
  79. }),
  80. fd: {},
  81. },
  82. decorators: {
  83. dev_type: [
  84. 'dev_type',
  85. {
  86. rules: [
  87. { required: true, message: this.$t('compute.pci.dev_type.placeholder') },
  88. ],
  89. },
  90. ],
  91. model: [
  92. 'model',
  93. {
  94. rules: [
  95. { required: true, message: this.$t('compute.pci.model.placeholder') },
  96. ],
  97. },
  98. ],
  99. vendor_id: [
  100. 'vendor_id',
  101. {
  102. validateFirst: true,
  103. rules: [
  104. { required: true, message: this.$t('compute.pci.vendor_id.placeholder') },
  105. { validator: this.validateVendorId(), trigger: 'blur' },
  106. ],
  107. },
  108. ],
  109. device_id: [
  110. 'device_id',
  111. {
  112. validateFirst: true,
  113. rules: [
  114. { required: true, message: this.$t('compute.pci.device_id.placeholder') },
  115. { validator: this.validateDeviceId(), trigger: 'blur' },
  116. ],
  117. },
  118. ],
  119. hosts: [
  120. 'hosts',
  121. ],
  122. hot_pluggable: [
  123. 'hot_pluggable',
  124. {
  125. initialValue: false,
  126. },
  127. ],
  128. disable_auto_detect: [
  129. 'disable_auto_detect',
  130. {
  131. initialValue: false,
  132. },
  133. ],
  134. },
  135. formItemLayout: {
  136. wrapperCol: {
  137. span: 20,
  138. },
  139. labelCol: {
  140. span: 4,
  141. },
  142. },
  143. hostParams: {
  144. details: false,
  145. baremetal: false,
  146. brand: typeClouds.brandMap.OneCloud.brand,
  147. },
  148. }
  149. },
  150. computed: {
  151. vendorAndDeviceLink () {
  152. return DOCS_MAP.pciVendorAndDevice()
  153. },
  154. },
  155. methods: {
  156. validateVendorId () {
  157. return (rule, value, callback) => {
  158. const reg = /^[a-f0-9]{4}$/
  159. if (reg.test(value)) {
  160. return callback()
  161. }
  162. return callback(new Error(this.$t('compute.pci.vendor_id.reg_error_msg')))
  163. }
  164. },
  165. validateDeviceId () {
  166. return (rule, value, callback) => {
  167. const reg = /^[a-f0-9]{4}$/
  168. if (reg.test(value)) {
  169. return callback()
  170. }
  171. return callback(new Error(this.$t('compute.pci.device_id.reg_error_msg')))
  172. }
  173. },
  174. doSubmit (data) {
  175. return new this.$Manager('isolated_device_models').create({
  176. data,
  177. })
  178. },
  179. async handleConfirm () {
  180. const { validateFields } = this.form.fc
  181. try {
  182. this.loading = true
  183. const values = await validateFields()
  184. const data = {
  185. dev_type: values.dev_type.trim(),
  186. model: values.model.trim(),
  187. vendor_id: values.vendor_id.trim(),
  188. device_id: values.device_id.trim(),
  189. hosts: values.hosts,
  190. hot_pluggable: values.hot_pluggable,
  191. disable_auto_detect: values.disable_auto_detect,
  192. }
  193. await this.doSubmit(data)
  194. this.loading = false
  195. this.cancelDialog()
  196. this.params.refresh && this.params.refresh()
  197. } catch (error) {
  198. this.loading = false
  199. throw error
  200. }
  201. },
  202. },
  203. }
  204. </script>