singleActions.js 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383
  1. import { mapGetters } from 'vuex'
  2. import i18n from '@/locales'
  3. import { findPlatform, getDisabledProvidersActionMeta } from '@/utils/common/hypervisor'
  4. import { getSetPublicAction } from '@/utils/common/tableActions'
  5. // import { PROVIDER_MAP } from '@/constants'
  6. const disableAdjustConfig = ['private', 'public']
  7. const canAdjustConfig = (obj) => {
  8. const config = {
  9. hasbrand: true,
  10. canUpdate: true,
  11. brand: '',
  12. }
  13. let brand = obj.brand || obj.provider
  14. config.brand = brand
  15. if (!brand) config.hasbrand = false
  16. brand = brand.toLowerCase()
  17. const platform = findPlatform(brand)
  18. if (disableAdjustConfig.includes(platform)) config.canUpdate = false
  19. return config
  20. }
  21. export default {
  22. created () {
  23. this.singleActions = [
  24. {
  25. label: i18n.t('network.text_629'),
  26. permission: 'networks_perform_set_schedtag',
  27. action: (obj) => {
  28. this.createDialog('AdjustLabelDialog', {
  29. data: [obj],
  30. columns: this.columns,
  31. onManager: this.onManager,
  32. })
  33. },
  34. meta: (obj) => {
  35. return {
  36. validate: this.isPower(obj),
  37. }
  38. },
  39. extraMeta: obj => {
  40. return getDisabledProvidersActionMeta({
  41. row: obj,
  42. disabledProviders: ['BingoCloud', 'ZettaKit', 'UIS'],
  43. })
  44. },
  45. },
  46. {
  47. label: i18n.t('network.text_129'),
  48. actions: obj => {
  49. return [
  50. {
  51. label: i18n.t('network.text_606'),
  52. permission: 'networks_update',
  53. action: () => {
  54. this.$router.push({ path: '/network/edit', query: { network_id: obj.id } })
  55. },
  56. meta: () => {
  57. let tooltip = ''
  58. const { brand, canUpdate } = canAdjustConfig(obj)
  59. const platform = findPlatform(brand)
  60. if (!canUpdate) {
  61. tooltip = i18n.t('network.text_649', [i18n.t(`env.${platform}`)])
  62. }
  63. if (this.isPower(obj)) {
  64. const { hasbrand, canUpdate } = canAdjustConfig(obj)
  65. /*
  66. if (obj.cloud_env === 'onpremise' && obj.vpc_id !== 'default') {
  67. return {
  68. validate: false,
  69. tooltip: i18n.t('network.text_650'),
  70. }
  71. }
  72. */
  73. if (!hasbrand) {
  74. return {
  75. validate: true,
  76. tooltip,
  77. }
  78. }
  79. return {
  80. validate: canUpdate,
  81. tooltip,
  82. }
  83. } else {
  84. tooltip = i18n.t('network.text_627')
  85. return {
  86. validate: false,
  87. tooltip,
  88. }
  89. }
  90. },
  91. extraMeta: obj => {
  92. return getDisabledProvidersActionMeta({
  93. row: obj,
  94. disabledProviders: ['BingoCloud'],
  95. })
  96. },
  97. },
  98. {
  99. label: i18n.t('network.text_225', [i18n.t('dictionary.project')]),
  100. permission: 'networks_perform_change_owner',
  101. action: () => {
  102. this.createDialog('ChangeOwenrDialog', {
  103. data: [obj],
  104. columns: this.columns,
  105. name: this.$t('dictionary.network'),
  106. onManager: this.onManager,
  107. resource: 'networks',
  108. })
  109. },
  110. meta: () => {
  111. const ret = {
  112. validate: false,
  113. tooltip: '',
  114. }
  115. if (this.isProjectMode) {
  116. ret.tooltip = i18n.t('monitor.text_9', [this.$t('dictionary.domain')])
  117. return ret
  118. }
  119. if (obj.is_public && obj.public_scope !== 'none') {
  120. ret.validate = false
  121. ret.tooltip = this.$t('common_280')
  122. return ret
  123. }
  124. return {
  125. validate: this.isPower(obj),
  126. }
  127. },
  128. extraMeta: obj => {
  129. return getDisabledProvidersActionMeta({
  130. row: obj,
  131. disabledProviders: ['BingoCloud', 'ZettaKit', 'UIS'],
  132. })
  133. },
  134. },
  135. getSetPublicAction(this, {
  136. name: this.$t('dictionary.network'),
  137. scope: 'project',
  138. resource: 'networks',
  139. }, {
  140. permission: 'networks_perform_public',
  141. extraMeta: obj => {
  142. return getDisabledProvidersActionMeta({
  143. row: obj,
  144. disabledProviders: ['BingoCloud', 'ZettaKit', 'UIS'],
  145. })
  146. },
  147. }),
  148. // {
  149. // label: '设置为共享',
  150. // permission: 'networks_perform_public',
  151. // action: () => {
  152. // this.createDialog('SetPublicDialog', {
  153. // data: [obj],
  154. // title: '设置为共享',
  155. // columns: this.columns,
  156. // onManager: this.onManager,
  157. // })
  158. // },
  159. // meta: () => {
  160. // return {
  161. // validate: this.isPower(obj),
  162. // }
  163. // },
  164. // },
  165. {
  166. label: i18n.t('network.text_632'),
  167. permission: 'networks_perform_split',
  168. action: () => {
  169. this.createDialog('NetworkSplitDialog', {
  170. data: [obj],
  171. columns: this.columns,
  172. onManager: this.onManager,
  173. refresh: this.refresh,
  174. })
  175. },
  176. meta: () => {
  177. if (this.isPower(obj)) {
  178. if (obj.external_id && obj.external_id.length > 0) { // 是公网 IP
  179. return {
  180. validate: false,
  181. tooltip: i18n.t('network.text_624'),
  182. }
  183. } else if (obj.cloud_env === 'onpremise' && obj.vpc_id !== 'default') {
  184. return {
  185. validate: false,
  186. tooltip: i18n.t('network.text_650'),
  187. }
  188. } else {
  189. return {
  190. validate: true,
  191. }
  192. }
  193. } else {
  194. return {
  195. validate: false,
  196. tooltip: i18n.t('network.text_627'),
  197. }
  198. }
  199. },
  200. extraMeta: obj => {
  201. return getDisabledProvidersActionMeta({
  202. row: obj,
  203. disabledProviders: ['BingoCloud', 'ZettaKit', 'UIS'],
  204. })
  205. },
  206. },
  207. {
  208. label: i18n.t('network.text_651'),
  209. permission: 'reservedips_create',
  210. action: (obj) => {
  211. this.createDialog('NetworkReversedIPDialog', {
  212. data: [obj],
  213. columns: this.columns,
  214. title: i18n.t('network.text_651'),
  215. onManager: this.onManager,
  216. })
  217. },
  218. meta: (obj) => {
  219. if (!this.isPower(obj)) {
  220. return {
  221. validate: false,
  222. tooltip: i18n.t('network.text_627'),
  223. }
  224. }
  225. return {
  226. validate: true,
  227. }
  228. },
  229. extraMeta: obj => {
  230. return getDisabledProvidersActionMeta({
  231. row: obj,
  232. disabledProviders: ['BingoCloud', 'ZettaKit', 'UIS'],
  233. })
  234. },
  235. },
  236. {
  237. label: this.$t('common_564'),
  238. permission: 'networks_update',
  239. action: () => {
  240. this.createDialog('NetworkUpdateIsAutoAllocDialog', {
  241. vm: this,
  242. data: [obj],
  243. columns: this.columns,
  244. title: this.$t('common_564'),
  245. name: this.$t('dictionary.network'),
  246. onManager: this.onManager,
  247. })
  248. },
  249. meta: (obj) => {
  250. if (!this.isPower(obj)) {
  251. return {
  252. validate: false,
  253. tooltip: i18n.t('network.text_627'),
  254. }
  255. }
  256. if (obj.server_type !== 'guest' && obj.server_type !== 'hostlocal') {
  257. return {
  258. validate: false,
  259. tooltip: this.$t('common_565'),
  260. }
  261. }
  262. return {
  263. validate: true,
  264. }
  265. },
  266. extraMeta: obj => {
  267. return getDisabledProvidersActionMeta({
  268. row: obj,
  269. disabledProviders: ['BingoCloud', 'ZettaKit', 'UIS'],
  270. })
  271. },
  272. },
  273. {
  274. label: this.$t('network.switch_wire'),
  275. permission: 'networks_perform_switch_wire',
  276. action: () => {
  277. this.createDialog('NetworkSwitchWireDialog', {
  278. title: this.$t('network.switch_wire'),
  279. data: [obj],
  280. columns: this.columns,
  281. onManager: this.onManager,
  282. })
  283. },
  284. meta: () => {
  285. const ret = { validate: obj.is_default_vpc }
  286. if (!ret.validate) {
  287. ret.tooltip = this.$t('network.not_support')
  288. }
  289. return ret
  290. },
  291. extraMeta: obj => {
  292. return getDisabledProvidersActionMeta({
  293. row: obj,
  294. disabledProviders: ['SangFor', 'ZettaKit', 'UIS'],
  295. })
  296. },
  297. },
  298. {
  299. label: i18n.t('network.text_201'),
  300. permission: 'networks_perform_syncstatus',
  301. action: () => {
  302. this.onManager('performAction', {
  303. steadyStatus: ['running', 'ready'],
  304. id: obj.id,
  305. managerArgs: {
  306. action: 'syncstatus',
  307. },
  308. })
  309. },
  310. meta: (obj) => {
  311. if (!this.isPower(obj)) {
  312. return {
  313. validate: false,
  314. tooltip: i18n.t('network.text_627'),
  315. }
  316. }
  317. if (obj.brand?.toLowerCase() === 'onecloud') {
  318. return {
  319. validate: false,
  320. tooltip: i18n.t('network.text_652'),
  321. }
  322. }
  323. return {
  324. validate: true,
  325. }
  326. },
  327. },
  328. {
  329. label: i18n.t('network.text_131'),
  330. permission: 'networks_delete',
  331. action: () => {
  332. this.createDialog('DeleteResDialog', {
  333. vm: this,
  334. data: [obj],
  335. columns: this.columns,
  336. title: i18n.t('network.text_131'),
  337. name: this.$t('dictionary.network'),
  338. onManager: this.onManager,
  339. })
  340. },
  341. meta: () => {
  342. if (!this.isPower(obj)) {
  343. return {
  344. validate: false,
  345. tooltip: i18n.t('network.text_627'),
  346. }
  347. }
  348. if (!this.$getDeleteResult(obj).validate) {
  349. return {
  350. validate: false,
  351. tooltip: this.$getDeleteResult(obj).tooltip,
  352. }
  353. }
  354. return {
  355. validate: true,
  356. tooltip: '',
  357. }
  358. },
  359. extraMeta: obj => {
  360. return getDisabledProvidersActionMeta({
  361. row: obj,
  362. disabledProviders: ['BingoCloud', 'SangFor'],
  363. })
  364. },
  365. },
  366. ]
  367. },
  368. },
  369. ]
  370. },
  371. computed: {
  372. ...mapGetters(['isAdminMode', 'isDomainMode', 'userInfo']),
  373. },
  374. methods: {
  375. isPower (obj) {
  376. if (this.isAdminMode) return true
  377. if (this.isDomainMode) return obj.domain_id === this.userInfo.projectDomainId
  378. return obj.tenant_id === this.userInfo.projectId
  379. },
  380. },
  381. }