singleActions.js 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343
  1. import { disableDeleteAction } from '@/utils/common/tableActions'
  2. import { checkSecgroup } from '@DB/views/utils'
  3. import { HYPERVISORS_MAP } from '@/constants'
  4. import i18n from '@/locales'
  5. export default {
  6. created () {
  7. this.singleActions = [
  8. {
  9. label: i18n.t('db.text_69'),
  10. permission: 'redis_elasticcaches_perform_sync',
  11. action: (obj) => {
  12. this.onManager('performAction', {
  13. id: obj.id,
  14. steadyStatus: 'running',
  15. managerArgs: {
  16. action: 'Sync',
  17. },
  18. })
  19. },
  20. },
  21. {
  22. label: i18n.t('db.text_155'),
  23. actions: (obj) => {
  24. const { provider, status } = obj
  25. const isRunning = status.toLowerCase() === 'running'
  26. const notRunninTip = !isRunning ? i18n.t('db.text_156') : null
  27. const isAuthModeOn = obj.auth_mode === 'on'
  28. const setAuthMode = () => {
  29. if (!isAuthModeOn && obj.brand !== 'Huawei') {
  30. return {
  31. label: i18n.t('db.text_304'),
  32. permission: 'redis_elasticcaches_perform_reset_password',
  33. action: () => {
  34. this.createDialog('RedisUpdateAuthModeDialog', {
  35. title: i18n.t('db.text_304'),
  36. data: [obj],
  37. columns: this.columns,
  38. onManager: this.onManager,
  39. refresh: this.refresh,
  40. name: this.$t('dictionary.elasticcaches'),
  41. })
  42. },
  43. meta: () => {
  44. let validate = true
  45. let tooltip = ''
  46. if (!isRunning) {
  47. validate = false
  48. tooltip = notRunninTip
  49. } else if (obj.brand === 'Qcloud' && obj.network_type !== 'vpc') {
  50. validate = false
  51. tooltip = i18n.t('db.text_354')
  52. } else if ((obj.brand === HYPERVISORS_MAP.aws.brand || obj.brand === HYPERVISORS_MAP.azure.brand) && validate) {
  53. validate = false
  54. tooltip = i18n.t('db.text_384', [obj.brand])
  55. }
  56. return {
  57. validate,
  58. tooltip,
  59. }
  60. },
  61. }
  62. }
  63. return {
  64. label: i18n.t('db.text_305'),
  65. permission: 'redis_elasticcaches_perform_update_auth_mode',
  66. action: () => {
  67. this.createDialog('RedisUpdateAuthModeDialog', {
  68. title: i18n.t('db.text_305'),
  69. data: [obj],
  70. columns: this.columns,
  71. onManager: this.onManager,
  72. refresh: this.refresh,
  73. name: this.$t('dictionary.elasticcaches'),
  74. })
  75. },
  76. meta: () => {
  77. let validate = true
  78. let tooltip = ''
  79. if (!isRunning) {
  80. validate = false
  81. tooltip = notRunninTip
  82. } else if (obj.brand === 'Huawei') {
  83. validate = false
  84. tooltip = i18n.t('db.text_306')
  85. } else if (obj.brand === 'Qcloud' && obj.network_type !== 'vpc') {
  86. validate = false
  87. tooltip = i18n.t('db.text_354')
  88. } else if ((obj.brand === HYPERVISORS_MAP.aws.brand || obj.brand === HYPERVISORS_MAP.azure.brand) && validate) {
  89. validate = false
  90. tooltip = i18n.t('db.text_384', [obj.brand])
  91. }
  92. return {
  93. validate,
  94. tooltip,
  95. }
  96. },
  97. }
  98. }
  99. return [
  100. {
  101. label: i18n.t('db.text_70'),
  102. permission: 'redis_elasticcaches_perform_restart',
  103. action: () => {
  104. this.createDialog('RedisRestartdialog', {
  105. title: i18n.t('db.text_70'),
  106. data: [obj],
  107. columns: this.columns,
  108. onManager: this.onManager,
  109. refresh: this.refresh,
  110. name: this.$t('dictionary.elasticcaches'),
  111. })
  112. },
  113. meta: () => {
  114. const ret = {
  115. validate: isRunning && obj.brand !== 'Qcloud',
  116. tooltip: notRunninTip || (obj.brand === 'Qcloud' ? i18n.t('db.text_358') : ''),
  117. }
  118. // aws 和 azure禁用
  119. if ((obj.brand === HYPERVISORS_MAP.aws.brand || obj.brand === HYPERVISORS_MAP.azure.brand) && ret.validate) {
  120. ret.validate = false
  121. ret.tooltip = this.$t('db.text_384', [obj.brand])
  122. }
  123. return ret
  124. },
  125. },
  126. {
  127. label: i18n.t('db.text_159'),
  128. permission: 'redis_elasticcaches_perform_change_spec',
  129. action: () => {
  130. this.createDialog('RedisSetConfigDialog', {
  131. title: i18n.t('db.text_159'),
  132. data: [obj],
  133. columns: this.columns,
  134. onManager: this.onManager,
  135. refresh: this.refresh,
  136. name: this.$t('dictionary.elasticcaches'),
  137. })
  138. },
  139. meta: () => {
  140. const isPrepaid = obj.billing_type === 'prepaid'
  141. // 腾讯云暂不支持调整配置
  142. const isQcloud = obj.brand.toLowerCase() === 'qcloud'
  143. const ret = {
  144. validate: isRunning && !isPrepaid && !isQcloud,
  145. tooltip: notRunninTip || (isPrepaid ? i18n.t('db.text_307') : '') || (isQcloud ? i18n.t('db.text_352') : ''),
  146. }
  147. // aws 和 azure, hcs禁用
  148. if ((obj.brand === HYPERVISORS_MAP.aws.brand || obj.brand === HYPERVISORS_MAP.azure.brand || obj.brand === HYPERVISORS_MAP.hcs.brand) && ret.validate) {
  149. ret.validate = false
  150. ret.tooltip = this.$t('db.text_384', [obj.brand])
  151. }
  152. return ret
  153. },
  154. },
  155. {
  156. label: i18n.t('db.text_239'),
  157. permission: 'redis_elasticcaches_perform_flush_instance',
  158. action: () => {
  159. this.createDialog('RedisClearDataDialog', {
  160. title: i18n.t('db.text_239'),
  161. data: [obj],
  162. columns: this.columns,
  163. onManager: this.onManager,
  164. refresh: this.refresh,
  165. name: this.$t('dictionary.elasticcaches'),
  166. })
  167. },
  168. meta: () => {
  169. const ret = {
  170. validate: isRunning,
  171. tooltip: notRunninTip,
  172. }
  173. // aws 和 azure禁用
  174. if ((obj.brand === HYPERVISORS_MAP.aws.brand || obj.brand === HYPERVISORS_MAP.azure.brand) && ret.validate) {
  175. ret.validate = false
  176. ret.tooltip = this.$t('db.text_384', [obj.brand])
  177. }
  178. return ret
  179. },
  180. },
  181. {
  182. label: provider === 'Huawei' ? i18n.t('db.text_308') : i18n.t('db.text_201'),
  183. permission: 'redis_elasticcaches_perform_reset_password',
  184. action: () => {
  185. this.createDialog('RedisResetPassworddialog', {
  186. title: provider === 'Huawei' ? i18n.t('db.text_308') : i18n.t('db.text_201'),
  187. data: [obj],
  188. columns: this.columns,
  189. onManager: this.onManager,
  190. refresh: this.refresh,
  191. name: this.$t('dictionary.elasticcaches'),
  192. })
  193. },
  194. meta: () => {
  195. const ret = {
  196. validate: isRunning,
  197. tooltip: notRunninTip,
  198. }
  199. // aws 和 azure禁用
  200. if ((obj.brand === HYPERVISORS_MAP.aws.brand || obj.brand === HYPERVISORS_MAP.azure.brand) && ret.validate) {
  201. ret.validate = false
  202. ret.tooltip = this.$t('db.text_384', [obj.brand])
  203. }
  204. return ret
  205. },
  206. },
  207. {
  208. label: i18n.t('db.text_160', [i18n.t('dictionary.project')]),
  209. permission: 'redis_elasticcaches_perform_change_owner',
  210. action: () => {
  211. this.createDialog('ChangeOwenrDialog', {
  212. title: i18n.t('db.text_160', [i18n.t('dictionary.project')]),
  213. data: [obj],
  214. columns: this.columns,
  215. onManager: this.onManager,
  216. refresh: this.refresh,
  217. name: this.$t('dictionary.elasticcaches'),
  218. resource: 'elasticcaches',
  219. })
  220. },
  221. },
  222. {
  223. label: this.$t('compute.text_1116'),
  224. permission: 'server_perform_add_secgroup',
  225. action: () => {
  226. this.createDialog('SetSecgroupDialog', {
  227. vm: this,
  228. data: [obj],
  229. name: this.$t('dictionary.elasticcache'),
  230. resource: 'elasticcache_id',
  231. columns: this.columns,
  232. onManager: this.onManager,
  233. refresh: this.refresh,
  234. })
  235. },
  236. meta: () => {
  237. const ret = checkSecgroup(obj, 'redis', ['Qcloud'])
  238. // aws 和 azure禁用
  239. if ((obj.brand === HYPERVISORS_MAP.aws.brand || obj.brand === HYPERVISORS_MAP.azure.brand) && ret.validate) {
  240. ret.validate = false
  241. ret.tooltip = this.$t('db.text_384', [obj.brand])
  242. }
  243. return ret
  244. },
  245. },
  246. setAuthMode(),
  247. {
  248. label: i18n.t('db.text_71'),
  249. permission: 'redis_elasticcaches_perform_postpaid_expire',
  250. action: () => {
  251. this.createDialog('SetDurationDialog', {
  252. data: [obj],
  253. columns: this.columns,
  254. alert: this.$t('db.text_393'),
  255. onManager: this.onManager,
  256. refresh: this.refresh,
  257. name: this.$t('dictionary.elasticcaches'),
  258. })
  259. },
  260. meta: () => {
  261. const ret = {
  262. validate: false,
  263. tooltip: null,
  264. }
  265. if (obj.billing_type === 'prepaid') {
  266. ret.tooltip = i18n.t('db.text_72')
  267. return ret
  268. }
  269. ret.validate = true
  270. return ret
  271. },
  272. },
  273. {
  274. label: i18n.t('db.text_157'),
  275. permission: 'redis_elasticcaches_perform_renew',
  276. action: () => {
  277. this.createDialog('RedisRenewDialog', {
  278. title: i18n.t('db.text_157'),
  279. name: this.$t('dictionary.elasticcaches'),
  280. data: [obj],
  281. alert: this.$t('network.text_765'),
  282. columns: this.columns,
  283. onManager: this.onManager,
  284. refresh: this.refresh,
  285. })
  286. },
  287. meta: () => {
  288. const isPrepaid = obj.billing_type === 'prepaid'
  289. const validate = (isRunning && isPrepaid)
  290. return {
  291. validate: validate,
  292. tooltip: notRunninTip || (!isPrepaid ? i18n.t('db.text_158') : null),
  293. }
  294. },
  295. },
  296. {
  297. label: i18n.t('db.text_351'),
  298. permission: 'redis_elasticcaches_perform_set_auto_renew',
  299. action: () => {
  300. this.createDialog('AutoRenewDialog', {
  301. name: i18n.t('dictionary.elasticcaches'),
  302. data: [obj],
  303. alert: this.$t('network.text_766'),
  304. columns: this.columns,
  305. onManager: this.onManager,
  306. refresh: this.refresh,
  307. })
  308. },
  309. meta: () => {
  310. const isPrepaid = obj.billing_type === 'prepaid'
  311. const validate = (isRunning && isPrepaid)
  312. return {
  313. validate: validate,
  314. tooltip: notRunninTip || (!isPrepaid ? i18n.t('db.text_158') : null),
  315. }
  316. },
  317. },
  318. disableDeleteAction(Object.assign(this, { permission: 'redis_elasticcaches_update' }), {
  319. name: this.$t('dictionary.elasticcaches'),
  320. }),
  321. {
  322. label: i18n.t('db.text_42'),
  323. permission: 'redis_elasticcaches_delete',
  324. action: () => {
  325. this.createDialog('DeleteResDialog', {
  326. vm: this,
  327. title: i18n.t('db.text_42'),
  328. name: this.$t('dictionary.elasticcaches'),
  329. data: [obj],
  330. columns: this.columns,
  331. onManager: this.onManager,
  332. refresh: this.refresh,
  333. })
  334. },
  335. meta: () => this.$getDeleteResult(obj),
  336. },
  337. ]
  338. },
  339. },
  340. ]
  341. },
  342. }