授权等功能补充

This commit is contained in:
zzy 2022-09-13 20:08:55 +08:00
parent 9b8188a288
commit fd840d4eed
22 changed files with 149 additions and 89 deletions

View File

@ -11,8 +11,9 @@ export default {
// localhost:8000/api/** -> https://preview.pro.ant.design/api/** // localhost:8000/api/** -> https://preview.pro.ant.design/api/**
'/tbg/api/v1': { '/tbg/api/v1': {
// 要代理的地址 // 要代理的地址
// target: 'http://81.71.13.173:9080', target: 'http://81.71.13.173:9080',
target: 'http://127.0.0.1:9999', // target: 'http://192.168.88.238:9999',
// target: 'http://127.0.0.1:9999',
// 配置了这个可以从 http 代理到 https // 配置了这个可以从 http 代理到 https
// 依赖 origin 的功能可能需要这个,比如 cookie // 依赖 origin 的功能可能需要这个,比如 cookie
changeOrigin: true, changeOrigin: true,

View File

@ -4,18 +4,15 @@ import { history } from 'umi';
import RightContent from '@/components/RightContent'; import RightContent from '@/components/RightContent';
import RoutePath from '@/routes/routePath'; import RoutePath from '@/routes/routePath';
import { CACHE_TOKEN } from '@/constants/cacheKey'; import { CACHE_TOKEN } from '@/constants/cacheKey';
import { getRoleList } from './services/system/role'; import { getAccounPermission } from './services/system/accountManage';
// ProLayout 支持的api https://procomponents.ant.design/components/layout // ProLayout 支持的api https://procomponents.ant.design/components/layout
export async function getInitialState() { export async function getInitialState() {
if (localStorage.getItem(CACHE_TOKEN)) { if (localStorage.getItem(CACHE_TOKEN)) {
const res = await getRoleList({}); const res = await getAccounPermission({});
// return {
// routeList: res,
// };
return { return {
routeList: [], routeList: res,
}; };
} }
} }

View File

@ -64,6 +64,9 @@ const Address: React.FC = () => {
]} ]}
request={async (params) => { request={async (params) => {
const res = await fetchTableData(getNFTContractList, params); const res = await fetchTableData(getNFTContractList, params);
if (res.data == null) {
return [];
}
return res; return res;
}} }}
/> />
@ -84,7 +87,6 @@ const Address: React.FC = () => {
message.success('添加成功'); message.success('添加成功');
setVisible(false); setVisible(false);
} catch (e) { } catch (e) {
console.log(e);
message.success('发生错误'); message.success('发生错误');
setVisible(false); setVisible(false);
} }

View File

@ -2,7 +2,6 @@ import React, { useRef, useState } from 'react';
import { createForm } from '@formily/core'; import { createForm } from '@formily/core';
import { createSchemaField } from '@formily/react'; import { createSchemaField } from '@formily/react';
import Modal, { ModalProps } from '@/components/Modal'; import Modal, { ModalProps } from '@/components/Modal';
// import { fetchTableData } from '@/utils/table';
import { Form, FormItem, Input, NumberPicker } from '@formily/antd'; import { Form, FormItem, Input, NumberPicker } from '@formily/antd';
import { Button } from 'antd'; import { Button } from 'antd';
import { initWeb3, NFTMint } from '@/utils/web3'; import { initWeb3, NFTMint } from '@/utils/web3';
@ -13,7 +12,6 @@ import { ContractType } from '@/constants/enum/contract';
interface AddNftModalPropsType extends ModalProps { interface AddNftModalPropsType extends ModalProps {
onOk: () => void; onOk: () => void;
onCancel: () => void; onCancel: () => void;
// loading: boolean;
} }
const SchemaField = createSchemaField({ const SchemaField = createSchemaField({
@ -42,7 +40,6 @@ const AddNftModal = ({ onOk, onCancel, ...rest }: AddNftModalPropsType) => {
toAddress: formState.values.toAddress, toAddress: formState.values.toAddress,
name: formState.values.name, name: formState.values.name,
}); });
console.log('tx_hash = ', tx_hash);
formState.values.tx_hash = tx_hash; formState.values.tx_hash = tx_hash;
await mintNFT(formState.values); await mintNFT(formState.values);
setLoading(false); setLoading(false);

View File

@ -43,7 +43,7 @@ const Address: React.FC = () => {
<div> <div>
<Table <Table
columns={columns} columns={columns}
rowKey="id" rowKey="tx_hash"
search={false} search={false}
actionRef={tableRef} actionRef={tableRef}
toolBarActions={[ toolBarActions={[

View File

@ -57,7 +57,6 @@ const NFTTradeList = () => {
rowKey="id" rowKey="id"
actionRef={tableRef} actionRef={tableRef}
request={async (params) => { request={async (params) => {
console.log('params = ', params);
if ((params.time ?? '') !== '') { if ((params.time ?? '') !== '') {
const start = Date.parse(params.time[0] + ' 00:00:00'); const start = Date.parse(params.time[0] + ' 00:00:00');
const end = Date.parse(params.time[1] + ' 23:59:59'); const end = Date.parse(params.time[1] + ' 23:59:59');

View File

@ -66,7 +66,7 @@ const CoinTypeList = () => {
<div> <div>
<Table <Table
columns={columns} columns={columns}
rowKey="id" rowKey="uuid"
search={false} search={false}
toolBarActions={[ toolBarActions={[
{ {

View File

@ -55,6 +55,7 @@ const RecordList = () => {
return ( return (
<Table <Table
columns={columns} columns={columns}
rowKey="tx_hash"
actionRef={tableRef} actionRef={tableRef}
request={async (params) => { request={async (params) => {
if ((params.searchTime ?? '') !== '') { if ((params.searchTime ?? '') !== '') {

View File

@ -69,7 +69,7 @@ const CollectionAddressList = () => {
<Table <Table
columns={columns} columns={columns}
search={false} search={false}
rowKey="id" rowKey="address"
toolBarActions={[ toolBarActions={[
{ {
type: 'add', type: 'add',

View File

@ -22,13 +22,12 @@ const SchemaField = createSchemaField({
const AddWalletModal = ({ onOk, onCancel, ...rest }: AddWalletModalPropsType) => { const AddWalletModal = ({ onOk, onCancel, ...rest }: AddWalletModalPropsType) => {
const [coinTypeData, setCoinTypeData] = useState({}); const [coinTypeData, setCoinTypeData] = useState({});
const getSelectData = async () => { const getSelectData = async () => {
const list = await getCoinTypeList({ page: 1, size: 10 }); const list = await getCoinTypeList({ page: 1, size: 10 });
setCoinTypeData(list); setCoinTypeData(list);
}; };
const useAsyncDataSource = ( const UseAsyncDataSource = (
pattern: FormPathPattern, pattern: FormPathPattern,
service: (field: Field) => Promise<{ label: string; value: any }[]>, service: (field: Field) => Promise<{ label: string; value: any }[]>,
) => { ) => {
@ -43,8 +42,7 @@ const AddWalletModal = ({ onOk, onCancel, ...rest }: AddWalletModalPropsType) =>
const form = createForm({ const form = createForm({
effects: () => { effects: () => {
// eslint-disable-next-line react-hooks/rules-of-hooks UseAsyncDataSource('name', async (field) => {
useAsyncDataSource('name', async (field) => {
const list = coinTypeData; const list = coinTypeData;
const option = []; const option = [];
for (let index = 0; index < list.items.length; index++) { for (let index = 0; index < list.items.length; index++) {

View File

@ -22,14 +22,7 @@ const SchemaField = createSchemaField({
}); });
const EditWalletModal = ({ onOk, onCancel, editModalData, ...rest }: EditWalletModalPropsType) => { const EditWalletModal = ({ onOk, onCancel, editModalData, ...rest }: EditWalletModalPropsType) => {
const [coinTypeData, setCoinTypeData] = useState({}); const UseAsyncDataSource = (
const getSelectData = async () => {
const list = await getCoinTypeList({ page: 1, size: 10 });
setCoinTypeData(list);
};
const useAsyncDataSource = (
pattern: FormPathPattern, pattern: FormPathPattern,
service: (field: Field) => Promise<{ label: string; value: any }[]>, service: (field: Field) => Promise<{ label: string; value: any }[]>,
) => { ) => {
@ -44,10 +37,8 @@ const EditWalletModal = ({ onOk, onCancel, editModalData, ...rest }: EditWalletM
const form = createForm({ const form = createForm({
effects: () => { effects: () => {
// eslint-disable-next-line react-hooks/rules-of-hooks UseAsyncDataSource('name', async (field) => {
useAsyncDataSource('name', async (field) => { const list = await getCoinTypeList({ page: 1, size: 10 });
getSelectData();
const list = coinTypeData;
const option = []; const option = [];
for (let index = 0; index < list.items.length; index++) { for (let index = 0; index < list.items.length; index++) {
const element = list.items[index]; const element = list.items[index];

View File

@ -107,7 +107,7 @@ const WithdrawList = () => {
<div> <div>
<Table <Table
columns={columns} columns={columns}
rowKey="id" rowKey="uuid"
actionRef={tableRef} actionRef={tableRef}
request={async (params) => { request={async (params) => {
const res = await fetchTableData(getWithdrawList, params); const res = await fetchTableData(getWithdrawList, params);

View File

@ -11,6 +11,7 @@ import DeleteButton from '@/components/Table/DeleteButton';
import { Popover, Switch } from 'antd'; import { Popover, Switch } from 'antd';
import AddAccountModal from '../components/AddAccountModal'; import AddAccountModal from '../components/AddAccountModal';
import EditAccountModal from '../components/EditAccountModal'; import EditAccountModal from '../components/EditAccountModal';
import { getRoleList } from '@/services/system/role';
const AccountManageList = () => { const AccountManageList = () => {
const [isModalVisible, setIsModalVisible] = useState(false); const [isModalVisible, setIsModalVisible] = useState(false);
@ -37,7 +38,15 @@ const AccountManageList = () => {
title: '角色', title: '角色',
dataIndex: 'role', dataIndex: 'role',
hideInSearch: true, hideInSearch: true,
ellipsis: true, valueType: 'select',
request: async () => {
const res = await getRoleList({ page: 1, size: 10 });
const options = new Array();
res.items.forEach((element) => {
options.push({ label: element.role_name, value: element.id });
});
return options;
},
}, },
{ {
title: '操作', title: '操作',

View File

@ -24,7 +24,7 @@ const SchemaField = createSchemaField({
const AddAccountModal = ({ onOk, onCancel, ...rest }: AddAccountModalPropsType) => { const AddAccountModal = ({ onOk, onCancel, ...rest }: AddAccountModalPropsType) => {
const [roleListData, setRoleListData] = useState({}); const [roleListData, setRoleListData] = useState({});
const useAsyncDataSource = ( const UseAsyncDataSource = (
pattern: FormPathPattern, pattern: FormPathPattern,
service: (field: Field) => Promise<{ label: string; value: any }[]>, service: (field: Field) => Promise<{ label: string; value: any }[]>,
) => { ) => {
@ -39,8 +39,7 @@ const AddAccountModal = ({ onOk, onCancel, ...rest }: AddAccountModalPropsType)
const form = createForm({ const form = createForm({
effects: () => { effects: () => {
// eslint-disable-next-line react-hooks/rules-of-hooks UseAsyncDataSource('role', async (field) => {
useAsyncDataSource('role', async (field) => {
const list = roleListData; const list = roleListData;
const option = []; const option = [];
for (let index = 0; index < list.items.length; index++) { for (let index = 0; index < list.items.length; index++) {
@ -69,7 +68,6 @@ const AddAccountModal = ({ onOk, onCancel, ...rest }: AddAccountModalPropsType)
form.submit(async () => { form.submit(async () => {
onOk(); onOk();
const formState = form.getFormState(); const formState = form.getFormState();
formState.values.role = parseInt(formState.values.role);
await addUser(formState.values); await addUser(formState.values);
}); });
}; };
@ -112,6 +110,7 @@ const AddAccountModal = ({ onOk, onCancel, ...rest }: AddAccountModalPropsType)
x-decorator="FormItem" x-decorator="FormItem"
x-component="Select" x-component="Select"
x-component-props={{ x-component-props={{
mode: 'multiple',
placeholder: '请选择角色', placeholder: '请选择角色',
}} }}
/> />

View File

@ -28,14 +28,14 @@ const EditAccountModal = ({
editModalData, editModalData,
...rest ...rest
}: EditAccountModalPropsType) => { }: EditAccountModalPropsType) => {
const [roleListData, setRoleListData] = useState({}); // const [roleListData, setRoleListData] = useState({});
const getSelectData = async () => { // const getSelectData = async () => {
const list = await getRoleList({ page: 1, size: 10 }); // const list =
setRoleListData(list); // setRoleListData(list);
}; // };
const useAsyncDataSource = ( const UseAsyncDataSource = (
pattern: FormPathPattern, pattern: FormPathPattern,
service: (field: Field) => Promise<{ label: string; value: any }[]>, service: (field: Field) => Promise<{ label: string; value: any }[]>,
) => { ) => {
@ -50,10 +50,8 @@ const EditAccountModal = ({
const form = createForm({ const form = createForm({
effects: () => { effects: () => {
// eslint-disable-next-line react-hooks/rules-of-hooks UseAsyncDataSource('role', async (field) => {
useAsyncDataSource('role', async (field) => { const list = await getRoleList({ page: 1, size: 10 });
getSelectData();
const list = roleListData;
const option = []; const option = [];
for (let index = 0; index < list.items.length; index++) { for (let index = 0; index < list.items.length; index++) {
const element = list.items[index]; const element = list.items[index];
@ -76,7 +74,6 @@ const EditAccountModal = ({
form.submit(async () => { form.submit(async () => {
onOk(); onOk();
const formState = form.getFormState(); const formState = form.getFormState();
formState.values.role = parseInt(formState.values.role);
await updateUser(formState.values); await updateUser(formState.values);
}); });
}; };

View File

@ -3,7 +3,7 @@ import Table, { ProColumns, ActionType } from '@/components/Table';
import { getNoticeList, createNotice, updateNotice, deleteNotice } from '@/services/system/notice'; import { getNoticeList, createNotice, updateNotice, deleteNotice } from '@/services/system/notice';
import { fetchTableData } from '@/utils/table'; import { fetchTableData } from '@/utils/table';
import DeleteButton from '@/components/Table/DeleteButton'; import DeleteButton from '@/components/Table/DeleteButton';
import { Switch } from 'antd'; import { Popover, Switch } from 'antd';
import AddNoticeModal from '../components/AddNoticeModal'; import AddNoticeModal from '../components/AddNoticeModal';
import EditNoticeModal from '../components/EditNoticeModal'; import EditNoticeModal from '../components/EditNoticeModal';
import { NoticeType } from '@/constants/enum/notice'; import { NoticeType } from '@/constants/enum/notice';
@ -80,6 +80,13 @@ const NoticeList = () => {
> >
</a>, </a>,
<Popover
content={
<div>
<p>/</p>
</div>
}
>
<Switch <Switch
key="switch" key="switch"
defaultChecked={row.status} defaultChecked={row.status}
@ -88,7 +95,10 @@ const NoticeList = () => {
row.status = checked; row.status = checked;
await updateNotice(row); await updateNotice(row);
}} }}
/>, />
,
</Popover>,
<DeleteButton <DeleteButton
key="delete" key="delete"
onDelete={() => { onDelete={() => {
@ -102,7 +112,7 @@ const NoticeList = () => {
<div> <div>
<Table <Table
columns={columns} columns={columns}
rowKey="id" rowKey="code"
search={false} search={false}
toolBarActions={[ toolBarActions={[
{ {

View File

@ -5,6 +5,7 @@ import DeleteButton from '@/components/Table/DeleteButton';
import { getPermission, upsertPermission } from '@/services/system/permission'; import { getPermission, upsertPermission } from '@/services/system/permission';
import AddPermissionModal from '../components/AddPermissionModal'; import AddPermissionModal from '../components/AddPermissionModal';
import EditPermissionModal from '../components/EditPermissionModal'; import EditPermissionModal from '../components/EditPermissionModal';
import { message } from 'antd';
const PermissionsList = () => { const PermissionsList = () => {
const [isModalVisible, setIsModalVisible] = useState(false); const [isModalVisible, setIsModalVisible] = useState(false);
@ -27,15 +28,20 @@ const PermissionsList = () => {
}; };
const deleteLoopChildren = (rowData, children) => { const deleteLoopChildren = (rowData, children) => {
debugger;
for (let index = 0; index < children.length; index++) { for (let index = 0; index < children.length; index++) {
const childrenElement = children[index]; const childrenElement = children[index];
if (rowData.name == childrenElement.name) { if (rowData.name == childrenElement.name) {
if (children.length == 1) {
return 1;
}
children.splice(index, 1); children.splice(index, 1);
return true; return true;
} else { } else {
if (Object.prototype.hasOwnProperty.call(childrenElement, 'children')) { if (Object.prototype.hasOwnProperty.call(childrenElement, 'children')) {
deleteLoopChildren(rowData, childrenElement.children); const childrenLength = deleteLoopChildren(rowData, childrenElement.children);
if (childrenLength == 1) {
delete childrenElement.children;
}
} else { } else {
continue; continue;
} }
@ -174,7 +180,7 @@ const PermissionsList = () => {
if (!result) { if (!result) {
rowData.children.push(val); rowData.children.push(val);
} else { } else {
console.log('已有改权限名'); message.warning('已有改权限名');
} }
} else { } else {
rowData.children = [val]; rowData.children = [val];

View File

@ -14,12 +14,14 @@ const RoleList = () => {
const [isModalVisible, setIsModalVisible] = useState(false); const [isModalVisible, setIsModalVisible] = useState(false);
const [isEditModal, setIsEditModal] = useState(false); const [isEditModal, setIsEditModal] = useState(false);
const [modalData, setModalData] = useState({}); const [modalData, setModalData] = useState({});
const [rowData, setRowData] = useState({});
const handleEdit = (row: any) => { const handleEdit = (row: any) => {
setModalData(row); setModalData(row);
setIsEditModal(true); setIsEditModal(true);
}; };
const handleAuth = (row: any) => { const handleAuth = (row: any) => {
setRowData(row);
setIsDrawerVisible(true); setIsDrawerVisible(true);
}; };
const handleDelete = async (id: any) => { const handleDelete = async (id: any) => {
@ -116,11 +118,13 @@ const RoleList = () => {
/> />
<AuthPermissionsDrawer <AuthPermissionsDrawer
visible={isDrawerVisible} visible={isDrawerVisible}
rowData={rowData}
onCancel={function () { onCancel={function () {
setIsDrawerVisible(false); setIsDrawerVisible(false);
}} }}
onOk={function () { onOk={async function (val) {
console.log('onOk'); await updateRole(val);
setIsDrawerVisible(false);
}} }}
/> />
</div> </div>

View File

@ -1,17 +1,15 @@
// 创建弹窗 // 创建弹窗
import React, { useRef, useState } from 'react'; import React, { useEffect, useRef, useState } from 'react';
import { Form, FormItem, Input } from '@formily/antd';
import { Button, Drawer, DrawerProps, message, Space } from 'antd'; import { Button, Drawer, DrawerProps, message, Space } from 'antd';
import { ActionType, ProColumns } from '@ant-design/pro-table'; import { ActionType, ProColumns } from '@ant-design/pro-table';
import Table from '@/components/Table'; import Table from '@/components/Table';
import { TableRowSelection } from 'antd/lib/table/interface'; import { TableRowSelection } from 'antd/lib/table/interface';
import routes from '@/routes';
import { getPermission } from '@/services/system/permission'; import { getPermission } from '@/services/system/permission';
interface AuthPermissionsDrawerPropsType extends DrawerProps { interface AuthPermissionsDrawerPropsType extends DrawerProps {
onCancel: () => void; onCancel: () => void;
onOk: (val: any) => void; onOk: (val: any) => void;
rowData: any;
} }
const columnsPermissions: ProColumns<any>[] = [ const columnsPermissions: ProColumns<any>[] = [
@ -22,9 +20,8 @@ const columnsPermissions: ProColumns<any>[] = [
]; ];
const valueMap = {}; const valueMap = {};
function loops(list, parent) { const loops = (list, parent) => {
return (list || []).map(({ children, name }) => { return (list || []).map(({ children, name }) => {
// console.log('children = ', children);
const node = (valueMap[name] = { const node = (valueMap[name] = {
parent, parent,
name, name,
@ -32,9 +29,9 @@ function loops(list, parent) {
node.children = loops(children, node); node.children = loops(children, node);
return node; return node;
}); });
} };
function getPath(name) { const getPath = (name) => {
const path = []; const path = [];
let current = valueMap[name]; let current = valueMap[name];
while (current) { while (current) {
@ -42,39 +39,75 @@ function getPath(name) {
current = current.parent; current = current.parent;
} }
return path; return path;
} };
const AuthPermissionsDrawer = ({ onOk, onCancel, ...rest }: AuthPermissionsDrawerPropsType) => { const mergeArray = (arr1, arr2) => {
const _arr = new Array();
for (let i = 0; i < arr1.length; i++) {
_arr.push(arr1[i]);
}
for (let i = 0; i < arr2.length; i++) {
let flag = true;
for (let j = 0; j < arr1.length; j++) {
if (arr2[i] == arr1[j]) {
flag = false;
break;
}
}
if (flag) {
_arr.push(arr2[i]);
}
}
return _arr;
};
const AuthPermissionsDrawer = ({
onOk,
onCancel,
rowData,
...rest
}: AuthPermissionsDrawerPropsType) => {
const tableRef = useRef<ActionType>(); const tableRef = useRef<ActionType>();
const [selectedKeys, setSelectedKeys] = useState(['']); const [selectedKeys, setSelectedKeys] = useState(new Array());
const [postSelectedKeys, setPostSelectedKeys] = useState([]);
const rowSelection: TableRowSelection<DataType> = { const rowSelection: TableRowSelection<DataType> = {
onChange: (selectedRowKeys, selectedRows) => { onChange: (selectedRowKeys, selectedRows) => {
setSelectedKeys(selectedRowKeys); setSelectedKeys(selectedRowKeys);
console.log(`selectedRowKeys: ${selectedRowKeys}`, 'selectedRows: ', selectedRows);
}, },
onSelect: (record, selected, selectedRows) => {
const path = getPath(record.name);
const newArray = selectedKeys.concat(path);
setPostSelectedKeys(newArray);
},
// onSelectAll: (selected, selectedRows, changeRows) => {
// console.log(selected, selectedRows, changeRows);
// },
}; };
const handleOk = () => { const handleOk = () => {
let postSelectedKeys = new Array();
selectedKeys.forEach((element) => {
const path = getPath(element);
postSelectedKeys = mergeArray(postSelectedKeys, path);
});
if (postSelectedKeys.length == 0) { if (postSelectedKeys.length == 0) {
message.warning('请选择权限。'); message.warning('请选择权限。');
return; return;
} }
onOk(postSelectedKeys); onOk({ id: rowData.id, permission: postSelectedKeys });
}; };
const handleCancel = () => { const handleCancel = () => {
onCancel(); onCancel();
}; };
useEffect(() => {
const parentArray = new Array();
let newPermission = new Array();
for (const key in valueMap) {
if (Object.prototype.hasOwnProperty.call(valueMap, key)) {
const element = valueMap[key];
if (element.children.length != 0) {
parentArray.push(element.name);
}
}
}
if (rowData.permission != undefined && rowData.permission != [] && rowData.permission != null) {
newPermission = rowData.permission.filter((item) => !parentArray.includes(item));
}
setSelectedKeys(newPermission);
}, [rowData.permission]);
return ( return (
<Drawer <Drawer

View File

@ -21,10 +21,13 @@ const UserManageList = () => {
return ( return (
<Table <Table
columns={columns} columns={columns}
rowKey="id" rowKey="address"
actionRef={tableRef} actionRef={tableRef}
request={async (params) => { request={async (params) => {
const res = await fetchTableData(getUserList, params); const res = await fetchTableData(getUserList, params);
if (res.data == null) {
return [];
}
return res; return res;
}} }}
/> />

View File

@ -73,3 +73,16 @@ export const deleteUser = (data) => {
data, data,
}); });
}; };
/**
*
* @param {object} params
* @returns {array} data
*/
export const getAccounPermission = (params) => {
return request.request({
url: '/user/role/get',
method: 'get',
params,
});
};

View File

@ -14,7 +14,7 @@ export async function initWeb3() {
provider = await detectEthereumProvider(); provider = await detectEthereumProvider();
if (!provider) { if (!provider) {
console.log('请安装MetaMask'); message.warning('请安装MetaMask');
return false; return false;
} }