feat(admin): implement user level, group and label modules with database, rpc and ui
This commit is contained in:
31
docs/ops/2026-02-10__admin__user-group-db-and-ui.md
Normal file
31
docs/ops/2026-02-10__admin__user-group-db-and-ui.md
Normal file
@@ -0,0 +1,31 @@
|
||||
# 用户分组数据库设计与 RPC (v1)
|
||||
|
||||
## 摘要
|
||||
为“用户分组”功能新增数据库表 `public.ak_user_groups`(支持逻辑删除),并提供管理端 RPC(分页列表/保存/删除/状态切换)。同时启用 RLS,默认仅允许管理端通过 RPC 访问。
|
||||
|
||||
## 动机
|
||||
- 完善用户精细化运营体系,支持对用户进行分组分类。
|
||||
- 替换前端 `pages/mall/admin/user/group.uvue` 中的硬编码 Mock 数据,实现真实数据持久化与完整交互。
|
||||
|
||||
## 影响范围
|
||||
- 数据库:新增 `ak_user_groups` 表及相关索引、RLS 策略、4 个管理端 RPC。
|
||||
- 前端:新增 `userGroupService.uts`,重构 `group.uvue` 页面。
|
||||
|
||||
## 变更清单
|
||||
- 数据库 SQL:
|
||||
- `docs/sql/10_schema/user/ak_user_groups_v1.sql`
|
||||
- `docs/sql/20_rls/user/ak_user_groups_rls_v1.sql`
|
||||
- `docs/sql/30_rpc/user/rpc_admin_user_group_list_v1.sql`
|
||||
- `docs/sql/30_rpc/user/rpc_admin_user_group_save_v1.sql`
|
||||
- `docs/sql/30_rpc/user/rpc_admin_user_group_delete_v1.sql`
|
||||
- `docs/sql/30_rpc/user/rpc_admin_user_group_set_status_v1.sql`
|
||||
- 前端代码:
|
||||
- `services/admin/userGroupService.uts`
|
||||
- `pages/mall/admin/user/group.uvue`
|
||||
|
||||
## 兼容性与风险
|
||||
- 逻辑删除:采用 `deleted_at` 字段,确保历史关联数据不被物理破坏。
|
||||
- 安全性:所有管理操作均通过 `SECURITY DEFINER` RPC 并校验 `admin/analytics` 角色。
|
||||
|
||||
## 验证方式
|
||||
- 执行 SQL 后,通过 Admin 端的“用户分组”菜单进行增删改查操作,观察数据库及界面响应。
|
||||
31
docs/ops/2026-02-10__admin__user-label-db-and-ui.md
Normal file
31
docs/ops/2026-02-10__admin__user-label-db-and-ui.md
Normal file
@@ -0,0 +1,31 @@
|
||||
# 用户标签数据库设计与 RPC (v1)
|
||||
|
||||
## 摘要
|
||||
为“用户标签”功能新增数据库表 `public.ak_user_labels`(支持逻辑删除),并提供管理端 RPC(分页列表/保存/删除/状态切换)。同时启用 RLS,默认仅允许管理端通过 RPC 访问。
|
||||
|
||||
## 动机
|
||||
- 完善用户画像体系,支持对用户进行行为特征标记。
|
||||
- 替换前端 `pages/mall/admin/user/label.uvue` 中的硬编码 Mock 数据,实现真实数据持久化。
|
||||
|
||||
## 影响范围
|
||||
- 数据库:新增 `ak_user_labels` 表及相关索引、RLS 策略、4 个管理端 RPC。
|
||||
- 前端:新增 `userLabelService.uts`,重构 `label.uvue` 页面。
|
||||
|
||||
## 变更清单
|
||||
- 数据库 SQL:
|
||||
- `docs/sql/10_schema/user/ak_user_labels_v1.sql`
|
||||
- `docs/sql/20_rls/user/ak_user_labels_rls_v1.sql`
|
||||
- `docs/sql/30_rpc/user/rpc_admin_user_label_list_v1.sql`
|
||||
- `docs/sql/30_rpc/user/rpc_admin_user_label_save_v1.sql`
|
||||
- `docs/sql/30_rpc/user/rpc_admin_user_label_delete_v1.sql`
|
||||
- `docs/sql/30_rpc/user/rpc_admin_user_label_set_status_v1.sql`
|
||||
- 前端代码:
|
||||
- `services/admin/userLabelService.uts`
|
||||
- `pages/mall/admin/user/label.uvue`
|
||||
|
||||
## 兼容性与风险
|
||||
- 逻辑删除:采用 `deleted_at` 字段,确保历史关联数据不被物理破坏。
|
||||
- 安全性:所有管理操作均通过 `SECURITY DEFINER` RPC 并校验 `admin/analytics` 角色。
|
||||
|
||||
## 验证方式
|
||||
- 执行 SQL 后,通过 Admin 端的“用户标签”菜单进行增删改查操作,观察数据库及界面响应。
|
||||
46
docs/ops/2026-02-10__admin__user-level-db-design.md
Normal file
46
docs/ops/2026-02-10__admin__user-level-db-design.md
Normal file
@@ -0,0 +1,46 @@
|
||||
# 用户等级数据库设计与 RPC(v1)
|
||||
|
||||
## 摘要
|
||||
为“用户等级”功能新增数据库表 `public.ak_user_levels`(支持逻辑删除),并提供 admin 侧管理 RPC(分页列表/保存/删除/状态切换/展示切换)。同时启用 RLS:消费者端仅可读取“启用且展示且未删除”的等级。
|
||||
|
||||
## 动机
|
||||
- 当前 admin 用户等级页面存在硬编码 mock 数据,需要接入数据库。
|
||||
- 统一等级数据口径,为消费者端展示等级提供可靠数据源。
|
||||
|
||||
## 影响范围
|
||||
- 数据库:新增表、索引;启用 RLS 并新增 select policy;新增 5 个 admin RPC。
|
||||
- 前端:后续可通过 `services/` 接入新 RPC,移除 `pages/mall/admin/user/level.uvue` 中 mock。
|
||||
|
||||
## 变更清单
|
||||
- 新增文件:
|
||||
- `docs/sql/10_schema/user/ak_user_levels_v1.sql`
|
||||
- `docs/sql/20_rls/user/ak_user_levels_rls_v1.sql`
|
||||
- `docs/sql/30_rpc/user/rpc_admin_user_level_list_v1.sql`
|
||||
- `docs/sql/30_rpc/user/rpc_admin_user_level_save_v1.sql`
|
||||
- `docs/sql/30_rpc/user/rpc_admin_user_level_delete_v1.sql`
|
||||
- `docs/sql/30_rpc/user/rpc_admin_user_level_set_visible_v1.sql`
|
||||
- `docs/sql/30_rpc/user/rpc_admin_user_level_set_status_v1.sql`
|
||||
|
||||
## 兼容性与风险
|
||||
- consumer 端读取:RLS 仅开放 `anon/authenticated` 对可见/启用/未删除等级的 SELECT;不会暴露删除或禁用的数据。
|
||||
- admin 端管理:通过 `SECURITY DEFINER` RPC 并进行角色鉴权,避免直通表的全局权限。
|
||||
- 逻辑删除:通过 `deleted_at` 字段实现,避免历史引用破坏。
|
||||
|
||||
## 回滚方案
|
||||
- 回滚 schema:删除表 `ak_user_levels`(需人工确认,不在本次脚本中提供)。
|
||||
- 回滚 rpc:删除对应函数(需人工确认,不在本次脚本中提供)。
|
||||
- 回滚 rls:移除 policy 并禁用 RLS(需人工确认)。
|
||||
|
||||
## 验证方式
|
||||
- 在 SQL 控制台依次执行:schema -> rls -> rpc。
|
||||
- 使用 admin 账号调用:
|
||||
- `rpc_admin_user_level_save` 创建数据
|
||||
- `rpc_admin_user_level_list` 验证分页返回
|
||||
- `rpc_admin_user_level_set_visible/status` 验证更新
|
||||
- `rpc_admin_user_level_delete` 验证逻辑删除
|
||||
- 使用普通账号/匿名访问验证仅能看到启用且展示的数据。
|
||||
|
||||
## 关联文档
|
||||
- `docs/project_spec/AGENT_PROJECT_SPEC.md`
|
||||
- `docs/sql/30_rpc/auth/get_current_user_role_v1.sql`
|
||||
- `docs/sql/11_roles_and_permissions_strategy.md`
|
||||
30
docs/sql/10_schema/user/ak_user_groups_v1.sql
Normal file
30
docs/sql/10_schema/user/ak_user_groups_v1.sql
Normal file
@@ -0,0 +1,30 @@
|
||||
-- =====================================================================================
|
||||
-- Schema: 用户分组表
|
||||
-- 位置:docs/sql/10_schema/user/ak_user_groups_v1.sql
|
||||
-- 对象类型:Schema (DDL)
|
||||
-- 版本:v1
|
||||
-- 说明:用户分组定义,支持逻辑删除和状态管理
|
||||
-- =====================================================================================
|
||||
|
||||
CREATE TABLE IF NOT EXISTS public.ak_user_groups (
|
||||
id UUID PRIMARY KEY DEFAULT gen_random_uuid(),
|
||||
|
||||
name TEXT NOT NULL,
|
||||
remark TEXT NULL,
|
||||
status INT NOT NULL DEFAULT 1, -- 1:启用, 0:禁用
|
||||
|
||||
created_at TIMESTAMPTZ NOT NULL DEFAULT now(),
|
||||
updated_at TIMESTAMPTZ NOT NULL DEFAULT now(),
|
||||
deleted_at TIMESTAMPTZ NULL,
|
||||
|
||||
CONSTRAINT ak_user_groups_name_length CHECK (char_length(name) >= 1)
|
||||
);
|
||||
|
||||
-- 唯一性约束(仅对未删除记录生效)
|
||||
CREATE UNIQUE INDEX IF NOT EXISTS ak_user_groups_name_uniq_active
|
||||
ON public.ak_user_groups (name)
|
||||
WHERE deleted_at IS NULL;
|
||||
|
||||
-- 常用查询索引
|
||||
CREATE INDEX IF NOT EXISTS ak_user_groups_status_idx ON public.ak_user_groups (status) WHERE deleted_at IS NULL;
|
||||
CREATE INDEX IF NOT EXISTS ak_user_groups_created_at_idx ON public.ak_user_groups (created_at DESC);
|
||||
33
docs/sql/10_schema/user/ak_user_labels_v1.sql
Normal file
33
docs/sql/10_schema/user/ak_user_labels_v1.sql
Normal file
@@ -0,0 +1,33 @@
|
||||
-- =====================================================================================
|
||||
-- Schema: 用户标签表
|
||||
-- 位置:docs/sql/10_schema/user/ak_user_labels_v1.sql
|
||||
-- 对象类型:Schema (DDL)
|
||||
-- 版本:v1
|
||||
-- 说明:用户标签定义,支持逻辑删除与状态管理
|
||||
-- =====================================================================================
|
||||
|
||||
CREATE TABLE IF NOT EXISTS public.ak_user_labels (
|
||||
id UUID PRIMARY KEY DEFAULT gen_random_uuid(),
|
||||
|
||||
name TEXT NOT NULL,
|
||||
color TEXT NULL,
|
||||
remark TEXT NULL,
|
||||
status INT NOT NULL DEFAULT 1,
|
||||
|
||||
created_at TIMESTAMPTZ NOT NULL DEFAULT now(),
|
||||
updated_at TIMESTAMPTZ NOT NULL DEFAULT now(),
|
||||
deleted_at TIMESTAMPTZ NULL,
|
||||
|
||||
CONSTRAINT ak_user_labels_name_length CHECK (char_length(name) >= 1)
|
||||
);
|
||||
|
||||
CREATE UNIQUE INDEX IF NOT EXISTS ak_user_labels_name_uniq_active
|
||||
ON public.ak_user_labels (name)
|
||||
WHERE deleted_at IS NULL;
|
||||
|
||||
CREATE INDEX IF NOT EXISTS ak_user_labels_status_idx
|
||||
ON public.ak_user_labels (status)
|
||||
WHERE deleted_at IS NULL;
|
||||
|
||||
CREATE INDEX IF NOT EXISTS ak_user_labels_created_at_idx
|
||||
ON public.ak_user_labels (created_at DESC);
|
||||
55
docs/sql/10_schema/user/ak_user_levels_v1.sql
Normal file
55
docs/sql/10_schema/user/ak_user_levels_v1.sql
Normal file
@@ -0,0 +1,55 @@
|
||||
-- =====================================================================================
|
||||
-- Schema: 用户等级表
|
||||
-- 位置:docs/sql/10_schema/user/
|
||||
-- 对象类型:Schema (DDL)
|
||||
-- 版本:v1
|
||||
-- 说明:用户等级(经验值/折扣/展示/状态),支持逻辑删除
|
||||
-- =====================================================================================
|
||||
|
||||
CREATE TABLE IF NOT EXISTS public.ak_user_levels (
|
||||
id UUID PRIMARY KEY DEFAULT gen_random_uuid(),
|
||||
|
||||
name TEXT NOT NULL,
|
||||
level_weight INT NOT NULL,
|
||||
min_experience INT NOT NULL DEFAULT 0,
|
||||
discount_percent INT NOT NULL DEFAULT 100,
|
||||
|
||||
is_visible BOOLEAN NOT NULL DEFAULT TRUE,
|
||||
status INT NOT NULL DEFAULT 1,
|
||||
|
||||
icon_url TEXT NULL,
|
||||
bg_image_url TEXT NULL,
|
||||
bg_style_json JSONB NULL,
|
||||
|
||||
remark TEXT NULL,
|
||||
|
||||
created_at TIMESTAMPTZ NOT NULL DEFAULT now(),
|
||||
updated_at TIMESTAMPTZ NOT NULL DEFAULT now(),
|
||||
deleted_at TIMESTAMPTZ NULL,
|
||||
|
||||
CONSTRAINT ak_user_levels_level_weight_nonnegative CHECK (level_weight >= 0),
|
||||
CONSTRAINT ak_user_levels_min_experience_nonnegative CHECK (min_experience >= 0),
|
||||
CONSTRAINT ak_user_levels_discount_percent_range CHECK (discount_percent BETWEEN 1 AND 100)
|
||||
);
|
||||
|
||||
-- 唯一性(仅对未删除记录生效)
|
||||
CREATE UNIQUE INDEX IF NOT EXISTS ak_user_levels_name_uniq_active
|
||||
ON public.ak_user_levels (name)
|
||||
WHERE deleted_at IS NULL;
|
||||
|
||||
CREATE UNIQUE INDEX IF NOT EXISTS ak_user_levels_level_weight_uniq_active
|
||||
ON public.ak_user_levels (level_weight)
|
||||
WHERE deleted_at IS NULL;
|
||||
|
||||
-- 常用查询索引
|
||||
CREATE INDEX IF NOT EXISTS ak_user_levels_active_filter_idx
|
||||
ON public.ak_user_levels (status, is_visible)
|
||||
WHERE deleted_at IS NULL;
|
||||
|
||||
CREATE INDEX IF NOT EXISTS ak_user_levels_min_experience_idx
|
||||
ON public.ak_user_levels (min_experience)
|
||||
WHERE deleted_at IS NULL;
|
||||
|
||||
CREATE INDEX IF NOT EXISTS ak_user_levels_level_weight_desc_idx
|
||||
ON public.ak_user_levels (level_weight DESC)
|
||||
WHERE deleted_at IS NULL;
|
||||
12
docs/sql/20_rls/user/ak_user_groups_rls_v1.sql
Normal file
12
docs/sql/20_rls/user/ak_user_groups_rls_v1.sql
Normal file
@@ -0,0 +1,12 @@
|
||||
-- =====================================================================================
|
||||
-- RLS: 用户分组表
|
||||
-- 位置:docs/sql/20_rls/user/ak_user_groups_rls_v1.sql
|
||||
-- 对象类型:RLS 策略
|
||||
-- 版本:v1
|
||||
-- 说明:管理端全量访问通过 RPC 完成;消费者端默认不开放直接访问
|
||||
-- =====================================================================================
|
||||
|
||||
ALTER TABLE public.ak_user_groups ENABLE ROW LEVEL SECURITY;
|
||||
|
||||
-- 如果未来消费者端需要展示所在分组,可以在此添加对应的 SELECT 策略
|
||||
-- 目前默认不向普通用户开放任何直接 SQL 读写权限
|
||||
12
docs/sql/20_rls/user/ak_user_labels_rls_v1.sql
Normal file
12
docs/sql/20_rls/user/ak_user_labels_rls_v1.sql
Normal file
@@ -0,0 +1,12 @@
|
||||
-- =====================================================================================
|
||||
-- RLS: 用户标签表
|
||||
-- 位置:docs/sql/20_rls/user/ak_user_labels_rls_v1.sql
|
||||
-- 对象类型:RLS 策略
|
||||
-- 版本:v1
|
||||
-- 说明:管理端全量访问通过 RPC 完成;消费者端默认不开放直接访问
|
||||
-- =====================================================================================
|
||||
|
||||
ALTER TABLE public.ak_user_labels ENABLE ROW LEVEL SECURITY;
|
||||
|
||||
-- 若后续消费者端需要展示标签,可在此添加 SELECT 策略
|
||||
-- 当前默认不向普通用户开放任何直接 SQL 读写权限
|
||||
23
docs/sql/20_rls/user/ak_user_levels_rls_v1.sql
Normal file
23
docs/sql/20_rls/user/ak_user_levels_rls_v1.sql
Normal file
@@ -0,0 +1,23 @@
|
||||
-- =====================================================================================
|
||||
-- RLS: 用户等级表
|
||||
-- 位置:docs/sql/20_rls/user/
|
||||
-- 对象类型:RLS 策略
|
||||
-- 版本:v1
|
||||
-- 说明:消费者端可读(仅可见/启用/未删除);管理端全量访问通过 RPC 完成
|
||||
-- =====================================================================================
|
||||
|
||||
ALTER TABLE public.ak_user_levels ENABLE ROW LEVEL SECURITY;
|
||||
|
||||
-- 消费者端:允许读取可见且启用的等级(未删除)
|
||||
DROP POLICY IF EXISTS ak_user_levels_public_select_visible_active ON public.ak_user_levels;
|
||||
CREATE POLICY ak_user_levels_public_select_visible_active
|
||||
ON public.ak_user_levels
|
||||
FOR SELECT
|
||||
TO anon, authenticated
|
||||
USING (
|
||||
deleted_at IS NULL
|
||||
AND status = 1
|
||||
AND is_visible = TRUE
|
||||
);
|
||||
|
||||
-- 默认不开放写权限(INSERT/UPDATE/DELETE)给 anon/authenticated
|
||||
36
docs/sql/30_rpc/user/rpc_admin_user_group_delete_v1.sql
Normal file
36
docs/sql/30_rpc/user/rpc_admin_user_group_delete_v1.sql
Normal file
@@ -0,0 +1,36 @@
|
||||
-- =====================================================================================
|
||||
-- RPC: rpc_admin_user_group_delete
|
||||
-- 位置:docs/sql/30_rpc/user/
|
||||
-- 对象类型:RPC 函数 (SECURITY DEFINER)
|
||||
-- 版本:v1
|
||||
-- 说明:逻辑删除用户分组(设置 deleted_at)
|
||||
-- =====================================================================================
|
||||
|
||||
CREATE OR REPLACE FUNCTION public.rpc_admin_user_group_delete(
|
||||
p_id UUID
|
||||
)
|
||||
RETURNS BOOLEAN
|
||||
SECURITY DEFINER
|
||||
SET search_path = public
|
||||
LANGUAGE plpgsql
|
||||
AS $$
|
||||
DECLARE
|
||||
v_ok BOOLEAN;
|
||||
BEGIN
|
||||
-- 1. 权限检查
|
||||
IF NOT EXISTS (
|
||||
SELECT 1 FROM public.ak_users
|
||||
WHERE auth_id = auth.uid() AND role IN ('admin', 'analytics')
|
||||
) THEN
|
||||
RAISE EXCEPTION 'Permission denied';
|
||||
END IF;
|
||||
|
||||
-- 2. 逻辑删除
|
||||
UPDATE public.ak_user_groups
|
||||
SET deleted_at = now(), updated_at = now()
|
||||
WHERE id = p_id AND deleted_at IS NULL;
|
||||
|
||||
GET DIAGNOSTICS v_ok = ROW_COUNT;
|
||||
RETURN v_ok;
|
||||
END;
|
||||
$$;
|
||||
60
docs/sql/30_rpc/user/rpc_admin_user_group_list_v1.sql
Normal file
60
docs/sql/30_rpc/user/rpc_admin_user_group_list_v1.sql
Normal file
@@ -0,0 +1,60 @@
|
||||
-- =====================================================================================
|
||||
-- RPC: rpc_admin_user_group_list
|
||||
-- 位置:docs/sql/30_rpc/user/
|
||||
-- 对象类型:RPC 函数 (SECURITY DEFINER)
|
||||
-- 版本:v1
|
||||
-- 说明:管理端分页获取用户分组列表,支持搜索、状态筛选及逻辑删除过滤
|
||||
-- =====================================================================================
|
||||
|
||||
CREATE OR REPLACE FUNCTION public.rpc_admin_user_group_list(
|
||||
p_page INT,
|
||||
p_page_size INT,
|
||||
p_search TEXT DEFAULT NULL,
|
||||
p_status INT DEFAULT NULL,
|
||||
p_include_deleted BOOLEAN DEFAULT FALSE
|
||||
)
|
||||
RETURNS JSONB
|
||||
SECURITY DEFINER
|
||||
SET search_path = public
|
||||
LANGUAGE plpgsql
|
||||
AS $$
|
||||
DECLARE
|
||||
v_total INT;
|
||||
v_items JSONB;
|
||||
BEGIN
|
||||
-- 1. 权限检查
|
||||
IF NOT EXISTS (
|
||||
SELECT 1 FROM public.ak_users
|
||||
WHERE auth_id = auth.uid() AND role IN ('admin', 'analytics')
|
||||
) THEN
|
||||
RAISE EXCEPTION 'Permission denied';
|
||||
END IF;
|
||||
|
||||
-- 2. 获取总数
|
||||
SELECT COUNT(*) INTO v_total
|
||||
FROM public.ak_user_groups
|
||||
WHERE (p_include_deleted OR deleted_at IS NULL)
|
||||
AND (p_search IS NULL OR name ILIKE '%' || p_search || '%' OR remark ILIKE '%' || p_search || '%')
|
||||
AND (p_status IS NULL OR status = p_status);
|
||||
|
||||
-- 3. 分页获取数据
|
||||
SELECT jsonb_agg(t) INTO v_items
|
||||
FROM (
|
||||
SELECT
|
||||
id, name, remark, status,
|
||||
created_at, updated_at, deleted_at
|
||||
FROM public.ak_user_groups
|
||||
WHERE (p_include_deleted OR deleted_at IS NULL)
|
||||
AND (p_search IS NULL OR name ILIKE '%' || p_search || '%' OR remark ILIKE '%' || p_search || '%')
|
||||
AND (p_status IS NULL OR status = p_status)
|
||||
ORDER BY created_at DESC
|
||||
LIMIT p_page_size
|
||||
OFFSET (p_page - 1) * p_page_size
|
||||
) t;
|
||||
|
||||
RETURN jsonb_build_object(
|
||||
'total', v_total,
|
||||
'items', COALESCE(v_items, '[]'::jsonb)
|
||||
);
|
||||
END;
|
||||
$$;
|
||||
66
docs/sql/30_rpc/user/rpc_admin_user_group_save_v1.sql
Normal file
66
docs/sql/30_rpc/user/rpc_admin_user_group_save_v1.sql
Normal file
@@ -0,0 +1,66 @@
|
||||
-- =====================================================================================
|
||||
-- RPC: rpc_admin_user_group_save
|
||||
-- 位置:docs/sql/30_rpc/user/
|
||||
-- 对象类型:RPC 函数 (SECURITY DEFINER)
|
||||
-- 版本:v1
|
||||
-- 说明:新增/更新用户分组(逻辑删除记录默认不允许更新)
|
||||
-- =====================================================================================
|
||||
|
||||
CREATE OR REPLACE FUNCTION public.rpc_admin_user_group_save(
|
||||
p_id UUID DEFAULT NULL,
|
||||
p_name TEXT,
|
||||
p_remark TEXT DEFAULT NULL,
|
||||
p_status INT DEFAULT 1
|
||||
)
|
||||
RETURNS UUID
|
||||
SECURITY DEFINER
|
||||
SET search_path = public
|
||||
LANGUAGE plpgsql
|
||||
AS $$
|
||||
DECLARE
|
||||
v_id UUID;
|
||||
BEGIN
|
||||
-- 1. 权限检查
|
||||
IF NOT EXISTS (
|
||||
SELECT 1 FROM public.ak_users
|
||||
WHERE auth_id = auth.uid() AND role IN ('admin', 'analytics')
|
||||
) THEN
|
||||
RAISE EXCEPTION 'Permission denied';
|
||||
END IF;
|
||||
|
||||
-- 2. 参数校验
|
||||
IF p_name IS NULL OR length(trim(p_name)) = 0 THEN
|
||||
RAISE EXCEPTION 'Invalid name';
|
||||
END IF;
|
||||
|
||||
-- 3. 新增
|
||||
IF p_id IS NULL THEN
|
||||
INSERT INTO public.ak_user_groups(
|
||||
name, remark, status,
|
||||
created_at, updated_at, deleted_at
|
||||
) VALUES (
|
||||
p_name, p_remark, COALESCE(p_status, 1),
|
||||
now(), now(), NULL
|
||||
)
|
||||
RETURNING id INTO v_id;
|
||||
|
||||
RETURN v_id;
|
||||
END IF;
|
||||
|
||||
-- 4. 更新(不允许更新已删除记录)
|
||||
UPDATE public.ak_user_groups
|
||||
SET
|
||||
name = p_name,
|
||||
remark = p_remark,
|
||||
status = COALESCE(p_status, status),
|
||||
updated_at = now()
|
||||
WHERE id = p_id AND deleted_at IS NULL
|
||||
RETURNING id INTO v_id;
|
||||
|
||||
IF v_id IS NULL THEN
|
||||
RAISE EXCEPTION 'Not found or deleted';
|
||||
END IF;
|
||||
|
||||
RETURN v_id;
|
||||
END;
|
||||
$$;
|
||||
37
docs/sql/30_rpc/user/rpc_admin_user_group_set_status_v1.sql
Normal file
37
docs/sql/30_rpc/user/rpc_admin_user_group_set_status_v1.sql
Normal file
@@ -0,0 +1,37 @@
|
||||
-- =====================================================================================
|
||||
-- RPC: rpc_admin_user_group_set_status
|
||||
-- 位置:docs/sql/30_rpc/user/
|
||||
-- 对象类型:RPC 函数 (SECURITY DEFINER)
|
||||
-- 版本:v1
|
||||
-- 说明:设置用户分组状态(启用/禁用)
|
||||
-- =====================================================================================
|
||||
|
||||
CREATE OR REPLACE FUNCTION public.rpc_admin_user_group_set_status(
|
||||
p_id UUID,
|
||||
p_status INT
|
||||
)
|
||||
RETURNS BOOLEAN
|
||||
SECURITY DEFINER
|
||||
SET search_path = public
|
||||
LANGUAGE plpgsql
|
||||
AS $$
|
||||
DECLARE
|
||||
v_ok BOOLEAN;
|
||||
BEGIN
|
||||
-- 1. 权限检查
|
||||
IF NOT EXISTS (
|
||||
SELECT 1 FROM public.ak_users
|
||||
WHERE auth_id = auth.uid() AND role IN ('admin', 'analytics')
|
||||
) THEN
|
||||
RAISE EXCEPTION 'Permission denied';
|
||||
END IF;
|
||||
|
||||
UPDATE public.ak_user_groups
|
||||
SET status = p_status,
|
||||
updated_at = now()
|
||||
WHERE id = p_id AND deleted_at IS NULL;
|
||||
|
||||
GET DIAGNOSTICS v_ok = ROW_COUNT;
|
||||
RETURN v_ok;
|
||||
END;
|
||||
$$;
|
||||
36
docs/sql/30_rpc/user/rpc_admin_user_label_delete_v1.sql
Normal file
36
docs/sql/30_rpc/user/rpc_admin_user_label_delete_v1.sql
Normal file
@@ -0,0 +1,36 @@
|
||||
-- =====================================================================================
|
||||
-- RPC: rpc_admin_user_label_delete
|
||||
-- 位置:docs/sql/30_rpc/user/
|
||||
-- 对象类型:RPC 函数 (SECURITY DEFINER)
|
||||
-- 版本:v1
|
||||
-- 说明:逻辑删除用户标签(设置 deleted_at)
|
||||
-- =====================================================================================
|
||||
|
||||
CREATE OR REPLACE FUNCTION public.rpc_admin_user_label_delete(
|
||||
p_id UUID
|
||||
)
|
||||
RETURNS BOOLEAN
|
||||
SECURITY DEFINER
|
||||
SET search_path = public
|
||||
LANGUAGE plpgsql
|
||||
AS $$
|
||||
DECLARE
|
||||
v_ok BOOLEAN;
|
||||
BEGIN
|
||||
-- 1. 权限检查
|
||||
IF NOT EXISTS (
|
||||
SELECT 1 FROM public.ak_users
|
||||
WHERE auth_id = auth.uid() AND role IN ('admin', 'analytics')
|
||||
) THEN
|
||||
RAISE EXCEPTION 'Permission denied';
|
||||
END IF;
|
||||
|
||||
-- 2. 逻辑删除
|
||||
UPDATE public.ak_user_labels
|
||||
SET deleted_at = now(), updated_at = now()
|
||||
WHERE id = p_id AND deleted_at IS NULL;
|
||||
|
||||
GET DIAGNOSTICS v_ok = ROW_COUNT;
|
||||
RETURN v_ok;
|
||||
END;
|
||||
$$;
|
||||
60
docs/sql/30_rpc/user/rpc_admin_user_label_list_v1.sql
Normal file
60
docs/sql/30_rpc/user/rpc_admin_user_label_list_v1.sql
Normal file
@@ -0,0 +1,60 @@
|
||||
-- =====================================================================================
|
||||
-- RPC: rpc_admin_user_label_list
|
||||
-- 位置:docs/sql/30_rpc/user/
|
||||
-- 对象类型:RPC 函数 (SECURITY DEFINER)
|
||||
-- 版本:v1
|
||||
-- 说明:管理端分页获取用户标签列表,支持搜索、状态筛选及逻辑删除过滤
|
||||
-- =====================================================================================
|
||||
|
||||
CREATE OR REPLACE FUNCTION public.rpc_admin_user_label_list(
|
||||
p_page INT,
|
||||
p_page_size INT,
|
||||
p_search TEXT DEFAULT NULL,
|
||||
p_status INT DEFAULT NULL,
|
||||
p_include_deleted BOOLEAN DEFAULT FALSE
|
||||
)
|
||||
RETURNS JSONB
|
||||
SECURITY DEFINER
|
||||
SET search_path = public
|
||||
LANGUAGE plpgsql
|
||||
AS $$
|
||||
DECLARE
|
||||
v_total INT;
|
||||
v_items JSONB;
|
||||
BEGIN
|
||||
-- 1. 权限检查
|
||||
IF NOT EXISTS (
|
||||
SELECT 1 FROM public.ak_users
|
||||
WHERE auth_id = auth.uid() AND role IN ('admin', 'analytics')
|
||||
) THEN
|
||||
RAISE EXCEPTION 'Permission denied';
|
||||
END IF;
|
||||
|
||||
-- 2. 获取总数
|
||||
SELECT COUNT(*) INTO v_total
|
||||
FROM public.ak_user_labels
|
||||
WHERE (p_include_deleted OR deleted_at IS NULL)
|
||||
AND (p_search IS NULL OR name ILIKE '%' || p_search || '%' OR remark ILIKE '%' || p_search || '%')
|
||||
AND (p_status IS NULL OR status = p_status);
|
||||
|
||||
-- 3. 分页获取数据
|
||||
SELECT jsonb_agg(t) INTO v_items
|
||||
FROM (
|
||||
SELECT
|
||||
id, name, color, remark, status,
|
||||
created_at, updated_at, deleted_at
|
||||
FROM public.ak_user_labels
|
||||
WHERE (p_include_deleted OR deleted_at IS NULL)
|
||||
AND (p_search IS NULL OR name ILIKE '%' || p_search || '%' OR remark ILIKE '%' || p_search || '%')
|
||||
AND (p_status IS NULL OR status = p_status)
|
||||
ORDER BY created_at DESC
|
||||
LIMIT p_page_size
|
||||
OFFSET (p_page - 1) * p_page_size
|
||||
) t;
|
||||
|
||||
RETURN jsonb_build_object(
|
||||
'total', v_total,
|
||||
'items', COALESCE(v_items, '[]'::jsonb)
|
||||
);
|
||||
END;
|
||||
$$;
|
||||
68
docs/sql/30_rpc/user/rpc_admin_user_label_save_v1.sql
Normal file
68
docs/sql/30_rpc/user/rpc_admin_user_label_save_v1.sql
Normal file
@@ -0,0 +1,68 @@
|
||||
-- =====================================================================================
|
||||
-- RPC: rpc_admin_user_label_save
|
||||
-- 位置:docs/sql/30_rpc/user/
|
||||
-- 对象类型:RPC 函数 (SECURITY DEFINER)
|
||||
-- 版本:v1
|
||||
-- 说明:新增/更新用户标签(逻辑删除记录默认不允许更新)
|
||||
-- =====================================================================================
|
||||
|
||||
CREATE OR REPLACE FUNCTION public.rpc_admin_user_label_save(
|
||||
p_id UUID DEFAULT NULL,
|
||||
p_name TEXT,
|
||||
p_color TEXT DEFAULT NULL,
|
||||
p_remark TEXT DEFAULT NULL,
|
||||
p_status INT DEFAULT 1
|
||||
)
|
||||
RETURNS UUID
|
||||
SECURITY DEFINER
|
||||
SET search_path = public
|
||||
LANGUAGE plpgsql
|
||||
AS $$
|
||||
DECLARE
|
||||
v_id UUID;
|
||||
BEGIN
|
||||
-- 1. 权限检查
|
||||
IF NOT EXISTS (
|
||||
SELECT 1 FROM public.ak_users
|
||||
WHERE auth_id = auth.uid() AND role IN ('admin', 'analytics')
|
||||
) THEN
|
||||
RAISE EXCEPTION 'Permission denied';
|
||||
END IF;
|
||||
|
||||
-- 2. 参数校验
|
||||
IF p_name IS NULL OR length(trim(p_name)) = 0 THEN
|
||||
RAISE EXCEPTION 'Invalid name';
|
||||
END IF;
|
||||
|
||||
-- 3. 新增
|
||||
IF p_id IS NULL THEN
|
||||
INSERT INTO public.ak_user_labels(
|
||||
name, color, remark, status,
|
||||
created_at, updated_at, deleted_at
|
||||
) VALUES (
|
||||
p_name, p_color, p_remark, COALESCE(p_status, 1),
|
||||
now(), now(), NULL
|
||||
)
|
||||
RETURNING id INTO v_id;
|
||||
|
||||
RETURN v_id;
|
||||
END IF;
|
||||
|
||||
-- 4. 更新(不允许更新已删除记录)
|
||||
UPDATE public.ak_user_labels
|
||||
SET
|
||||
name = p_name,
|
||||
color = p_color,
|
||||
remark = p_remark,
|
||||
status = COALESCE(p_status, status),
|
||||
updated_at = now()
|
||||
WHERE id = p_id AND deleted_at IS NULL
|
||||
RETURNING id INTO v_id;
|
||||
|
||||
IF v_id IS NULL THEN
|
||||
RAISE EXCEPTION 'Not found or deleted';
|
||||
END IF;
|
||||
|
||||
RETURN v_id;
|
||||
END;
|
||||
$$;
|
||||
37
docs/sql/30_rpc/user/rpc_admin_user_label_set_status_v1.sql
Normal file
37
docs/sql/30_rpc/user/rpc_admin_user_label_set_status_v1.sql
Normal file
@@ -0,0 +1,37 @@
|
||||
-- =====================================================================================
|
||||
-- RPC: rpc_admin_user_label_set_status
|
||||
-- 位置:docs/sql/30_rpc/user/
|
||||
-- 对象类型:RPC 函数 (SECURITY DEFINER)
|
||||
-- 版本:v1
|
||||
-- 说明:设置用户标签状态(启用/禁用)
|
||||
-- =====================================================================================
|
||||
|
||||
CREATE OR REPLACE FUNCTION public.rpc_admin_user_label_set_status(
|
||||
p_id UUID,
|
||||
p_status INT
|
||||
)
|
||||
RETURNS BOOLEAN
|
||||
SECURITY DEFINER
|
||||
SET search_path = public
|
||||
LANGUAGE plpgsql
|
||||
AS $$
|
||||
DECLARE
|
||||
v_ok BOOLEAN;
|
||||
BEGIN
|
||||
-- 1. 权限检查
|
||||
IF NOT EXISTS (
|
||||
SELECT 1 FROM public.ak_users
|
||||
WHERE auth_id = auth.uid() AND role IN ('admin', 'analytics')
|
||||
) THEN
|
||||
RAISE EXCEPTION 'Permission denied';
|
||||
END IF;
|
||||
|
||||
UPDATE public.ak_user_labels
|
||||
SET status = p_status,
|
||||
updated_at = now()
|
||||
WHERE id = p_id AND deleted_at IS NULL;
|
||||
|
||||
GET DIAGNOSTICS v_ok = ROW_COUNT;
|
||||
RETURN v_ok;
|
||||
END;
|
||||
$$;
|
||||
36
docs/sql/30_rpc/user/rpc_admin_user_level_delete_v1.sql
Normal file
36
docs/sql/30_rpc/user/rpc_admin_user_level_delete_v1.sql
Normal file
@@ -0,0 +1,36 @@
|
||||
-- =====================================================================================
|
||||
-- RPC: rpc_admin_user_level_delete
|
||||
-- 位置:docs/sql/30_rpc/user/
|
||||
-- 对象类型:RPC 函数 (SECURITY DEFINER)
|
||||
-- 版本:v1
|
||||
-- 说明:逻辑删除用户等级(设置 deleted_at)
|
||||
-- =====================================================================================
|
||||
|
||||
CREATE OR REPLACE FUNCTION public.rpc_admin_user_level_delete(
|
||||
p_id UUID
|
||||
)
|
||||
RETURNS BOOLEAN
|
||||
SECURITY DEFINER
|
||||
SET search_path = public
|
||||
LANGUAGE plpgsql
|
||||
AS $$
|
||||
DECLARE
|
||||
v_ok BOOLEAN;
|
||||
BEGIN
|
||||
-- 1. 权限检查
|
||||
IF NOT EXISTS (
|
||||
SELECT 1 FROM public.ak_users
|
||||
WHERE auth_id = auth.uid() AND role IN ('admin', 'analytics')
|
||||
) THEN
|
||||
RAISE EXCEPTION 'Permission denied';
|
||||
END IF;
|
||||
|
||||
-- 2. 逻辑删除
|
||||
UPDATE public.ak_user_levels
|
||||
SET deleted_at = now(), updated_at = now()
|
||||
WHERE id = p_id AND deleted_at IS NULL;
|
||||
|
||||
GET DIAGNOSTICS v_ok = ROW_COUNT;
|
||||
RETURN v_ok;
|
||||
END;
|
||||
$$;
|
||||
64
docs/sql/30_rpc/user/rpc_admin_user_level_list_v1.sql
Normal file
64
docs/sql/30_rpc/user/rpc_admin_user_level_list_v1.sql
Normal file
@@ -0,0 +1,64 @@
|
||||
-- =====================================================================================
|
||||
-- RPC: rpc_admin_user_level_list
|
||||
-- 位置:docs/sql/30_rpc/user/
|
||||
-- 对象类型:RPC 函数 (SECURITY DEFINER)
|
||||
-- 版本:v1
|
||||
-- 说明:管理端分页获取用户等级列表,支持搜索、状态筛选及逻辑删除过滤
|
||||
-- =====================================================================================
|
||||
|
||||
CREATE OR REPLACE FUNCTION public.rpc_admin_user_level_list(
|
||||
p_page INT,
|
||||
p_page_size INT,
|
||||
p_search TEXT DEFAULT NULL,
|
||||
p_status INT DEFAULT NULL,
|
||||
p_is_visible BOOLEAN DEFAULT NULL,
|
||||
p_include_deleted BOOLEAN DEFAULT FALSE
|
||||
)
|
||||
RETURNS JSONB
|
||||
SECURITY DEFINER
|
||||
SET search_path = public
|
||||
LANGUAGE plpgsql
|
||||
AS $$
|
||||
DECLARE
|
||||
v_total INT;
|
||||
v_items JSONB;
|
||||
BEGIN
|
||||
-- 1. 权限检查 (依赖 public.get_current_user_role())
|
||||
IF NOT EXISTS (
|
||||
SELECT 1 FROM public.ak_users
|
||||
WHERE auth_id = auth.uid() AND role IN ('admin', 'analytics')
|
||||
) THEN
|
||||
RAISE EXCEPTION 'Permission denied';
|
||||
END IF;
|
||||
|
||||
-- 2. 获取总数
|
||||
SELECT COUNT(*) INTO v_total
|
||||
FROM public.ak_user_levels
|
||||
WHERE (p_include_deleted OR deleted_at IS NULL)
|
||||
AND (p_search IS NULL OR name ILIKE '%' || p_search || '%')
|
||||
AND (p_status IS NULL OR status = p_status)
|
||||
AND (p_is_visible IS NULL OR is_visible = p_is_visible);
|
||||
|
||||
-- 3. 分页获取数据
|
||||
SELECT jsonb_agg(t) INTO v_items
|
||||
FROM (
|
||||
SELECT
|
||||
id, name, level_weight, min_experience, discount_percent,
|
||||
is_visible, status, icon_url, bg_image_url, bg_style_json,
|
||||
remark, created_at, updated_at, deleted_at
|
||||
FROM public.ak_user_levels
|
||||
WHERE (p_include_deleted OR deleted_at IS NULL)
|
||||
AND (p_search IS NULL OR name ILIKE '%' || p_search || '%')
|
||||
AND (p_status IS NULL OR status = p_status)
|
||||
AND (p_is_visible IS NULL OR is_visible = p_is_visible)
|
||||
ORDER BY level_weight ASC
|
||||
LIMIT p_page_size
|
||||
OFFSET (p_page - 1) * p_page_size
|
||||
) t;
|
||||
|
||||
RETURN jsonb_build_object(
|
||||
'total', v_total,
|
||||
'items', COALESCE(v_items, '[]'::jsonb)
|
||||
);
|
||||
END;
|
||||
$$;
|
||||
94
docs/sql/30_rpc/user/rpc_admin_user_level_save_v1.sql
Normal file
94
docs/sql/30_rpc/user/rpc_admin_user_level_save_v1.sql
Normal file
@@ -0,0 +1,94 @@
|
||||
-- =====================================================================================
|
||||
-- RPC: rpc_admin_user_level_save
|
||||
-- 位置:docs/sql/30_rpc/user/
|
||||
-- 对象类型:RPC 函数 (SECURITY DEFINER)
|
||||
-- 版本:v1
|
||||
-- 说明:新增/更新用户等级(逻辑删除记录默认不允许更新)
|
||||
-- =====================================================================================
|
||||
|
||||
CREATE OR REPLACE FUNCTION public.rpc_admin_user_level_save(
|
||||
p_id UUID DEFAULT NULL,
|
||||
p_name TEXT,
|
||||
p_level_weight INT,
|
||||
p_min_experience INT,
|
||||
p_discount_percent INT,
|
||||
p_is_visible BOOLEAN,
|
||||
p_status INT,
|
||||
p_icon_url TEXT DEFAULT NULL,
|
||||
p_bg_image_url TEXT DEFAULT NULL,
|
||||
p_bg_style_json JSONB DEFAULT NULL,
|
||||
p_remark TEXT DEFAULT NULL
|
||||
)
|
||||
RETURNS UUID
|
||||
SECURITY DEFINER
|
||||
SET search_path = public
|
||||
LANGUAGE plpgsql
|
||||
AS $$
|
||||
DECLARE
|
||||
v_id UUID;
|
||||
BEGIN
|
||||
-- 1. 权限检查
|
||||
IF NOT EXISTS (
|
||||
SELECT 1 FROM public.ak_users
|
||||
WHERE auth_id = auth.uid() AND role IN ('admin', 'analytics')
|
||||
) THEN
|
||||
RAISE EXCEPTION 'Permission denied';
|
||||
END IF;
|
||||
|
||||
-- 2. 参数校验(最小化)
|
||||
IF p_name IS NULL OR length(trim(p_name)) = 0 THEN
|
||||
RAISE EXCEPTION 'Invalid name';
|
||||
END IF;
|
||||
|
||||
IF p_level_weight < 0 OR p_min_experience < 0 THEN
|
||||
RAISE EXCEPTION 'Invalid level_weight or min_experience';
|
||||
END IF;
|
||||
|
||||
IF p_discount_percent < 1 OR p_discount_percent > 100 THEN
|
||||
RAISE EXCEPTION 'Invalid discount_percent';
|
||||
END IF;
|
||||
|
||||
-- 3. 新增
|
||||
IF p_id IS NULL THEN
|
||||
INSERT INTO public.ak_user_levels(
|
||||
name, level_weight, min_experience, discount_percent,
|
||||
is_visible, status,
|
||||
icon_url, bg_image_url, bg_style_json,
|
||||
remark,
|
||||
created_at, updated_at, deleted_at
|
||||
) VALUES (
|
||||
p_name, p_level_weight, p_min_experience, p_discount_percent,
|
||||
p_is_visible, p_status,
|
||||
p_icon_url, p_bg_image_url, p_bg_style_json,
|
||||
p_remark,
|
||||
now(), now(), NULL
|
||||
)
|
||||
RETURNING id INTO v_id;
|
||||
|
||||
RETURN v_id;
|
||||
END IF;
|
||||
|
||||
-- 4. 更新(不允许更新已删除记录)
|
||||
UPDATE public.ak_user_levels
|
||||
SET
|
||||
name = p_name,
|
||||
level_weight = p_level_weight,
|
||||
min_experience = p_min_experience,
|
||||
discount_percent = p_discount_percent,
|
||||
is_visible = p_is_visible,
|
||||
status = p_status,
|
||||
icon_url = p_icon_url,
|
||||
bg_image_url = p_bg_image_url,
|
||||
bg_style_json = p_bg_style_json,
|
||||
remark = p_remark,
|
||||
updated_at = now()
|
||||
WHERE id = p_id AND deleted_at IS NULL
|
||||
RETURNING id INTO v_id;
|
||||
|
||||
IF v_id IS NULL THEN
|
||||
RAISE EXCEPTION 'Not found or deleted';
|
||||
END IF;
|
||||
|
||||
RETURN v_id;
|
||||
END;
|
||||
$$;
|
||||
37
docs/sql/30_rpc/user/rpc_admin_user_level_set_status_v1.sql
Normal file
37
docs/sql/30_rpc/user/rpc_admin_user_level_set_status_v1.sql
Normal file
@@ -0,0 +1,37 @@
|
||||
-- =====================================================================================
|
||||
-- RPC: rpc_admin_user_level_set_status
|
||||
-- 位置:docs/sql/30_rpc/user/
|
||||
-- 对象类型:RPC 函数 (SECURITY DEFINER)
|
||||
-- 版本:v1
|
||||
-- 说明:设置用户等级状态(启用/禁用)
|
||||
-- =====================================================================================
|
||||
|
||||
CREATE OR REPLACE FUNCTION public.rpc_admin_user_level_set_status(
|
||||
p_id UUID,
|
||||
p_status INT
|
||||
)
|
||||
RETURNS BOOLEAN
|
||||
SECURITY DEFINER
|
||||
SET search_path = public
|
||||
LANGUAGE plpgsql
|
||||
AS $$
|
||||
DECLARE
|
||||
v_ok BOOLEAN;
|
||||
BEGIN
|
||||
-- 1. 权限检查
|
||||
IF NOT EXISTS (
|
||||
SELECT 1 FROM public.ak_users
|
||||
WHERE auth_id = auth.uid() AND role IN ('admin', 'analytics')
|
||||
) THEN
|
||||
RAISE EXCEPTION 'Permission denied';
|
||||
END IF;
|
||||
|
||||
UPDATE public.ak_user_levels
|
||||
SET status = p_status,
|
||||
updated_at = now()
|
||||
WHERE id = p_id AND deleted_at IS NULL;
|
||||
|
||||
GET DIAGNOSTICS v_ok = ROW_COUNT;
|
||||
RETURN v_ok;
|
||||
END;
|
||||
$$;
|
||||
37
docs/sql/30_rpc/user/rpc_admin_user_level_set_visible_v1.sql
Normal file
37
docs/sql/30_rpc/user/rpc_admin_user_level_set_visible_v1.sql
Normal file
@@ -0,0 +1,37 @@
|
||||
-- =====================================================================================
|
||||
-- RPC: rpc_admin_user_level_set_visible
|
||||
-- 位置:docs/sql/30_rpc/user/
|
||||
-- 对象类型:RPC 函数 (SECURITY DEFINER)
|
||||
-- 版本:v1
|
||||
-- 说明:设置用户等级是否展示
|
||||
-- =====================================================================================
|
||||
|
||||
CREATE OR REPLACE FUNCTION public.rpc_admin_user_level_set_visible(
|
||||
p_id UUID,
|
||||
p_is_visible BOOLEAN
|
||||
)
|
||||
RETURNS BOOLEAN
|
||||
SECURITY DEFINER
|
||||
SET search_path = public
|
||||
LANGUAGE plpgsql
|
||||
AS $$
|
||||
DECLARE
|
||||
v_ok BOOLEAN;
|
||||
BEGIN
|
||||
-- 1. 权限检查
|
||||
IF NOT EXISTS (
|
||||
SELECT 1 FROM public.ak_users
|
||||
WHERE auth_id = auth.uid() AND role IN ('admin', 'analytics')
|
||||
) THEN
|
||||
RAISE EXCEPTION 'Permission denied';
|
||||
END IF;
|
||||
|
||||
UPDATE public.ak_user_levels
|
||||
SET is_visible = p_is_visible,
|
||||
updated_at = now()
|
||||
WHERE id = p_id AND deleted_at IS NULL;
|
||||
|
||||
GET DIAGNOSTICS v_ok = ROW_COUNT;
|
||||
RETURN v_ok;
|
||||
END;
|
||||
$$;
|
||||
@@ -3,7 +3,12 @@
|
||||
<view class="content-card">
|
||||
<!-- 操作按钮行 -->
|
||||
<view class="action-bar">
|
||||
<view class="filter-item">
|
||||
<input class="filter-input" v-model="searchText" placeholder="搜索分组名称/备注" @confirm="handleSearch" />
|
||||
</view>
|
||||
<button class="btn primary small" @click="onAddGroup">添加分组</button>
|
||||
<button class="btn ghost small" @click="handleSearch">查询</button>
|
||||
<button class="btn ghost small" @click="handleReset">重置</button>
|
||||
</view>
|
||||
|
||||
<!-- 分组列表表格 -->
|
||||
@@ -11,19 +16,29 @@
|
||||
<!-- 表头 -->
|
||||
<view class="table-header">
|
||||
<view class="col col-id"><text>ID</text></view>
|
||||
<view class="col col-name"><text>分组</text></view>
|
||||
<view class="col col-name"><text>分组名称</text></view>
|
||||
<view class="col col-remark"><text>备注</text></view>
|
||||
<view class="col col-status"><text>状态</text></view>
|
||||
<view class="col col-ops"><text>操作</text></view>
|
||||
</view>
|
||||
|
||||
<!-- 表格内容 -->
|
||||
<view class="table-body">
|
||||
<view v-for="group in groupList" :key="group.id" class="table-row">
|
||||
<view v-if="loading" class="table-loading"><text>加载中...</text></view>
|
||||
<view v-else-if="groupList.length === 0" class="table-empty"><text>暂无数据</text></view>
|
||||
<view v-else v-for="(group, index) in groupList" :key="group.id" class="table-row">
|
||||
<view class="col col-id"><text>{{ group.id }}</text></view>
|
||||
<view class="col col-name"><text>{{ group.name }}</text></view>
|
||||
<view class="col col-remark"><text>{{ group.remark || '-' }}</text></view>
|
||||
<view class="col col-status">
|
||||
<view :class="['switch-box', group.status === 1 ? 'active' : '']" @click="onToggleStatus(index)">
|
||||
<view class="switch-dot"></view>
|
||||
</view>
|
||||
</view>
|
||||
<view class="col col-ops">
|
||||
<text class="op-link" @click="onEditGroup(group)">修改</text>
|
||||
<view class="op-divider">|</view>
|
||||
<text class="op-link" @click="onDeleteGroup(group)">删除</text>
|
||||
<text class="op-link text-danger" @click="onDeleteGroup(group.id)">删除</text>
|
||||
</view>
|
||||
</view>
|
||||
</view>
|
||||
@@ -31,19 +46,15 @@
|
||||
|
||||
<!-- 分页区域 -->
|
||||
<view class="pagination-row">
|
||||
<text class="total-text">共 {{ groupList.length }} 条</text>
|
||||
<view class="page-size-selector">
|
||||
<text>15条/页</text>
|
||||
<text class="arrow">▼</text>
|
||||
</view>
|
||||
<text class="total-text">共 {{ total }} 条</text>
|
||||
<view class="page-btns">
|
||||
<view class="page-btn disabled"><text>‹</text></view>
|
||||
<view class="page-btn active"><text>1</text></view>
|
||||
<view class="page-btn disabled"><text>›</text></view>
|
||||
<view :class="['page-btn', page <= 1 ? 'disabled' : '']" @click="prevPage"><text>‹</text></view>
|
||||
<view class="page-btn active"><text>{{ page }}</text></view>
|
||||
<view :class="['page-btn', page >= totalPages ? 'disabled' : '']" @click="nextPage"><text>›</text></view>
|
||||
</view>
|
||||
<view class="page-jump">
|
||||
<text>前往</text>
|
||||
<input class="jump-input" value="1" />
|
||||
<input class="jump-input" v-model="jumpPage" @confirm="goToJumpPage" />
|
||||
<text>页</text>
|
||||
</view>
|
||||
</view>
|
||||
@@ -66,9 +77,26 @@
|
||||
class="form-input"
|
||||
v-model="formData.name"
|
||||
placeholder="请输入分组名称"
|
||||
autofocus
|
||||
/>
|
||||
</view>
|
||||
<view class="form-item" style="margin-top: 20px;">
|
||||
<view class="label-box">
|
||||
<text class="label">备注说明:</text>
|
||||
</view>
|
||||
<textarea
|
||||
class="form-textarea"
|
||||
v-model="formData.remark"
|
||||
placeholder="请输入备注说明"
|
||||
/>
|
||||
</view>
|
||||
<view class="form-item" style="margin-top: 20px;">
|
||||
<view class="label-box">
|
||||
<text class="label">状态:</text>
|
||||
</view>
|
||||
<view :class="['switch-box', formData.status === 1 ? 'active' : '']" @click="formData.status = (formData.status === 1 ? 0 : 1)">
|
||||
<view class="switch-dot"></view>
|
||||
</view>
|
||||
</view>
|
||||
</view>
|
||||
<view class="modal-footer">
|
||||
<button class="btn ghost" @click="closeModal">取消</button>
|
||||
@@ -80,15 +108,51 @@
|
||||
</template>
|
||||
|
||||
<script setup lang="uts">
|
||||
import { ref, reactive, computed } from 'vue'
|
||||
import { ref, reactive, computed, onMounted } from 'vue'
|
||||
import {
|
||||
fetchAdminUserGroupPage,
|
||||
saveAdminUserGroup,
|
||||
deleteAdminUserGroup,
|
||||
setAdminUserGroupStatus,
|
||||
type AdminUserGroup
|
||||
} from '@/services/admin/userGroupService.uts'
|
||||
|
||||
// 分组数据
|
||||
const groupList = ref([
|
||||
{ id: 251, name: 'A类客户' },
|
||||
{ id: 252, name: 'B类客户' },
|
||||
{ id: 253, name: 'C类客户' },
|
||||
{ id: 254, name: 'D类客户' }
|
||||
])
|
||||
const searchText = ref('')
|
||||
const total = ref(0)
|
||||
const groupList = ref<AdminUserGroup[]>([])
|
||||
const loading = ref(false)
|
||||
|
||||
const page = ref(1)
|
||||
const pageSize = ref(15)
|
||||
const jumpPage = ref('')
|
||||
|
||||
const totalPages = computed((): number => {
|
||||
if (pageSize.value <= 0) return 1
|
||||
const pages = Math.ceil(total.value / pageSize.value)
|
||||
return pages <= 0 ? 1 : pages
|
||||
})
|
||||
|
||||
const loadGroupList = async () => {
|
||||
loading.value = true
|
||||
try {
|
||||
const res = await fetchAdminUserGroupPage(page.value, pageSize.value, {
|
||||
search: searchText.value || null,
|
||||
status: null,
|
||||
includeDeleted: false
|
||||
})
|
||||
|
||||
groupList.value = res.items
|
||||
total.value = res.total
|
||||
} catch (e) {
|
||||
uni.showToast({ title: '加载失败', icon: 'none' })
|
||||
} finally {
|
||||
loading.value = false
|
||||
}
|
||||
}
|
||||
|
||||
onMounted(() => {
|
||||
loadGroupList()
|
||||
})
|
||||
|
||||
// 弹窗状态
|
||||
const showModal = ref(false)
|
||||
@@ -97,35 +161,101 @@ const modalTitle = computed(() => isEdit.value ? '修改分组' : '添加分组'
|
||||
|
||||
// 表单数据
|
||||
const formData = reactive({
|
||||
id: 0,
|
||||
name: ''
|
||||
id: '',
|
||||
name: '',
|
||||
remark: '',
|
||||
status: 1
|
||||
})
|
||||
|
||||
// 搜索与重置
|
||||
function handleSearch() {
|
||||
page.value = 1
|
||||
loadGroupList()
|
||||
}
|
||||
|
||||
function handleReset() {
|
||||
searchText.value = ''
|
||||
page.value = 1
|
||||
loadGroupList()
|
||||
}
|
||||
|
||||
// 分页控制
|
||||
function prevPage() {
|
||||
if (page.value > 1) {
|
||||
page.value--
|
||||
loadGroupList()
|
||||
}
|
||||
}
|
||||
|
||||
function nextPage() {
|
||||
if (page.value < totalPages.value) {
|
||||
page.value++
|
||||
loadGroupList()
|
||||
}
|
||||
}
|
||||
|
||||
function goToJumpPage() {
|
||||
const targetPage = parseInt(jumpPage.value)
|
||||
if (!isNaN(targetPage) && targetPage >= 1 && targetPage <= totalPages.value) {
|
||||
page.value = targetPage
|
||||
loadGroupList()
|
||||
jumpPage.value = ''
|
||||
} else {
|
||||
uni.showToast({ title: '请输入有效的页码', icon: 'none' })
|
||||
}
|
||||
}
|
||||
|
||||
// 状态切换
|
||||
async function onToggleStatus(index: number) {
|
||||
const group = groupList.value[index]
|
||||
const targetStatus = group.status === 1 ? 0 : 1
|
||||
try {
|
||||
const ok = await setAdminUserGroupStatus(group.id, targetStatus)
|
||||
if (ok) {
|
||||
group.status = targetStatus
|
||||
uni.showToast({ title: '状态更新成功' })
|
||||
}
|
||||
} catch (e) {
|
||||
uni.showToast({ title: '状态更新失败', icon: 'none' })
|
||||
}
|
||||
}
|
||||
|
||||
// 添加分组
|
||||
function onAddGroup() {
|
||||
isEdit.value = false
|
||||
formData.id = 0
|
||||
formData.id = ''
|
||||
formData.name = ''
|
||||
formData.remark = ''
|
||||
formData.status = 1
|
||||
showModal.value = true
|
||||
}
|
||||
|
||||
// 修改分组
|
||||
function onEditGroup(group: any) {
|
||||
function onEditGroup(group: AdminUserGroup) {
|
||||
isEdit.value = true
|
||||
formData.id = group.id
|
||||
formData.name = group.name
|
||||
formData.remark = group.remark || ''
|
||||
formData.status = group.status
|
||||
showModal.value = true
|
||||
}
|
||||
|
||||
// 删除分组
|
||||
function onDeleteGroup(group: any) {
|
||||
function onDeleteGroup(id: string) {
|
||||
uni.showModal({
|
||||
title: '提示',
|
||||
content: '确定要删除该分组吗?',
|
||||
success: (res) => {
|
||||
success: async (res) => {
|
||||
if (res.confirm) {
|
||||
groupList.value = groupList.value.filter(item => item.id !== group.id)
|
||||
uni.showToast({ title: '删除成功', icon: 'success' })
|
||||
try {
|
||||
const ok = await deleteAdminUserGroup(id)
|
||||
if (ok) {
|
||||
uni.showToast({ title: '删除成功' })
|
||||
loadGroupList()
|
||||
}
|
||||
} catch (e) {
|
||||
uni.showToast({ title: '删除失败', icon: 'none' })
|
||||
}
|
||||
}
|
||||
}
|
||||
})
|
||||
@@ -137,30 +267,28 @@ function closeModal() {
|
||||
}
|
||||
|
||||
// 提交表单
|
||||
function submitForm() {
|
||||
async function submitForm() {
|
||||
if (!formData.name) {
|
||||
uni.showToast({ title: '请输入分组名称', icon: 'none' })
|
||||
return
|
||||
}
|
||||
|
||||
if (isEdit.value) {
|
||||
// 模拟修改
|
||||
const index = groupList.value.findIndex(item => item.id === formData.id)
|
||||
if (index > -1) {
|
||||
groupList.value[index].name = formData.name
|
||||
}
|
||||
uni.showToast({ title: '修改成功', icon: 'success' })
|
||||
} else {
|
||||
// 模拟添加
|
||||
const newId = groupList.value.length > 0 ? Math.max(...groupList.value.map(g => g.id)) + 1 : 1
|
||||
groupList.value.push({
|
||||
id: newId,
|
||||
name: formData.name
|
||||
try {
|
||||
const resId = await saveAdminUserGroup({
|
||||
id: isEdit.value ? formData.id : null,
|
||||
name: formData.name,
|
||||
remark: formData.remark,
|
||||
status: formData.status
|
||||
})
|
||||
uni.showToast({ title: '添加成功', icon: 'success' })
|
||||
}
|
||||
|
||||
closeModal()
|
||||
if (resId != null) {
|
||||
uni.showToast({ title: isEdit.value ? '修改成功' : '添加成功' })
|
||||
closeModal()
|
||||
loadGroupList()
|
||||
}
|
||||
} catch (e) {
|
||||
uni.showToast({ title: '保存失败', icon: 'none' })
|
||||
}
|
||||
}
|
||||
</script>
|
||||
|
||||
@@ -181,6 +309,24 @@ function submitForm() {
|
||||
margin-bottom: 20px;
|
||||
display: flex;
|
||||
flex-direction: row;
|
||||
align-items: center;
|
||||
gap: 12px;
|
||||
}
|
||||
|
||||
.filter-item {
|
||||
display: flex;
|
||||
flex-direction: row;
|
||||
align-items: center;
|
||||
}
|
||||
|
||||
.filter-input {
|
||||
width: 200px;
|
||||
height: 32px;
|
||||
padding: 0 12px;
|
||||
border: 1px solid #d9d9d9;
|
||||
border-radius: 2px;
|
||||
font-size: 14px;
|
||||
background-color: #fff;
|
||||
}
|
||||
|
||||
/* 按钮样式 */
|
||||
@@ -274,6 +420,28 @@ function submitForm() {
|
||||
justify-content: flex-end;
|
||||
}
|
||||
|
||||
.col-remark {
|
||||
flex: 1;
|
||||
}
|
||||
|
||||
.col-status {
|
||||
width: 120px;
|
||||
display: flex;
|
||||
justify-content: center;
|
||||
}
|
||||
|
||||
.table-loading,
|
||||
.table-empty {
|
||||
padding: 24px;
|
||||
text-align: center;
|
||||
color: #999;
|
||||
font-size: 14px;
|
||||
}
|
||||
|
||||
.text-danger {
|
||||
color: #ff4d4f;
|
||||
}
|
||||
|
||||
.op-link {
|
||||
color: #1890ff;
|
||||
cursor: pointer;
|
||||
@@ -291,6 +459,36 @@ function submitForm() {
|
||||
opacity: 0.5;
|
||||
}
|
||||
|
||||
/* Switch 开关 */
|
||||
.switch-box {
|
||||
width: 44px;
|
||||
height: 22px;
|
||||
background-color: #dcdfe6;
|
||||
border-radius: 11px;
|
||||
position: relative;
|
||||
transition: background-color 0.3s;
|
||||
cursor: pointer;
|
||||
}
|
||||
|
||||
.switch-box.active {
|
||||
background-color: #1890ff;
|
||||
}
|
||||
|
||||
.switch-dot {
|
||||
width: 18px;
|
||||
height: 18px;
|
||||
background-color: #fff;
|
||||
border-radius: 9px;
|
||||
position: absolute;
|
||||
top: 2px;
|
||||
left: 2px;
|
||||
transition: transform 0.3s;
|
||||
}
|
||||
|
||||
.switch-box.active .switch-dot {
|
||||
transform: translateX(22px);
|
||||
}
|
||||
|
||||
/* 分页样式 */
|
||||
.pagination-row {
|
||||
margin-top: 24px;
|
||||
@@ -454,6 +652,20 @@ function submitForm() {
|
||||
}
|
||||
}
|
||||
|
||||
.form-textarea {
|
||||
flex: 1;
|
||||
height: 80px;
|
||||
padding: 4px 11px;
|
||||
border: 1px solid #d9d9d9;
|
||||
border-radius: 2px;
|
||||
font-size: 14px;
|
||||
|
||||
&:focus {
|
||||
border-color: #40a9ff;
|
||||
outline: none;
|
||||
}
|
||||
}
|
||||
|
||||
.modal-footer {
|
||||
padding: 10px 16px;
|
||||
border-top: 1px solid #f0f0f0;
|
||||
|
||||
@@ -1,9 +1,14 @@
|
||||
<template>
|
||||
<view class="user-label-page">
|
||||
<view class="content-card">
|
||||
<!-- 操作按钮行 -->
|
||||
<!-- 搜索与操作栏 -->
|
||||
<view class="action-bar">
|
||||
<view class="filter-item">
|
||||
<input class="filter-input" v-model="searchText" placeholder="搜索标签名称/备注" @confirm="handleSearch" />
|
||||
</view>
|
||||
<button class="btn primary small" @click="onAddLabel">添加标签</button>
|
||||
<button class="btn ghost small" @click="handleSearch">查询</button>
|
||||
<button class="btn ghost small" @click="handleReset">重置</button>
|
||||
</view>
|
||||
|
||||
<!-- 标签列表表格 -->
|
||||
@@ -12,18 +17,30 @@
|
||||
<view class="table-header">
|
||||
<view class="col col-id"><text>ID</text></view>
|
||||
<view class="col col-name"><text>标签名称</text></view>
|
||||
<view class="col col-remark"><text>备注</text></view>
|
||||
<view class="col col-status"><text>状态</text></view>
|
||||
<view class="col col-ops"><text>操作</text></view>
|
||||
</view>
|
||||
|
||||
<!-- 表格内容 -->
|
||||
<view class="table-body">
|
||||
<view v-for="label in labelList" :key="label.id" class="table-row">
|
||||
<view v-if="loading" class="table-loading"><text>加载中...</text></view>
|
||||
<view v-else-if="labelList.length === 0" class="table-empty"><text>暂无数据</text></view>
|
||||
<view v-else v-for="(label, index) in labelList" :key="label.id" class="table-row">
|
||||
<view class="col col-id"><text>{{ label.id }}</text></view>
|
||||
<view class="col col-name"><text>{{ label.name }}</text></view>
|
||||
<view class="col col-name">
|
||||
<text :style="{ color: label.color || '#666' }">{{ label.name }}</text>
|
||||
</view>
|
||||
<view class="col col-remark"><text>{{ label.remark || '-' }}</text></view>
|
||||
<view class="col col-status">
|
||||
<view :class="['switch-box', label.status === 1 ? 'active' : '']" @click="onToggleStatus(index)">
|
||||
<view class="switch-dot"></view>
|
||||
</view>
|
||||
</view>
|
||||
<view class="col col-ops">
|
||||
<text class="op-link" @click="onEditLabel(label)">修改</text>
|
||||
<view class="op-divider">|</view>
|
||||
<text class="op-link" @click="onDeleteLabel(label)">删除</text>
|
||||
<text class="op-link text-danger" @click="onDeleteLabel(label.id)">删除</text>
|
||||
</view>
|
||||
</view>
|
||||
</view>
|
||||
@@ -31,19 +48,15 @@
|
||||
|
||||
<!-- 分页区域 -->
|
||||
<view class="pagination-row">
|
||||
<text class="total-text">共 {{ labelList.length }} 条</text>
|
||||
<view class="page-size-selector">
|
||||
<text>15条/页</text>
|
||||
<text class="arrow">▼</text>
|
||||
</view>
|
||||
<text class="total-text">共 {{ total }} 条</text>
|
||||
<view class="page-btns">
|
||||
<view class="page-btn disabled"><text>‹</text></view>
|
||||
<view class="page-btn active"><text>1</text></view>
|
||||
<view class="page-btn disabled"><text>›</text></view>
|
||||
<view :class="['page-btn', page <= 1 ? 'disabled' : '']" @click="prevPage"><text>‹</text></view>
|
||||
<view class="page-btn active"><text>{{ page }}</text></view>
|
||||
<view :class="['page-btn', page >= totalPages ? 'disabled' : '']" @click="nextPage"><text>›</text></view>
|
||||
</view>
|
||||
<view class="page-jump">
|
||||
<text>前往</text>
|
||||
<input class="jump-input" value="1" />
|
||||
<input class="jump-input" v-model="jumpPage" @confirm="goToJumpPage" />
|
||||
<text>页</text>
|
||||
</view>
|
||||
</view>
|
||||
@@ -66,9 +79,36 @@
|
||||
class="form-input"
|
||||
v-model="formData.name"
|
||||
placeholder="请输入标签名称"
|
||||
autofocus
|
||||
/>
|
||||
</view>
|
||||
<view class="form-item" style="margin-top: 20px;">
|
||||
<view class="label-box">
|
||||
<text class="label">标签颜色:</text>
|
||||
</view>
|
||||
<input
|
||||
class="form-input"
|
||||
v-model="formData.color"
|
||||
placeholder="例如: #1890ff"
|
||||
/>
|
||||
</view>
|
||||
<view class="form-item" style="margin-top: 20px;">
|
||||
<view class="label-box">
|
||||
<text class="label">备注说明:</text>
|
||||
</view>
|
||||
<textarea
|
||||
class="form-textarea"
|
||||
v-model="formData.remark"
|
||||
placeholder="请输入备注说明"
|
||||
/>
|
||||
</view>
|
||||
<view class="form-item" style="margin-top: 20px;">
|
||||
<view class="label-box">
|
||||
<text class="label">状态:</text>
|
||||
</view>
|
||||
<view :class="['switch-box', formData.status === 1 ? 'active' : '']" @click="formData.status = (formData.status === 1 ? 0 : 1)">
|
||||
<view class="switch-dot"></view>
|
||||
</view>
|
||||
</view>
|
||||
</view>
|
||||
<view class="modal-footer">
|
||||
<button class="btn ghost" @click="closeModal">取消</button>
|
||||
@@ -80,15 +120,86 @@
|
||||
</template>
|
||||
|
||||
<script setup lang="uts">
|
||||
import { ref, reactive, computed } from 'vue'
|
||||
import { ref, reactive, computed, onMounted } from 'vue'
|
||||
import {
|
||||
fetchAdminUserLabelPage,
|
||||
saveAdminUserLabel,
|
||||
deleteAdminUserLabel,
|
||||
setAdminUserLabelStatus,
|
||||
type AdminUserLabel
|
||||
} from '@/services/admin/userLabelService.uts'
|
||||
|
||||
// 标签数据
|
||||
const labelList = ref([
|
||||
{ id: 1, name: '新客户' },
|
||||
{ id: 2, name: '老客户' },
|
||||
{ id: 3, name: '活跃客户' },
|
||||
{ id: 4, name: '潜在客户' }
|
||||
])
|
||||
const searchText = ref('')
|
||||
const total = ref(0)
|
||||
const labelList = ref<AdminUserLabel[]>([])
|
||||
const loading = ref(false)
|
||||
|
||||
const page = ref(1)
|
||||
const pageSize = ref(15)
|
||||
const jumpPage = ref('')
|
||||
|
||||
const totalPages = computed((): number => {
|
||||
if (pageSize.value <= 0) return 1
|
||||
const pages = Math.ceil(total.value / pageSize.value)
|
||||
return pages <= 0 ? 1 : pages
|
||||
})
|
||||
|
||||
const loadLabelList = async () => {
|
||||
loading.value = true
|
||||
try {
|
||||
const res = await fetchAdminUserLabelPage(page.value, pageSize.value, {
|
||||
search: searchText.value || null,
|
||||
status: null,
|
||||
includeDeleted: false
|
||||
})
|
||||
labelList.value = res.items
|
||||
total.value = res.total
|
||||
} catch (e) {
|
||||
uni.showToast({ title: '加载失败', icon: 'none' })
|
||||
} finally {
|
||||
loading.value = false
|
||||
}
|
||||
}
|
||||
|
||||
onMounted(() => {
|
||||
loadLabelList()
|
||||
})
|
||||
|
||||
function handleSearch() {
|
||||
page.value = 1
|
||||
loadLabelList()
|
||||
}
|
||||
|
||||
function handleReset() {
|
||||
searchText.value = ''
|
||||
page.value = 1
|
||||
loadLabelList()
|
||||
}
|
||||
|
||||
function prevPage() {
|
||||
if (page.value > 1) {
|
||||
page.value--
|
||||
loadLabelList()
|
||||
}
|
||||
}
|
||||
|
||||
function nextPage() {
|
||||
if (page.value < totalPages.value) {
|
||||
page.value++
|
||||
loadLabelList()
|
||||
}
|
||||
}
|
||||
|
||||
function goToJumpPage() {
|
||||
const targetPage = parseInt(jumpPage.value)
|
||||
if (!isNaN(targetPage) && targetPage >= 1 && targetPage <= totalPages.value) {
|
||||
page.value = targetPage
|
||||
loadLabelList()
|
||||
jumpPage.value = ''
|
||||
} else {
|
||||
uni.showToast({ title: '请输入有效的页码', icon: 'none' })
|
||||
}
|
||||
}
|
||||
|
||||
// 弹窗状态
|
||||
const showModal = ref(false)
|
||||
@@ -97,68 +208,100 @@ const modalTitle = computed(() => isEdit.value ? '修改标签' : '添加标签'
|
||||
|
||||
// 表单数据
|
||||
const formData = reactive({
|
||||
id: 0,
|
||||
name: ''
|
||||
id: '',
|
||||
name: '',
|
||||
color: '',
|
||||
remark: '',
|
||||
status: 1
|
||||
})
|
||||
|
||||
// 添加标签
|
||||
function onAddLabel() {
|
||||
isEdit.value = false
|
||||
formData.id = 0
|
||||
formData.id = ''
|
||||
formData.name = ''
|
||||
formData.color = ''
|
||||
formData.remark = ''
|
||||
formData.status = 1
|
||||
showModal.value = true
|
||||
}
|
||||
|
||||
// 修改标签
|
||||
function onEditLabel(label: any) {
|
||||
function onEditLabel(label: AdminUserLabel) {
|
||||
isEdit.value = true
|
||||
formData.id = label.id
|
||||
formData.name = label.name
|
||||
formData.color = label.color ?? ''
|
||||
formData.remark = label.remark ?? ''
|
||||
formData.status = label.status
|
||||
showModal.value = true
|
||||
}
|
||||
|
||||
// 删除标签
|
||||
function onDeleteLabel(label: any) {
|
||||
function onDeleteLabel(id: string) {
|
||||
uni.showModal({
|
||||
title: '提示',
|
||||
content: '确定要删除该标签吗?',
|
||||
success: (res) => {
|
||||
success: async (res) => {
|
||||
if (res.confirm) {
|
||||
labelList.value = labelList.value.filter(item => item.id !== label.id)
|
||||
uni.showToast({ title: '删除成功', icon: 'success' })
|
||||
try {
|
||||
const ok = await deleteAdminUserLabel(id)
|
||||
if (ok) {
|
||||
uni.showToast({ title: '删除成功' })
|
||||
loadLabelList()
|
||||
} else {
|
||||
uni.showToast({ title: '删除失败', icon: 'none' })
|
||||
}
|
||||
} catch (e) {
|
||||
uni.showToast({ title: '删除失败', icon: 'none' })
|
||||
}
|
||||
}
|
||||
}
|
||||
})
|
||||
}
|
||||
|
||||
// 关闭弹窗
|
||||
async function onToggleStatus(index: number) {
|
||||
const item = labelList.value[index]
|
||||
const targetStatus = item.status === 1 ? 0 : 1
|
||||
try {
|
||||
const ok = await setAdminUserLabelStatus(item.id, targetStatus)
|
||||
if (ok) {
|
||||
item.status = targetStatus
|
||||
uni.showToast({ title: '状态更新成功' })
|
||||
} else {
|
||||
uni.showToast({ title: '状态更新失败', icon: 'none' })
|
||||
}
|
||||
} catch (e) {
|
||||
uni.showToast({ title: '状态更新失败', icon: 'none' })
|
||||
}
|
||||
}
|
||||
|
||||
function closeModal() {
|
||||
showModal.value = false
|
||||
}
|
||||
|
||||
// 提交表单
|
||||
function submitForm() {
|
||||
async function submitForm() {
|
||||
if (!formData.name) {
|
||||
uni.showToast({ title: '请输入标签名称', icon: 'none' })
|
||||
return
|
||||
}
|
||||
|
||||
if (isEdit.value) {
|
||||
const index = labelList.value.findIndex(item => item.id === formData.id)
|
||||
if (index > -1) {
|
||||
labelList.value[index].name = formData.name
|
||||
}
|
||||
uni.showToast({ title: '修改成功', icon: 'success' })
|
||||
} else {
|
||||
const newId = labelList.value.length > 0 ? Math.max(...labelList.value.map(g => g.id)) + 1 : 1
|
||||
labelList.value.push({
|
||||
id: newId,
|
||||
name: formData.name
|
||||
try {
|
||||
const resId = await saveAdminUserLabel({
|
||||
id: isEdit.value ? formData.id : null,
|
||||
name: formData.name,
|
||||
color: formData.color || null,
|
||||
remark: formData.remark || null,
|
||||
status: formData.status
|
||||
})
|
||||
uni.showToast({ title: '添加成功', icon: 'success' })
|
||||
}
|
||||
|
||||
closeModal()
|
||||
if (resId != null) {
|
||||
uni.showToast({ title: isEdit.value ? '修改成功' : '添加成功' })
|
||||
closeModal()
|
||||
loadLabelList()
|
||||
} else {
|
||||
uni.showToast({ title: '保存失败', icon: 'none' })
|
||||
}
|
||||
} catch (e) {
|
||||
uni.showToast({ title: '保存失败', icon: 'none' })
|
||||
}
|
||||
}
|
||||
</script>
|
||||
|
||||
@@ -179,6 +322,24 @@ function submitForm() {
|
||||
margin-bottom: 20px;
|
||||
display: flex;
|
||||
flex-direction: row;
|
||||
align-items: center;
|
||||
gap: 12px;
|
||||
}
|
||||
|
||||
.filter-item {
|
||||
display: flex;
|
||||
flex-direction: row;
|
||||
align-items: center;
|
||||
}
|
||||
|
||||
.filter-input {
|
||||
width: 200px;
|
||||
height: 32px;
|
||||
padding: 0 12px;
|
||||
border: 1px solid #d9d9d9;
|
||||
border-radius: 2px;
|
||||
font-size: 14px;
|
||||
background-color: #fff;
|
||||
}
|
||||
|
||||
/* 按钮样式 */
|
||||
@@ -265,6 +426,16 @@ function submitForm() {
|
||||
flex: 1;
|
||||
}
|
||||
|
||||
.col-remark {
|
||||
flex: 1.5;
|
||||
}
|
||||
|
||||
.col-status {
|
||||
width: 120px;
|
||||
display: flex;
|
||||
justify-content: center;
|
||||
}
|
||||
|
||||
.col-ops {
|
||||
width: 150px;
|
||||
display: flex;
|
||||
@@ -272,6 +443,14 @@ function submitForm() {
|
||||
justify-content: flex-end;
|
||||
}
|
||||
|
||||
.table-loading,
|
||||
.table-empty {
|
||||
padding: 24px;
|
||||
text-align: center;
|
||||
color: #999;
|
||||
font-size: 14px;
|
||||
}
|
||||
|
||||
.op-link {
|
||||
color: #1890ff;
|
||||
cursor: pointer;
|
||||
@@ -289,10 +468,45 @@ function submitForm() {
|
||||
opacity: 0.5;
|
||||
}
|
||||
|
||||
.text-danger {
|
||||
color: #ff4d4f;
|
||||
}
|
||||
|
||||
/* Switch 开关 */
|
||||
.switch-box {
|
||||
width: 44px;
|
||||
height: 22px;
|
||||
background-color: #dcdfe6;
|
||||
border-radius: 11px;
|
||||
position: relative;
|
||||
transition: background-color 0.3s;
|
||||
cursor: pointer;
|
||||
}
|
||||
|
||||
.switch-box.active {
|
||||
background-color: #1890ff;
|
||||
}
|
||||
|
||||
.switch-dot {
|
||||
width: 18px;
|
||||
height: 18px;
|
||||
background-color: #fff;
|
||||
border-radius: 9px;
|
||||
position: absolute;
|
||||
top: 2px;
|
||||
left: 2px;
|
||||
transition: transform 0.3s;
|
||||
}
|
||||
|
||||
.switch-box.active .switch-dot {
|
||||
transform: translateX(22px);
|
||||
}
|
||||
|
||||
/* 分页样式 */
|
||||
.pagination-row {
|
||||
margin-top: 24px;
|
||||
display: flex;
|
||||
flex-direction: row;
|
||||
align-items: center;
|
||||
justify-content: flex-end;
|
||||
color: #666;
|
||||
@@ -303,24 +517,9 @@ function submitForm() {
|
||||
margin-right: 16px;
|
||||
}
|
||||
|
||||
.page-size-selector {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
padding: 0 8px;
|
||||
height: 32px;
|
||||
border: 1px solid #d9d9d9;
|
||||
border-radius: 2px;
|
||||
margin-right: 16px;
|
||||
|
||||
.arrow {
|
||||
font-size: 10px;
|
||||
margin-left: 8px;
|
||||
color: #999;
|
||||
}
|
||||
}
|
||||
|
||||
.page-btns {
|
||||
display: flex;
|
||||
flex-direction: row;
|
||||
margin-right: 16px;
|
||||
}
|
||||
|
||||
@@ -349,6 +548,7 @@ function submitForm() {
|
||||
|
||||
.page-jump {
|
||||
display: flex;
|
||||
flex-direction: row;
|
||||
align-items: center;
|
||||
|
||||
.jump-input {
|
||||
@@ -448,6 +648,20 @@ function submitForm() {
|
||||
}
|
||||
}
|
||||
|
||||
.form-textarea {
|
||||
flex: 1;
|
||||
height: 80px;
|
||||
padding: 4px 11px;
|
||||
border: 1px solid #d9d9d9;
|
||||
border-radius: 2px;
|
||||
font-size: 14px;
|
||||
|
||||
&:focus {
|
||||
border-color: #40a9ff;
|
||||
outline: none;
|
||||
}
|
||||
}
|
||||
|
||||
.modal-footer {
|
||||
padding: 10px 16px;
|
||||
border-top: 1px solid #f0f0f0;
|
||||
|
||||
@@ -157,7 +157,13 @@
|
||||
</template>
|
||||
|
||||
<script setup lang="uts">
|
||||
import { ref, reactive } from 'vue'
|
||||
import { ref, reactive, onMounted, computed } from 'vue'
|
||||
import {
|
||||
fetchAdminUserLevelPage,
|
||||
saveAdminUserLevel,
|
||||
deleteAdminUserLevel,
|
||||
setAdminUserLevelVisible
|
||||
} from '@/services/admin/userLevelService.uts'
|
||||
|
||||
interface LevelItem {
|
||||
id: number
|
||||
@@ -172,18 +178,76 @@ interface LevelItem {
|
||||
}
|
||||
|
||||
const filterName = ref('')
|
||||
const total = ref(5)
|
||||
const levelList = ref<LevelItem[]>([
|
||||
{ id: 1, name: 'V1', level: 1, iconBg: '#fdf6ec', iconSymbol: '👑', bgGradient: 'linear-gradient(to bottom right, #f5e6d3, #e8d5bc)', discount: 99, experience: 500, isShow: true },
|
||||
{ id: 2, name: 'V2', level: 2, iconBg: '#ecf5ff', iconSymbol: '💎', bgGradient: 'linear-gradient(to bottom right, #d3e9f5, #bcd9e8)', discount: 97, experience: 1000, isShow: true },
|
||||
{ id: 3, name: 'V3', level: 3, iconBg: '#f4f4f5', iconSymbol: '⭐', bgGradient: 'linear-gradient(to bottom right, #e3e3e3, #cbcbcb)', discount: 95, experience: 3000, isShow: true },
|
||||
{ id: 4, name: 'V4', level: 4, iconBg: '#fef0f0', iconSymbol: '👑', bgGradient: 'linear-gradient(to bottom right, #f5dfd3, #e8c6bc)', discount: 93, experience: 8000, isShow: true },
|
||||
{ id: 5, name: 'V5', level: 5, iconBg: '#f0f9eb', iconSymbol: '💠', bgGradient: 'linear-gradient(to bottom right, #d3e1f5, #bccce8)', discount: 70, experience: 15000, isShow: true }
|
||||
])
|
||||
const total = ref(0)
|
||||
const levelList = ref<AdminUserLevel[]>([])
|
||||
const loading = ref(false)
|
||||
const page = ref(1)
|
||||
const pageSize = ref(15)
|
||||
const jumpPage = ref('')
|
||||
|
||||
const totalPages = computed((): number => {
|
||||
if (pageSize.value <= 0) return 1
|
||||
const pages = Math.ceil(total.value / pageSize.value)
|
||||
return pages <= 0 ? 1 : pages
|
||||
})
|
||||
|
||||
const loadLevelList = async () => {
|
||||
loading.value = true
|
||||
try {
|
||||
const res = await fetchAdminUserLevelPage(page.value, pageSize.value, {
|
||||
search: filterName.value || null,
|
||||
isVisible: null, // 全部
|
||||
status: null
|
||||
})
|
||||
|
||||
levelList.value = res.items
|
||||
total.value = res.total
|
||||
} catch (e) {
|
||||
uni.showToast({ title: '加载失败', icon: 'none' })
|
||||
} finally {
|
||||
loading.value = false
|
||||
}
|
||||
}
|
||||
|
||||
onMounted(() => {
|
||||
loadLevelList()
|
||||
})
|
||||
|
||||
const handleQuery = () => {
|
||||
page.value = 1
|
||||
loadLevelList()
|
||||
}
|
||||
|
||||
const prevPage = () => {
|
||||
if (page.value > 1) {
|
||||
page.value--
|
||||
loadLevelList()
|
||||
}
|
||||
}
|
||||
|
||||
const nextPage = () => {
|
||||
if (page.value < totalPages.value) {
|
||||
page.value++
|
||||
loadLevelList()
|
||||
}
|
||||
}
|
||||
|
||||
const goToJumpPage = () => {
|
||||
const targetPage = parseInt(jumpPage.value)
|
||||
if (!isNaN(targetPage) && targetPage >= 1 && targetPage <= totalPages.value) {
|
||||
page.value = targetPage
|
||||
loadLevelList()
|
||||
jumpPage.value = ''
|
||||
} else {
|
||||
uni.showToast({ title: '请输入有效的页码', icon: 'none' })
|
||||
}
|
||||
}
|
||||
|
||||
const showDrawer = ref(false)
|
||||
const isClosing = ref(false)
|
||||
const isEdit = ref(false)
|
||||
const editingId = ref<string | null>(null)
|
||||
|
||||
const form = reactive({
|
||||
name: '',
|
||||
level: 1,
|
||||
@@ -192,11 +256,11 @@ const form = reactive({
|
||||
isShow: true
|
||||
})
|
||||
|
||||
const handleQuery = () => { console.log('Querying...') }
|
||||
const handleAdd = () => {
|
||||
isEdit.value = false
|
||||
editingId.value = null
|
||||
form.name = ''
|
||||
form.level = levelList.value.length + 1
|
||||
form.level = 1
|
||||
form.discount = 100
|
||||
form.experience = 0
|
||||
form.isShow = true
|
||||
@@ -204,32 +268,74 @@ const handleAdd = () => {
|
||||
isClosing.value = false
|
||||
}
|
||||
|
||||
const handleEdit = (item: LevelItem) => {
|
||||
const handleEdit = (item: AdminUserLevel) => {
|
||||
isEdit.value = true
|
||||
editingId.value = item.id
|
||||
form.name = item.name
|
||||
form.level = item.level
|
||||
form.discount = item.discount
|
||||
form.experience = item.experience
|
||||
form.isShow = item.isShow
|
||||
form.level = item.level_weight
|
||||
form.discount = item.discount_percent
|
||||
form.experience = item.min_experience
|
||||
form.isShow = item.is_visible
|
||||
showDrawer.value = true
|
||||
isClosing.value = false
|
||||
}
|
||||
|
||||
const closeDrawer = () => {
|
||||
isClosing.value = true
|
||||
setTimeout(() => {
|
||||
showDrawer.value = false
|
||||
isClosing.value = false
|
||||
}, 300)
|
||||
const handleDelete = (id: string) => {
|
||||
uni.showModal({
|
||||
title: '确认删除',
|
||||
content: '确定要删除该用户等级吗?',
|
||||
success: async (res) => {
|
||||
if (res.confirm) {
|
||||
const ok = await deleteAdminUserLevel(id)
|
||||
if (ok) {
|
||||
uni.showToast({ title: '删除成功' })
|
||||
loadLevelList()
|
||||
} else {
|
||||
uni.showToast({ title: '删除失败', icon: 'none' })
|
||||
}
|
||||
}
|
||||
}
|
||||
})
|
||||
}
|
||||
|
||||
const toggleShow = (index: number) => {
|
||||
levelList.value[index].isShow = !levelList.value[index].isShow
|
||||
const toggleShow = async (index: number) => {
|
||||
const item = levelList.value[index]
|
||||
const targetVisible = !item.is_visible
|
||||
const ok = await setAdminUserLevelVisible(item.id, targetVisible)
|
||||
if (ok) {
|
||||
item.is_visible = targetVisible
|
||||
} else {
|
||||
uni.showToast({ title: '修改失败', icon: 'none' })
|
||||
}
|
||||
}
|
||||
|
||||
const handleSave = () => {
|
||||
console.log('Saving...', form)
|
||||
closeDrawer()
|
||||
const handleSave = async () => {
|
||||
if (!form.name) {
|
||||
uni.showToast({ title: '请输入等级名称', icon: 'none' })
|
||||
return
|
||||
}
|
||||
|
||||
try {
|
||||
const resId = await saveAdminUserLevel({
|
||||
id: editingId.value,
|
||||
name: form.name,
|
||||
level_weight: form.level,
|
||||
min_experience: form.experience,
|
||||
discount_percent: form.discount,
|
||||
is_visible: form.isShow,
|
||||
status: 1 // 默认启用
|
||||
})
|
||||
|
||||
if (resId != null) {
|
||||
uni.showToast({ title: '保存成功' })
|
||||
closeDrawer()
|
||||
loadLevelList()
|
||||
} else {
|
||||
uni.showToast({ title: '保存失败', icon: 'none' })
|
||||
}
|
||||
} catch (e) {
|
||||
uni.showToast({ title: '保存出错', icon: 'none' })
|
||||
}
|
||||
}
|
||||
</script>
|
||||
|
||||
|
||||
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