List.vue 7.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251
  1. <template>
  2. <page-list
  3. show-tag-config
  4. :columns="templateListColumns || columns"
  5. :group-actions="groupActions"
  6. :list="list"
  7. :single-actions="singleActions"
  8. :showSingleActions="isTemplate ? false : showActions"
  9. :showGroupActions="showActions && showGroupActions"
  10. :export-data-options="exportDataOptions"
  11. :show-tag-columns="true"
  12. :show-tag-columns2="true"
  13. :show-tag-filter="true"
  14. :tag-config-params="tagConfigParams"
  15. :show-page="!isTemplate" />
  16. </template>
  17. <script>
  18. import * as R from 'ramda'
  19. import ListMixin from '@/mixins/list'
  20. import ResTemplateListMixin from '@/mixins/resTemplateList'
  21. import { getNameFilter, getStatusFilter, getTenantFilter, getBrandFilter, getCloudProviderFilter, getAccountFilter, getDescriptionFilter } from '@/utils/common/tableFilter'
  22. import expectStatus from '@/constants/expectStatus'
  23. import WindowsMixin from '@/mixins/windows'
  24. import globalSearchMixins from '@/mixins/globalSearch'
  25. import SingleActionsMixin from '../mixins/singleActions'
  26. import ColumnsMixin from '../mixins/columns'
  27. export default {
  28. name: 'MongoDBList',
  29. mixins: [WindowsMixin, ListMixin, ColumnsMixin, SingleActionsMixin, ResTemplateListMixin, globalSearchMixins],
  30. props: {
  31. id: String,
  32. getParams: {
  33. type: Object,
  34. },
  35. },
  36. data () {
  37. return {
  38. list: this.$list.createList(this, {
  39. ctx: this,
  40. id: this.id,
  41. resource: 'mongodbs',
  42. apiVersion: 'v1',
  43. getParams: this.getParam,
  44. isTemplate: this.isTemplate,
  45. templateLimit: this.templateLimit,
  46. steadyStatus: Object.values(expectStatus.mongodb).flat(),
  47. filterOptions: {
  48. name: getNameFilter(),
  49. external_id: {
  50. label: this.$t('table.title.external_id'),
  51. },
  52. id: {
  53. label: this.$t('table.title.id'),
  54. },
  55. description: getDescriptionFilter(),
  56. status: getStatusFilter('mongodb'),
  57. ip_addr: {
  58. field: 'ip_addr',
  59. label: this.$t('db.text_152'),
  60. filter: true,
  61. formatter: val => {
  62. return `ip_addr.contains(${val})`
  63. },
  64. },
  65. brand: getBrandFilter('readonly_mongodb_brands'),
  66. account: getAccountFilter(),
  67. manager: getCloudProviderFilter(),
  68. region: {
  69. label: this.$t('db.text_40'),
  70. },
  71. projects: getTenantFilter(),
  72. },
  73. responseData: this.responseData,
  74. autoHiddenFilterKey: 'mongodb_hidden_columns',
  75. }),
  76. groupActions: [
  77. {
  78. label: this.$t('db.text_69'),
  79. permission: 'mongodbs_perform_syncstatus',
  80. action: () => {
  81. this.onManager('batchPerformAction', {
  82. steadyStatus: ['running', 'ready'],
  83. managerArgs: {
  84. action: 'syncstatus',
  85. },
  86. })
  87. },
  88. meta: () => {
  89. const selectedLength = this.list.selectedItems.length
  90. const notSelectedTooltip = selectedLength <= 0 ? this.$t('db.text_68') : ''
  91. return {
  92. validate: selectedLength,
  93. tooltip: notSelectedTooltip,
  94. }
  95. },
  96. },
  97. {
  98. label: this.$t('db.text_213'),
  99. actions: (obj) => {
  100. return [
  101. {
  102. label: this.$t('compute.text_283'),
  103. permission: 'mongodbs_perform_set_user_metadata',
  104. action: () => {
  105. this.createDialog('SetTagDialog', {
  106. data: this.list.selectedItems,
  107. columns: this.columns,
  108. onManager: this.onManager,
  109. params: {
  110. resources: 'mongodbs',
  111. },
  112. mode: 'add',
  113. })
  114. },
  115. },
  116. {
  117. label: this.$t('common_277'),
  118. permission: 'mongodbs_update',
  119. action: (row) => {
  120. this.createDialog('ChangeDisableDelete', {
  121. name: this.$t('dictionary.mongodb'),
  122. columns: this.columns,
  123. onManager: this.onManager,
  124. data: this.list.selectedItems,
  125. })
  126. },
  127. },
  128. {
  129. label: this.$t('compute.perform_delete'),
  130. permission: 'mongodbs_perform_delete',
  131. action: () => {
  132. this.createDialog('DeleteResDialog', {
  133. vm: this,
  134. data: this.list.selectedItems,
  135. columns: this.columns,
  136. title: this.$t('compute.text_617'),
  137. name: this.$t('dictionary.mongodb'),
  138. onManager: this.onManager,
  139. })
  140. },
  141. meta: () => {
  142. const ret = {
  143. validate: false,
  144. tooltip: '',
  145. }
  146. const someDisableDelete = this.list.selectedItems.some((item) => {
  147. return this.booleanTransfer(item.disable_delete) && this.booleanTransfer(item.protected)
  148. })
  149. if (someDisableDelete) {
  150. ret.tooltip = this.$t('common.text00008')
  151. return ret
  152. }
  153. return this.$getDeleteResult(this.list.selectedItems)
  154. },
  155. }]
  156. },
  157. meta: () => {
  158. const selectedLength = this.list.selectedItems.length
  159. const notSelectedTooltip = selectedLength <= 0 ? this.$t('db.text_68') : ''
  160. return {
  161. validate: selectedLength,
  162. tooltip: notSelectedTooltip,
  163. }
  164. },
  165. },
  166. ],
  167. tagConfigParams: {
  168. resource: 'mongodbs',
  169. queryTreeId: 'project-tag-value-tree',
  170. },
  171. }
  172. },
  173. computed: {
  174. showActions () {
  175. return !this.$isScopedPolicyMenuHidden('mongodb_hidden_columns.perform_action')
  176. },
  177. exportDataOptions () {
  178. return {
  179. items: [
  180. { label: 'ID', key: 'id' },
  181. ...this.columns,
  182. ],
  183. title: this.$t('dictionary.mongodb'),
  184. downloadType: 'local',
  185. fixedItems: [
  186. { key: 'vcpu_count', label: 'CPU' },
  187. { key: 'disk_size_mb', label: this.$t('table.title.disk') + '(M)' },
  188. { key: 'vmem_size_mb', label: this.$t('table.title.vmem_size') + '(M)' },
  189. { key: 'port', label: 'port' },
  190. ],
  191. }
  192. },
  193. },
  194. created () {
  195. this.list.fetchData()
  196. this.initSidePageTab('mongodb-detail')
  197. },
  198. methods: {
  199. getParam () {
  200. const ret = {
  201. ...this.getParams,
  202. details: true,
  203. }
  204. return ret
  205. },
  206. getSeachStatus () {
  207. const selectedStatus = ['running', 'unknown', 'sync_failed']
  208. const status = []
  209. for (const key in this.$t('status.redis')) {
  210. if (selectedStatus.indexOf(key) > -1) {
  211. status.push({
  212. key,
  213. label: this.$t('status.redis')[key],
  214. })
  215. }
  216. }
  217. return status
  218. },
  219. handleOpenSidepage (row, tab) {
  220. this.sidePageTriggerHandle(this, 'MongoDBSidePage', {
  221. id: row.id,
  222. resource: 'mongodbs',
  223. getParams: {
  224. details: true,
  225. },
  226. steadyStatus: Object.values(expectStatus.mongodb).flat(),
  227. }, {
  228. list: this.list,
  229. tab,
  230. })
  231. },
  232. booleanTransfer (val) {
  233. if (R.is(String, val)) {
  234. return val === 'true'
  235. }
  236. return val
  237. },
  238. },
  239. }
  240. </script>
  241. <style lang="less">
  242. .td-ellipsis{
  243. width: 150px;
  244. word-break: keep-all;
  245. white-space: nowrap;
  246. overflow: hidden;
  247. text-overflow: ellipsis;
  248. }
  249. </style>