feat(admin): implement user level, group and label modules with database, rpc and ui
This commit is contained in:
91
services/admin/userGroupService.uts
Normal file
91
services/admin/userGroupService.uts
Normal file
@@ -0,0 +1,91 @@
|
||||
import { rpcOrNull, rpcOrValue } from '@/services/analytics/rpc.uts'
|
||||
|
||||
export type AdminUserGroup = {
|
||||
id: string
|
||||
name: string
|
||||
remark: string | null
|
||||
status: number
|
||||
created_at: string | null
|
||||
updated_at: string | null
|
||||
deleted_at: string | null
|
||||
}
|
||||
|
||||
export type AdminUserGroupPageResult = {
|
||||
total: number
|
||||
items: Array<AdminUserGroup>
|
||||
}
|
||||
|
||||
export type AdminUserGroupPageFilters = {
|
||||
search?: string | null
|
||||
status?: number | null
|
||||
includeDeleted?: boolean
|
||||
}
|
||||
|
||||
/**
|
||||
* 分页获取用户分组列表
|
||||
*/
|
||||
export async function fetchAdminUserGroupPage(
|
||||
page: number,
|
||||
pageSize: number,
|
||||
filters: AdminUserGroupPageFilters = {}
|
||||
): Promise<AdminUserGroupPageResult> {
|
||||
const res = await rpcOrNull('rpc_admin_user_group_list', {
|
||||
p_page: page,
|
||||
p_page_size: pageSize,
|
||||
p_search: filters.search ?? null,
|
||||
p_status: filters.status ?? null,
|
||||
p_include_deleted: filters.includeDeleted ?? false
|
||||
} as any)
|
||||
|
||||
if (res == null) return { total: 0, items: [] as Array<AdminUserGroup> }
|
||||
|
||||
const anyTotal = (res as any).total
|
||||
const anyItems = (res as any).items
|
||||
|
||||
const total = typeof anyTotal === 'number' ? anyTotal : parseInt(String(anyTotal ?? '0'))
|
||||
const items = Array.isArray(anyItems) ? (anyItems as Array<any>) : ([] as Array<any>)
|
||||
|
||||
return { total, items: items as Array<AdminUserGroup> }
|
||||
}
|
||||
|
||||
export type SaveAdminUserGroupInput = {
|
||||
id?: string | null
|
||||
name: string
|
||||
remark?: string | null
|
||||
status?: number
|
||||
}
|
||||
|
||||
/**
|
||||
* 保存/更新用户分组
|
||||
*/
|
||||
export async function saveAdminUserGroup(input: SaveAdminUserGroupInput): Promise<string | null> {
|
||||
const res = await rpcOrValue('rpc_admin_user_group_save', {
|
||||
p_id: input.id ?? null,
|
||||
p_name: input.name,
|
||||
p_remark: input.remark ?? null,
|
||||
p_status: input.status ?? 1
|
||||
} as any)
|
||||
|
||||
return res != null ? String(res) : null
|
||||
}
|
||||
|
||||
/**
|
||||
* 逻辑删除用户分组
|
||||
*/
|
||||
export async function deleteAdminUserGroup(id: string): Promise<boolean> {
|
||||
const ok = await rpcOrValue('rpc_admin_user_group_delete', {
|
||||
p_id: id
|
||||
} as any)
|
||||
return ok === true
|
||||
}
|
||||
|
||||
/**
|
||||
* 设置用户分组状态
|
||||
*/
|
||||
export async function setAdminUserGroupStatus(id: string, status: number): Promise<boolean> {
|
||||
const ok = await rpcOrValue('rpc_admin_user_group_set_status', {
|
||||
p_id: id,
|
||||
p_status: status
|
||||
} as any)
|
||||
return ok === true
|
||||
}
|
||||
82
services/admin/userLabelService.uts
Normal file
82
services/admin/userLabelService.uts
Normal file
@@ -0,0 +1,82 @@
|
||||
import { rpcOrNull, rpcOrValue } from '@/services/analytics/rpc.uts'
|
||||
|
||||
export type AdminUserLabel = {
|
||||
id: string
|
||||
name: string
|
||||
color: string | null
|
||||
remark: string | null
|
||||
status: number
|
||||
created_at: string | null
|
||||
updated_at: string | null
|
||||
deleted_at: string | null
|
||||
}
|
||||
|
||||
export type AdminUserLabelPageResult = {
|
||||
total: number
|
||||
items: Array<AdminUserLabel>
|
||||
}
|
||||
|
||||
export type AdminUserLabelPageFilters = {
|
||||
search?: string | null
|
||||
status?: number | null
|
||||
includeDeleted?: boolean
|
||||
}
|
||||
|
||||
export async function fetchAdminUserLabelPage(
|
||||
page: number,
|
||||
pageSize: number,
|
||||
filters: AdminUserLabelPageFilters = {}
|
||||
): Promise<AdminUserLabelPageResult> {
|
||||
const res = await rpcOrNull('rpc_admin_user_label_list', {
|
||||
p_page: page,
|
||||
p_page_size: pageSize,
|
||||
p_search: filters.search ?? null,
|
||||
p_status: filters.status ?? null,
|
||||
p_include_deleted: filters.includeDeleted ?? false
|
||||
} as any)
|
||||
|
||||
if (res == null) return { total: 0, items: [] as Array<AdminUserLabel> }
|
||||
|
||||
const anyTotal = (res as any).total
|
||||
const anyItems = (res as any).items
|
||||
|
||||
const total = typeof anyTotal === 'number' ? anyTotal : parseInt(String(anyTotal ?? '0'))
|
||||
const items = Array.isArray(anyItems) ? (anyItems as Array<any>) : ([] as Array<any>)
|
||||
|
||||
return { total, items: items as Array<AdminUserLabel> }
|
||||
}
|
||||
|
||||
export type SaveAdminUserLabelInput = {
|
||||
id?: string | null
|
||||
name: string
|
||||
color?: string | null
|
||||
remark?: string | null
|
||||
status?: number
|
||||
}
|
||||
|
||||
export async function saveAdminUserLabel(input: SaveAdminUserLabelInput): Promise<string | null> {
|
||||
const res = await rpcOrValue('rpc_admin_user_label_save', {
|
||||
p_id: input.id ?? null,
|
||||
p_name: input.name,
|
||||
p_color: input.color ?? null,
|
||||
p_remark: input.remark ?? null,
|
||||
p_status: input.status ?? 1
|
||||
} as any)
|
||||
|
||||
return res != null ? String(res) : null
|
||||
}
|
||||
|
||||
export async function deleteAdminUserLabel(id: string): Promise<boolean> {
|
||||
const ok = await rpcOrValue('rpc_admin_user_label_delete', {
|
||||
p_id: id
|
||||
} as any)
|
||||
return ok === true
|
||||
}
|
||||
|
||||
export async function setAdminUserLabelStatus(id: string, status: number): Promise<boolean> {
|
||||
const ok = await rpcOrValue('rpc_admin_user_label_set_status', {
|
||||
p_id: id,
|
||||
p_status: status
|
||||
} as any)
|
||||
return ok === true
|
||||
}
|
||||
110
services/admin/userLevelService.uts
Normal file
110
services/admin/userLevelService.uts
Normal file
@@ -0,0 +1,110 @@
|
||||
import { rpcOrNull, rpcOrValue } from '@/services/analytics/rpc.uts'
|
||||
|
||||
export type AdminUserLevel = {
|
||||
id: string
|
||||
name: string
|
||||
level_weight: number
|
||||
min_experience: number
|
||||
discount_percent: number
|
||||
is_visible: boolean
|
||||
status: number
|
||||
icon_url?: string | null
|
||||
bg_image_url?: string | null
|
||||
bg_style_json?: any
|
||||
remark?: string | null
|
||||
created_at?: string | null
|
||||
updated_at?: string | null
|
||||
deleted_at?: string | null
|
||||
}
|
||||
|
||||
export type AdminUserLevelPageResult = {
|
||||
total: number
|
||||
items: Array<AdminUserLevel>
|
||||
}
|
||||
|
||||
export type AdminUserLevelPageFilters = {
|
||||
search?: string
|
||||
status?: number | null
|
||||
isVisible?: boolean | null
|
||||
includeDeleted?: boolean
|
||||
}
|
||||
|
||||
export async function fetchAdminUserLevelPage(
|
||||
page: number,
|
||||
pageSize: number,
|
||||
filters: AdminUserLevelPageFilters = {}
|
||||
): Promise<AdminUserLevelPageResult> {
|
||||
const res = await rpcOrNull('rpc_admin_user_level_list', {
|
||||
p_page: page,
|
||||
p_page_size: pageSize,
|
||||
p_search: filters.search ?? null,
|
||||
p_status: filters.status ?? null,
|
||||
p_is_visible: filters.isVisible ?? null,
|
||||
p_include_deleted: filters.includeDeleted ?? false
|
||||
} as any)
|
||||
|
||||
if (res == null) return { total: 0, items: [] as Array<AdminUserLevel> }
|
||||
|
||||
const anyTotal = (res as any).total
|
||||
const anyItems = (res as any).items
|
||||
|
||||
const total = typeof anyTotal === 'number' ? anyTotal : parseInt(String(anyTotal ?? '0'))
|
||||
const items = Array.isArray(anyItems) ? (anyItems as Array<any>) : ([] as Array<any>)
|
||||
|
||||
return { total, items: items as Array<AdminUserLevel> }
|
||||
}
|
||||
|
||||
export type SaveAdminUserLevelInput = {
|
||||
id?: string | null
|
||||
name: string
|
||||
level_weight: number
|
||||
min_experience: number
|
||||
discount_percent: number
|
||||
is_visible: boolean
|
||||
status: number
|
||||
icon_url?: string | null
|
||||
bg_image_url?: string | null
|
||||
bg_style_json?: any
|
||||
remark?: string | null
|
||||
}
|
||||
|
||||
export async function saveAdminUserLevel(input: SaveAdminUserLevelInput): Promise<string | null> {
|
||||
const res = await rpcOrValue('rpc_admin_user_level_save', {
|
||||
p_id: input.id ?? null,
|
||||
p_name: input.name,
|
||||
p_level_weight: input.level_weight,
|
||||
p_min_experience: input.min_experience,
|
||||
p_discount_percent: input.discount_percent,
|
||||
p_is_visible: input.is_visible,
|
||||
p_status: input.status,
|
||||
p_icon_url: input.icon_url ?? null,
|
||||
p_bg_image_url: input.bg_image_url ?? null,
|
||||
p_bg_style_json: input.bg_style_json ?? null,
|
||||
p_remark: input.remark ?? null
|
||||
} as any)
|
||||
|
||||
return res != null ? String(res) : null
|
||||
}
|
||||
|
||||
export async function deleteAdminUserLevel(id: string): Promise<boolean> {
|
||||
const ok = await rpcOrValue('rpc_admin_user_level_delete', {
|
||||
p_id: id
|
||||
} as any)
|
||||
return ok === true
|
||||
}
|
||||
|
||||
export async function setAdminUserLevelVisible(id: string, isVisible: boolean): Promise<boolean> {
|
||||
const ok = await rpcOrValue('rpc_admin_user_level_set_visible', {
|
||||
p_id: id,
|
||||
p_is_visible: isVisible
|
||||
} as any)
|
||||
return ok === true
|
||||
}
|
||||
|
||||
export async function setAdminUserLevelStatus(id: string, status: number): Promise<boolean> {
|
||||
const ok = await rpcOrValue('rpc_admin_user_level_set_status', {
|
||||
p_id: id,
|
||||
p_status: status
|
||||
} as any)
|
||||
return ok === true
|
||||
}
|
||||
Reference in New Issue
Block a user