diff --git a/dist.zip b/dist.zip index a1429ac..4dba4f3 100644 Binary files a/dist.zip and b/dist.zip differ diff --git a/src/access.ts b/src/access.ts index 1037848..ca84238 100644 --- a/src/access.ts +++ b/src/access.ts @@ -16,5 +16,9 @@ export default function access(initialState: { } return routeList.includes(route.name); }, + canShowButton: (buttonName) => { + // return true; + return routeList.includes(buttonName); + }, }; } diff --git a/src/components/RightContent/AvatarDropdown.tsx b/src/components/RightContent/AvatarDropdown.tsx index b7a6994..8cf221d 100644 --- a/src/components/RightContent/AvatarDropdown.tsx +++ b/src/components/RightContent/AvatarDropdown.tsx @@ -7,7 +7,7 @@ import HeaderDropdown from '../HeaderDropdown'; import styles from './index.less'; import type { MenuInfo } from 'rc-menu/lib/interface'; import RoutePath from '@/routes/routePath'; -import { CACHE_TOKEN } from '@/constants/cacheKey'; +import { CACHE_TOKEN, CACHE_USERNAME } from '@/constants/cacheKey'; import ModifyPasswordModal from '@/components/ModifyPassword/ModifyPasswordModal'; export type GlobalHeaderRightProps = { @@ -23,6 +23,7 @@ const loginOut = async () => { // Note: There may be security issues, please note if (window.location.pathname !== RoutePath.LOGIN && !redirect) { localStorage.removeItem(CACHE_TOKEN); + localStorage.removeItem(CACHE_USERNAME); history.replace({ pathname: RoutePath.LOGIN, search: stringify({ @@ -66,7 +67,7 @@ const AvatarDropdown: React.FC = ({ menu }) => { const currentUser = { avatar: 'https://gw.alipayobjects.com/zos/rmsportal/BiazfanxmamNRoxxVxka.png', - name: 'admin', + name: localStorage.getItem(CACHE_USERNAME), }; if (!currentUser || !currentUser.name) { diff --git a/src/components/Table/index.tsx b/src/components/Table/index.tsx index 49d4c02..7a30159 100644 --- a/src/components/Table/index.tsx +++ b/src/components/Table/index.tsx @@ -12,9 +12,11 @@ import { } from 'antd'; import { PlusOutlined } from '@ant-design/icons'; import ProTable, { ProColumns, ActionType, ProTableProps } from '@ant-design/pro-table'; +import { Access, useAccess } from 'umi'; export interface toolBarActionsItem { type: 'add' | 'batchDelete'; + permission?: string; text?: string; onConfirm: (val?: string[]) => void; } @@ -29,6 +31,8 @@ type Record = { }; const Table = >(props: PropsType) => { + const access = useAccess(); + const { columns: columnsProps = [], search: searchProps = {}, @@ -88,7 +92,9 @@ const Table = >(props: PropsType) => { const optionRender = (_: any, val: any, ...rest: any) => { return ( }> - {(item.render && (item.render(_, val, ...rest) as []))?.map((item2) => item2)} + {(item.render && (item.render(_, val, ...rest) as []))?.map((item2) => { + return item2; + })} ); }; @@ -165,28 +171,32 @@ const Table = >(props: PropsType) => { toolBarActions.forEach((item) => { if (item.type === 'add') { buttonList.push( - , + + + , ); } else if (item.type === 'batchDelete') { buttonList.push( - , + + + , ); } }); diff --git a/src/constants/cacheKey.ts b/src/constants/cacheKey.ts index aa73703..84da570 100644 --- a/src/constants/cacheKey.ts +++ b/src/constants/cacheKey.ts @@ -1 +1,2 @@ export const CACHE_TOKEN = 'token'; +export const CACHE_USERNAME = 'name'; diff --git a/src/pages/Login/index.tsx b/src/pages/Login/index.tsx index fb3105e..17362cb 100644 --- a/src/pages/Login/index.tsx +++ b/src/pages/Login/index.tsx @@ -5,7 +5,7 @@ import { useIntl, history, FormattedMessage, useModel } from 'umi'; import { login } from '@/services/login'; import defaultSettings from '../../../config/defaultSettings'; import styles from './index.less'; -import { CACHE_TOKEN } from '@/constants/cacheKey'; +import { CACHE_TOKEN, CACHE_USERNAME } from '@/constants/cacheKey'; import access from '@/access'; const Login: React.FC = () => { @@ -13,9 +13,9 @@ const Login: React.FC = () => { const { initialState, refresh } = useModel('@@initialState'); const handleSubmit = async (values: API.LoginParams) => { // 登录 - const res: any = await login({ ...values }); localStorage.setItem(CACHE_TOKEN, res.token); + localStorage.setItem(CACHE_USERNAME, values.name); /** 此方法会跳转到 redirect 参数所在的位置 */ if (!history) return; const { query } = history.location; diff --git a/src/pages/Nft/NftContract/List/index.tsx b/src/pages/Nft/NftContract/List/index.tsx index ae79545..5803d28 100644 --- a/src/pages/Nft/NftContract/List/index.tsx +++ b/src/pages/Nft/NftContract/List/index.tsx @@ -51,6 +51,7 @@ const Address: React.FC = () => { { type: 'add', text: '新建NFT合约', + permission: '新建NFT合约', onConfirm: async () => { const res = await getContractInfo({ erc: ContractType.NFT721 }); if (res.bin != '') { diff --git a/src/pages/Nft/NftToken/List/index.tsx b/src/pages/Nft/NftToken/List/index.tsx index 258fcd5..7990c32 100644 --- a/src/pages/Nft/NftToken/List/index.tsx +++ b/src/pages/Nft/NftToken/List/index.tsx @@ -50,6 +50,7 @@ const Address: React.FC = () => { { type: 'add', text: '添加NFT', + permission: '添加NFT', onConfirm: () => { setVisible(true); }, diff --git a/src/pages/Recharge/CoinType/List/index.tsx b/src/pages/Recharge/CoinType/List/index.tsx index f9836b9..f9d0248 100644 --- a/src/pages/Recharge/CoinType/List/index.tsx +++ b/src/pages/Recharge/CoinType/List/index.tsx @@ -7,8 +7,10 @@ import AddCoinTypeModal from '../components/AddCoinTypeModal'; import EditCoinTypeModal from '../components/EditCoinTypeModal'; import { initWeb3, deployContract, transfer } from '@/utils/web3'; import { ContractType } from '@/constants/enum/contract'; +import { Access, useAccess } from 'umi'; const CoinTypeList = () => { + const access = useAccess(); const tableRef = useRef(); const [isModalVisible, setIsModalVisible] = useState(false); @@ -51,14 +53,16 @@ const CoinTypeList = () => { valueType: 'option', width: 150, render: (_, row) => [ - { - handleEdit(row); - }} - > - 编辑 - , + + { + handleEdit(row); + }} + > + 编辑 + + , ], }, ]; @@ -71,6 +75,7 @@ const CoinTypeList = () => { toolBarActions={[ { type: 'add', + permission: '代币添加', onConfirm: () => { setIsModalVisible(true); }, diff --git a/src/pages/Recharge/Wallet/List/index.tsx b/src/pages/Recharge/Wallet/List/index.tsx index effcefe..18e6dc0 100644 --- a/src/pages/Recharge/Wallet/List/index.tsx +++ b/src/pages/Recharge/Wallet/List/index.tsx @@ -11,9 +11,11 @@ import { fetchTableData } from '@/utils/table'; import DeleteButton from '@/components/Table/DeleteButton'; import AddWalletModal from '../components/AddWalletModal'; import EditWalletModal from '../components/EditWalletModal'; +import { Access, useAccess } from 'umi'; const CollectionAddressList = () => { const tableRef = useRef(); + const access = useAccess(); const [isModalVisible, setIsModalVisible] = useState(false); const [isEditModalVisible, setIsEditModalVisible] = useState(false); @@ -47,20 +49,24 @@ const CollectionAddressList = () => { valueType: 'option', width: 150, render: (_, row) => [ - { - handleEdit(row); - }} - > - 编辑 - , - { - handleDelete(row.address); - }} - />, + + { + handleEdit(row); + }} + > + 编辑 + + , + + { + handleDelete(row.address); + }} + /> + , ], }, ]; @@ -73,6 +79,7 @@ const CollectionAddressList = () => { toolBarActions={[ { type: 'add', + permission: '收款地址添加', onConfirm: () => { setIsModalVisible(true); }, diff --git a/src/pages/Recharge/Withdraw/List/index.tsx b/src/pages/Recharge/Withdraw/List/index.tsx index 81f393d..ac5a929 100644 --- a/src/pages/Recharge/Withdraw/List/index.tsx +++ b/src/pages/Recharge/Withdraw/List/index.tsx @@ -6,9 +6,11 @@ import ConfirmButton from '@/components/Table/ConfirmButton'; import moment from 'moment'; import { WithdrawType } from '@/constants/enum/withdraw'; import RejectButton from '@/components/Table/RejectButton'; +import { Access, useAccess } from 'umi'; const WithdrawList = () => { const tableRef = useRef(); + const access = useAccess(); const handleClick = async (uuid, status) => { await solveWithdraw({ uuid: uuid, status: status }); @@ -81,24 +83,28 @@ const WithdrawList = () => { width: 150, render: (_, row) => [ row.status === 30000 ? ( - { - handleClick(row.uuid, WithdrawType.SUCCESS); - }} - /> + + { + handleClick(row.uuid, WithdrawType.SUCCESS); + }} + /> + ) : null, row.status === 30000 ? ( - { - handleClick(row.uuid, WithdrawType.FAILED); - }} - /> + + { + handleClick(row.uuid, WithdrawType.FAILED); + }} + /> + ) : null, ], }, diff --git a/src/pages/System/Account/List/index.tsx b/src/pages/System/Account/List/index.tsx index 4c70992..f098360 100644 --- a/src/pages/System/Account/List/index.tsx +++ b/src/pages/System/Account/List/index.tsx @@ -12,6 +12,7 @@ import { Popover, Switch } from 'antd'; import AddAccountModal from '../components/AddAccountModal'; import EditAccountModal from '../components/EditAccountModal'; import { getRoleList } from '@/services/system/role'; +import { Access, useAccess } from 'umi'; const AccountManageList = () => { const [isModalVisible, setIsModalVisible] = useState(false); @@ -27,6 +28,8 @@ const AccountManageList = () => { await deleteUser({ name: name }); }; const tableRef = useRef(); + const access = useAccess(); + const columns: ProColumns[] = [ { title: '账号', @@ -53,37 +56,44 @@ const AccountManageList = () => { valueType: 'option', width: 180, render: (_, row) => [ - { - handleEdit(row); - }} - > - 编辑 - , - -

账号启用/禁用

- - } - > - { - await changeUserStatus({ name: row.name, status: checked }); + + { + handleEdit(row); + }} + > + 编辑 + + , + + +

账号启用/禁用

+ + } + > + { + await changeUserStatus({ name: row.name, status: checked }); + }} + /> +
+
, + + { + handleDelete(row.name); + tableRef.current?.reload(); }} /> -
, - { - handleDelete(row.name); - tableRef.current?.reload(); - }} - />, + , ], }, ]; @@ -96,6 +106,7 @@ const AccountManageList = () => { toolBarActions={[ { type: 'add', + permission: '账号添加', onConfirm: () => { setIsModalVisible(true); }, diff --git a/src/pages/System/Notice/List/index.tsx b/src/pages/System/Notice/List/index.tsx index decd712..8acbbc1 100644 --- a/src/pages/System/Notice/List/index.tsx +++ b/src/pages/System/Notice/List/index.tsx @@ -7,9 +7,11 @@ import { Popover, Switch } from 'antd'; import AddNoticeModal from '../components/AddNoticeModal'; import EditNoticeModal from '../components/EditNoticeModal'; import { NoticeType } from '@/constants/enum/notice'; +import { Access, useAccess } from 'umi'; const NoticeList = () => { const tableRef = useRef(); + const access = useAccess(); const [isModalVisible, setIsModalVisible] = useState(false); const [isEditModalVisible, setIsEditModalVisible] = useState(false); @@ -72,39 +74,44 @@ const NoticeList = () => { valueType: 'option', width: 180, render: (_, row) => [ - { - handleEdit(row); - }} - > - 编辑 - , - -

通知启用/禁用

- - } - > - { - row.status = checked; - await updateNotice(row); + + { + handleEdit(row); + }} + > + 编辑 + + , + + +

通知启用/禁用

+ + } + > + { + row.status = checked; + await updateNotice(row); + }} + /> + , +
+
, + + { + handleDelete(row.code); }} /> - , -
, - - { - handleDelete(row.code); - }} - />, + , ], }, ]; @@ -117,6 +124,7 @@ const NoticeList = () => { toolBarActions={[ { type: 'add', + permission: '通知添加', onConfirm: () => { setIsModalVisible(true); }, diff --git a/src/pages/System/Permissions/List/index.tsx b/src/pages/System/Permissions/List/index.tsx index 89a1183..7fc106e 100644 --- a/src/pages/System/Permissions/List/index.tsx +++ b/src/pages/System/Permissions/List/index.tsx @@ -6,6 +6,7 @@ import { getPermission, upsertPermission } from '@/services/system/permission'; import AddPermissionModal from '../components/AddPermissionModal'; import EditPermissionModal from '../components/EditPermissionModal'; import { message } from 'antd'; +import { Access, useAccess } from 'umi'; const PermissionsList = () => { const [isModalVisible, setIsModalVisible] = useState(false); @@ -17,6 +18,7 @@ const PermissionsList = () => { const [rowData, setRowData] = useState({}); const tableRef = useRef(); + const access = useAccess(); const handleAdd = (row: any) => { setRowData(row); @@ -111,31 +113,37 @@ const PermissionsList = () => { valueType: 'option', width: 180, render: (_, row) => [ - { - setIsAddFirst(false); - handleAdd(row); - }} - > - 添加 - , - { - setModalData(row); - handleEdit(row); - }} - > - 编辑 - , - Object.prototype.hasOwnProperty.call(row, 'children') ? null : ( - { - handleDelete(row); + + { + setIsAddFirst(false); + handleAdd(row); }} - /> + > + 添加 + + , + + { + setModalData(row); + handleEdit(row); + }} + > + 编辑 + + , + Object.prototype.hasOwnProperty.call(row, 'children') ? null : ( + + { + handleDelete(row); + }} + /> + ), ], }, @@ -151,6 +159,7 @@ const PermissionsList = () => { toolBarActions={[ { type: 'add', + permission: '权限添加', onConfirm: () => { setIsAddFirst(true); setIsModalVisible(true); diff --git a/src/pages/System/Role/List/index.tsx b/src/pages/System/Role/List/index.tsx index d092688..21b4ae0 100644 --- a/src/pages/System/Role/List/index.tsx +++ b/src/pages/System/Role/List/index.tsx @@ -6,9 +6,11 @@ import DeleteButton from '@/components/Table/DeleteButton'; import AddRoleModal from '../components/AddRoleModal'; import EditRoleModal from '../components/EditRoleModal'; import AuthPermissionsDrawer from '../components/AuthPermissionsDrawer'; +import { Access, useAccess } from 'umi'; const RoleList = () => { const tableRef = useRef(); + const access = useAccess(); const [isDrawerVisible, setIsDrawerVisible] = useState(false); const [isModalVisible, setIsModalVisible] = useState(false); @@ -47,28 +49,34 @@ const RoleList = () => { valueType: 'option', width: 180, render: (_, row) => [ - { - handleEdit(row); - }} - > - 编辑 - , - { - handleAuth(row); - }} - > - 授权 - , - { - handleDelete(row.id); - }} - />, + + { + handleEdit(row); + }} + > + 编辑 + + , + + { + handleAuth(row); + }} + > + 授权 + + , + + { + handleDelete(row.id); + }} + /> + , ], }, ]; @@ -82,6 +90,7 @@ const RoleList = () => { toolBarActions={[ { type: 'add', + permission: '角色添加', onConfirm: () => { setIsModalVisible(true); }, diff --git a/src/pages/System/SecretKey/index.tsx b/src/pages/System/SecretKey/index.tsx index d060404..6c8ad0c 100644 --- a/src/pages/System/SecretKey/index.tsx +++ b/src/pages/System/SecretKey/index.tsx @@ -2,10 +2,12 @@ import React, { useState, useEffect } from 'react'; import { Button, Input, Popconfirm } from 'antd'; import styles from './index.less'; import { createSecretKey, getSecretKey } from '@/services/system/secretKey'; +import { Access, useAccess } from 'umi'; const { TextArea } = Input; const SecretKey: React.FC = () => { + const access = useAccess(); const [secretKey, setSecretKey] = useState(''); const create = async () => { @@ -24,11 +26,13 @@ const SecretKey: React.FC = () => { return (
- - - + + + + +