AccessKeyCreate.vue 3.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108
  1. <template>
  2. <base-dialog @cancel="cancelDialog">
  3. <div slot="header">{{this.params.title}}</div>
  4. <div slot="body" v-loading="loading" style="min-height: 130px">
  5. <template v-if="isSuccess">
  6. <div class="text-center mt-2">
  7. <a-icon type="check-circle" style="font-size: 46px;" theme="twoTone" twoToneColor="#52c41a" />
  8. <h4 style="color: #52c41a;" class="mt-2">{{$t('scope.text_9')}}</h4>
  9. <a @click.stop="downloadFile"><a-icon type="download" class="mr-2" />{{$t('scope.text_10')}}</a>
  10. </div>
  11. <div class="mt-2">
  12. <div class="d-flex">
  13. <div style="width: 140px;" class="text-right flex-shrink-0 flex-grow-0">AccessKey:</div>
  14. <div class="flex-fill">
  15. <list-body-cell-wrap copy :row="data" field="key_id" />
  16. </div>
  17. </div>
  18. <div class="d-flex mt-2">
  19. <div style="width: 140px;" class="text-right flex-shrink-0 flex-grow-0">AccessKeySecret:</div>
  20. <div class="flex-fill">
  21. <list-body-cell-wrap copy :row="data" field="secret" />
  22. </div>
  23. </div>
  24. </div>
  25. </template>
  26. <template v-else>
  27. <div class="text-center">
  28. <a-icon type="close-circle" style="font-size: 46px;" theme="twoTone" twoToneColor="#f5222d" />
  29. <h4 style="color: #f5222d;" class="mt-2">{{$t('scope.text_11')}}</h4>
  30. <a-button type="link" @click="doCreateAk">{{$t('scope.text_12')}}</a-button>
  31. </div>
  32. </template>
  33. </div>
  34. <div slot="footer">
  35. <a-button type="primary" @click="cancelDialog">{{ $t("dialog.ok") }}</a-button>
  36. <a-button @click="cancelDialog">{{ $t('dialog.cancel') }}</a-button>
  37. </div>
  38. </base-dialog>
  39. </template>
  40. <script>
  41. import DialogMixin from '@/mixins/dialog'
  42. import WindowsMixin from '@/mixins/windows'
  43. export default {
  44. name: 'CredentialAccessKeyCreate',
  45. mixins: [DialogMixin, WindowsMixin],
  46. data () {
  47. return {
  48. loading: false,
  49. isSuccess: false,
  50. data: {},
  51. }
  52. },
  53. destroyed () {
  54. this.manager = null
  55. },
  56. created () {
  57. this.manager = new this.$Manager('credentials', 'v1')
  58. this.doCreateAk()
  59. },
  60. methods: {
  61. async doCreateAk () {
  62. this.loading = true
  63. try {
  64. const response = await this.manager.rpc({ methodname: 'DoCreateAccessKeySecret' })
  65. const data = response.data || {}
  66. this.data = data
  67. this.isSuccess = true
  68. this.params.refresh()
  69. } catch (error) {
  70. this.isSuccess = false
  71. } finally {
  72. this.loading = false
  73. }
  74. },
  75. downloadFile (e) {
  76. const thead = [
  77. {
  78. title: 'AccessKey',
  79. field: 'key_id',
  80. },
  81. {
  82. title: 'AccessKeySecret',
  83. field: 'secret',
  84. },
  85. ]
  86. const tbody = [this.data]
  87. const theadStr = thead.map(({ title }) => title).join(',')
  88. let tbodyStr = ''
  89. tbody.forEach(tr => {
  90. const trArr = thead.map(ths => {
  91. const k = ths.field
  92. if (tr[k] && typeof tr[k] === 'string') {
  93. return tr[k]
  94. } else {
  95. return '-'
  96. }
  97. })
  98. tbodyStr += trArr.join(',')
  99. tbodyStr += '\n'
  100. })
  101. const str = encodeURIComponent(`${theadStr}\n${tbodyStr}`)
  102. e.target.href = 'data:text/csv;charset=utf-8,\ufeff' + str
  103. e.target.download = 'accesskey.csv'
  104. },
  105. },
  106. }
  107. </script>