ActionConfig.vue 3.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105
  1. <template>
  2. <base-dialog @cancel="cancelDialog">
  3. <div slot="header">{{$t('iam.action_info')}}</div>
  4. <div slot="body" style="min-height:300px">
  5. <div>
  6. <a-checkbox
  7. class="mr-2"
  8. :checked="checkedAll"
  9. @change="handleCheckAllChange"
  10. :indeterminate="isIndeterminate"
  11. :disabled="params.resource.disabled || params.isViewer">{{$t('system.text_320')}}</a-checkbox>
  12. </div>
  13. <a-row class="mt-4">
  14. <template v-for="item of params.actions">
  15. <a-col
  16. v-if="item.label"
  17. :span="6"
  18. :key="item.action"
  19. class="mb-2 checkbox-item d-flex align-items-center">
  20. <a-checkbox :checked="checked.includes(item.action)" :value="item.action" :disabled="item.disabled || params.isViewer" class="text-truncate checkbox-property" @change="handleCheckChange">
  21. <span :title="item.label">{{ item.label }}</span>
  22. </a-checkbox>
  23. </a-col>
  24. </template>
  25. </a-row>
  26. </div>
  27. <div slot="footer">
  28. <a-button type="primary" @click="handleConfirm" :loading="loading">{{ $t('dialog.ok') }}</a-button>
  29. <a-button v-if="!params.isViewer" @click="cancelDialog">{{ $t('dialog.cancel') }}</a-button>
  30. </div>
  31. </base-dialog>
  32. </template>
  33. <script>
  34. import DialogMixin from '@/mixins/dialog'
  35. import WindowsMixin from '@/mixins/windows'
  36. export default {
  37. name: 'PolicyExtraActionConfig',
  38. mixins: [DialogMixin, WindowsMixin],
  39. data () {
  40. const initChecked = []
  41. this.params.actions.map(action => {
  42. if (this.params.checked.includes(action.action)) {
  43. initChecked.push(action.action)
  44. }
  45. // [create,list,get,delete,update]做联动
  46. // const actionTypes = action.action.split('_')
  47. // if (actionTypes[1] &&
  48. // actionTypes[1] === '*' &&
  49. // ['create', 'list', 'get', 'delete', 'update'].includes(actionTypes[0]) &&
  50. // this.params.resource &&
  51. // this.params.resource.checked &&
  52. // this.params.resource.checked.includes(actionTypes[0])) {
  53. // initChecked.push(action.action)
  54. // }
  55. })
  56. return {
  57. checked: initChecked,
  58. }
  59. },
  60. computed: {
  61. checkedAll () {
  62. let ret = true
  63. this.params.actions.map(item => {
  64. if (!this.checked.includes(item.action)) {
  65. ret = false
  66. }
  67. })
  68. return ret
  69. },
  70. isIndeterminate () {
  71. return this.checked.length && this.checked.length < this.params.actions.length
  72. },
  73. },
  74. created () {
  75. },
  76. methods: {
  77. handleCheckAllChange () {
  78. if (this.checkedAll) {
  79. this.checked = []
  80. } else {
  81. this.checked = this.params.actions.map(action => action.action)
  82. }
  83. },
  84. handleCheckChange (e) {
  85. const { value, checked } = e.target
  86. if (checked && !this.checked.includes(value)) {
  87. this.checked = [...this.checked, value]
  88. } else if (!checked) {
  89. this.checked = this.checked.filter(action => action !== value)
  90. }
  91. // [create,list,get,delete,update]做联动
  92. const actionTypes = value.split('_')
  93. if (actionTypes[1] && actionTypes[1] === '*' && ['create', 'list', 'get', 'delete', 'update'].includes(actionTypes[0])) {
  94. this.params.extraChangeNormal(actionTypes[0], checked)
  95. }
  96. },
  97. async handleConfirm () {
  98. this.params.checkedChange && this.params.checkedChange(this.checked)
  99. this.cancelDialog()
  100. },
  101. },
  102. }
  103. </script>