singleActions.js 7.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200
  1. import { mapGetters } from 'vuex'
  2. import { getSetPublicAction } from '@/utils/common/tableActions'
  3. import i18n from '@/locales'
  4. export default {
  5. computed: {
  6. ...mapGetters(['isAdminMode', 'isDomainMode', 'userInfo']),
  7. },
  8. created () {
  9. const validateAction = function (obj) {
  10. if (obj.is_guest_image === true || obj.is_guest_image === 'true') {
  11. return false
  12. }
  13. return true
  14. }
  15. const validateActionTooltip = function (obj) {
  16. if (obj.is_guest_image === true || obj.is_guest_image === 'true') {
  17. return i18n.t('compute.text_622')
  18. }
  19. return ''
  20. }
  21. const ownerDomain = obj => this.$store.getters.isAdminMode || obj.domain_id === this.$store.getters.userInfo.projectDomainId
  22. const isOwnerProject = project => project === this.$store.getters.userInfo.projectId || project === this.$store.getters.userInfo.projectName
  23. this.singleActions = [
  24. {
  25. label: i18n.t('compute.text_247'),
  26. permission: 'guestimages_update',
  27. action: obj => {
  28. this.createDialog('ImageEditAttributesDialog', {
  29. data: [obj],
  30. columns: this.columns,
  31. refresh: this.refresh,
  32. })
  33. },
  34. meta: obj => {
  35. if (!validateAction(obj)) {
  36. return {
  37. validate: false,
  38. tooltip: validateActionTooltip(obj),
  39. }
  40. }
  41. if (this.isAdminMode) {
  42. return {
  43. validate: true,
  44. }
  45. } else if (this.isDomainMode) {
  46. return {
  47. validate: ownerDomain(obj),
  48. tooltip: i18n.t('compute.text_623', [i18n.t('dictionary.domain')]),
  49. }
  50. }
  51. return {
  52. validate: isOwnerProject(obj.tenant_id),
  53. tooltip: !isOwnerProject(obj.tenant_id) ? i18n.t('compute.text_623', [i18n.t('dictionary.domain')]) : '',
  54. }
  55. },
  56. },
  57. {
  58. label: i18n.t('compute.text_352'),
  59. actions: obj => {
  60. return [
  61. getSetPublicAction(this, {
  62. name: this.$t('dictionary.guestimage'),
  63. scope: 'project',
  64. resource: 'guestimages',
  65. apiVersion: 'v1',
  66. }, {
  67. permission: 'images_perform_public,guestimages_perform_private',
  68. meta: () => {
  69. function validate (val, tooltip = validateActionTooltip(obj)) {
  70. return {
  71. validate: val,
  72. tooltip,
  73. }
  74. }
  75. if (obj.is_standard) validate(false, i18n.t('compute.text_612'))
  76. if (!validateAction(obj)) validate(false)
  77. // 1、管理后台视图可以对所有镜像进行操作;
  78. // 2、域管理后台视图只能对该域下的镜像进行操作,不能对其他域共享的镜像进行操作;
  79. // 3、项目视图只能对该项目下的镜像进行操作,不能对其他域、其他项目共享的镜像进行操作。
  80. if (this.isAdminMode) validate(true)
  81. if (!this.isAdminMode && !this.isDomainAdmin) validate(this.userInfo.projectId === obj.tenant_id)
  82. if (this.isDomainMode) validate(this.userInfo.projectDomainId === obj.domain_id)
  83. return {
  84. validate: true,
  85. }
  86. },
  87. }),
  88. // {
  89. // label: '设置共享',
  90. // permission: 'images_perform_public',
  91. // action: () => {
  92. // this.createDialog('SetPublicDialog', {
  93. // data: [obj],
  94. // columns: this.columns,
  95. // onManager: this.onManager,
  96. // refresh: this.refresh,
  97. // })
  98. // },
  99. // meta: () => {
  100. // function validate (val, tooltip = validateActionTooltip(obj)) {
  101. // return {
  102. // validate: val,
  103. // tooltip,
  104. // }
  105. // }
  106. // if (obj.is_standard) validate(false, '公共镜像不支持设置')
  107. // if (!validateAction(obj)) validate(false)
  108. // // 1、管理后台视图可以对所有镜像进行操作;
  109. // // 2、域管理后台视图只能对该域下的镜像进行操作,不能对其他域共享的镜像进行操作;
  110. // // 3、项目视图只能对该项目下的镜像进行操作,不能对其他域、其他项目共享的镜像进行操作。
  111. // if (this.isAdminMode) validate(true)
  112. // if (!this.isAdminMode && !this.isDomainAdmin) validate(this.userInfo.projectId === obj.tenant_id)
  113. // if (this.isDomainMode) validate(this.userInfo.projectDomainId === obj.domain_id)
  114. // return {
  115. // validate: true,
  116. // }
  117. // },
  118. // },
  119. {
  120. label: this.$t('compute.perform_change_owner', [this.$t('dictionary.project')]),
  121. permission: 'guestimages_perform_change_owner',
  122. action: () => {
  123. this.createDialog('ChangeOwenrDialog', {
  124. data: [obj],
  125. columns: this.columns,
  126. onManager: this.onManager,
  127. name: this.$t('dictionary.guestimage'),
  128. resource: 'guestimages',
  129. apiVersion: 'v1',
  130. })
  131. },
  132. meta: () => {
  133. const ret = {
  134. validate: true,
  135. tooltip: null,
  136. }
  137. if (!this.isAdminMode && !this.isDomainMode) {
  138. ret.validate = false
  139. ret.tooltip = i18n.t('compute.text_613')
  140. return ret
  141. }
  142. if (obj.is_public) {
  143. ret.validate = false
  144. ret.tooltip = i18n.t('compute.text_614')
  145. return ret
  146. }
  147. return ret
  148. },
  149. },
  150. {
  151. label: i18n.t('common_277'),
  152. permission: 'guestimages_update',
  153. action: (row) => {
  154. this.createDialog('ChangeDisableDelete', {
  155. name: this.$t('dictionary.guestimage'),
  156. columns: this.columns,
  157. onManager: this.onManager,
  158. data: [row],
  159. })
  160. },
  161. },
  162. {
  163. label: i18n.t('compute.perform_delete'),
  164. permission: 'guestimages_delete',
  165. action: () => {
  166. this.createDialog('DeleteResDialog', {
  167. vm: this,
  168. data: [obj],
  169. columns: this.columns,
  170. title: i18n.t('compute.perform_delete'),
  171. name: this.$t('dictionary.guestimage'),
  172. onManager: this.onManager,
  173. alert: this.$t('compute.text_1393'),
  174. requestData: {
  175. override_pending_delete: true,
  176. },
  177. })
  178. },
  179. meta: () => {
  180. if (this.isDomainAdmin && obj.domain_id !== this.userInfo.projectDomainId) {
  181. return {
  182. validate: false,
  183. tooltip: i18n.t('compute.text_625', [i18n.t('dictionary.domain')]),
  184. }
  185. }
  186. if (!validateAction(obj)) return { validate: false, tooltip: validateActionTooltip(obj) }
  187. return this.$getDeleteResult(obj)
  188. },
  189. },
  190. ]
  191. },
  192. },
  193. ]
  194. },
  195. }