index.vue 2.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283
  1. <template>
  2. <div>
  3. <a-form-item class="mb-0">
  4. <a-radio-group v-decorator="decorators.encryptEnable" @change="change">
  5. <a-radio-button value="">{{ $t('compute.text_116') }}</a-radio-button>
  6. <a-radio-button value="new">{{ $t('compute.prompt.encrypt.new') }}</a-radio-button>
  7. <a-radio-button value="existing">{{ $t('compute.prompt.encrypt.existing') }}</a-radio-button>
  8. </a-radio-group>
  9. </a-form-item>
  10. <a-form-item v-if="showAlgs">
  11. <a-radio-group v-decorator="decorators.encrypt_key_alg">
  12. <a-radio-button value="">{{ $t('compute.text_1') }}</a-radio-button>
  13. <a-radio-button value="aes-256">AES256</a-radio-button>
  14. <!--a-radio-button value="sm4">SM4</a-radio-button-->
  15. </a-radio-group>
  16. </a-form-item>
  17. <a-form-item v-if="showKeys">
  18. <a-select v-decorator="decorators.encrypt_key_id" :placeholder="$t('compute.prompt.encrypt_key')">
  19. <a-select-option v-for="item in encryptKeyOptions" :key="item.value" :value="item.value">
  20. {{item.text}}
  21. </a-select-option>
  22. </a-select>
  23. </a-form-item>
  24. </div>
  25. </template>
  26. <script>
  27. export default {
  28. name: 'EncryptKeys',
  29. props: {
  30. decorators: {
  31. type: Object,
  32. required: true,
  33. validator: val => {
  34. if (val.encryptEnable === 'existing' && !val.encrypt_key_id) {
  35. return false
  36. }
  37. if (val.encryptEnable === 'new' && !val.encrypt_key_alg) {
  38. return false
  39. }
  40. return true
  41. },
  42. },
  43. },
  44. data () {
  45. return {
  46. showKeys: this.decorators.encryptEnable[1].initialValue === 'existing',
  47. showAlgs: this.decorators.encryptEnable[1].initialValue === 'new',
  48. encryptKeyOptions: [],
  49. }
  50. },
  51. computed: {
  52. },
  53. created () {
  54. this.fetchEncryptKeyOptions()
  55. },
  56. methods: {
  57. change (val) {
  58. if (val.target.value === 'existing') {
  59. this.showKeys = true
  60. this.showAlgs = false
  61. } else if (val.target.value === 'new') {
  62. this.showKeys = false
  63. this.showAlgs = true
  64. } else {
  65. this.showKeys = false
  66. this.showAlgs = false
  67. }
  68. },
  69. async fetchEncryptKeyOptions () {
  70. const credManager = new this.$Manager('credentials', 'v1')
  71. const result = await credManager.rpc({ methodname: 'GetEncryptKeysRpc' })
  72. const opts = []
  73. for (let i = 0; i < result.data.length; i++) {
  74. const value = result.data[i].key_id
  75. const text = result.data[i].key_name + ' (' + result.data[i].key_id + ',' + result.data[i].alg.toUpperCase() + ')'
  76. opts.push({ value: value, text: text })
  77. }
  78. this.encryptKeyOptions = opts
  79. },
  80. },
  81. }
  82. </script>