ScheduledtaskCreate.vue 3.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131
  1. <template>
  2. <base-dialog @cancel="cancelDialog">
  3. <div slot="header">{{ $t('cloudenv.text_432') }}</div>
  4. <div slot="body">
  5. <dialog-selected-tips :name="$t('cloudenv.text_12')" class="mt-3" :count="params.data.length" :action="$t('cloudenv.text_432')" />
  6. <dialog-table v-if="columns && columns.length" :data="params.data" :columns="columns" />
  7. <a-form :form="form.fc" v-bind="formItemLayout" hideRequiredMark>
  8. <a-form-item :label="$t('cloudenv.text_95')">
  9. <a-input :placeholder="$t('cloudenv.text_190')" v-decorator="decorators.name" />
  10. <template v-slot:extra>
  11. <name-repeated res="scheduledtasks" :name="form.fd.name" />
  12. </template>
  13. </a-form-item>
  14. <a-form-item :label="$t('cloudenv.text_360')">
  15. {{ $t('cloudenv.sync_account') }}
  16. </a-form-item>
  17. <scheduled-task-time ref="taskTime" :form="form" />
  18. </a-form>
  19. </div>
  20. <div slot="footer">
  21. <a-button type="primary" @click="handleConfirm" :loading="loading">{{ $t("dialog.ok") }}</a-button>
  22. <a-button @click="cancelDialog">{{ $t('dialog.cancel') }}</a-button>
  23. </div>
  24. </base-dialog>
  25. </template>
  26. <script>
  27. import ScheduledTaskTime from '@Cloudenv/sections/ScheduledTaskTime'
  28. import {
  29. getStatusTableColumn,
  30. getEnabledTableColumn,
  31. } from '@/utils/common/tableColumn'
  32. import NameRepeated from '@/sections/NameRepeated'
  33. import DialogMixin from '@/mixins/dialog'
  34. import WindowsMixin from '@/mixins/windows'
  35. export default {
  36. name: 'ScheduledtaskCreateDialog',
  37. components: {
  38. NameRepeated,
  39. ScheduledTaskTime,
  40. },
  41. mixins: [DialogMixin, WindowsMixin],
  42. data () {
  43. return {
  44. loading: false,
  45. decorators: {
  46. name: [
  47. 'name',
  48. {
  49. rules: [
  50. { required: true, message: `${this.$t('common.placeholder')}${this.$t('common.name')}` },
  51. ],
  52. },
  53. ],
  54. },
  55. form: {
  56. fc: this.$form.createForm(this, {
  57. onValuesChange: (props, values) => {
  58. Object.keys(values).forEach((key) => {
  59. this.form.fd[key] = values[key]
  60. })
  61. },
  62. }),
  63. fd: {
  64. name: '',
  65. },
  66. },
  67. columns: [
  68. {
  69. field: 'name',
  70. title: this.$t('table.title.name'),
  71. minWidth: 100,
  72. slots: {
  73. default: ({ row }) => {
  74. return row.name
  75. },
  76. },
  77. },
  78. getStatusTableColumn({ statusModule: 'cloudaccount', minWidth: 90 }),
  79. getEnabledTableColumn({ minWidth: 90 }),
  80. ],
  81. formItemLayout: {
  82. wrapperCol: {
  83. md: { span: 18 },
  84. xl: { span: 20 },
  85. xxl: { span: 21 },
  86. },
  87. labelCol: {
  88. md: { span: 6 },
  89. xl: { span: 4 },
  90. xxl: { span: 3 },
  91. },
  92. },
  93. cycleTypeOpts: [
  94. { key: 'hour', label: this.$t('cloudenv.cycle_type.hour') },
  95. { key: 'day', label: this.$t('cloudenv.cycle_type.day') },
  96. { key: 'week', label: this.$t('cloudenv.cycle_type.week') },
  97. { key: 'month', label: this.$t('cloudenv.cycle_type.month') },
  98. ],
  99. }
  100. },
  101. methods: {
  102. generateData (values) {
  103. const params = {
  104. resource_type: 'cloudaccount',
  105. label_type: 'id',
  106. labels: [this.params.resId],
  107. operation: 'sync',
  108. generate_name: values.name,
  109. }
  110. this.$refs.taskTime.transformParams(params, values)
  111. return params
  112. },
  113. async handleConfirm () {
  114. this.loading = true
  115. try {
  116. const values = await this.form.fc.validateFields()
  117. const params = this.generateData(values)
  118. await new this.$Manager('scheduledtasks', 'v1').create({ data: params })
  119. this.params.callback && this.params.callback()
  120. this.cancelDialog()
  121. } catch (error) {
  122. throw error
  123. } finally {
  124. this.loading = false
  125. }
  126. },
  127. },
  128. }
  129. </script>