ScriptAdd.vue 1.8 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283
  1. <template>
  2. <a-form-item :wrapper-col="offsetWrapperCol">
  3. <div class="script-add-wrap">
  4. <template v-if="loading"><loader loading /></template>
  5. <template v-else>
  6. <a-alert :message="$t('compute.text_800')" banner />
  7. <code-mirror :value="value" :options="cmOptions" />
  8. <div class="text-right">
  9. <a-button
  10. type="link"
  11. icon="copy"
  12. class="pl-0 pr-0"
  13. @click="handleCopy">{{$t('compute.text_801')}}</a-button>
  14. </div>
  15. </template>
  16. </div>
  17. </a-form-item>
  18. </template>
  19. <script>
  20. import 'codemirror/mode/shell/shell'
  21. export default {
  22. name: 'PhysicalmachineScriptAdd',
  23. props: {
  24. offsetWrapperCol: {
  25. type: Object,
  26. required: true,
  27. },
  28. },
  29. data () {
  30. return {
  31. loading: false,
  32. value: '',
  33. cmOptions: {
  34. styleActiveLine: true,
  35. lineNumbers: true,
  36. lineWrapping: true,
  37. line: true,
  38. readOnly: true,
  39. theme: 'material',
  40. },
  41. }
  42. },
  43. destroyed () {
  44. this.manager = null
  45. },
  46. created () {
  47. this.manager = new this.$Manager('hosts')
  48. this.fetchScript()
  49. },
  50. methods: {
  51. async fetchScript () {
  52. this.loading = true
  53. try {
  54. const response = await this.manager.get({ id: 'bm-start-register-script' })
  55. this.value = `sudo sh -c "$(${response.data.script})"`
  56. } finally {
  57. this.loading = false
  58. }
  59. },
  60. handleCopy () {
  61. this.$copyText(this.value).then(() => {
  62. this.$message.success(this.$t('compute.text_802'))
  63. }).catch(() => {
  64. this.$message.error(this.$t('compute.text_803'))
  65. })
  66. },
  67. },
  68. }
  69. </script>
  70. <style lang="less" scoped>
  71. .script-add-wrap {
  72. line-height: 1.5rem;
  73. max-width: 600px;
  74. ::v-deep {
  75. .CodeMirror {
  76. height: auto !important;
  77. }
  78. }
  79. }
  80. </style>