singleActions.js 4.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155
  1. import { mapGetters } from 'vuex'
  2. import { disableDeleteAction } from '@/utils/common/tableActions'
  3. import i18n from '@/locales'
  4. export default {
  5. created () {
  6. this.singleActions = [
  7. {
  8. label: i18n.t('network.text_201'),
  9. permission: 'cdn_domains_perform_syncstatus',
  10. action: obj => {
  11. this.onManager('performAction', {
  12. steadyStatus: ['offline', 'online'],
  13. id: obj.id,
  14. managerArgs: {
  15. action: 'syncstatus',
  16. },
  17. })
  18. },
  19. meta: (obj) => {
  20. if (!this.isOwner(obj)) {
  21. return {
  22. validate: false,
  23. tooltip: i18n.t('network.text_627'),
  24. }
  25. }
  26. return {
  27. validate: true,
  28. }
  29. },
  30. },
  31. {
  32. label: i18n.t('network.text_129'),
  33. actions: (obj) => {
  34. return [
  35. {
  36. label: i18n.t('compute.text_1100'),
  37. permission: 'cdn_domains_perform_change_config',
  38. action: () => {
  39. this.createDialog('CdnDomainChangeConfigDialog', {
  40. data: [obj],
  41. columns: this.columns,
  42. onManager: this.onManager,
  43. })
  44. },
  45. meta: () => {
  46. if (obj.provider !== 'Cloudflare') {
  47. return {
  48. validate: false,
  49. tooltip: i18n.t('compute.text_1388'),
  50. }
  51. }
  52. return { validate: true }
  53. },
  54. },
  55. {
  56. label: i18n.t('network.cdn.clear_cache'),
  57. permission: 'cdn_domains_perform_clear_cache',
  58. action: () => {
  59. this.createDialog('CdnDomainClearCacheDialog', {
  60. data: [obj],
  61. columns: this.columns,
  62. onManager: this.onManager,
  63. })
  64. },
  65. meta: () => {
  66. if (obj.provider !== 'Cloudflare') {
  67. return {
  68. validate: false,
  69. tooltip: i18n.t('compute.text_1388'),
  70. }
  71. }
  72. return { validate: true }
  73. },
  74. },
  75. {
  76. label: i18n.t('network.text_225', [i18n.t('dictionary.project')]),
  77. permission: 'cdn_domains_perform_change_owner',
  78. action: () => {
  79. this.createDialog('ChangeOwenrDialog', {
  80. data: [obj],
  81. columns: this.columns,
  82. name: this.$t('dictionary.cdn_domain'),
  83. onManager: this.onManager,
  84. resource: 'cdn_domains',
  85. })
  86. },
  87. meta: () => {
  88. const ret = {
  89. validate: false,
  90. tooltip: '',
  91. }
  92. if (this.isProjectMode) {
  93. ret.tooltip = i18n.t('common_601')
  94. return ret
  95. }
  96. return {
  97. validate: true,
  98. }
  99. },
  100. },
  101. disableDeleteAction(Object.assign(this, {
  102. permission: 'cdn_domains_update',
  103. }), {
  104. name: this.$t('dictionary.cdn_domain'),
  105. meta: () => {
  106. if (!this.isOwner(obj)) {
  107. return {
  108. validate: false,
  109. tooltip: i18n.t('network.text_627'),
  110. }
  111. }
  112. },
  113. }),
  114. {
  115. label: i18n.t('network.text_131'),
  116. permission: 'cdn_domains_delete',
  117. action: () => {
  118. this.createDialog('DeleteResDialog', {
  119. vm: this,
  120. title: i18n.t('network.text_131'),
  121. name: this.$t('dictionary.cdn_domain'),
  122. data: [obj],
  123. columns: this.columns,
  124. onManager: this.onManager,
  125. requestData: { force: true },
  126. refresh: this.refresh,
  127. })
  128. },
  129. meta: () => {
  130. if (!this.isOwner(obj)) {
  131. return {
  132. validate: false,
  133. tooltip: i18n.t('network.text_627'),
  134. }
  135. }
  136. return this.$getDeleteResult(obj)
  137. },
  138. },
  139. ]
  140. },
  141. },
  142. ]
  143. },
  144. computed: {
  145. ...mapGetters(['isAdminMode', 'isDomainMode', 'userInfo']),
  146. },
  147. methods: {
  148. isOwner (obj) {
  149. if (this.isAdminMode) return true
  150. if (this.isDomainMode) return obj.domain_id === this.userInfo.projectDomainId
  151. return false
  152. },
  153. },
  154. }