Detail.vue 3.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139
  1. <template>
  2. <detail
  3. :onManager="onManager"
  4. :data="data"
  5. :base-info="baseInfo"
  6. :extra-info="extraInfo"
  7. resource="credentials" />
  8. </template>
  9. <script>
  10. import { getTimeTableColumn } from '@/utils/common/tableColumn'
  11. export default {
  12. name: 'ContainerSecretDetail',
  13. props: {
  14. data: {
  15. type: Object,
  16. required: true,
  17. },
  18. onManager: {
  19. type: Function,
  20. required: true,
  21. },
  22. },
  23. data () {
  24. return {
  25. visibleBlobKeys: {},
  26. baseInfo: [
  27. {
  28. field: 'name',
  29. title: this.$t('common.name'),
  30. },
  31. {
  32. field: 'type',
  33. title: this.$t('table.title.type'),
  34. },
  35. getTimeTableColumn({
  36. field: 'created_at',
  37. title: this.$t('table.title.create_time'),
  38. }),
  39. ],
  40. extraInfo: [
  41. {
  42. field: 'blob',
  43. title: this.$t('aice.container_secret'),
  44. slots: {
  45. default: ({ row }, h) => {
  46. const blob = row.blob
  47. if (!blob) return '-'
  48. let obj = blob
  49. if (typeof blob === 'string') {
  50. try {
  51. obj = JSON.parse(blob)
  52. } catch (e) {
  53. return blob
  54. }
  55. }
  56. if (typeof obj !== 'object' || obj === null) return '-'
  57. const entries = Object.entries(obj)
  58. if (entries.length === 0) return '-'
  59. return h('div', { class: 'container-secret-blob' }, entries.map(([k, v]) => {
  60. const visible = this.visibleBlobKeys[k]
  61. const displayValue = visible ? String(v) : '••••••'
  62. return h('div', { key: k, class: 'blob-row' }, [
  63. h('span', { class: 'blob-key' }, k),
  64. h('span', { class: 'blob-sep' }, ': '),
  65. h('span', { class: 'blob-value' }, displayValue),
  66. h('a-icon', {
  67. class: 'blob-eye ml-1',
  68. props: {
  69. type: visible ? 'eye-invisible' : 'eye',
  70. theme: 'twoTone',
  71. twoToneColor: '#1890ff',
  72. },
  73. on: {
  74. click: () => this.toggleBlobKey(k),
  75. },
  76. }),
  77. h('a-icon', {
  78. class: 'blob-copy ml-1',
  79. props: {
  80. type: 'copy',
  81. theme: 'twoTone',
  82. twoToneColor: '#1890ff',
  83. },
  84. on: {
  85. click: () => this.copyBlobValue(v),
  86. },
  87. }),
  88. ])
  89. }))
  90. },
  91. },
  92. },
  93. ],
  94. }
  95. },
  96. methods: {
  97. toggleBlobKey (key) {
  98. this.$set(this.visibleBlobKeys, key, !this.visibleBlobKeys[key])
  99. },
  100. async copyBlobValue (value) {
  101. try {
  102. await this.$copyText(String(value))
  103. this.$message.success(this.$t('common.copy'))
  104. } catch (e) {
  105. this.$message.error(this.$t('common.copyError'))
  106. }
  107. },
  108. },
  109. }
  110. </script>
  111. <style scoped>
  112. .container-secret-blob {
  113. word-break: break-all;
  114. }
  115. .blob-row {
  116. margin-bottom: 4px;
  117. }
  118. .blob-key {
  119. font-weight: 500;
  120. color: #1890ff;
  121. }
  122. .blob-sep {
  123. margin: 0 4px;
  124. }
  125. .blob-value {
  126. color: #333;
  127. }
  128. .blob-eye {
  129. cursor: pointer;
  130. vertical-align: middle;
  131. }
  132. .blob-copy {
  133. cursor: pointer;
  134. vertical-align: middle;
  135. }
  136. </style>