User.vue 1.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990
  1. <script setup lang="ts">
  2. import { ContentWrap } from '@/components/ContentWrap'
  3. import { useI18n } from '@/hooks/web/useI18n'
  4. import { Table } from '@/components/Table'
  5. import { getUserListApi } from '@/api/login'
  6. import { UserType } from '@/api/login/types'
  7. import { ref, h } from 'vue'
  8. import { ElButton } from 'element-plus'
  9. import { TableColumn, TableSlotDefault } from '@/types/table'
  10. interface Params {
  11. pageIndex?: number
  12. pageSize?: number
  13. }
  14. const { t } = useI18n()
  15. const columns: TableColumn[] = [
  16. {
  17. field: 'index',
  18. label: t('userDemo.index'),
  19. type: 'index'
  20. },
  21. {
  22. field: 'username',
  23. label: t('userDemo.username')
  24. },
  25. {
  26. field: 'password',
  27. label: t('userDemo.password')
  28. },
  29. {
  30. field: 'role',
  31. label: t('userDemo.role')
  32. },
  33. {
  34. field: 'remark',
  35. label: t('userDemo.remark'),
  36. formatter: (row: UserType) => {
  37. return h(
  38. 'span',
  39. row.username === 'admin' ? t('userDemo.remarkMessage1') : t('userDemo.remarkMessage2')
  40. )
  41. }
  42. },
  43. {
  44. field: 'action',
  45. label: t('userDemo.action')
  46. }
  47. ]
  48. const loading = ref(true)
  49. let tableDataList = ref<UserType[]>([])
  50. const getTableList = async (params?: Params) => {
  51. const res = await getUserListApi({
  52. params: params || {
  53. pageIndex: 1,
  54. pageSize: 10
  55. }
  56. })
  57. // .catch(() => {})
  58. // .finally(() => {
  59. // loading.value = false
  60. // })
  61. if (res) {
  62. tableDataList.value = res.data.list
  63. loading.value = false
  64. }
  65. }
  66. getTableList()
  67. const actionFn = (data: TableSlotDefault) => {
  68. console.log(data)
  69. }
  70. </script>
  71. <template>
  72. <ContentWrap :title="t('userDemo.title')" :message="t('userDemo.message')">
  73. <Table :columns="columns" :data="tableDataList" :loading="loading" :selection="false">
  74. <template #action="data">
  75. <ElButton type="primary" @click="actionFn(data as TableSlotDefault)">
  76. {{ t('tableDemo.action') }}
  77. </ElButton>
  78. </template>
  79. </Table>
  80. </ContentWrap>
  81. </template>