index.vue 3.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697
  1. <template>
  2. <v-card class="pa-5 card-box">
  3. <div class="mb-3">
  4. <v-btn color="primary" variant="tonal" :disabled="!selected.length" @click="handleAction('all', 0, {})">{{ $t('enterprise.userManagement.enable') }}</v-btn>
  5. <v-btn class="ml-3" color="primary" variant="tonal" :disabled="!selected.length" @click="handleAction('all', 1, {})">{{ $t('enterprise.userManagement.disable') }}</v-btn>
  6. </div>
  7. <v-data-table
  8. v-model="selected"
  9. :headers="headers"
  10. :items="items"
  11. show-select
  12. hide-default-header
  13. height="70vh"
  14. item-value="id"
  15. >
  16. <template #bottom></template>
  17. <template v-slot:item.actions="{ item }">
  18. <v-btn v-if="item.status === '1' && item.userType !== '1'" color="primary" variant="text" @click="handleAction('', 0, item)">{{ $t('enterprise.userManagement.enable') }}</v-btn>
  19. <v-btn v-if="item.status === '0' && item.userType !== '1'" color="primary" variant="text" @click="handleAction('', 1, item)">{{ $t('enterprise.userManagement.disable') }}</v-btn>
  20. </template>
  21. </v-data-table>
  22. <CtPagination
  23. :total="total"
  24. :page="query.pageNo"
  25. :limit="query.pageSize"
  26. @handleChange="handleChangePage"
  27. ></CtPagination>
  28. </v-card>
  29. </template>
  30. <script setup>
  31. defineOptions({ name: 'system-management-user'})
  32. import { ref } from 'vue'
  33. import { timesTampChange } from '@/utils/date'
  34. import { useI18n } from '@/hooks/web/useI18n'
  35. import { getEnterpriseUserList, systemUserEnable, systemUserDisable } from '@/api/enterprise'
  36. import Confirm from '@/plugins/confirm'
  37. import Snackbar from '@/plugins/snackbar'
  38. const { t } = useI18n()
  39. const total = ref(10)
  40. const items = ref([])
  41. const selected = ref([])
  42. const query = ref({
  43. pageNo: 1,
  44. pageSize: 10
  45. })
  46. const headers = [
  47. { title: t('login.username'), key: 'name' },
  48. { title: t('enterprise.userManagement.affiliatedEnterprise'), key: 'enterpriseName' },
  49. { title: t('enterprise.userManagement.phone'), key: 'phone' },
  50. { title: t('enterprise.userManagement.email'), key: 'email' },
  51. { title: t('enterprise.userManagement.accountType'), key: 'userType', value: item => item.userType === '1' ? t('enterprise.userManagement.administrators') : t('enterprise.userManagement.regularUser')},
  52. { title: t('enterprise.userManagement.lastLoginTime'), key: 'loginDate', value: item => timesTampChange(item.loginDate) },
  53. { title: t('common.actions'), key: 'actions' }
  54. ]
  55. // 获取企业用户列表
  56. const getData = async () => {
  57. const { list, total: number } = await getEnterpriseUserList(query.value)
  58. items.value = list
  59. total.value = number
  60. }
  61. getData()
  62. const handleChangePage = (e) => {
  63. query.value.pageNo = e
  64. getData()
  65. }
  66. const apiList = [
  67. { api: systemUserEnable, desc: t('enterprise.userManagement.enableAccount') },
  68. { api: systemUserDisable, desc: t('enterprise.userManagement.disableAccount') }
  69. ]
  70. // 启用、禁用账户
  71. const handleAction = (type, index, item) => {
  72. const ids = type ? selected.value : [item.id]
  73. Confirm(t('common.confirmTitle'), apiList[index].desc).then(async () => {
  74. await apiList[index].api(ids)
  75. Snackbar.success(t('common.operationSuccessful'))
  76. selected.value = []
  77. query.value.pageNo = 1
  78. getData()
  79. })
  80. }
  81. </script>
  82. <style scoped lang="scss">
  83. :deep(.v-table > .v-table__wrapper > table > thead) {
  84. background-color: #f7f8fa !important
  85. }
  86. :deep(.v-selection-control__input) {
  87. color: #767778
  88. }
  89. </style>