| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383 |
- import { mapGetters } from 'vuex'
- import i18n from '@/locales'
- import { findPlatform, getDisabledProvidersActionMeta } from '@/utils/common/hypervisor'
- import { getSetPublicAction } from '@/utils/common/tableActions'
- // import { PROVIDER_MAP } from '@/constants'
- const disableAdjustConfig = ['private', 'public']
- const canAdjustConfig = (obj) => {
- const config = {
- hasbrand: true,
- canUpdate: true,
- brand: '',
- }
- let brand = obj.brand || obj.provider
- config.brand = brand
- if (!brand) config.hasbrand = false
- brand = brand.toLowerCase()
- const platform = findPlatform(brand)
- if (disableAdjustConfig.includes(platform)) config.canUpdate = false
- return config
- }
- export default {
- created () {
- this.singleActions = [
- {
- label: i18n.t('network.text_629'),
- permission: 'networks_perform_set_schedtag',
- action: (obj) => {
- this.createDialog('AdjustLabelDialog', {
- data: [obj],
- columns: this.columns,
- onManager: this.onManager,
- })
- },
- meta: (obj) => {
- return {
- validate: this.isPower(obj),
- }
- },
- extraMeta: obj => {
- return getDisabledProvidersActionMeta({
- row: obj,
- disabledProviders: ['BingoCloud', 'ZettaKit', 'UIS'],
- })
- },
- },
- {
- label: i18n.t('network.text_129'),
- actions: obj => {
- return [
- {
- label: i18n.t('network.text_606'),
- permission: 'networks_update',
- action: () => {
- this.$router.push({ path: '/network/edit', query: { network_id: obj.id } })
- },
- meta: () => {
- let tooltip = ''
- const { brand, canUpdate } = canAdjustConfig(obj)
- const platform = findPlatform(brand)
- if (!canUpdate) {
- tooltip = i18n.t('network.text_649', [i18n.t(`env.${platform}`)])
- }
- if (this.isPower(obj)) {
- const { hasbrand, canUpdate } = canAdjustConfig(obj)
- /*
- if (obj.cloud_env === 'onpremise' && obj.vpc_id !== 'default') {
- return {
- validate: false,
- tooltip: i18n.t('network.text_650'),
- }
- }
- */
- if (!hasbrand) {
- return {
- validate: true,
- tooltip,
- }
- }
- return {
- validate: canUpdate,
- tooltip,
- }
- } else {
- tooltip = i18n.t('network.text_627')
- return {
- validate: false,
- tooltip,
- }
- }
- },
- extraMeta: obj => {
- return getDisabledProvidersActionMeta({
- row: obj,
- disabledProviders: ['BingoCloud'],
- })
- },
- },
- {
- label: i18n.t('network.text_225', [i18n.t('dictionary.project')]),
- permission: 'networks_perform_change_owner',
- action: () => {
- this.createDialog('ChangeOwenrDialog', {
- data: [obj],
- columns: this.columns,
- name: this.$t('dictionary.network'),
- onManager: this.onManager,
- resource: 'networks',
- })
- },
- meta: () => {
- const ret = {
- validate: false,
- tooltip: '',
- }
- if (this.isProjectMode) {
- ret.tooltip = i18n.t('monitor.text_9', [this.$t('dictionary.domain')])
- return ret
- }
- if (obj.is_public && obj.public_scope !== 'none') {
- ret.validate = false
- ret.tooltip = this.$t('common_280')
- return ret
- }
- return {
- validate: this.isPower(obj),
- }
- },
- extraMeta: obj => {
- return getDisabledProvidersActionMeta({
- row: obj,
- disabledProviders: ['BingoCloud', 'ZettaKit', 'UIS'],
- })
- },
- },
- getSetPublicAction(this, {
- name: this.$t('dictionary.network'),
- scope: 'project',
- resource: 'networks',
- }, {
- permission: 'networks_perform_public',
- extraMeta: obj => {
- return getDisabledProvidersActionMeta({
- row: obj,
- disabledProviders: ['BingoCloud', 'ZettaKit', 'UIS'],
- })
- },
- }),
- // {
- // label: '设置为共享',
- // permission: 'networks_perform_public',
- // action: () => {
- // this.createDialog('SetPublicDialog', {
- // data: [obj],
- // title: '设置为共享',
- // columns: this.columns,
- // onManager: this.onManager,
- // })
- // },
- // meta: () => {
- // return {
- // validate: this.isPower(obj),
- // }
- // },
- // },
- {
- label: i18n.t('network.text_632'),
- permission: 'networks_perform_split',
- action: () => {
- this.createDialog('NetworkSplitDialog', {
- data: [obj],
- columns: this.columns,
- onManager: this.onManager,
- refresh: this.refresh,
- })
- },
- meta: () => {
- if (this.isPower(obj)) {
- if (obj.external_id && obj.external_id.length > 0) { // 是公网 IP
- return {
- validate: false,
- tooltip: i18n.t('network.text_624'),
- }
- } else if (obj.cloud_env === 'onpremise' && obj.vpc_id !== 'default') {
- return {
- validate: false,
- tooltip: i18n.t('network.text_650'),
- }
- } else {
- return {
- validate: true,
- }
- }
- } else {
- return {
- validate: false,
- tooltip: i18n.t('network.text_627'),
- }
- }
- },
- extraMeta: obj => {
- return getDisabledProvidersActionMeta({
- row: obj,
- disabledProviders: ['BingoCloud', 'ZettaKit', 'UIS'],
- })
- },
- },
- {
- label: i18n.t('network.text_651'),
- permission: 'reservedips_create',
- action: (obj) => {
- this.createDialog('NetworkReversedIPDialog', {
- data: [obj],
- columns: this.columns,
- title: i18n.t('network.text_651'),
- onManager: this.onManager,
- })
- },
- meta: (obj) => {
- if (!this.isPower(obj)) {
- return {
- validate: false,
- tooltip: i18n.t('network.text_627'),
- }
- }
- return {
- validate: true,
- }
- },
- extraMeta: obj => {
- return getDisabledProvidersActionMeta({
- row: obj,
- disabledProviders: ['BingoCloud', 'ZettaKit', 'UIS'],
- })
- },
- },
- {
- label: this.$t('common_564'),
- permission: 'networks_update',
- action: () => {
- this.createDialog('NetworkUpdateIsAutoAllocDialog', {
- vm: this,
- data: [obj],
- columns: this.columns,
- title: this.$t('common_564'),
- name: this.$t('dictionary.network'),
- onManager: this.onManager,
- })
- },
- meta: (obj) => {
- if (!this.isPower(obj)) {
- return {
- validate: false,
- tooltip: i18n.t('network.text_627'),
- }
- }
- if (obj.server_type !== 'guest' && obj.server_type !== 'hostlocal') {
- return {
- validate: false,
- tooltip: this.$t('common_565'),
- }
- }
- return {
- validate: true,
- }
- },
- extraMeta: obj => {
- return getDisabledProvidersActionMeta({
- row: obj,
- disabledProviders: ['BingoCloud', 'ZettaKit', 'UIS'],
- })
- },
- },
- {
- label: this.$t('network.switch_wire'),
- permission: 'networks_perform_switch_wire',
- action: () => {
- this.createDialog('NetworkSwitchWireDialog', {
- title: this.$t('network.switch_wire'),
- data: [obj],
- columns: this.columns,
- onManager: this.onManager,
- })
- },
- meta: () => {
- const ret = { validate: obj.is_default_vpc }
- if (!ret.validate) {
- ret.tooltip = this.$t('network.not_support')
- }
- return ret
- },
- extraMeta: obj => {
- return getDisabledProvidersActionMeta({
- row: obj,
- disabledProviders: ['SangFor', 'ZettaKit', 'UIS'],
- })
- },
- },
- {
- label: i18n.t('network.text_201'),
- permission: 'networks_perform_syncstatus',
- action: () => {
- this.onManager('performAction', {
- steadyStatus: ['running', 'ready'],
- id: obj.id,
- managerArgs: {
- action: 'syncstatus',
- },
- })
- },
- meta: (obj) => {
- if (!this.isPower(obj)) {
- return {
- validate: false,
- tooltip: i18n.t('network.text_627'),
- }
- }
- if (obj.brand?.toLowerCase() === 'onecloud') {
- return {
- validate: false,
- tooltip: i18n.t('network.text_652'),
- }
- }
- return {
- validate: true,
- }
- },
- },
- {
- label: i18n.t('network.text_131'),
- permission: 'networks_delete',
- action: () => {
- this.createDialog('DeleteResDialog', {
- vm: this,
- data: [obj],
- columns: this.columns,
- title: i18n.t('network.text_131'),
- name: this.$t('dictionary.network'),
- onManager: this.onManager,
- })
- },
- meta: () => {
- if (!this.isPower(obj)) {
- return {
- validate: false,
- tooltip: i18n.t('network.text_627'),
- }
- }
- if (!this.$getDeleteResult(obj).validate) {
- return {
- validate: false,
- tooltip: this.$getDeleteResult(obj).tooltip,
- }
- }
- return {
- validate: true,
- tooltip: '',
- }
- },
- extraMeta: obj => {
- return getDisabledProvidersActionMeta({
- row: obj,
- disabledProviders: ['BingoCloud', 'SangFor'],
- })
- },
- },
- ]
- },
- },
- ]
- },
- computed: {
- ...mapGetters(['isAdminMode', 'isDomainMode', 'userInfo']),
- },
- methods: {
- isPower (obj) {
- if (this.isAdminMode) return true
- if (this.isDomainMode) return obj.domain_id === this.userInfo.projectDomainId
- return obj.tenant_id === this.userInfo.projectId
- },
- },
- }
|