List.vue 6.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235
  1. <template>
  2. <page-list
  3. show-tag-filter
  4. show-tag-columns
  5. show-ext-tags
  6. :list="list"
  7. :columns="columns"
  8. :group-actions="groupActions"
  9. :single-actions="singleActions"
  10. :showSearchbox="showSearchbox"
  11. :showGroupActions="showGroupActions"
  12. :export-data-options="exportDataOptions"
  13. :ext-tag-params="{ service: 'identity' }" />
  14. </template>
  15. <script>
  16. import ListMixin from '@/mixins/list'
  17. import WindowsMixin from '@/mixins/windows'
  18. import { getEnabledFilter, getProjectDomainFilter, getDescriptionFilter, getCreatedAtFilter } from '@/utils/common/tableFilter'
  19. import { getEnabledSwitchActions } from '@/utils/common/tableActions'
  20. import GlobalSearchMixin from '@/mixins/globalSearch'
  21. import SingleActionsMixin from '../mixins/singleActions'
  22. import ColumnsMixin from '../mixins/columns'
  23. export default {
  24. name: 'UserList',
  25. mixins: [WindowsMixin, ListMixin, GlobalSearchMixin, ColumnsMixin, SingleActionsMixin],
  26. props: {
  27. id: String,
  28. getParams: {
  29. type: Object,
  30. },
  31. isAllowCreate: {
  32. type: Boolean,
  33. default: true,
  34. },
  35. },
  36. data () {
  37. return {
  38. list: this.$list.createList(this, {
  39. id: this.id,
  40. resource: 'users',
  41. apiVersion: 'v1',
  42. getParams: this.getParam,
  43. sortKeys: ['name', 'project_domain'],
  44. filterOptions: {
  45. id: {
  46. label: this.$t('table.title.id'),
  47. },
  48. name: {
  49. label: this.$t('system.text_101'),
  50. filter: true,
  51. formatter: val => {
  52. return `name.contains("${val}")`
  53. },
  54. },
  55. description: getDescriptionFilter(),
  56. displayname: {
  57. label: this.$t('scope.text_245'),
  58. filter: true,
  59. formatter: val => {
  60. return `displayname.contains("${val}")`
  61. },
  62. },
  63. enabled: getEnabledFilter(),
  64. allow_web_console: {
  65. label: this.$t('system.text_475'),
  66. dropdown: true,
  67. items: [
  68. { label: this.$t('system.text_476'), key: true },
  69. { label: this.$t('system.text_477'), key: false },
  70. ],
  71. },
  72. project_domain: getProjectDomainFilter(),
  73. created_at: getCreatedAtFilter(),
  74. idp_id: {
  75. label: this.$t('dictionary.identity_provider'),
  76. },
  77. },
  78. responseData: this.responseData,
  79. hiddenColumns: ['created_at'],
  80. }),
  81. userTotal: 0,
  82. }
  83. },
  84. computed: {
  85. groupActions () {
  86. const actions = [
  87. {
  88. label: this.$t('system.text_128'),
  89. permission: 'users_create',
  90. action: () => {
  91. this.$router.push('/systemuser/create')
  92. },
  93. meta: () => {
  94. const ret = {
  95. buttonType: 'primary',
  96. }
  97. return ret
  98. },
  99. },
  100. {
  101. label: this.$t('system.text_478'),
  102. permission: 'users_create',
  103. action: () => {
  104. this.createDialog('UserImprotDialog', {
  105. onManager: this.onManager,
  106. refresh: this.refresh,
  107. })
  108. },
  109. },
  110. {
  111. label: this.$t('system.text_166'),
  112. actions: () => {
  113. return [
  114. {
  115. label: this.$t('system.text_479'),
  116. permission: 'users_update',
  117. action: () => {
  118. this.createDialog('UserUpdateDialog', {
  119. data: this.list.selectedItems,
  120. columns: this.columns,
  121. onManager: this.onManager,
  122. })
  123. },
  124. },
  125. ...getEnabledSwitchActions(this, undefined, ['users_perform_enable', 'users_perform_disable'], {
  126. actions: [
  127. () => {
  128. this.onManager('batchPerformAction', {
  129. ids: this.list.selectedItems.map(({ id }) => id),
  130. managerArgs: {
  131. action: 'enable',
  132. },
  133. })
  134. },
  135. () => {
  136. this.onManager('batchPerformAction', {
  137. ids: this.list.selectedItems.map(({ id }) => id),
  138. managerArgs: {
  139. action: 'disable',
  140. },
  141. })
  142. },
  143. ],
  144. }),
  145. {
  146. label: this.$t('system.text_129'),
  147. permission: 'users_delete',
  148. action: () => {
  149. this.createDialog('DeleteResDialog', {
  150. vm: this,
  151. data: this.list.selectedItems,
  152. columns: this.columns,
  153. title: this.$t('system.text_480'),
  154. name: this.$t('dictionary.user'),
  155. onManager: this.onManager,
  156. })
  157. },
  158. meta: () => {
  159. return {
  160. validate: this.list.allowDelete(),
  161. }
  162. },
  163. },
  164. ]
  165. },
  166. meta: () => ({
  167. validate: !!this.list.selectedItems.length,
  168. }),
  169. },
  170. ]
  171. if (!this.isAllowCreate) {
  172. actions.shift()
  173. actions.shift()
  174. }
  175. return actions
  176. },
  177. exportDataOptions () {
  178. const ret = {
  179. downloadType: 'local',
  180. title: this.$t('dictionary.user'),
  181. items: [
  182. { key: 'id', label: 'ID' },
  183. ...this.columns,
  184. {
  185. key: 'projects',
  186. label: this.$t('common_494'),
  187. formatter: ({ row }) => {
  188. const { projects = [] } = row
  189. return projects.map(item => item.name).join(',')
  190. },
  191. },
  192. {
  193. key: 'groups',
  194. label: this.$t('common_495'),
  195. formatter: ({ row }) => {
  196. const { groups = [] } = row
  197. return groups.map(item => item.name).join(',')
  198. },
  199. },
  200. ],
  201. }
  202. return ret
  203. },
  204. },
  205. created () {
  206. this.initSidePageTab('user-detail')
  207. this.$bus.$on('RefreshUser', (id) => {
  208. this.list.singleRefresh(id)
  209. })
  210. this.list.fetchData()
  211. },
  212. methods: {
  213. getParam () {
  214. const ret = {
  215. ...this.getParams,
  216. details: true,
  217. }
  218. return ret
  219. },
  220. handleOpenSidepage (row, tab) {
  221. this.sidePageTriggerHandle(this, 'UserSidePage', {
  222. id: row.id,
  223. resource: 'users',
  224. apiVersion: 'v1',
  225. getParams: this.getParam,
  226. }, {
  227. list: this.list,
  228. tab,
  229. })
  230. },
  231. },
  232. }
  233. </script>