EditYaml.vue 2.0 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071
  1. <template>
  2. <base-dialog @cancel="cancelDialog">
  3. <div slot="header">{{$t('k8s.text_47')}}</div>
  4. <div class="k8s-edit-yaml-dialog w-100" v-if="configText" slot="body">
  5. <code-mirror v-model="configText" :options="cmOptions" />
  6. </div>
  7. <div slot="footer">
  8. <a-button type="primary" @click="handleConfirm" :loading="loading">{{ $t('dialog.ok') }}</a-button>
  9. <a-button @click="cancelDialog">{{ $t('dialog.cancel') }}</a-button>
  10. </div>
  11. </base-dialog>
  12. </template>
  13. <script>
  14. import * as R from 'ramda'
  15. import jsYaml from 'js-yaml'
  16. import DialogMixin from '@/mixins/dialog'
  17. import WindowsMixin from '@/mixins/windows'
  18. export default {
  19. name: 'K8SEditYamlDialog',
  20. mixins: [DialogMixin, WindowsMixin],
  21. data () {
  22. return {
  23. loading: false,
  24. scope: this.$store.getters.scope,
  25. configText: R.is(Object, this.params.configText) ? jsYaml.safeDump(this.params.configText, { lineWidth: Infinity }) : this.params.configText,
  26. data: this.params.data[0],
  27. cmOptions: {
  28. tabSize: 4,
  29. styleActiveLine: true,
  30. lineNumbers: true,
  31. line: true,
  32. mode: 'text/x-yaml',
  33. lineWrapping: true,
  34. theme: 'material',
  35. },
  36. }
  37. },
  38. methods: {
  39. async handleConfirm () {
  40. const { clusterID, namespace, id } = this.data
  41. let qs = `${id}/rawdata?cluster=${clusterID}`
  42. if (namespace) qs += `&namespace=${namespace}`
  43. let data = null
  44. try {
  45. data = jsYaml.safeLoad(this.configText)
  46. } catch (error) {
  47. this.$message.error(this.$t('k8s.text_48'))
  48. throw error
  49. }
  50. await this.params.manager.update({
  51. id: qs,
  52. data,
  53. })
  54. this.$message.success(this.$t('k8s.text_46'))
  55. this.params.refresh()
  56. this.cancelDialog()
  57. if (R.is(Function, this.params.success)) this.params.success()
  58. },
  59. },
  60. }
  61. </script>
  62. <style lang="less" scoped>
  63. .k8s-edit-yaml-dialog {
  64. ::v-deep .CodeMirror {
  65. height: 600px;
  66. }
  67. }
  68. </style>