List.vue 6.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229
  1. <template>
  2. <page-list
  3. :list="list"
  4. :columns="columns"
  5. :single-actions="singleActions"
  6. :group-actions="groupActions"
  7. :export-data-options="exportDataOptions" />
  8. </template>
  9. <script>
  10. import WindowsMixin from '@/mixins/windows'
  11. import ListMixin from '@/mixins/list'
  12. import { getEnabledSwitchActions, getSetPublicAction } from '@/utils/common/tableActions'
  13. import SingleActionsMixin from '../mixins/singleActions'
  14. import ColumnsMixin from '../mixins/columns'
  15. import {
  16. ROBOT_TYPES,
  17. } from '../constants'
  18. import {
  19. getStatusFilter,
  20. getEnabledFilter,
  21. getTenantFilter,
  22. getDomainFilter,
  23. getCreatedAtFilter,
  24. } from '@/utils/common/tableFilter'
  25. export default {
  26. name: 'RobotList',
  27. mixins: [WindowsMixin, ListMixin, ColumnsMixin, SingleActionsMixin],
  28. props: {
  29. id: String,
  30. getParams: {
  31. type: Object,
  32. },
  33. },
  34. data () {
  35. return {
  36. list: this.$list.createList(this, {
  37. id: this.id,
  38. resource: 'robots',
  39. apiVersion: 'v1',
  40. getParams: this.getParam,
  41. filterOptions: {
  42. name: {
  43. label: this.$t('system.text_101'),
  44. filter: true,
  45. formatter: val => {
  46. return `name.contains("${val}")`
  47. },
  48. },
  49. status: getStatusFilter('robot'),
  50. enabled: getEnabledFilter(),
  51. type: {
  52. label: this.$t('system.text_48'),
  53. dropdown: true,
  54. items: ROBOT_TYPES,
  55. },
  56. projects: getTenantFilter(),
  57. project_domains: getDomainFilter(),
  58. created_at: getCreatedAtFilter(),
  59. },
  60. hiddenColumns: ['address', 'created_at'],
  61. }),
  62. exportDataOptions: {
  63. items: [
  64. { label: 'ID', key: 'id' },
  65. { label: this.$t('system.text_101'), key: 'name' },
  66. { label: this.$t('table.title.enable_status'), key: 'enabled' },
  67. { label: this.$t('system.text_48'), key: 'type' },
  68. { label: this.$t('res.project'), key: 'tenant' },
  69. { label: this.$t('table.title.share_range'), key: 'public_scope' },
  70. { label: 'Webhook/URL', key: 'address' },
  71. { label: this.$t('common.createdAt'), key: 'created_at' },
  72. ],
  73. },
  74. groupActions: [{
  75. label: this.$t('system.text_128'),
  76. permission: 'robots_create',
  77. action: () => {
  78. this.createDialog('CreateRobotDialog', {
  79. onManager: this.onManager,
  80. refresh: this.refresh,
  81. })
  82. },
  83. meta: () => {
  84. return {
  85. buttonType: 'primary',
  86. }
  87. },
  88. }, {
  89. label: this.$t('system.text_166'),
  90. actions: () => {
  91. return [
  92. getSetPublicAction(this, {
  93. name: this.$t('system.robot'),
  94. scope: 'project',
  95. resource: 'robots',
  96. apiVersion: 'v1',
  97. }, {
  98. permission: 'robots_perform_public',
  99. meta: (row) => {
  100. const ret = {
  101. validate: true,
  102. tooltip: null,
  103. }
  104. if (this.list.selectedItems.some(item => !this.isPower(item))) {
  105. ret.validate = false
  106. ret.tooltip = this.$t('system.robot.shared')
  107. return ret
  108. }
  109. return ret
  110. },
  111. }),
  112. {
  113. label: this.$t('compute.perform_change_owner', [this.$t('dictionary.project')]),
  114. permission: 'robots_perform_change_owner',
  115. action: () => {
  116. this.createDialog('ChangeOwenrDialog', {
  117. data: this.list.selectedItems,
  118. columns: this.columns,
  119. onManager: this.onManager,
  120. name: this.$t('system.robot'),
  121. resource: 'robots',
  122. apiVersion: 'v1',
  123. })
  124. },
  125. meta: (row) => {
  126. const ret = {
  127. validate: true,
  128. tooltip: null,
  129. }
  130. if (this.list.selectedItems.some(item => !this.isPower(item))) {
  131. ret.validate = false
  132. ret.tooltip = this.$t('system.robot.shared')
  133. return ret
  134. }
  135. return ret
  136. },
  137. },
  138. ...getEnabledSwitchActions(this, undefined, ['robots_perform_enable', 'robots_perform_disable'], {
  139. resourceName: this.$t('system.robot'),
  140. metas: [
  141. () => {
  142. const ret = {
  143. validate: true,
  144. tooltip: null,
  145. }
  146. if (this.list.selectedItems.some(item => !this.isPower(item))) {
  147. ret.validate = false
  148. ret.tooltip = this.$t('system.robot.shared')
  149. return ret
  150. }
  151. return ret
  152. },
  153. () => {
  154. const ret = {
  155. validate: true,
  156. tooltip: null,
  157. }
  158. if (this.list.selectedItems.some(item => !this.isPower(item))) {
  159. ret.validate = false
  160. ret.tooltip = this.$t('system.robot.shared')
  161. return ret
  162. }
  163. return ret
  164. },
  165. ],
  166. }),
  167. {
  168. label: this.$t('system.text_129'),
  169. permission: 'robots_delete',
  170. action: () => {
  171. this.createDialog('DeleteResDialog', {
  172. vm: this,
  173. data: this.list.selectedItems,
  174. columns: this.columns,
  175. title: this.$t('system.text_129'),
  176. name: this.$t('system.robot'),
  177. onManager: this.onManager,
  178. })
  179. },
  180. meta: () => {
  181. const ret = {
  182. validate: true,
  183. tooltip: null,
  184. }
  185. if (this.list.selectedItems.some(item => !this.isPower(item))) {
  186. ret.validate = false
  187. ret.tooltip = this.$t('system.robot.shared')
  188. return ret
  189. }
  190. return this.$getDeleteResult(this.list.selectedItems)
  191. },
  192. },
  193. ]
  194. },
  195. meta: () => {
  196. return {
  197. validate: !!this.list.selectedItems.length,
  198. }
  199. },
  200. }],
  201. }
  202. },
  203. created () {
  204. this.initSidePageTab('detail')
  205. this.list.fetchData()
  206. },
  207. methods: {
  208. getParam () {
  209. const ret = {
  210. ...this.getParams,
  211. details: true,
  212. }
  213. return ret
  214. },
  215. handleOpenSidepage (row) {
  216. this.sidePageTriggerHandle(this, 'RobotSidePage', {
  217. id: row.id,
  218. resource: 'robots',
  219. apiVersion: 'v1',
  220. getParams: this.getParam,
  221. }, {
  222. list: this.list,
  223. })
  224. },
  225. },
  226. }
  227. </script>