singleActions.js 18 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489
  1. import { mapGetters } from 'vuex'
  2. import * as R from 'ramda'
  3. import _ from 'lodash'
  4. import { getSetPublicAction } from '@/utils/common/tableActions'
  5. import i18n from '@/locales'
  6. export default {
  7. computed: {
  8. ...mapGetters(['isAdminMode', 'isDomainMode', 'userInfo']),
  9. },
  10. created () {
  11. const validateAction = function (obj) {
  12. if (obj.is_guest_image === true || obj.is_guest_image === 'true') {
  13. return false
  14. }
  15. return true
  16. }
  17. const validateActionTooltip = function (obj) {
  18. if (obj.is_guest_image === true || obj.is_guest_image === 'true') {
  19. return i18n.t('compute.text_622')
  20. }
  21. return ''
  22. }
  23. const ownerDomain = obj => this.$store.getters.isAdminMode || obj.domain_id === this.$store.getters.userInfo.projectDomainId
  24. const isOwnerProject = project => project === this.$store.getters.userInfo.projectId || project === this.$store.getters.userInfo.projectName
  25. this.singleActions = [
  26. {
  27. label: i18n.t('compute.text_663'),
  28. permission: 'server_create',
  29. action: obj => {
  30. this.createDialog('ImageCreateServerDialog', {
  31. data: [obj],
  32. columns: this.columns,
  33. })
  34. },
  35. meta: obj => {
  36. const ret = {
  37. validate: true,
  38. tooltip: '',
  39. }
  40. if (obj.status !== 'active') {
  41. ret.validate = false
  42. ret.tooltip = i18n.t('compute.text_681')
  43. }
  44. if (!_.get(obj, 'properties.os_type')) {
  45. ret.validate = false
  46. ret.tooltip = i18n.t('compute.image_create_server')
  47. }
  48. return ret
  49. },
  50. hidden: () => this.$isScopedPolicyMenuHidden('image_hidden_menus.image_create_server') || this.$route.path.includes('app-package'),
  51. },
  52. {
  53. label: i18n.t('compute.text_247'),
  54. permission: 'images_update',
  55. action: obj => {
  56. this.createDialog('ImageEditAttributesDialog', {
  57. data: [obj],
  58. columns: this.columns,
  59. refresh: this.refresh,
  60. onManager: this.onManager,
  61. })
  62. },
  63. meta: obj => {
  64. if (!validateAction(obj)) {
  65. return {
  66. validate: false,
  67. tooltip: validateActionTooltip(obj),
  68. }
  69. }
  70. if (this.isAdminMode) {
  71. return {
  72. validate: true,
  73. }
  74. } else if (this.isDomainMode) {
  75. return {
  76. validate: ownerDomain(obj),
  77. tooltip: i18n.t('compute.text_682'),
  78. }
  79. }
  80. return {
  81. validate: isOwnerProject(obj.tenant_id),
  82. tooltip: !isOwnerProject(obj.tenant_id) ? i18n.t('compute.text_623', [i18n.t('dictionary.domain')]) : '',
  83. }
  84. },
  85. hidden: () => this.$isScopedPolicyMenuHidden('image_hidden_menus.image_edit_attribute'),
  86. },
  87. {
  88. label: i18n.t('compute.text_352'),
  89. actions: obj => {
  90. return [
  91. {
  92. label: i18n.t('compute.text_683'),
  93. permission: 'images_update',
  94. action: () => {
  95. this.updateStandard(true, [obj])
  96. },
  97. meta: () => {
  98. let ret = {
  99. validate: false,
  100. tooltip: '',
  101. }
  102. const actions = new Map([
  103. ['admin', () => {
  104. if (this.booleanTransfer(obj.is_standard)) {
  105. ret.tooltip = i18n.t('compute.text_644')
  106. }
  107. return ret
  108. }],
  109. ['domain', () => {
  110. ret.tooltip = i18n.t('compute.text_646')
  111. return ret
  112. }],
  113. ['user', () => {
  114. ret.tooltip = i18n.t('compute.text_646')
  115. return ret
  116. }],
  117. ])
  118. const action = actions.get(this.isAdminMode ? 'admin' : '') || actions.get(this.isDomainMode ? 'domain' : 'user')
  119. ret = action.call(this)
  120. if (ret.tooltip) return ret
  121. return { validate: true, tooltip: '' }
  122. },
  123. hidden: () => this.$isScopedPolicyMenuHidden('image_hidden_menus.iamge_set_public_image'),
  124. },
  125. {
  126. label: i18n.t('compute.text_684'),
  127. permission: 'images_update',
  128. action: () => {
  129. this.updateStandard(false, [obj])
  130. },
  131. meta: () => {
  132. let ret = {
  133. validate: false,
  134. tooltip: '',
  135. }
  136. const actions = new Map([
  137. ['admin', () => {
  138. if (!this.booleanTransfer(obj.is_standard)) {
  139. ret.tooltip = i18n.t('compute.text_685')
  140. }
  141. return ret
  142. }],
  143. ['domain', () => {
  144. ret.tooltip = i18n.t('compute.text_646')
  145. return ret
  146. }],
  147. ['user', () => {
  148. ret.tooltip = i18n.t('compute.text_646')
  149. return ret
  150. }],
  151. ])
  152. const action = actions.get(this.isAdminMode ? 'admin' : '') || actions.get(this.isDomainMode ? 'domain' : 'user')
  153. ret = action.call(this)
  154. if (ret.tooltip) return ret
  155. return { validate: true, tooltip: '' }
  156. },
  157. hidden: () => this.$isScopedPolicyMenuHidden('image_hidden_menus.image_set_customize_image'),
  158. },
  159. getSetPublicAction(this, {
  160. name: this.$route.path.includes('app-package') ? this.$t('dictionary.app_package') : this.$t('dictionary.image'),
  161. scope: 'project',
  162. resource: 'images',
  163. apiVersion: 'v1',
  164. }, {
  165. permission: 'images_perform_public,images_perform_private',
  166. meta: () => {
  167. let ret = {
  168. validate: false,
  169. tooltip: '',
  170. }
  171. const actions = new Map([
  172. ['admin', () => {
  173. if (this.booleanTransfer(obj.is_standard)) {
  174. ret.tooltip = i18n.t('compute.text_644')
  175. }
  176. return ret
  177. }],
  178. ['domain', () => {
  179. if ((obj.shared_domains && obj.shared_domains.length > 0) || obj.public_scope === 'system') {
  180. ret.tooltip = i18n.t('compute.text_686')
  181. return ret
  182. }
  183. if (this.booleanTransfer(obj.is_standard)) {
  184. ret.tooltip = i18n.t('compute.text_644')
  185. return ret
  186. }
  187. return ret
  188. }],
  189. ['user', () => {
  190. ret.tooltip = i18n.t('compute.text_613')
  191. if (!this.booleanTransfer(obj.is_standard) && obj.public_scope === 'system') {
  192. ret.tooltip = i18n.t('compute.text_646')
  193. return ret
  194. }
  195. return ret
  196. }],
  197. ])
  198. const action = actions.get(this.isAdminMode ? 'admin' : '') || actions.get(this.isDomainMode ? 'domain' : 'user')
  199. ret = action.call(this)
  200. if (ret.tooltip) return ret
  201. return { validate: true, tooltip: '' }
  202. },
  203. hidden: () => this.$isScopedPolicyMenuHidden('image_hidden_menus.image_set_public'),
  204. }),
  205. {
  206. label: i18n.t('compute.perform_image_probe'),
  207. permission: 'images_perform_probe',
  208. action: () => {
  209. this.onManager('performAction', {
  210. steadyStatus: ['active'],
  211. id: obj.id,
  212. managerArgs: {
  213. action: 'probe',
  214. },
  215. })
  216. },
  217. meta: () => {
  218. const ret = {
  219. validate: true,
  220. tooltip: null,
  221. }
  222. if (obj.status !== 'active' && obj.status !== 'saved') {
  223. ret.validate = false
  224. ret.tooltip = i18n.t('compute.image_probe_prompt')
  225. }
  226. return ret
  227. },
  228. hidden: () => this.$isScopedPolicyMenuHidden('image_hidden_menus.image_perform_probe'),
  229. },
  230. // {
  231. // label: '设置共享',
  232. // permission: 'images_perform_public',
  233. // action: () => {
  234. // this.createDialog('SetPublicDialog', {
  235. // data: [obj],
  236. // columns: this.columns,
  237. // onManager: this.onManager,
  238. // })
  239. // },
  240. // meta: () => {
  241. // let ret = {
  242. // validate: false,
  243. // tooltip: '',
  244. // }
  245. // const actions = new Map([
  246. // ['admin', () => {
  247. // if (this.booleanTransfer(obj.is_standard)) {
  248. // ret.tooltip = '公共镜像不支持该操作'
  249. // }
  250. // return ret
  251. // }],
  252. // ['domain', () => {
  253. // if (this.booleanTransfer(obj.is_standard)) {
  254. // ret.tooltip = '公共镜像不支持该操作'
  255. // return ret
  256. // }
  257. // if (obj.public_scope === 'system') {
  258. // ret.tooltip = '系统共享镜像不支持该操作'
  259. // return ret
  260. // }
  261. // return ret
  262. // }],
  263. // ['user', () => {
  264. // ret.tooltip = '只有管理员支持该操作'
  265. // if (!this.booleanTransfer(obj.is_standard) && obj.public_scope === 'system') {
  266. // ret.tooltip = '只有系统管理员支持该操作'
  267. // return ret
  268. // }
  269. // return ret
  270. // }],
  271. // ])
  272. // let action = actions.get(this.isAdminMode ? 'admin' : '') || actions.get(this.isDomainMode ? 'domain' : 'user')
  273. // ret = action.call(this)
  274. // if (ret.tooltip) return ret
  275. // return { validate: true, tooltip: '' }
  276. // },
  277. // },
  278. {
  279. label: this.$t('compute.perform_change_owner', [this.$t('dictionary.project')]),
  280. permission: 'images_perform_change_owner',
  281. action: () => {
  282. this.createDialog('ChangeOwenrDialog', {
  283. data: [obj],
  284. columns: this.columns,
  285. onManager: this.onManager,
  286. name: this.$route.path.includes('app-package') ? this.$t('dictionary.app_package') : this.$t('dictionary.image'),
  287. resource: 'images',
  288. apiVersion: 'v1',
  289. })
  290. },
  291. meta: () => {
  292. const ret = {
  293. validate: true,
  294. tooltip: null,
  295. }
  296. if (!this.isAdminMode && !this.isDomainMode) {
  297. ret.validate = false
  298. ret.tooltip = i18n.t('compute.text_613')
  299. return ret
  300. }
  301. if (this.booleanTransfer(obj.is_public)) {
  302. ret.validate = false
  303. ret.tooltip = i18n.t('compute.text_614')
  304. return ret
  305. }
  306. return ret
  307. },
  308. hidden: () => this.$isScopedPolicyMenuHidden('image_hidden_menus.image_change_project'),
  309. },
  310. {
  311. label: this.$t('dashboard.text_105'),
  312. permission: 'images_get',
  313. action: () => {
  314. this.createDialog('ImageExportDialog', {
  315. data: [obj],
  316. columns: this.columns,
  317. onManager: this.onManager,
  318. })
  319. },
  320. meta: () => {
  321. const ret = {
  322. validate: false,
  323. tooltip: '',
  324. }
  325. if (obj.status !== 'active') {
  326. ret.tooltip = this.$t('cloudenv.text_368', [this.$t('status.image')[obj.status]])
  327. return ret
  328. }
  329. if (obj.is_standard === true || obj.is_standard === 'true') {
  330. ret.tooltip = this.$t('compute.standard_not_export')
  331. return ret
  332. }
  333. return { validate: true, tooltip: '' }
  334. },
  335. },
  336. {
  337. label: i18n.t('common_277'),
  338. permission: 'images_delete',
  339. action: (row) => {
  340. this.createDialog('ChangeDisableDelete', {
  341. name: this.$route.path.includes('app-package') ? this.$t('dictionary.app_package') : i18n.t('compute.text_97'),
  342. columns: this.columns,
  343. onManager: this.onManager,
  344. data: [row],
  345. })
  346. },
  347. meta: () => {
  348. let ret = {
  349. validate: false,
  350. tooltip: '',
  351. }
  352. const actions = new Map([
  353. ['admin', () => {
  354. if (this.booleanTransfer(obj.is_standard)) {
  355. ret.tooltip = i18n.t('compute.text_687')
  356. return ret
  357. }
  358. return ret
  359. }],
  360. ['domain', () => {
  361. if (this.booleanTransfer(obj.is_standard)) {
  362. ret.tooltip = i18n.t('compute.text_688')
  363. return ret
  364. }
  365. if (!ownerDomain(obj)) {
  366. ret.tooltip = i18n.t('compute.text_689')
  367. return ret
  368. }
  369. return ret
  370. }],
  371. ['user', () => {
  372. if (this.booleanTransfer(obj.is_standard)) {
  373. ret.tooltip = i18n.t('compute.text_688')
  374. return ret
  375. }
  376. if (!isOwnerProject(obj.tenant_id)) {
  377. ret.tooltip = i18n.t('compute.text_690')
  378. return ret
  379. }
  380. return ret
  381. }],
  382. ])
  383. const action = actions.get(this.isAdminMode ? 'admin' : '') || actions.get(this.isDomainMode ? 'domain' : 'user')
  384. ret = action.call(this)
  385. if (ret.tooltip) return ret
  386. return { validate: true, tooltip: '' }
  387. },
  388. hidden: () => this.$isScopedPolicyMenuHidden('image_hidden_menus.image_set_delete_protection'),
  389. },
  390. {
  391. label: i18n.t('compute.perform_delete'),
  392. permission: 'images_delete',
  393. action: () => {
  394. this.createDialog('DeleteResDialog', {
  395. vm: this,
  396. data: [obj],
  397. alert: this.$t('compute.text_1393'),
  398. columns: this.columns,
  399. title: i18n.t('compute.perform_delete'),
  400. name: this.$route.path.includes('app-package') ? this.$t('dictionary.app_package') : this.$t('dictionary.image'),
  401. onManager: this.onManager,
  402. })
  403. },
  404. meta: () => {
  405. let ret = {
  406. validate: false,
  407. tooltip: '',
  408. }
  409. const actions = new Map([
  410. ['admin', () => {
  411. if (this.booleanTransfer(obj.is_standard)) {
  412. ret.tooltip = i18n.t('compute.text_648')
  413. return ret
  414. }
  415. if (this.booleanTransfer(obj.disable_delete) && this.booleanTransfer(obj.protected)) {
  416. ret.tooltip = i18n.t('common.text00008')
  417. return ret
  418. }
  419. return ret
  420. }],
  421. ['domain', () => {
  422. if (this.booleanTransfer(obj.is_standard)) {
  423. ret.tooltip = i18n.t('compute.text_649')
  424. return ret
  425. }
  426. if (!ownerDomain(obj)) {
  427. ret.tooltip = i18n.t('compute.text_650')
  428. return ret
  429. }
  430. if (this.booleanTransfer(obj.disable_delete) && this.booleanTransfer(obj.protected)) {
  431. ret.tooltip = i18n.t('common.text00008')
  432. return ret
  433. }
  434. return ret
  435. }],
  436. ['user', () => {
  437. if (this.booleanTransfer(obj.is_standard)) {
  438. ret.tooltip = i18n.t('compute.text_649')
  439. return ret
  440. }
  441. if (!isOwnerProject(obj.tenant_id)) {
  442. ret.tooltip = i18n.t('compute.text_651')
  443. return ret
  444. }
  445. if (this.booleanTransfer(obj.disable_delete) && this.booleanTransfer(obj.protected)) {
  446. ret.tooltip = i18n.t('common.text00008')
  447. return ret
  448. }
  449. return ret
  450. }],
  451. ])
  452. const action = actions.get(this.isAdminMode ? 'admin' : '') || actions.get(this.isDomainMode ? 'domain' : 'user')
  453. ret = action.call(this)
  454. if (ret.tooltip) return ret
  455. return this.$getDeleteResult(obj)
  456. },
  457. hidden: () => this.$isScopedPolicyMenuHidden('image_hidden_menus.image_delete'),
  458. },
  459. ]
  460. },
  461. },
  462. ]
  463. },
  464. methods: {
  465. updateStandard (isStandard, selectedItems) {
  466. const params = {
  467. is_standard: isStandard,
  468. }
  469. this.onManager('batchPerformAction', {
  470. id: selectedItems.map(item => item.id),
  471. managerArgs: {
  472. action: 'mark-standard',
  473. data: params,
  474. },
  475. })
  476. },
  477. booleanTransfer (val) {
  478. if (R.is(String, val)) {
  479. return val === 'true'
  480. }
  481. return val
  482. },
  483. },
  484. }