delete admin

This commit is contained in:
2026-05-13 13:31:18 +03:30
parent 2bef84e089
commit f994a61567
4 changed files with 84 additions and 14 deletions
+53 -3
View File
@@ -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<Array<User>>('/admin/user/table', params)
function isUserTableOutput(data: unknown): data is TableOutput<User> {
if (data === null || typeof data !== 'object') return false
const d = data as Record<string, unknown>
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<TableOutput<User>> => {
const raw = await useAxios.post<unknown>('/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}`)
@@ -36,16 +36,12 @@
</template>
<Icon icon="vuesax-linear:edit" color="#4572E9" />
</a-tooltip>
<!-- <a-tooltip
placement="bottom"
class="cursor-pointer"
@click="emits('delete', record.id)"
>
<a-tooltip placement="bottom" class="cursor-pointer" @click="emits('delete', record.id)">
<template #title>
<span>حذف</span>
<span>حذف مدیر</span>
</template>
<Icon icon="vuesax-linear:trash" color="#EB3535" />
</a-tooltip>-->
<Icon icon="vuesax-linear:user-remove" color="#EB3535" />
</a-tooltip>
</div>
</template>
</BaseTable>
+10 -3
View File
@@ -2,7 +2,14 @@
<div>
<!-- <BasicMainCard>-->
<div class="flex w-full h-full">
<tbl ref="table" class="w-full h-full" @info="info" @edit="edit" @add="add" />
<tbl
ref="table"
class="w-full h-full"
@info="info"
@edit="edit"
@add="add"
@delete="deleteManager"
/>
<!-- <BasicMenu :menu="menu" width="13rem" @onChange="tabSelected" />
<component :is="selectedComponent" class="mr-5" />-->
@@ -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: 'آیا از حذف کاربر اطمینان دارید؟',