List.vue 10.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337
  1. <template>
  2. <page-list
  3. show-tag-columns
  4. show-tag-filter
  5. :list="list"
  6. :columns="templateListColumns || columns"
  7. :group-actions="groupActions"
  8. :single-actions="singleActions"
  9. :showSearchbox="showSearchbox"
  10. :show-single-actions="!isTemplate"
  11. :showGroupActions="showGroupActions"
  12. :export-data-options="exportDataOptions"
  13. :show-page="!isTemplate" />
  14. </template>
  15. <script>
  16. import ListMixin from '@/mixins/list'
  17. import WindowsMixin from '@/mixins/windows'
  18. import { getDomainChangeOwnerAction, getSetPublicAction } from '@/utils/common/tableActions'
  19. import { getNameFilter, getProjectDomainFilter, getDescriptionFilter, getCreatedAtFilter, getBrandFilter, getAccountFilter } from '@/utils/common/tableFilter'
  20. import GlobalSearchMixin from '@/mixins/globalSearch'
  21. import { HYPERVISORS } from '@/constants/index'
  22. import ResTemplateListMixin from '@/mixins/resTemplateList'
  23. import { getWiresMergeAction } from '../utils/groupactions'
  24. import SingleActionsMixin from '../mixins/singleActions'
  25. import ColumnsMixin from '../mixins/columns'
  26. import { BAND_WIDTH_OPTION } from '../../../constants'
  27. export default {
  28. name: 'WireList',
  29. mixins: [WindowsMixin, ListMixin, GlobalSearchMixin, ColumnsMixin, SingleActionsMixin, ResTemplateListMixin],
  30. props: {
  31. id: String,
  32. getParams: {
  33. type: Object,
  34. default: () => ({}),
  35. },
  36. cloudEnv: {
  37. type: String,
  38. },
  39. cloudEnvOptions: {
  40. type: Array,
  41. },
  42. },
  43. data () {
  44. const brandFilter = []
  45. const netBrands = getBrandFilter('network_manage_brands')
  46. console.log(netBrands)
  47. let hasOneCloud = false
  48. for (var i = 0; i < netBrands.items.length; i++) {
  49. const testIsPublic = (key) => {
  50. for (var j = 0; j < HYPERVISORS.length; j++) {
  51. if (HYPERVISORS[j].provider === key && HYPERVISORS[j].cloud_env === 'public') {
  52. return true
  53. }
  54. }
  55. return false
  56. }
  57. if (testIsPublic(netBrands.items[i].key)) {
  58. continue
  59. }
  60. if (netBrands.items[i].key === 'OneCloud') {
  61. hasOneCloud = true
  62. }
  63. brandFilter.push(netBrands.items[i])
  64. }
  65. if (!hasOneCloud) {
  66. brandFilter.push({ key: 'OneCloud', label: 'OneCloud' })
  67. }
  68. console.log(brandFilter)
  69. netBrands.items = brandFilter
  70. console.log(netBrands)
  71. return {
  72. expandConfig: {
  73. loadMethod: this.loadDetails,
  74. lazy: true,
  75. },
  76. list: this.$list.createList(this, {
  77. ctx: this,
  78. id: this.id,
  79. resource: 'wires',
  80. getParams: this.getParam,
  81. filterOptions: {
  82. id: {
  83. label: this.$t('table.title.id'),
  84. },
  85. status: {
  86. label: this.$t('network.text_27'),
  87. dropdown: true,
  88. items: [
  89. { label: this.$t('network.text_615'), key: 'available' },
  90. ],
  91. filter: true,
  92. formatter: val => {
  93. return `status.in(${val.map(item => `'${item}'`).join(',')})`
  94. },
  95. },
  96. name: getNameFilter(),
  97. description: getDescriptionFilter(),
  98. bandwidth: {
  99. label: this.$t('network.text_694'),
  100. dropdown: true,
  101. multiple: true,
  102. items: BAND_WIDTH_OPTION.map(({ label, value }) => {
  103. return { label, key: value }
  104. }),
  105. },
  106. vpc: {
  107. label: 'VPC',
  108. },
  109. region: {
  110. label: this.$t('network.text_199'),
  111. },
  112. brand: netBrands,
  113. cloudaccount: getAccountFilter(),
  114. project_domains: getProjectDomainFilter(),
  115. created_at: getCreatedAtFilter(),
  116. },
  117. isTemplate: this.isTemplate,
  118. templateLimit: this.templateLimit,
  119. responseData: this.responseData,
  120. hiddenColumns: ['created_at'],
  121. }),
  122. groupActions: [
  123. {
  124. label: this.$t('network.text_26'),
  125. permission: 'wires_create',
  126. action: () => {
  127. this.createDialog('WireCreateDialog', {
  128. title: this.$t('network.text_26'),
  129. onManager: this.onManager,
  130. })
  131. },
  132. meta: () => ({
  133. buttonType: 'primary',
  134. }),
  135. },
  136. {
  137. label: this.$t('common.batchAction'),
  138. actions: () => {
  139. return [
  140. getWiresMergeAction(this, {
  141. data: this.list.selectedItems,
  142. name: this.$t('network.wire.merge'),
  143. scope: 'domain',
  144. resource: 'wires',
  145. refresh: this.refresh,
  146. }, {
  147. permission: 'wires_perform_merge_from',
  148. }),
  149. getDomainChangeOwnerAction(this, {
  150. name: this.$t('dictionary.wire'),
  151. resource: 'wires',
  152. }, {
  153. permission: 'wires_perform_change_owner',
  154. }),
  155. getSetPublicAction(this, {
  156. name: this.$t('dictionary.wire'),
  157. scope: 'domain',
  158. resource: 'wires',
  159. }, {
  160. permission: 'wires_perform_public',
  161. }),
  162. {
  163. label: this.$t('table.action.set_tag'),
  164. permission: 'wires_perform_set_user_metadata',
  165. action: () => {
  166. this.createDialog('SetTagDialog', {
  167. data: this.list.selectedItems,
  168. columns: this.columns,
  169. onManager: this.onManager,
  170. mode: 'add',
  171. params: {
  172. resources: 'wire',
  173. },
  174. tipName: this.$t('dictionary.hostwire'),
  175. })
  176. },
  177. meta: () => {
  178. if (this.list.selectedItems.some(item => !this.isPower(item))) {
  179. return {
  180. validate: false,
  181. tooltip: this.$t('network.text_627'),
  182. }
  183. }
  184. return {
  185. validate: true,
  186. }
  187. },
  188. },
  189. {
  190. label: this.$t('network.text_131'),
  191. permission: 'wires_delete',
  192. action: () => {
  193. this.createDialog('DeleteResDialog', {
  194. vm: this,
  195. data: this.list.selectedItems,
  196. columns: this.columns,
  197. title: this.$t('network.text_131'),
  198. name: this.$t('dictionary.hostwire'),
  199. onManager: this.onManager,
  200. })
  201. },
  202. meta: () => {
  203. if (this.list.selectedItems.some(item => !this.isPower(item))) {
  204. return {
  205. validate: false,
  206. tooltip: this.$t('network.text_627'),
  207. }
  208. }
  209. return {
  210. validate: this.list.allowDelete(),
  211. }
  212. },
  213. },
  214. ]
  215. },
  216. meta: () => {
  217. return {
  218. validate: this.list.selectedItems && this.list.selectedItems.length,
  219. }
  220. },
  221. },
  222. ],
  223. }
  224. },
  225. computed: {
  226. exportDataOptions () {
  227. return {
  228. title: this.$t('network.text_571'),
  229. downloadType: 'local',
  230. items: [
  231. { label: 'ID', key: 'id' },
  232. { field: 'external_id', title: this.$t('table.title.external_id') },
  233. ...this.columns,
  234. ],
  235. }
  236. },
  237. },
  238. watch: {
  239. cloudEnv (val) {
  240. switch (val) {
  241. case 'onpremise':
  242. this.envParams = { is_on_premise: true }
  243. break
  244. case 'private':
  245. this.envParams = { private_cloud: true }
  246. break
  247. default:
  248. this.envParams = {}
  249. }
  250. const params = this.list.getParams
  251. delete params.is_on_premise
  252. delete params.private_cloud
  253. delete params.public_cloud
  254. this.list.getParams = { ...params, ...this.envParams }
  255. this.list.fetchData()
  256. },
  257. },
  258. created () {
  259. this.initSidePageTab('wire-detail')
  260. this.list.fetchData()
  261. },
  262. methods: {
  263. loadDetails ({ row }) {
  264. return new Promise(resolve => {
  265. if (row.wireNetworks && row.wireHosts) {
  266. resolve()
  267. }
  268. this.getDetails(row.id).then(data => {
  269. this.$set(row, 'wireNetworks', data.wireNetworks || [])
  270. this.$set(row, 'wireHosts', data.wireHosts || [])
  271. resolve()
  272. })
  273. })
  274. },
  275. async getDetails (wireId) {
  276. const wireNetworks = await this.getNetworkDetails(wireId)
  277. const wireHosts = await this.getHostDetails(wireId)
  278. return { wireNetworks, wireHosts }
  279. },
  280. async getNetworkDetails (wireId) {
  281. try {
  282. const { data: { data } } = await new this.$Manager('networks').list({
  283. params: {
  284. limit: 0,
  285. wire: wireId,
  286. scope: this.$store.getters.scope,
  287. },
  288. })
  289. return data
  290. } catch (error) {
  291. throw error
  292. }
  293. },
  294. async getHostDetails (wireId) {
  295. try {
  296. const { data: { data } } = await new this.$Manager('hosts').list({
  297. params: {
  298. limit: 0,
  299. wire: wireId,
  300. baremetal: false,
  301. scope: this.$store.getters.scope,
  302. },
  303. })
  304. return data
  305. } catch (error) {
  306. throw error
  307. }
  308. },
  309. isPower (obj) {
  310. if (this.isAdminMode) return true
  311. if (this.isDomainMode) return obj.domain_id === this.userInfo.projectDomainId
  312. return obj.tenant_id === this.userInfo.projectId
  313. },
  314. getParam () {
  315. const ret = {
  316. details: true,
  317. show_emulated: false,
  318. ...this.getParams,
  319. }
  320. return ret
  321. },
  322. handleOpenSidepage (row, tab) {
  323. this.sidePageTriggerHandle(this, 'WireSidePage', {
  324. id: row.id,
  325. resource: 'wires',
  326. getParams: this.getParam,
  327. }, {
  328. list: this.list,
  329. tab,
  330. })
  331. },
  332. },
  333. }
  334. </script>