List.vue 10 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347
  1. <template>
  2. <page-list
  3. show-tag-columns
  4. show-tag-filter
  5. ref="pageList"
  6. :list="list"
  7. :columns="[...(templateListColumns || columns), ...extraColumns]"
  8. :group-actions="groupActions"
  9. :single-actions="customSingleActions || singleActions"
  10. :export-data-options="exportDataOptions"
  11. :showSearchbox="showSearchbox"
  12. :defaultSearchKey="defaultSearchKey"
  13. :showGroupActions="showGroupActions"
  14. :show-single-actions="!isTemplate"
  15. :show-page="!isTemplate" />
  16. </template>
  17. <script>
  18. import * as R from 'ramda'
  19. import { mapGetters } from 'vuex'
  20. import ListMixin from '@/mixins/list'
  21. import WindowsMixin from '@/mixins/windows'
  22. import ResTemplateListMixin from '@/mixins/resTemplateList'
  23. import { getNameFilter, getTenantFilter, getDomainFilter, getRegionFilter, getBrandFilter, getAccountFilter, getDescriptionFilter, getCreatedAtFilter } from '@/utils/common/tableFilter'
  24. import globalSearchMixins from '@/mixins/globalSearch'
  25. import { getSetPublicAction } from '@/utils/common/tableActions'
  26. import expectStatus from '@/constants/expectStatus'
  27. import regexp from '@/utils/regexp'
  28. import SingleActionsMixin from '../mixins/singleActions'
  29. import ColumnsMixin from '../mixins/columns'
  30. import { exportDataOptions } from '../utils'
  31. export default {
  32. name: 'SecgroupList',
  33. mixins: [WindowsMixin, ListMixin, globalSearchMixins, ColumnsMixin, SingleActionsMixin, ResTemplateListMixin],
  34. props: {
  35. id: String,
  36. getParams: {
  37. type: [Function, Object],
  38. default: () => ({
  39. details: true,
  40. }),
  41. },
  42. secgroupType: {
  43. type: String,
  44. default: 'default',
  45. },
  46. frontGroupActions: {
  47. type: Function,
  48. },
  49. showCreateAction: {
  50. type: Boolean,
  51. default: true,
  52. },
  53. hiddenSidepageTabs: {
  54. type: Array,
  55. default: () => ([]),
  56. },
  57. hiddenActions: {
  58. type: Array,
  59. default: () => ([]),
  60. },
  61. hiddenColumns: {
  62. type: Array,
  63. default: () => ([]),
  64. },
  65. customGroupActions: {
  66. type: Array,
  67. },
  68. customSingleActions: {
  69. type: Array,
  70. },
  71. frontGroupMethods: {
  72. type: String,
  73. validator (value) {
  74. return ['coverage', 'append'].includes(value)
  75. },
  76. },
  77. cloudEnv: String,
  78. extraColumns: {
  79. type: Array,
  80. default: () => ([]),
  81. },
  82. },
  83. data () {
  84. return {
  85. list: this.$list.createList(this, {
  86. ctx: this,
  87. id: this.id,
  88. idKey: this.secgroupType === 'network' ? 'guest_network' : 'id',
  89. resource: this.secgroupType === 'network' ? 'guestnetworksecgroups' : 'secgroups',
  90. getParams: this.getParam,
  91. isTemplate: this.isTemplate,
  92. templateLimit: this.templateLimit,
  93. steadyStatus: this.secgroupType === 'network' ? null : Object.values(expectStatus.secgroup).flat(),
  94. filterOptions: {
  95. name: getNameFilter(),
  96. id: {
  97. label: 'ID',
  98. },
  99. description: getDescriptionFilter(),
  100. region: getRegionFilter(),
  101. cloudaccount: getAccountFilter(),
  102. brand: getBrandFilter('brands'),
  103. projects: getTenantFilter(),
  104. project_domains: getDomainFilter(),
  105. created_at: getCreatedAtFilter(),
  106. },
  107. responseData: this.responseData,
  108. hiddenColumns: this.hiddenColumns && this.hiddenColumns.length ? this.hiddenColumns : ['created_at'],
  109. }),
  110. exportDataOptions,
  111. }
  112. },
  113. computed: {
  114. ...mapGetters(['isAdminMode', 'isDomainMode', 'userInfo', 'isProjectMode']),
  115. groupActions () {
  116. const _frontGroupActions = this.frontGroupActions ? this.frontGroupActions.bind(this)() || [] : []
  117. const createAction = {
  118. index: 0,
  119. label: this.$t('compute.perform_create'),
  120. permission: 'secgroups_create',
  121. action: () => {
  122. // this.createDialog('CreateSecgroupDialog', {
  123. // title: this.$t('compute.perform_create'),
  124. // onManager: this.onManager,
  125. // refresh: this.refresh,
  126. // })
  127. this.$router.push({
  128. name: 'SecgroupCreate',
  129. query: {
  130. type: this.cloudEnv,
  131. },
  132. })
  133. },
  134. meta: () => {
  135. return {
  136. buttonType: 'primary',
  137. validate: !this.cloudEnvEmpty,
  138. tooltip: this.cloudEnvEmpty ? this.$t('common.no_platform_available') : '',
  139. }
  140. },
  141. hidden: () => this.hiddenActions.includes('create'),
  142. }
  143. const defaultActions = [
  144. // {
  145. // index: 2,
  146. // label: this.$t('compute.text_991'),
  147. // permission: 'secgroups_perform_add_rules',
  148. // action: () => {
  149. // this.createDialog('AddRulesDialog', {
  150. // data: this.list.selectedItems,
  151. // columns: this.columns,
  152. // title: this.$t('compute.text_991'),
  153. // onManager: this.onManager,
  154. // refresh: this.refresh,
  155. // })
  156. // },
  157. // meta: () => {
  158. // if (this.list.selectedItems.length > 0) {
  159. // if (!this.list.selectedItems.every(item => item.cloud_env === 'onpremise')) {
  160. // return {
  161. // validate: false,
  162. // tooltip: this.$t('compute.idc_secgroup_support_add_rules'),
  163. // }
  164. // }
  165. // if (this.isAdminMode) {
  166. // return {
  167. // validate: true,
  168. // }
  169. // } else {
  170. // return this.$isOwner(this.list.selectedItems)
  171. // }
  172. // }
  173. // return {
  174. // validate: false,
  175. // tooltip: this.$t('compute.text_992'),
  176. // }
  177. // },
  178. // },
  179. getSetPublicAction(this, {
  180. name: this.$t('dictionary.secgroup'),
  181. scope: 'project',
  182. resource: 'secgroups',
  183. }, {
  184. permission: 'secgroups_perform_public',
  185. meta: () => {
  186. return {
  187. validate: this.list.selectedItems.length,
  188. }
  189. },
  190. }),
  191. {
  192. label: this.$t('table.action.set_tag'),
  193. permission: 'secgroups_perform_set_user_metadata',
  194. action: () => {
  195. this.createDialog('SetTagDialog', {
  196. data: this.list.selectedItems,
  197. columns: this.columns,
  198. onManager: this.onManager,
  199. mode: 'add',
  200. params: {
  201. resources: 'secgroup',
  202. },
  203. tipName: this.$t('dictionary.secgroup'),
  204. })
  205. },
  206. meta: () => {
  207. return {
  208. validate: this.list.selectedItems.length,
  209. }
  210. },
  211. },
  212. {
  213. index: 3,
  214. label: this.$t('compute.perform_delete'),
  215. permission: 'secgroups_delete',
  216. action: () => {
  217. this.createDialog('DeleteResDialog', {
  218. vm: this,
  219. data: this.list.selectedItems,
  220. alert: this.$t('compute.text_1395'),
  221. columns: this.columns,
  222. title: this.$t('compute.perform_delete'),
  223. name: this.$t('dictionary.secgroup'),
  224. onManager: this.onManager,
  225. })
  226. },
  227. meta: (obj) => this.$getDeleteResult(this.list.selectedItems),
  228. },
  229. ]
  230. if (this.showCreateAction) {
  231. defaultActions.unshift(createAction)
  232. }
  233. if (this.frontGroupMethods === 'coverage') return _frontGroupActions
  234. return _frontGroupActions.concat(defaultActions).sort((a, b) => a.index - b.index)
  235. },
  236. },
  237. watch: {
  238. 'list.loading': {
  239. handler (val) {
  240. if (this.$refs && this.$refs.pageList && this.$refs.pageList.$refs && this.$refs.pageList.$refs.table && this.$refs.pageList.$refs.table.$refs) {
  241. const grid = this.$refs.pageList.$refs.table.$refs.grid
  242. if (this.list.filter.ip || this.list.filter.ports) {
  243. this.$nextTick(() => {
  244. grid.setAllRowExpand(true)
  245. })
  246. } else {
  247. grid.clearRowExpand()
  248. }
  249. }
  250. },
  251. },
  252. cloudEnv (val) {
  253. this.$nextTick(() => {
  254. this.list.fetchData(0)
  255. })
  256. },
  257. },
  258. created () {
  259. this.initSidePageTab('secgroup-detail')
  260. this.list.fetchData()
  261. this.$bus.$on('secgroup-list-refresh', () => {
  262. this.list.refresh()
  263. })
  264. },
  265. methods: {
  266. getParam () {
  267. const ret = {
  268. ...(R.is(Function, this.getParams) ? this.getParams() : this.getParams),
  269. }
  270. if (this.cloudEnv) ret.cloud_env = this.cloudEnv
  271. if (ret.project_id) {
  272. ret.project_ids = [ret.project_id]
  273. delete ret.project_id
  274. }
  275. return ret
  276. },
  277. handleOpenSidepage (row, tab) {
  278. const params = this.getParam()
  279. delete params.server
  280. this.sidePageTriggerHandle(this, 'SecGroupSidePage', {
  281. id: row.id || row.secgroup_id,
  282. resource: 'secgroups',
  283. getParams: params,
  284. }, {
  285. list: this.list,
  286. hiddenSidepageTabs: this.hiddenSidepageTabs,
  287. hiddenColumns: this.hiddenColumns,
  288. hiddenActions: this.hiddenActions,
  289. tab,
  290. row,
  291. })
  292. },
  293. async loadRules ({ row }) {
  294. let manager = new this.$Manager('secgrouprules')
  295. try {
  296. const response = await manager.list({
  297. params: {
  298. secgroup: row.id,
  299. scope: this.$store.getters.scope,
  300. limit: 0,
  301. },
  302. })
  303. row.rules = response.data.data || []
  304. return response
  305. } catch (error) {
  306. throw error
  307. } finally {
  308. manager = null
  309. }
  310. },
  311. // openEditRulesDialog (rule, row) {
  312. // if (this.isProjectMode && this.userInfo.projectId !== row.tenant_id) {
  313. // return
  314. // }
  315. // if (this.isDomainMode && this.userInfo.domain.id !== row.domain_id) {
  316. // return
  317. // }
  318. // this.createDialog('EditRulesDialog', {
  319. // data: [rule],
  320. // title: 'edit',
  321. // columns: this.columns,
  322. // refresh: () => {
  323. // this.list.refresh()
  324. // },
  325. // })
  326. // },
  327. openAssociateVirtualMachineDialog (obj) {
  328. this.createDialog('AssociateVirtualMachineDialog', {
  329. data: [obj],
  330. refresh: () => {
  331. this.list.refresh()
  332. },
  333. })
  334. },
  335. defaultSearchKey (search) {
  336. if (regexp.isPrefixStr(search)) {
  337. return 'ip'
  338. }
  339. if (regexp.isNumber(search)) {
  340. return 'ports'
  341. }
  342. },
  343. },
  344. }
  345. </script>