feat: 1:优化token查询页 2:用户管理页面新增修改密码功能 3:调整景区与二维码关系

This commit is contained in:
2025-10-23 12:12:39 +08:00
parent e11fee3f53
commit 84db79fb22
8 changed files with 133 additions and 58 deletions
@@ -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<TourismItem | undefined>(undefined);
const [params, setParams] = useState<Record<string, any>>({});
const [qrcodeOpen, setQrcodeOpen] = useState(false);
const [qrcodeTourism, setQrcodeTourism] = useState<TourismItem | undefined>(undefined);
// 首次进入时,默认按“当前租户 + 包含下级租户”查询,避免全量数据
useEffect(() => {
@@ -54,6 +57,7 @@ const TourismPage: React.FC = () => {
key: 'action',
render: (_: any, record: TourismItem) => (
<Space>
<a onClick={() => { setQrcodeTourism(record); setQrcodeOpen(true); }}>打卡点</a>
<a onClick={() => { setCurrent(record); setEditOpen(true); }}>编辑</a>
<Popconfirm
title={`确认删除项目[${record.tourismName}]?`}
@@ -144,6 +148,15 @@ const TourismPage: React.FC = () => {
} finally { hide(); }
}}
/>
{qrcodeOpen && qrcodeTourism?.id ? (
<QrcodeListModal
open={qrcodeOpen}
onOpenChange={setQrcodeOpen}
tourismId={qrcodeTourism.id as number}
tourismName={qrcodeTourism.tourismName}
/>
) : null}
</PageContainer>
);
};
@@ -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<any[]>([]);
const [params, setParams] = useState<{ tenantId?: string; username?: string }>({});
const [form] = Form.useForm();
const actionRef = useRef<ActionType>();
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<TokenItem>[] = [
{ 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) => (
<Popconfirm
title={`确认删除 Token?`}
@@ -45,40 +30,31 @@ const TokenPage: React.FC = () => {
actionRef.current?.reload();
} catch (e) {
message.error('删除失败');
} finally { hide(); }
} finally {
hide();
}
}}
>
<a>删除</a>
</Popconfirm>
)
),
},
];
return (
<PageContainer header={{ title: 'Token 管理' }}>
<SearchBarPlus
defaultCollapsed
split
span={6}
onTenantChanged={() => actionRef.current?.reload?.()}
onFinish={async (values) => setParams(values)}
>
<ProFormSelect
name="tenantId"
label="所属应用"
fieldProps={{ allowClear: false }}
options={apps.map((item) => ({ label: item.clientId, value: item.clientId }))}
/>
<ProFormText name="username" label="搜索" placeholder="请输入用户名" />
</SearchBarPlus>
<GlassCard>
<ProTable<TokenItem>
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={() => [
<Button key="refresh" type="primary" onClick={() => actionRef.current?.reload?.()}>
查询
</Button>,
]}
search={false}
pagination={{ showSizeChanger: true, showQuickJumper: true }}
/>
@@ -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<string, any>;
}
const UserTable = forwardRef<UserTableRef, UserTableProps>(({ onEdit, onResetPassword, onDelete, extraParams }, ref) => {
const UserTable = forwardRef<UserTableRef, UserTableProps>(({ onEdit, onResetPassword, onChangePassword, onDelete, extraParams }, ref) => {
const actionRef = useRef<ActionType>();
useImperativeHandle(ref, () => ({
@@ -35,7 +36,7 @@ const UserTable = forwardRef<UserTableRef, UserTableProps>(({ 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<UserTableRef, UserTableProps>(({ onEdit, onResetPas
)
},
{
title: '操作', valueType: 'option', width: 220,
title: '操作', valueType: 'option', width: 280,
render: (_, entity) => (
<Space>
<a onClick={() => onEdit(entity)}>编辑</a>
<a onClick={() => onChangePassword(entity)}>修改密码</a>
<a onClick={() => onResetPassword(entity)}>重置密码</a>
<Popconfirm title={`确认删除用户[${entity.username}]?`} onConfirm={() => onDelete(entity)}>
<a style={{ color: '#1677ff' }}>删除</a>
@@ -71,7 +73,7 @@ const UserTable = forwardRef<UserTableRef, UserTableProps>(({ 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}
@@ -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<UserTableRef>(null);
@@ -15,18 +16,27 @@ const UsersPage: React.FC = () => {
const [createVisible, setCreateVisible] = useState(false);
const [editVisible, setEditVisible] = useState(false);
const [currentRow, setCurrentRow] = useState<UserItem | undefined>(undefined);
const [pwdVisible, setPwdVisible] = useState(false);
const [pwdUser, setPwdUser] = useState<UserItem | undefined>(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 = () => {
<UserTable
ref={tableRef}
onEdit={(r) => { 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 = () => {
/>
</GlassCard>
{/* 新建(仅系统用户) */}
{/* 新建(仅系统用户)*/}
<UserForm title="新建用户" visible={createVisible} onVisibleChange={setCreateVisible} onFinish={addUser} showCompany={!isAppType ? true : false} />
{/* 编辑 */}
<UserForm title="修改用户" visible={editVisible} onVisibleChange={setEditVisible} onFinish={editUser} initialValues={currentRow} showCompany={!isAppType ? true : false} />
{/* 修改密码 */}
<ChangePasswordModal visible={pwdVisible} user={pwdUser} onVisibleChange={setPwdVisible} onFinish={submitChangePwd} />
</PageContainer>
);
};