index.vue 3.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135
  1. <script setup lang="ts">
  2. import RegularPage from '@/components/RegularPage.vue'
  3. import { onMounted, ref } from 'vue'
  4. import { useSearchable } from '@/composables/useSearchable'
  5. import type { User, UserSearchFilter } from '@/model/user'
  6. import { searchUsers } from '@/api/user'
  7. import type { BaseTableColumns } from 'tdesign-vue-next'
  8. import RoleSettingDialog from '@/pages/user/components/RoleSettingDialog.vue'
  9. const {
  10. data,
  11. loading,
  12. pagination,
  13. onPageChange,
  14. fetchData
  15. } = useSearchable<UserSearchFilter, User>(searchUsers)
  16. const columns: BaseTableColumns = [
  17. {
  18. title: '用户编号',
  19. colKey: 'id',
  20. width: 100,
  21. },
  22. {
  23. title: '用户名',
  24. colKey: 'name',
  25. width: 100,
  26. },
  27. {
  28. title: '角色',
  29. colKey: 'roles',
  30. width: 100,
  31. },
  32. {
  33. title: '操作',
  34. colKey: 'operation',
  35. width: 100,
  36. },
  37. ]
  38. onMounted(fetchData)
  39. const roleSettingDialogVisible = ref(false)
  40. const selectUser = ref<User | null>(null)
  41. const showRoleSettingDialog = (user: User) => {
  42. selectUser.value = user
  43. roleSettingDialogVisible.value = true
  44. }
  45. const handleRoleSettingSuccess = () => {
  46. fetchData()
  47. roleSettingDialogVisible.value = false
  48. }
  49. </script>
  50. <template>
  51. <RegularPage title="用户管理">
  52. <template #action-area>
  53. <TButton>创建用户</TButton>
  54. </template>
  55. <template #search-area>
  56. <TForm label-align="left" label-width="80px">
  57. <TRow :gutter="[64, 32]">
  58. <TCol :span="3">
  59. <TFormItem label="用户编号">
  60. <TInput placeholder="请输入需要搜索的用户姓名"></TInput>
  61. </TFormItem>
  62. </TCol>
  63. <TCol :span="3">
  64. <TFormItem label="用户名">
  65. <TInput placeholder="请输入需要搜索的用户姓名"></TInput>
  66. </TFormItem>
  67. </TCol>
  68. <TCol :span="3">
  69. <TFormItem label="手机号码">
  70. <TInput placeholder="请输入需要搜索的用户姓名"></TInput>
  71. </TFormItem>
  72. </TCol>
  73. <TCol :span="3">
  74. <TFormItem label="手机号码">
  75. <TInput placeholder="请输入需要搜索的用户姓名"></TInput>
  76. </TFormItem>
  77. </TCol>
  78. <TCol :span="3">
  79. <TFormItem label="角色">
  80. <TSelect placeholder="请选择角色"></TSelect>
  81. </TFormItem>
  82. </TCol>
  83. <TCol :span="3">
  84. <TFormItem label="平台">
  85. <TSelect placeholder="请选择平台"></TSelect>
  86. </TFormItem>
  87. </TCol>
  88. <TCol :span="3">
  89. <TSpace>
  90. <TButton>搜索</TButton>
  91. <TButton theme="default">重置</TButton>
  92. </TSpace>
  93. </TCol>
  94. </TRow>
  95. </TForm>
  96. </template>
  97. <TTable
  98. :loading="loading"
  99. row-key="index"
  100. :data="data"
  101. :columns="columns"
  102. cell-empty-content="-"
  103. :pagination="{ total: pagination.total, current: pagination.page, pageSize: pagination.size, onChange: onPageChange }"
  104. >
  105. <template #roles="{row}">
  106. <TSpace>
  107. <TTag v-for="role in row.roles" :key="role.id" theme="success" variant="light">{{ role.label }}</TTag>
  108. </TSpace>
  109. </template>
  110. <template #operation="{row}">
  111. <TSpace :size="1">
  112. <TButton variant="text" size="small" theme="primary">编辑</TButton>
  113. <TButton variant="text" size="small" theme="primary">设置平台</TButton>
  114. <TButton variant="text" size="small" theme="primary" @click="() => showRoleSettingDialog(row)">设置角色</TButton>
  115. </TSpace>
  116. </template>
  117. </TTable>
  118. <RoleSettingDialog v-model:visible="roleSettingDialogVisible" :user="selectUser" @cancel="roleSettingDialogVisible = false" @success="handleRoleSettingSuccess"></RoleSettingDialog>
  119. </RegularPage>
  120. </template>
  121. <style scoped>
  122. </style>