|
@@ -1,17 +1,28 @@
|
|
|
import { fetchInitialCredentials, fetchProductList, fetchUpdateProduct } from '@/services/product';
|
|
import { fetchInitialCredentials, fetchProductList, fetchUpdateProduct } from '@/services/product';
|
|
|
import { ActionType, PageContainer, ProColumns, ProTable } from '@ant-design/pro-components';
|
|
import { ActionType, PageContainer, ProColumns, ProTable } from '@ant-design/pro-components';
|
|
|
-import { useIntl, useNavigate } from '@umijs/max';
|
|
|
|
|
|
|
+import { useIntl, useLocation, useNavigate } from '@umijs/max';
|
|
|
import { Button, Popconfirm, Tag, message } from 'antd';
|
|
import { Button, Popconfirm, Tag, message } from 'antd';
|
|
|
import { useRef, useState } from 'react';
|
|
import { useRef, useState } from 'react';
|
|
|
import { ProductForm } from './components/Form';
|
|
import { ProductForm } from './components/Form';
|
|
|
import { CredentialModal } from './Detail/components/CredentialModal';
|
|
import { CredentialModal } from './Detail/components/CredentialModal';
|
|
|
|
|
|
|
|
|
|
+interface LocationState {
|
|
|
|
|
+ page?: number;
|
|
|
|
|
+ pageSize?: number;
|
|
|
|
|
+}
|
|
|
|
|
+
|
|
|
export default function ProductPage() {
|
|
export default function ProductPage() {
|
|
|
const intl = useIntl();
|
|
const intl = useIntl();
|
|
|
const navigate = useNavigate();
|
|
const navigate = useNavigate();
|
|
|
|
|
+ const location = useLocation();
|
|
|
|
|
+ const state = (location.state ?? {}) as LocationState;
|
|
|
const actionRef = useRef<ActionType>();
|
|
const actionRef = useRef<ActionType>();
|
|
|
const [credData, setCredData] = useState<API.FetchInitialCredentialsResp | null>(null);
|
|
const [credData, setCredData] = useState<API.FetchInitialCredentialsResp | null>(null);
|
|
|
const [credOpen, setCredOpen] = useState(false);
|
|
const [credOpen, setCredOpen] = useState(false);
|
|
|
|
|
+ const [pagination, setPagination] = useState({
|
|
|
|
|
+ current: state.page ?? 1,
|
|
|
|
|
+ pageSize: state.pageSize ?? 20,
|
|
|
|
|
+ });
|
|
|
|
|
|
|
|
const handleCreateSuccess = async (ticket?: string) => {
|
|
const handleCreateSuccess = async (ticket?: string) => {
|
|
|
actionRef.current?.reload();
|
|
actionRef.current?.reload();
|
|
@@ -37,7 +48,17 @@ export default function ProductPage() {
|
|
|
title: '名称',
|
|
title: '名称',
|
|
|
dataIndex: 'name',
|
|
dataIndex: 'name',
|
|
|
width: 160,
|
|
width: 160,
|
|
|
- render: (_, r) => <a onClick={() => navigate(`/admin/products/${r.id}`)}>{r.name}</a>,
|
|
|
|
|
|
|
+ render: (_, r) => (
|
|
|
|
|
+ <a
|
|
|
|
|
+ onClick={() =>
|
|
|
|
|
+ navigate(`/admin/products/${r.id}`, {
|
|
|
|
|
+ state: { page: pagination.current, pageSize: pagination.pageSize },
|
|
|
|
|
+ })
|
|
|
|
|
+ }
|
|
|
|
|
+ >
|
|
|
|
|
+ {r.name}
|
|
|
|
|
+ </a>
|
|
|
|
|
+ ),
|
|
|
},
|
|
},
|
|
|
{ title: 'Code', dataIndex: 'code', width: 160, copyable: true },
|
|
{ title: 'Code', dataIndex: 'code', width: 160, copyable: true },
|
|
|
{ title: 'App Key', dataIndex: 'appKey', width: 300, copyable: true },
|
|
{ title: 'App Key', dataIndex: 'appKey', width: 300, copyable: true },
|
|
@@ -65,10 +86,10 @@ export default function ProductPage() {
|
|
|
/>,
|
|
/>,
|
|
|
<Popconfirm
|
|
<Popconfirm
|
|
|
key="status"
|
|
key="status"
|
|
|
- title={r.status === 1 ? '确认禁用?' : '确认启用?'}
|
|
|
|
|
|
|
+ title={r.status === 1 ? `确认禁用「${r.name}」?` : `确认启用「${r.name}」?`}
|
|
|
onConfirm={() => handleToggleStatus(r)}
|
|
onConfirm={() => handleToggleStatus(r)}
|
|
|
>
|
|
>
|
|
|
- <a className={r.status === 1 ? 'text-red-500' : ''}>{r.status === 1 ? '禁用' : '启用'}</a>
|
|
|
|
|
|
|
+ <a>{r.status === 1 ? '禁用' : '启用'}</a>
|
|
|
</Popconfirm>,
|
|
</Popconfirm>,
|
|
|
],
|
|
],
|
|
|
},
|
|
},
|
|
@@ -85,9 +106,12 @@ export default function ProductPage() {
|
|
|
scroll={{ x: 900 }}
|
|
scroll={{ x: 900 }}
|
|
|
tableLayout="fixed"
|
|
tableLayout="fixed"
|
|
|
pagination={{
|
|
pagination={{
|
|
|
|
|
+ current: pagination.current,
|
|
|
|
|
+ pageSize: pagination.pageSize,
|
|
|
defaultPageSize: 20,
|
|
defaultPageSize: 20,
|
|
|
pageSizeOptions: [10, 20, 50, 100],
|
|
pageSizeOptions: [10, 20, 50, 100],
|
|
|
showSizeChanger: true,
|
|
showSizeChanger: true,
|
|
|
|
|
+ onChange: (page, pageSize) => setPagination({ current: page, pageSize }),
|
|
|
}}
|
|
}}
|
|
|
toolBarRender={() => [
|
|
toolBarRender={() => [
|
|
|
<ProductForm
|
|
<ProductForm
|