index.vue 2.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113
  1. <template>
  2. <vxe-grid :data="rules" :columns="columns" resizable />
  3. </template>
  4. <script>
  5. import _ from 'lodash'
  6. import ActionButton from '@/components/PageList/Actions/ActionButton'
  7. import WindowsMixin from '@/mixins/windows'
  8. export default {
  9. name: 'K8SRoleRulesSidepage',
  10. mixins: [WindowsMixin],
  11. props: {
  12. data: {
  13. type: Object,
  14. required: true,
  15. },
  16. onManager: {
  17. type: Function,
  18. required: true,
  19. },
  20. rulesPath: {
  21. type: String,
  22. default: 'rules',
  23. },
  24. resource: {
  25. type: String,
  26. },
  27. },
  28. data () {
  29. return {
  30. columns: [
  31. {
  32. field: 'verbs',
  33. title: 'Actions',
  34. slots: {
  35. default: ({ row }, h) => {
  36. if (!row.verbs) return '-'
  37. return row.verbs.map(val => (<div>{ val }</div>))
  38. },
  39. },
  40. },
  41. {
  42. field: 'apiGroups',
  43. title: 'API Groups',
  44. slots: {
  45. default: ({ row }, h) => {
  46. if (!row.apiGroups) return '-'
  47. return row.apiGroups.map(val => (<div>{ val || '""' }</div>))
  48. },
  49. },
  50. },
  51. {
  52. field: 'resources',
  53. title: 'Resources',
  54. slots: {
  55. default: ({ row }, h) => {
  56. if (!row.resources) return '-'
  57. return row.resources.map(val => (<div>{ val }</div>))
  58. },
  59. },
  60. },
  61. {
  62. field: 'actions',
  63. title: this.$t('common.action'),
  64. slots: {
  65. default: ({ row, rowIndex }, h) => {
  66. const item = {
  67. label: this.$t('common.delete'),
  68. action: row => {
  69. this.deleteRule(rowIndex)
  70. },
  71. }
  72. return [h(ActionButton, {
  73. props: {
  74. row,
  75. item,
  76. buttonSize: 'small',
  77. buttonStyle: {
  78. fontSize: '12px',
  79. },
  80. },
  81. })]
  82. },
  83. },
  84. },
  85. ],
  86. }
  87. },
  88. computed: {
  89. rules () {
  90. return _.get(this.data, this.rulesPath)
  91. },
  92. },
  93. methods: {
  94. deleteRule (rowIndex) {
  95. const rule = this.rules[rowIndex]
  96. this.createDialog('K8SRemoveRuleDialog', {
  97. resourceData: this.data,
  98. rulesPath: this.rulesPath,
  99. data: [rule],
  100. rowIndex,
  101. inSpecTemplate: this.resource.includes('federated'),
  102. columns: this.columns.slice(0, 3),
  103. onManager: this.onManager,
  104. success: () => {
  105. this.$emit('single-refresh', this.data.id)
  106. },
  107. })
  108. },
  109. },
  110. }
  111. </script>