User.vue 1.8 KB

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