singleActions.js 6.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186
  1. import { mapGetters } from 'vuex'
  2. import { disableDeleteAction } from '@/utils/common/tableActions'
  3. import i18n from '@/locales'
  4. import { checkReadOnly } from '../utils'
  5. export default {
  6. created () {
  7. this.singleActions = [
  8. {
  9. label: i18n.t('network.text_201'),
  10. permission: 'natgateways_perform_syncstatus',
  11. action: obj => {
  12. this.onManager('performAction', {
  13. steadyStatus: ['available'],
  14. id: obj.id,
  15. managerArgs: {
  16. action: 'syncstatus',
  17. },
  18. })
  19. },
  20. meta: (obj) => {
  21. // const ret = checkReadOnly(obj, i18n.t('network.text_201'))
  22. // if (!ret.validate) return ret
  23. if (!this.isOwner(obj)) {
  24. return {
  25. validate: false,
  26. tooltip: i18n.t('network.text_627'),
  27. }
  28. }
  29. return {
  30. validate: true,
  31. }
  32. },
  33. },
  34. {
  35. label: i18n.t('network.text_129'),
  36. actions: (obj) => {
  37. const { status } = obj
  38. const isAvailable = status.toLowerCase() === 'available'
  39. const notAvailableTip = !isAvailable ? i18n.t('network.instance.not.available.tooltip') : null
  40. return [
  41. {
  42. label: i18n.t('network.expired_release'),
  43. permission: 'natgateways_perform_postpaid_expire',
  44. action: () => {
  45. this.createDialog('SetDurationDialog', {
  46. data: [obj],
  47. alert: this.$t('network.text_764'),
  48. columns: this.columns,
  49. onManager: this.onManager,
  50. name: this.$t('dictionary.nat'),
  51. refresh: this.refresh,
  52. })
  53. },
  54. meta: () => {
  55. const ret = checkReadOnly(obj, i18n.t('network.expired_release'))
  56. if (!ret.validate) return ret
  57. if (obj.billing_type === 'prepaid') {
  58. ret.validate = false
  59. ret.tooltip = i18n.t('network.nat.prepaid.unsupported')
  60. return ret
  61. }
  62. if (!this.isOwner(obj)) {
  63. return {
  64. validate: false,
  65. tooltip: i18n.t('network.text_627'),
  66. }
  67. }
  68. return ret
  69. },
  70. },
  71. {
  72. label: i18n.t('network.renew'),
  73. permission: 'natgateways_perform_renew',
  74. action: () => {
  75. this.createDialog('RenewDialog', {
  76. name: this.$t('dictionary.nat'),
  77. data: [obj],
  78. alert: this.$t('network.text_765'),
  79. columns: this.columns,
  80. onManager: this.onManager,
  81. refresh: this.refresh,
  82. })
  83. },
  84. meta: () => {
  85. const ret = checkReadOnly(obj, i18n.t('network.renew'))
  86. if (!ret.validate) return ret
  87. if (obj.billing_type === 'postpaid') {
  88. ret.validate = false
  89. ret.tooltip = i18n.t('network.nat.postpaid.unsupported')
  90. return ret
  91. }
  92. if (!this.isOwner(obj)) {
  93. return {
  94. validate: false,
  95. tooltip: i18n.t('network.text_627'),
  96. }
  97. }
  98. return ret
  99. },
  100. },
  101. {
  102. label: i18n.t('network.auto.renew'),
  103. permission: 'natgateways_perform_set_auto_renew',
  104. action: () => {
  105. this.createDialog('AutoRenewDialog', {
  106. name: i18n.t('dictionary.nat'),
  107. data: [obj],
  108. alert: this.$t('network.text_766'),
  109. columns: this.columns,
  110. onManager: this.onManager,
  111. refresh: this.refresh,
  112. })
  113. },
  114. meta: () => {
  115. const isPrepaid = obj.billing_type === 'prepaid'
  116. const validate = (isAvailable && isPrepaid)
  117. const ret = checkReadOnly(obj, i18n.t('network.auto.renew'))
  118. if (!ret.validate) return ret
  119. if (!this.isOwner(obj)) {
  120. return {
  121. validate: false,
  122. tooltip: i18n.t('network.text_627'),
  123. }
  124. }
  125. return {
  126. validate: validate,
  127. tooltip: notAvailableTip || (!isPrepaid ? i18n.t('network.nat.postpaid.unsupported') : null),
  128. }
  129. },
  130. },
  131. disableDeleteAction(this, {
  132. name: this.$t('dictionary.nat'),
  133. permission: 'natgateways_update',
  134. hidden: () => {
  135. if (!this.isOwner(obj)) {
  136. return {
  137. validate: false,
  138. tooltip: i18n.t('network.text_627'),
  139. }
  140. }
  141. },
  142. }),
  143. {
  144. label: i18n.t('network.text_131'),
  145. permission: 'natgateways_delete',
  146. action: () => {
  147. this.createDialog('DeleteResDialog', {
  148. vm: this,
  149. title: i18n.t('network.text_131'),
  150. name: this.$t('dictionary.nat'),
  151. data: [obj],
  152. columns: this.columns,
  153. onManager: this.onManager,
  154. requestData: { force: true },
  155. refresh: this.refresh,
  156. })
  157. },
  158. meta: () => {
  159. const ret = checkReadOnly(obj, i18n.t('network.text_131'))
  160. if (!ret.validate) return ret
  161. if (!this.isOwner(obj)) {
  162. return {
  163. validate: false,
  164. tooltip: i18n.t('network.text_627'),
  165. }
  166. }
  167. return this.$getDeleteResult(obj)
  168. },
  169. },
  170. ]
  171. },
  172. },
  173. ]
  174. },
  175. computed: {
  176. ...mapGetters(['isAdminMode', 'isDomainMode', 'userInfo']),
  177. },
  178. methods: {
  179. isOwner (obj) {
  180. if (this.isAdminMode) return true
  181. if (this.isDomainMode) return obj.domain_id === this.userInfo.projectDomainId
  182. return false
  183. },
  184. },
  185. }