Clone.vue 2.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394
  1. <template>
  2. <base-dialog @cancel="cancelDialog">
  3. <div slot="header">{{$t('table.action.clone')}}</div>
  4. <div slot="body">
  5. <dialog-selected-tips :count="params.data.length" :action="$t('table.action.clone')" :name="$t('res.policy')" />
  6. <dialog-table :data="params.data" :columns="params.columns.slice(0, 3)" />
  7. <a-form
  8. :form="form.fc"
  9. v-bind="formItemLayout">
  10. <a-form-item :label="$t('table.title.name')">
  11. <a-input v-decorator="decorators.name" />
  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: 'PolicyCloneDialog',
  26. mixins: [DialogMixin, WindowsMixin],
  27. data () {
  28. return {
  29. loading: false,
  30. form: {
  31. fc: this.$form.createForm(this),
  32. },
  33. contactArrOpts: [],
  34. decorators: {
  35. name: [
  36. 'name',
  37. {
  38. rules: [
  39. {
  40. required: true,
  41. message: this.$t('common.tips.input', [this.$t('res.policy')]),
  42. whitespace: true,
  43. },
  44. ],
  45. },
  46. ],
  47. },
  48. formItemLayout: {
  49. wrapperCol: {
  50. span: 21,
  51. },
  52. labelCol: {
  53. span: 3,
  54. },
  55. },
  56. }
  57. },
  58. destroyed () {
  59. this.manager = null
  60. },
  61. created () {
  62. this.manager = new this.$Manager('policies', 'v1')
  63. },
  64. methods: {
  65. async handleConfirm () {
  66. this.loading = true
  67. try {
  68. const values = await this.form.fc.validateFields()
  69. const { name } = values
  70. const { scope, policy, description } = this.params.data[0]
  71. const data = {
  72. type: name,
  73. scope,
  74. policy,
  75. }
  76. if (description) {
  77. data.description = description
  78. }
  79. await this.manager.create({
  80. data,
  81. })
  82. this.loading = false
  83. this.params.success()
  84. this.cancelDialog()
  85. } catch (error) {
  86. this.loading = false
  87. throw error
  88. }
  89. },
  90. },
  91. }
  92. </script>