index.vue 1.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778
  1. <template>
  2. <div class="K8S-source-information-sidepage mb-5 mt-2">
  3. <code-mirror v-model="text" :options="cmOptions" />
  4. <a-button
  5. class="mt-2 mr-2"
  6. v-clipboard:copy="text"
  7. v-clipboard:success="_ => $message.success($t('k8s.text_31'))"
  8. v-clipboard:error="_ => $message.error($t('k8s.text_32'))"><a-icon type="copy" />{{$t('k8s.text_33')}}</a-button>
  9. <a-button type="primary" @click="update">{{$t('k8s.text_95')}}</a-button>
  10. </div>
  11. </template>
  12. <script>
  13. import 'codemirror/mode/yaml/yaml.js'
  14. import 'codemirror/theme/material.css'
  15. import jsYaml from 'js-yaml'
  16. export default {
  17. name: 'K8SSourceInformationSidepage',
  18. props: {
  19. resource: {
  20. type: String,
  21. required: true,
  22. },
  23. data: {
  24. type: Object,
  25. required: true,
  26. },
  27. },
  28. data () {
  29. return {
  30. cmOptions: {
  31. tabSize: 4,
  32. styleActiveLine: true,
  33. lineNumbers: true,
  34. line: true,
  35. mode: 'text/x-yaml',
  36. lineWrapping: true,
  37. theme: 'material',
  38. },
  39. text: '',
  40. }
  41. },
  42. created () {
  43. this.fetchData()
  44. },
  45. methods: {
  46. fetchData () {
  47. const params = {}
  48. new this.$Manager(this.resource, 'v1').getSpecific({
  49. id: this.data.id,
  50. spec: 'rawdata',
  51. params,
  52. }).then(({ data }) => {
  53. this.text = jsYaml.safeDump(data, { lineWidth: Infinity })
  54. })
  55. },
  56. update () {
  57. const resource = this.resource
  58. const data = jsYaml.safeLoad(this.text)
  59. new this.$Manager(resource, 'v1').update({
  60. id: `${this.data.id}/rawdata`,
  61. data,
  62. }).then(({ data }) => {
  63. this.$message.success(this.$t('k8s.text_96', [this.data.name]))
  64. })
  65. },
  66. },
  67. }
  68. </script>
  69. <style lang="less" scoped>
  70. .K8S-source-information-sidepage {
  71. ::v-deep .CodeMirror {
  72. height: 500px;
  73. }
  74. }
  75. </style>