InputCreate.vue 2.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114
  1. <template>
  2. <div>
  3. <a-alert :message="$t('k8s.text_286')" banner />
  4. <a-form
  5. class="mt-3"
  6. :form="form.fc">
  7. <a-form-item
  8. :label="$t('k8s.text_19')"
  9. v-bind="formItemLayout">
  10. <cluster-select
  11. @input="setCluster"
  12. :clusterObj.sync="clusterObj"
  13. v-decorator="decorators.cluster"
  14. style="width: 140px;" />
  15. </a-form-item>
  16. <a-form-item
  17. :label="$t('k8s.text_287')"
  18. v-bind="formItemLayout">
  19. <code-mirror v-decorator="decorators.yaml" :options="cmOptions" />
  20. </a-form-item>
  21. <a-form-item :wrapper-col="{ span: 20, offset: 3 }">
  22. <a-button class="mr-2" type="primary" @click="handleConfirm" :loading="loading">{{$t('k8s.text_288')}}</a-button>
  23. <a-button @click="cancel">{{$t('k8s.text_162')}}</a-button>
  24. </a-form-item>
  25. </a-form>
  26. </div>
  27. </template>
  28. <script>
  29. import 'codemirror/mode/yaml/yaml.js'
  30. import 'codemirror/theme/material.css'
  31. import ClusterSelect from '@K8S/sections/ClusterSelect'
  32. import k8sCreateMixin from '@K8S/mixins/create'
  33. export default {
  34. name: 'InputCreate',
  35. components: {
  36. ClusterSelect,
  37. },
  38. mixins: [k8sCreateMixin],
  39. data () {
  40. return {
  41. loading: false,
  42. form: {
  43. fc: this.$form.createForm(this),
  44. },
  45. decorators: {
  46. cluster: [
  47. 'cluster',
  48. {
  49. rules: [
  50. { required: true, message: this.$t('k8s.text_30') },
  51. ],
  52. },
  53. ],
  54. yaml: [
  55. 'yaml',
  56. {
  57. rules: [
  58. { required: true, message: this.$t('k8s.text_289') },
  59. ],
  60. },
  61. ],
  62. },
  63. formItemLayout: {
  64. wrapperCol: { span: 20 },
  65. labelCol: { span: 3 },
  66. },
  67. clusterObj: {},
  68. cmOptions: {
  69. tabSize: 4,
  70. styleActiveLine: true,
  71. lineNumbers: true,
  72. line: true,
  73. mode: 'text/x-yaml',
  74. lineWrapping: true,
  75. theme: 'material',
  76. },
  77. }
  78. },
  79. created () {
  80. this.inputM = new this.$Manager('appfromfiles', 'v1')
  81. },
  82. destroyed () {
  83. this.inputM = null
  84. },
  85. methods: {
  86. doCreate (data) {
  87. return this.inputM.create({
  88. data: {
  89. content: data.yaml,
  90. cluster: data.cluster,
  91. },
  92. })
  93. },
  94. async handleConfirm () {
  95. this.loading = true
  96. try {
  97. const values = await this.form.fc.validateFields()
  98. await this.doCreate(values)
  99. this.loading = false
  100. this.$message.success(this.$t('k8s.text_184'))
  101. this.$router.push('/k8s-namespace')
  102. } catch (error) {
  103. this.loading = false
  104. throw error
  105. }
  106. },
  107. cancel () {
  108. this.$router.push('/k8s-namespace')
  109. },
  110. },
  111. }
  112. </script>