Detail.vue 8.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258
  1. <template>
  2. <detail
  3. :data="data"
  4. :onManager="onManager"
  5. :base-info="baseInfo"
  6. :extra-info="extraInfo"
  7. :nameRules="[{ required: true, message: this.$t('common.text00042') }]"
  8. :hiddenKeys="['tenant']"
  9. status-module="cloudaccount" />
  10. </template>
  11. <script>
  12. import XLSX from 'xlsx'
  13. import { getBrandTableColumn, getEnabledTableColumn, getStatusTableColumn } from '@/utils/common/tableColumn'
  14. import { getUserTagColumn, getExtTagColumn } from '@/utils/common/detailColumn'
  15. import { findPlatform } from '@/utils/common/hypervisor'
  16. import WindowsMixin from '@/mixins/windows'
  17. import { hasMeterService } from '@/utils/auth'
  18. import {
  19. getAccessUrlTableColumn,
  20. getBalanceTableColumn,
  21. getGuestCountTableColumn,
  22. getHostCountTableColumn,
  23. getPublicScopeTableColumn,
  24. getResourceMatchProjectTableColumn,
  25. getBlockResourceTableColumn,
  26. } from '../utils/columns'
  27. export default {
  28. name: 'CloudaccountDetail',
  29. mixins: [WindowsMixin],
  30. props: {
  31. onManager: {
  32. type: Function,
  33. required: true,
  34. },
  35. data: {
  36. type: Object,
  37. required: true,
  38. },
  39. columns: {
  40. type: Array,
  41. required: true,
  42. },
  43. },
  44. data () {
  45. return {
  46. discount: 0,
  47. discountLoaded: false,
  48. clearPermissionsLoading: false,
  49. permissionColumns: [
  50. {
  51. field: 'name',
  52. width: '30%',
  53. title: this.$t('cloudenv.Service'),
  54. formatter: ({ row }) => {
  55. return this.$te(`dictionary.res.${row.name}`) ? this.$t(`dictionary.res.${row.name}`) : row.name
  56. },
  57. },
  58. {
  59. field: 'permissions',
  60. title: this.$t('cloudenv.lake_of_permissions'),
  61. slots: {
  62. default: ({ row }, h) => {
  63. const { permissions = [] } = row
  64. const ret = []
  65. permissions.map(key => {
  66. ret.push(<a-tag class="mb-1 mt-1">{key}</a-tag>)
  67. })
  68. return ret
  69. },
  70. },
  71. },
  72. ],
  73. baseInfo: [
  74. getUserTagColumn({ onManager: this.onManager, resource: 'cloudaccount', columns: () => this.columns, tipName: this.$t('cloudenv.text_12') }),
  75. getExtTagColumn({ onManager: this.onManager, resource: 'cloudaccount', columns: () => this.columns, tipName: this.$t('cloudenv.text_12') }),
  76. getResourceMatchProjectTableColumn({ isEdit: true, editCallback: this.editCallback }),
  77. getBlockResourceTableColumn(),
  78. getPublicScopeTableColumn({ vm: this, resource: 'cloudaccounts' }),
  79. getBrandTableColumn(),
  80. {
  81. field: 'account',
  82. title: this.$t('cloudenv.text_94'),
  83. slots: {
  84. default: ({ row }) => {
  85. return [
  86. <div class='text-truncate'>
  87. <list-body-cell-wrap copy row={ row } field='account' title={ row.account } />
  88. </div>,
  89. ]
  90. },
  91. },
  92. },
  93. {
  94. field: 'account_id',
  95. title: this.$t('cloudenv.text_94') + 'ID',
  96. slots: {
  97. default: ({ row }) => {
  98. return [
  99. <div class='text-truncate'>
  100. <list-body-cell-wrap copy row={ row } field='account_id' title={ row.account_id } />
  101. </div>,
  102. ]
  103. },
  104. },
  105. },
  106. {
  107. field: 'proxy_setting.name',
  108. title: this.$t('cloudenv.text_14'),
  109. slots: {
  110. default: ({ row }) => {
  111. if (row.proxy_setting) {
  112. const { id, name } = row.proxy_setting
  113. return [
  114. <div class='text-truncate'>
  115. <side-page-trigger name="ProxysettingSidePage" id={id} list={this.list} vm={this}>{name}</side-page-trigger>
  116. </div>,
  117. ]
  118. }
  119. return '-'
  120. },
  121. },
  122. },
  123. getEnabledTableColumn(),
  124. getStatusTableColumn({ statusModule: 'enabled', field: 'saml_auth', title: this.$t('cloudenv.ssh_authentication') }),
  125. {
  126. field: 'read_only',
  127. title: this.$t('cloudenv.read_only'),
  128. formatter: ({ row }) => {
  129. return row.read_only ? this.$t('scope.text_251') : this.$t('scope.text_252')
  130. },
  131. },
  132. {
  133. field: 'last_sync',
  134. title: this.$t('cloudenv.text_103'),
  135. formatter: ({ row }) => {
  136. return this.$moment(row.last_sync).format()
  137. },
  138. },
  139. ],
  140. extraInfo: [
  141. {
  142. title: this.$t('cloudenv.text_317'),
  143. items: [
  144. getAccessUrlTableColumn(),
  145. getStatusTableColumn({ statusModule: 'cloudaccountHealthStatus', title: this.$t('cloudenv.text_93'), field: 'health_status' }),
  146. {
  147. field: 'discount',
  148. title: this.$t('cloudaccount.table.title.discount'),
  149. slots: {
  150. default: () => {
  151. if (!hasMeterService()) return '-'
  152. if (!this.discountLoaded) {
  153. return [<a-icon type='loading' style='font-size: 12px;' class='primary-color' />]
  154. }
  155. return [<span>{ (this.discount * 100).toFixed(2) }%</span>]
  156. },
  157. },
  158. hidden: () => findPlatform(this.data.brand.toLowerCase()) !== 'public',
  159. },
  160. getBalanceTableColumn(),
  161. getGuestCountTableColumn(),
  162. getHostCountTableColumn(),
  163. ],
  164. },
  165. {
  166. title: this.$t('cloudenv.text_329'),
  167. hidden: () => !this.lakeOfPermissionsData.length,
  168. items: [
  169. {
  170. title: this.$t('common.action'),
  171. field: 'action',
  172. slots: {
  173. default: ({ row }, h) => {
  174. return [<a-button type="link" style="height:21px;padding: 0" disabled={!this.lakeOfPermissionsData.length} loading={this.clearPermissionsLoading} onClick={this.clearPermissions.bind(this)}>{this.$t('cloudenv.clear_lake_of_permissions')}</a-button>,
  175. <a-button type="link" class="ml-3" style="height:21px;padding: 0" disabled={!this.lakeOfPermissionsData.length} onClick={this.exportPermissions.bind(this)}>{this.$t('table.action.export')}</a-button>]
  176. },
  177. },
  178. },
  179. {
  180. title: this.$t('cloudenv.lake_of_permissions'),
  181. field: 'lake_of_permissions',
  182. slots: {
  183. default: ({ row }, h) => {
  184. return [
  185. <vxe-grid class="mb-2" data={ this.lakeOfPermissionsData } columns={ this.permissionColumns } />,
  186. ]
  187. },
  188. },
  189. },
  190. ],
  191. },
  192. ],
  193. }
  194. },
  195. computed: {
  196. lakeOfPermissionsData () {
  197. const { lake_of_permissions } = this.data
  198. if (!lake_of_permissions) return []
  199. const ret = []
  200. for (const key in lake_of_permissions) {
  201. ret.push({ name: key, permissions: lake_of_permissions[key].permissions })
  202. }
  203. return ret
  204. },
  205. },
  206. created () {
  207. this.fetchDiscount()
  208. },
  209. methods: {
  210. editCallback () {
  211. this.createDialog('CloudaccountSetPojectmappingDialog', {
  212. data: [this.data],
  213. columns: this.columns,
  214. onManager: this.onManager,
  215. })
  216. },
  217. async clearPermissions () {
  218. try {
  219. this.clearPermissionsLoading = true
  220. await this.onManager('update', {
  221. id: this.data.id,
  222. managerArgs: {
  223. data: { clean_lake_of_permissions: true },
  224. },
  225. })
  226. } finally {
  227. this.clearPermissionsLoading = false
  228. }
  229. },
  230. exportPermissions () {
  231. const data = [[this.$t('cloudenv.Service'), this.$t('cloudenv.lake_of_permissions')]]
  232. this.lakeOfPermissionsData.map(item => {
  233. data.push([item.name, item.permissions.join(',')])
  234. })
  235. const filename = `${this.data.name}${this.$t('cloudenv.lake_of_permissions')}.xlsx`
  236. const ws_name = 'Sheet1'
  237. const wb = XLSX.utils.book_new()
  238. const ws = XLSX.utils.aoa_to_sheet(data)
  239. XLSX.utils.book_append_sheet(wb, ws, ws_name)
  240. XLSX.writeFile(wb, filename)
  241. },
  242. async fetchDiscount () {
  243. if (!hasMeterService()) return
  244. try {
  245. const response = await this.$http({
  246. method: 'GET',
  247. url: `/v1/prices/discount/${this.data.id}`,
  248. })
  249. this.discount = response.data.discount
  250. } finally {
  251. this.discountLoaded = true
  252. }
  253. },
  254. },
  255. }
  256. </script>