From 84db79fb226a64a1f54ae610a252a7359964df91 Mon Sep 17 00:00:00 2001 From: duzhichao <1098974448@qq.com> Date: Thu, 23 Oct 2025 12:12:39 +0800 Subject: [PATCH] =?UTF-8?q?feat:=201=EF=BC=9A=E4=BC=98=E5=8C=96token?= =?UTF-8?q?=E6=9F=A5=E8=AF=A2=E9=A1=B5=202=EF=BC=9A=E7=94=A8=E6=88=B7?= =?UTF-8?q?=E7=AE=A1=E7=90=86=E9=A1=B5=E9=9D=A2=E6=96=B0=E5=A2=9E=E4=BF=AE?= =?UTF-8?q?=E6=94=B9=E5=AF=86=E7=A0=81=E5=8A=9F=E8=83=BD=203=EF=BC=9A?= =?UTF-8?q?=E8=B0=83=E6=95=B4=E6=99=AF=E5=8C=BA=E4=B8=8E=E4=BA=8C=E7=BB=B4?= =?UTF-8?q?=E7=A0=81=E5=85=B3=E7=B3=BB?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../src/components/ui/SearchBarPlus/index.tsx | 19 +++++- .../src/pages/orders/Tourism/index.tsx | 13 ++++ .../src/pages/system/Token/index.tsx | 60 ++++++------------- .../system/User/components/UserTable.tsx | 10 ++-- .../src/pages/system/User/index.tsx | 59 +++++++++++++++--- zlt-web/react-web-next/src/services/orders.ts | 7 +++ zlt-web/react-web-next/src/services/system.ts | 14 +++++ zlt-web/react-web-next/src/services/token.ts | 9 ++- 8 files changed, 133 insertions(+), 58 deletions(-) diff --git a/zlt-web/react-web-next/src/components/ui/SearchBarPlus/index.tsx b/zlt-web/react-web-next/src/components/ui/SearchBarPlus/index.tsx index 3c7acd32..94bd5191 100644 --- a/zlt-web/react-web-next/src/components/ui/SearchBarPlus/index.tsx +++ b/zlt-web/react-web-next/src/components/ui/SearchBarPlus/index.tsx @@ -1,10 +1,11 @@ import React from 'react'; import { QueryFilter } from '@ant-design/pro-components'; +import { Button } from 'antd'; import TenantSelector from '@/components/ui/TenantSelector'; import { tenantApi } from '@/services/tenant'; export interface SearchBarPlusProps { - // QueryFilter 透传属性(常用) + // QueryFilter 常用属性 defaultCollapsed?: boolean; split?: boolean; span?: number | { xs?: number; sm?: number; md?: number; lg?: number; xl?: number; xxl?: number }; @@ -14,12 +15,14 @@ export interface SearchBarPlusProps { children?: React.ReactNode; // 是否显示租户筛选(默认显示) showTenant?: boolean; - // 租户变化回调:用于触发表格 reload 等 + // 租户变化回调:用于触发表格 reload onTenantChanged?: (tenantId: string, includeChildren: boolean) => void; // 租户筛选放置位置:start 放在最前,end 放在最后(默认 start) tenantPosition?: 'start' | 'end'; // 是否调用后端“切换查询租户”接口(默认不调用,避免跨页面副作用) useSwitchTenant?: boolean; + // 是否隐藏重置按钮(默认 false) + hideReset?: boolean; } const SearchBarPlus: React.FC = ({ @@ -33,6 +36,7 @@ const SearchBarPlus: React.FC = ({ onTenantChanged, tenantPosition = 'start', useSwitchTenant = false, + hideReset = false, }) => { const handleFinish = async (values: Record) => { try { @@ -52,6 +56,17 @@ const SearchBarPlus: React.FC = ({ span={span as any} form={form} onFinish={handleFinish} + submitter={ + hideReset + ? { + render: (props: any) => [ + , + ], + } + : undefined + } > {showTenant && tenantPosition === 'start' ? : null} {children} diff --git a/zlt-web/react-web-next/src/pages/orders/Tourism/index.tsx b/zlt-web/react-web-next/src/pages/orders/Tourism/index.tsx index f7b583e1..c99cb701 100644 --- a/zlt-web/react-web-next/src/pages/orders/Tourism/index.tsx +++ b/zlt-web/react-web-next/src/pages/orders/Tourism/index.tsx @@ -5,6 +5,7 @@ import { ActionBar, GlassCard, GradientButton, SearchBarPlus } from '@/component import { PlusOutlined } from '@ant-design/icons'; import { ordersApi } from '@/services/orders'; import TourismForm, { TourismItem } from './components/TourismForm'; +import QrcodeListModal from './components/QrcodeListModal'; import { tenantApi } from '@/services/tenant'; const TourismPage: React.FC = () => { @@ -12,6 +13,8 @@ const TourismPage: React.FC = () => { const [editOpen, setEditOpen] = useState(false); const [current, setCurrent] = useState(undefined); const [params, setParams] = useState>({}); + const [qrcodeOpen, setQrcodeOpen] = useState(false); + const [qrcodeTourism, setQrcodeTourism] = useState(undefined); // 首次进入时,默认按“当前租户 + 包含下级租户”查询,避免全量数据 useEffect(() => { @@ -54,6 +57,7 @@ const TourismPage: React.FC = () => { key: 'action', render: (_: any, record: TourismItem) => ( + { setQrcodeTourism(record); setQrcodeOpen(true); }}>打卡点 { setCurrent(record); setEditOpen(true); }}>编辑 { } finally { hide(); } }} /> + + {qrcodeOpen && qrcodeTourism?.id ? ( + + ) : null} ); }; diff --git a/zlt-web/react-web-next/src/pages/system/Token/index.tsx b/zlt-web/react-web-next/src/pages/system/Token/index.tsx index bb1d2978..b5fa9b47 100644 --- a/zlt-web/react-web-next/src/pages/system/Token/index.tsx +++ b/zlt-web/react-web-next/src/pages/system/Token/index.tsx @@ -1,30 +1,14 @@ -import React, { useEffect, useRef, useState } from 'react'; -import { PageContainer, ProFormSelect, ProFormText, ProTable } from '@ant-design/pro-components'; -import type { ActionType } from '@ant-design/pro-components'; -import { Popconfirm, Form, message } from 'antd'; -import { roleApi } from '@/services/role'; +import React, { useRef } from 'react'; +import { PageContainer, ProTable } from '@ant-design/pro-components'; +import type { ActionType, ProColumns } from '@ant-design/pro-components'; +import { Popconfirm, message, Button } from 'antd'; import { tokenApi, TokenItem } from '@/services/token'; -import { GlassCard, SearchBarPlus } from '@/components/ui'; +import { GlassCard } from '@/components/ui'; const TokenPage: React.FC = () => { - const [apps, setApps] = useState([]); - const [params, setParams] = useState<{ tenantId?: string; username?: string }>({}); - const [form] = Form.useForm(); const actionRef = useRef(); - useEffect(() => { - (async () => { - const appData = (await roleApi.apps()) || []; - setApps(appData); - if (appData.length > 0) { - const tenantId = appData[0].clientId; - setParams({ tenantId }); - form.setFieldsValue({ tenantId }); - } - })(); - }, []); - - const columns = [ + const columns: ProColumns[] = [ { dataIndex: 'index', valueType: 'indexBorder' }, { title: 'Token', dataIndex: 'tokenValue', width: 200 }, { title: '过期时间', dataIndex: 'expiration', valueType: 'dateTime' }, @@ -33,7 +17,8 @@ const TokenPage: React.FC = () => { { title: '所属应用', dataIndex: 'clientId' }, { title: '账号类型', dataIndex: 'accountType' }, { - title: '操作', key: 'action', + title: '操作', + key: 'action', render: (_: any, entity: TokenItem) => ( { actionRef.current?.reload(); } catch (e) { message.error('删除失败'); - } finally { hide(); } + } finally { + hide(); + } }} > 删除 - ) + ), }, ]; return ( - actionRef.current?.reload?.()} - onFinish={async (values) => setParams(values)} - > - ({ label: item.clientId, value: item.clientId }))} - /> - - - rowKey="tokenValue" headerTitle="Token 列表" actionRef={actionRef} - request={async (p) => tokenApi.page({ ...p, ...params } as any)} + request={async (p) => tokenApi.page({ ...p } as any)} columns={columns as any} + toolBarRender={() => [ + , + ]} search={false} pagination={{ showSizeChanger: true, showQuickJumper: true }} /> diff --git a/zlt-web/react-web-next/src/pages/system/User/components/UserTable.tsx b/zlt-web/react-web-next/src/pages/system/User/components/UserTable.tsx index 2f7b790f..78287bb0 100644 --- a/zlt-web/react-web-next/src/pages/system/User/components/UserTable.tsx +++ b/zlt-web/react-web-next/src/pages/system/User/components/UserTable.tsx @@ -11,12 +11,13 @@ export interface UserTableRef { export interface UserTableProps { onEdit: (record: UserItem) => void; onResetPassword: (record: UserItem) => void; + onChangePassword: (record: UserItem) => void; onDelete: (record: UserItem) => void; // 额外查询参数(由外部查询条件统一注入) extraParams?: Record; } -const UserTable = forwardRef(({ onEdit, onResetPassword, onDelete, extraParams }, ref) => { +const UserTable = forwardRef(({ onEdit, onResetPassword, onChangePassword, onDelete, extraParams }, ref) => { const actionRef = useRef(); useImperativeHandle(ref, () => ({ @@ -35,7 +36,7 @@ const UserTable = forwardRef(({ onEdit, onResetPas { title: '用户名', dataIndex: 'username' }, { title: '用户昵称', dataIndex: 'nickname' }, { title: '手机号', dataIndex: 'mobile' }, - { title: '性别', dataIndex: 'sex', valueType: 'select', valueEnum: { 0: { text: '男' }, 1: { text: '女' } }, width: 80 }, + { title: '性别', dataIndex: 'sex', valueType: 'select', valueEnum: { 0: { text: '女' }, 1: { text: '男' } }, width: 80 }, { title: '创建时间', dataIndex: 'createTime', valueType: 'dateTime', search: false }, { title: '状态', dataIndex: 'enabled', search: false, @@ -44,10 +45,11 @@ const UserTable = forwardRef(({ onEdit, onResetPas ) }, { - title: '操作', valueType: 'option', width: 220, + title: '操作', valueType: 'option', width: 280, render: (_, entity) => ( onEdit(entity)}>编辑 + onChangePassword(entity)}>修改密码 onResetPassword(entity)}>重置密码 onDelete(entity)}> 删除 @@ -71,7 +73,7 @@ const UserTable = forwardRef(({ onEdit, onResetPas const { data, total } = await systemApi.users({ ...(safeP as any), ...(safeExtra as any) } as any); return { data, total, success: true }; }} - pagination={{ pageSize: 10 }} + pagination={{ pageSize: 20 }} // 统一关闭 ProTable 自带搜索,由 SearchBarPlus 统一驱动 search={false} toolBarRender={false} diff --git a/zlt-web/react-web-next/src/pages/system/User/index.tsx b/zlt-web/react-web-next/src/pages/system/User/index.tsx index e3995198..5d9c0c9d 100644 --- a/zlt-web/react-web-next/src/pages/system/User/index.tsx +++ b/zlt-web/react-web-next/src/pages/system/User/index.tsx @@ -6,6 +6,7 @@ import { systemApi, UserItem } from '@/services/system'; import UserTable, { UserTableRef } from './components/UserTable'; import Toolbar from './components/Toolbar'; import UserForm from './components/UserForm'; +import ChangePasswordModal from './components/ChangePasswordModal'; const UsersPage: React.FC = () => { const tableRef = useRef(null); @@ -15,18 +16,27 @@ const UsersPage: React.FC = () => { const [createVisible, setCreateVisible] = useState(false); const [editVisible, setEditVisible] = useState(false); const [currentRow, setCurrentRow] = useState(undefined); + const [pwdVisible, setPwdVisible] = useState(false); + const [pwdUser, setPwdUser] = useState(undefined); const addUser = async (values: UserItem & { company?: string; type?: string }) => { const hide = message.loading('正在添加'); try { - await systemApi.saveOrUpdateUser({ ...(values as any), roleId: (values as any)?.roleIds ? (values as any).roleIds.join(',') : (values as any)?.roleId } as any); + const res: any = await systemApi.saveOrUpdateUserRaw({ + ...(values as any), + roleId: (values as any)?.roleIds ? (values as any).roleIds.join(',') : (values as any)?.roleId, + } as any); + const code = res?.resp_code ?? res?.code; + if (typeof code === 'number' && code !== 0) { + throw new Error(res?.resp_msg || res?.message || '添加用户失败'); + } hide(); message.success('添加用户成功'); tableRef.current?.reload(); return true; - } catch (e) { + } catch (e: any) { hide(); - message.error('添加用户失败'); + message.error(e?.message || '添加用户失败'); return false; } }; @@ -34,14 +44,22 @@ const UsersPage: React.FC = () => { const editUser = async (values: UserItem & { company?: string; type?: string }) => { const hide = message.loading('正在更新'); try { - await systemApi.saveOrUpdateUser({ ...(currentRow as any), ...(values as any), roleId: (values as any)?.roleIds ? (values as any).roleIds.join(',') : (values as any)?.roleId } as any); + const res: any = await systemApi.saveOrUpdateUserRaw({ + ...(currentRow as any), + ...(values as any), + roleId: (values as any)?.roleIds ? (values as any).roleIds.join(',') : (values as any)?.roleId, + } as any); + const code = res?.resp_code ?? res?.code; + if (typeof code === 'number' && code !== 0) { + throw new Error(res?.resp_msg || res?.message || '修改用户失败'); + } hide(); message.success('修改用户成功'); tableRef.current?.reload(); return true; - } catch (e) { + } catch (e: any) { hide(); - message.error('修改用户失败'); + message.error(e?.message || '修改用户失败'); return false; } }; @@ -58,6 +76,28 @@ const UsersPage: React.FC = () => { } }; + const openChangePwd = (record: UserItem) => { + setPwdUser(record); + setPwdVisible(true); + }; + + const submitChangePwd = async (values: { newPassword: string; confirmPassword: string }) => { + const hide = message.loading('正在修改密码'); + try { + await systemApi.changePassword(pwdUser!.id!, values.newPassword); + hide(); + message.success('修改密码成功'); + setPwdVisible(false); + setPwdUser(undefined); + tableRef.current?.reload(); + return true; + } catch (e) { + hide(); + message.error('修改密码失败'); + return false; + } + }; + const delUser = async (record: UserItem) => { const hide = message.loading('正在删除'); try { @@ -83,6 +123,7 @@ const UsersPage: React.FC = () => { defaultCollapsed={false} split span={6} + hideReset showTenant={!isAppType} onTenantChanged={(tenantId, includeChildren) => { // 租户切换时,直接更新查询参数,ProTable 会因 params 变更自动请求 @@ -106,6 +147,7 @@ const UsersPage: React.FC = () => { { setCurrentRow(r); setEditVisible(true); }} + onChangePassword={(r) => openChangePwd(r)} onResetPassword={(r) => resetPwd(r)} onDelete={(r) => delUser(r)} // 通过 __refresh 强制区分每次点击 @@ -113,11 +155,14 @@ const UsersPage: React.FC = () => { /> - {/* 新建(仅系统用户) */} + {/* 新建(仅系统用户)*/} {/* 编辑 */} + + {/* 修改密码 */} + ); }; diff --git a/zlt-web/react-web-next/src/services/orders.ts b/zlt-web/react-web-next/src/services/orders.ts index 41a38fd3..0124ecf4 100644 --- a/zlt-web/react-web-next/src/services/orders.ts +++ b/zlt-web/react-web-next/src/services/orders.ts @@ -49,6 +49,13 @@ export const ordersApi = { return (res as any).data || res; }, + // 按景区ID查询二维码列表 + qrcodeListByTourism: async (params: { current?: number; pageSize?: number; tourismId: number; [k: string]: any }) => { + const { current, pageSize, ...rest } = params || {}; + const res = await request('/api-order/qrcode', { method: 'GET', params: { page: current, limit: pageSize, ...rest } }); + return { data: (res as any).data, total: (res as any).count }; + }, + // 旅游景区 tourism: async (params: { current?: number; pageSize?: number; [k: string]: any }) => { const { current, pageSize, ...rest } = params || {}; diff --git a/zlt-web/react-web-next/src/services/system.ts b/zlt-web/react-web-next/src/services/system.ts index 193566eb..88febec3 100644 --- a/zlt-web/react-web-next/src/services/system.ts +++ b/zlt-web/react-web-next/src/services/system.ts @@ -40,6 +40,11 @@ export const systemApi = { const res = await request('/api-user/users/saveOrUpdate', { method: 'POST', data }); return (res as any).data || res; }, + // 原样返回后端包装,便于上层拿到 resp_code/resp_msg 做精确提示 + saveOrUpdateUserRaw: async (data: Partial) => { + const res = await request('/api-user/users/saveOrUpdate', { method: 'POST', data }); + return res as any; + }, // 启用/禁用 updateEnabled: async (id: number, enabled: boolean) => { @@ -52,6 +57,15 @@ export const systemApi = { const res = await request(`/api-user/users/${id}/password`, { method: 'PUT' }); return (res as any).data || res; }, + // 修改密码(支持管理员为指定用户设置自定义密码,或用户自助修改) + // 后端签名:PUT /users/password,Body: { id, oldPassword?, newPassword } + changePassword: async (id: number, newPassword: string, oldPassword?: string) => { + const res = await request('/api-user/users/password', { + method: 'PUT', + data: { id, newPassword, oldPassword }, + }); + return (res as any).data || res; + }, // 删除用户 deleteUser: async (id: number) => { diff --git a/zlt-web/react-web-next/src/services/token.ts b/zlt-web/react-web-next/src/services/token.ts index cf54aea3..3092d593 100644 --- a/zlt-web/react-web-next/src/services/token.ts +++ b/zlt-web/react-web-next/src/services/token.ts @@ -10,9 +10,12 @@ export interface TokenItem { } export const tokenApi = { - page: async (params: { current?: number; pageSize?: number; tenantId: string; username?: string }) => { - if (!params?.tenantId) return { data: [], total: 0 }; - const res = await request('/api-uaa/tokens', { method: 'GET', params: { page: params.current, limit: params.pageSize, ...params } }); + page: async (params: { current?: number; pageSize?: number; tenantId?: string; username?: string }) => { + const p2 = { tenantId: 'webApp', ...params }; + const res = await request('/api-uaa/tokens', { + method: 'GET', + params: { page: p2.current, limit: p2.pageSize, ...p2 }, + }); const data = (res as any).data; const total = (res as any).count ?? data?.length ?? 0; return { data, total } as { data: TokenItem[]; total: number };