index.vue 2.0 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889
  1. <template>
  2. <div class="data-view">
  3. <div class="data-view-item mt-3" v-for="item in dataList" :key="item.title">
  4. <div class="data-view-item_title mb-1">{{ item.title }}</div>
  5. <code-mirror v-model="item.content" :options="cmOptions" />
  6. </div>
  7. <a-button class="mt-4" type="primary" v-if="dataList && dataList.length" @click="update" :loading="loading">{{$t('k8s.text_45')}}</a-button>
  8. </div>
  9. </template>
  10. <script>
  11. import * as R from 'ramda'
  12. import 'codemirror/mode/javascript/javascript.js'
  13. import 'codemirror/theme/material.css'
  14. export default {
  15. name: 'K8SDataViewSidepageDetail',
  16. props: {
  17. data: {
  18. type: Object,
  19. required: true,
  20. },
  21. onManager: {
  22. type: Function,
  23. required: true,
  24. },
  25. },
  26. data () {
  27. const dataList = []
  28. if (R.is(Object, this.data.data)) {
  29. R.forEachObjIndexed((value, key) => {
  30. dataList.push({
  31. title: key,
  32. content: value,
  33. })
  34. }, this.data.data)
  35. }
  36. return {
  37. cmOptions: {
  38. tabSize: 2,
  39. styleActiveLine: true,
  40. lineNumbers: true,
  41. line: true,
  42. name: 'javascript',
  43. json: true,
  44. theme: 'material',
  45. lineWrapping: true,
  46. mode: 'text/html',
  47. matchBrackets: true,
  48. },
  49. dataList,
  50. loading: false,
  51. }
  52. },
  53. methods: {
  54. async update () {
  55. try {
  56. const data = {}
  57. this.dataList.forEach(val => {
  58. data[val.title] = val.content
  59. })
  60. const { name, cluster, namespace } = this.data
  61. this.loading = true
  62. await this.onManager('update', {
  63. id: name,
  64. managerArgs: {
  65. data: { data, namespace, cluster },
  66. },
  67. })
  68. this.$message.success(this.$t('k8s.text_46'))
  69. this.loading = false
  70. } catch (error) {
  71. this.loading = false
  72. throw error
  73. }
  74. },
  75. },
  76. }
  77. </script>
  78. <style lang="less" scoped>
  79. .data-view {
  80. &::v-deep {
  81. .CodeMirror {
  82. height: 600px !important;
  83. }
  84. }
  85. }
  86. </style>