diff --git a/components.d.ts b/components.d.ts index 48da1e9..4690207 100644 --- a/components.d.ts +++ b/components.d.ts @@ -10,9 +10,12 @@ export {} declare module '@vue/runtime-core' { export interface GlobalComponents { _index: typeof import('./src/core/components/_sample/_index.vue')['default'] + AAffix: typeof import('ant-design-vue/es')['Affix'] AAvatar: typeof import('ant-design-vue/es')['Avatar'] + ABadge: typeof import('ant-design-vue/es')['Badge'] AButton: typeof import('ant-design-vue/es')['Button'] ACard: typeof import('ant-design-vue/es')['Card'] + ACheckbox: typeof import('ant-design-vue/es')['Checkbox'] AConfigProvider: typeof import('ant-design-vue/es')['ConfigProvider'] ADivider: typeof import('ant-design-vue/es')['Divider'] ADrawer: typeof import('ant-design-vue/es')['Drawer'] @@ -29,9 +32,23 @@ declare module '@vue/runtime-core' { AMenuDivider: typeof import('ant-design-vue/es')['MenuDivider'] AMenuItem: typeof import('ant-design-vue/es')['MenuItem'] AModal: typeof import('ant-design-vue/es')['Modal'] + APagination: typeof import('ant-design-vue/es')['Pagination'] + APopconfirm: typeof import('ant-design-vue/es')['Popconfirm'] + APopover: typeof import('ant-design-vue/es')['Popover'] + ARadio: typeof import('ant-design-vue/es')['Radio'] + ARadioButton: typeof import('ant-design-vue/es')['RadioButton'] + ARadioGroup: typeof import('ant-design-vue/es')['RadioGroup'] + ASelect: typeof import('ant-design-vue/es')['Select'] + ASelectOption: typeof import('ant-design-vue/es')['SelectOption'] ASpin: typeof import('ant-design-vue/es')['Spin'] ASubMenu: typeof import('ant-design-vue/es')['SubMenu'] ASwitch: typeof import('ant-design-vue/es')['Switch'] + ATable: typeof import('ant-design-vue/es')['Table'] + ATabPane: typeof import('ant-design-vue/es')['TabPane'] + ATabs: typeof import('ant-design-vue/es')['Tabs'] + ATextarea: typeof import('ant-design-vue/es')['Textarea'] + ATooltip: typeof import('ant-design-vue/es')['Tooltip'] + AUpload: typeof import('ant-design-vue/es')['Upload'] BaseButton: typeof import('./src/core/components/BaseButton/index.ts')['default'] BaseCard: typeof import('./src/core/components/BaseCard/index.ts')['default'] BaseDatePicker: typeof import('./src/core/components/BaseDatePicker/index.ts')['default'] diff --git a/src/api/user.ts b/src/api/user.ts index 28431d4..65706eb 100644 --- a/src/api/user.ts +++ b/src/api/user.ts @@ -1,6 +1,6 @@ import useAxios from '@core/utils/useAxios' import type { AddId, User } from '@/model/user' -import type { TableInput } from '@core/type/baseTable' +import type { TableInput, TableOutput } from '@core/type/baseTable' import type {Referrals} from '@/model/referrals' import type {Funds} from "@/model/funds"; @@ -23,8 +23,58 @@ export const updateUser = async (id: number, obj: User) => export const deleteUser = async (id: number) => await useAxios.delete(`/admin/user/${id}`) -export const getUserTable = async (params: TableInput) => - await useAxios.post>('/admin/user/table', params) +function isUserTableOutput(data: unknown): data is TableOutput { + if (data === null || typeof data !== 'object') return false + const d = data as Record + return Array.isArray(d.rows) && d.query !== null && typeof d.query === 'object' +} + +/** BaseTable expects `{ rows, query }`; backend may return a plain array or Laravel paginator. */ +export const getUserTable = async (params: TableInput): Promise> => { + const raw = await useAxios.post('/admin/user/table', params) + if (isUserTableOutput(raw)) { + return raw + } + // Laravel LengthAwarePaginator + if (raw && typeof raw === 'object' && Array.isArray((raw as { data?: unknown }).data)) { + const r = raw as { + data: User[] + current_page?: number + per_page?: number + total?: number + } + return { + rows: r.data, + query: { + ...params, + page: r.current_page ?? params.page, + limit: r.per_page ?? params.limit, + total: r.total ?? r.data.length + } + } + } + if (Array.isArray(raw)) { + return { + rows: raw as User[], + query: { ...params, total: raw.length } + } + } + if (raw && typeof raw === 'object' && Array.isArray((raw as { rows?: User[] }).rows)) { + const r = raw as { rows: User[]; total?: number } + return { + rows: r.rows, + query: { ...params, total: r.total ?? r.rows.length } + } + } + const users = (raw as { users?: User[] })?.users + if (Array.isArray(users)) { + return { + rows: users, + query: { ...params, total: users.length } + } + } + return { rows: [], query: { ...params, total: 0 } } +} export const changeUserActivation = async (id: number) => await useAxios.get(`/admin/user/active/${id}`) diff --git a/src/pages/menuPages/users/components/table.vue b/src/pages/menuPages/users/components/table.vue index 2e7c887..dd2d093 100644 --- a/src/pages/menuPages/users/components/table.vue +++ b/src/pages/menuPages/users/components/table.vue @@ -36,16 +36,12 @@ - + + diff --git a/src/pages/menuPages/users/index.vue b/src/pages/menuPages/users/index.vue index e22f479..b79f34d 100644 --- a/src/pages/menuPages/users/index.vue +++ b/src/pages/menuPages/users/index.vue @@ -2,7 +2,14 @@
- + @@ -161,8 +168,8 @@ const resetData = () => { } } -//delete -const deleteItem = (id: number) => confirmDeleteItem('کاربر', id, deleteUser, refreshTable) +//delete — DELETE /admin/user/:id +const deleteManager = (id: number) => confirmDeleteItem('مدیر', id, deleteUser, refreshTable) /* Modal.confirm({ title: 'آیا از حذف کاربر اطمینان دارید؟',