singleActions.js 7.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213
  1. import expectStatus from '@/constants/expectStatus'
  2. import { PROVIDER_MAP } from '@/constants'
  3. import { getEnabledSwitchActions, disableDeleteAction } from '@/utils/common/tableActions'
  4. import i18n from '@/locales'
  5. import { validateEnabled, validateDisable } from '../utils'
  6. export default {
  7. created () {
  8. this.singleActions = [
  9. {
  10. label: i18n.t('network.text_201'),
  11. permission: 'lb_loadbalancers_perform_syncstatus',
  12. action: obj => {
  13. this.onManager('performAction', {
  14. steadyStatus: ['running', 'ready'],
  15. id: obj.id,
  16. managerArgs: {
  17. action: 'syncstatus',
  18. },
  19. })
  20. },
  21. meta: (obj) => {
  22. if (obj.brand && obj.brand.toLowerCase() === 'onecloud') {
  23. return {
  24. validate: false,
  25. tooltip: i18n.t('network.text_652'),
  26. }
  27. }
  28. return {
  29. validate: true,
  30. }
  31. },
  32. },
  33. {
  34. label: i18n.t('network.text_129'),
  35. actions: (obj) => {
  36. return [
  37. {
  38. label: i18n.t('compute.text_1179'),
  39. permission: 'lb_loadbalancers_perform_associate_eip',
  40. action: () => {
  41. this.createDialog('LbBindEipDialog', {
  42. data: [obj],
  43. columns: this.columns,
  44. onManager: this.onManager,
  45. singleRefresh: this.singleRefresh,
  46. })
  47. },
  48. meta: () => {
  49. const ret = {
  50. validate: true,
  51. }
  52. if (!['OneCloud', 'Huawei'].includes(obj.brand) || obj.eip_mode === 'elastic_ip') {
  53. ret.validate = false
  54. }
  55. if (obj.status === 'disabled') {
  56. ret.validate = false
  57. ret.tooltip = i18n.t('network.text_311')
  58. }
  59. return ret
  60. },
  61. },
  62. {
  63. label: i18n.t('compute.text_1264'),
  64. permission: 'lb_loadbalancers_perform_dissociate_eip',
  65. action: () => {
  66. this.createDialog('LbUnbindEipDialog', {
  67. data: [obj],
  68. columns: this.columns,
  69. onManager: this.onManager,
  70. singleRefresh: this.singleRefresh,
  71. })
  72. },
  73. meta: () => {
  74. const ret = {
  75. validate: true,
  76. }
  77. if (!['OneCloud', 'Huawei'].includes(obj.brand) || obj.eip_mode !== 'elastic_ip' || !obj.eip_id) {
  78. ret.validate = false
  79. }
  80. return ret
  81. },
  82. },
  83. {
  84. label: i18n.t('network.text_253'),
  85. permission: 'lb_loadbalancers_update',
  86. action: () => {
  87. this.createDialog('LbUpdateCluster', {
  88. title: i18n.t('network.text_253'),
  89. data: [obj],
  90. columns: this.columns,
  91. onManager: this.onManager,
  92. refresh: this.refresh,
  93. })
  94. },
  95. meta: () => {
  96. const isOneCloud = obj.brand === 'OneCloud'
  97. return {
  98. validate: isOneCloud,
  99. tooltip: !isOneCloud && i18n.t('network.text_254'),
  100. }
  101. },
  102. },
  103. {
  104. label: this.$t('compute.perform_change_owner', [this.$t('dictionary.project')]),
  105. permission: 'lb_loadbalancers_perform_change_owner',
  106. action: () => {
  107. this.createDialog('ChangeOwenrDialog', {
  108. data: [obj],
  109. custom_columns: this.columns.filter(o => ['name', 'address', 'tenant'].includes(o.field)),
  110. onManager: this.onManager,
  111. name: this.$t('network.text_714'),
  112. resource: 'loadbalancers',
  113. })
  114. },
  115. meta: () => {
  116. const ret = {
  117. validate: false,
  118. tooltip: null,
  119. }
  120. ret.validate = true
  121. return ret
  122. },
  123. },
  124. ...getEnabledSwitchActions(this, undefined, ['lb_loadbalancers_perform_enable', 'lb_loadbalancers_perform_disable'], {
  125. actions: [
  126. (obj) => {
  127. this.onManager('performAction', {
  128. steadyStatus: Object.values(expectStatus.lb).flat(),
  129. id: obj.id,
  130. managerArgs: {
  131. action: 'status',
  132. data: {
  133. id: obj.id,
  134. status: 'enabled',
  135. },
  136. },
  137. })
  138. },
  139. (obj) => {
  140. this.onManager('performAction', {
  141. steadyStatus: Object.values(expectStatus.lb).flat(),
  142. id: obj.id,
  143. managerArgs: {
  144. action: 'status',
  145. data: {
  146. id: obj.id,
  147. status: 'disabled',
  148. },
  149. },
  150. })
  151. },
  152. ],
  153. metas: [
  154. (obj) => {
  155. let ret = {
  156. validate: true,
  157. tooltip: null,
  158. }
  159. ret = this.$isValidateResourceLock(obj)
  160. if (!ret.validate) return ret
  161. return validateEnabled([obj])
  162. },
  163. (obj) => {
  164. let ret = {
  165. validate: true,
  166. tooltip: null,
  167. }
  168. ret = this.$isValidateResourceLock(obj)
  169. if (!ret.validate) return ret
  170. return validateDisable([obj])
  171. },
  172. ],
  173. }),
  174. disableDeleteAction(Object.assign(this, {
  175. permission: 'lb_loadbalancers_update',
  176. }), {
  177. name: this.$t('dictionary.loadbalancer'),
  178. }),
  179. {
  180. label: i18n.t('network.text_131'),
  181. permission: 'lb_loadbalancers_delete',
  182. action: () => {
  183. this.createDialog('DeleteLbDialog', {
  184. vm: this,
  185. title: i18n.t('network.text_131'),
  186. data: [obj],
  187. columns: this.columns,
  188. onManager: this.onManager,
  189. })
  190. },
  191. meta: () => this.$getDeleteResult(obj),
  192. },
  193. ]
  194. },
  195. meta: (obj) => {
  196. let ret = {
  197. validate: true,
  198. tooltip: null,
  199. }
  200. if (obj.provider && (obj.provider.toLowerCase() === 'azure' || obj.provider.toLowerCase() === 'google')) {
  201. return {
  202. validate: false,
  203. tooltip: i18n.t('network.text_309', [PROVIDER_MAP[obj.provider].label]),
  204. }
  205. }
  206. ret = this.$isValidateResourceLock(obj)
  207. return ret
  208. },
  209. },
  210. ]
  211. },
  212. }