授权等功能补充

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/**
'/tbg/api/v1': {
// 要代理的地址
// target: 'http://81.71.13.173:9080',
target: 'http://127.0.0.1:9999',
target: 'http://81.71.13.173:9080',
// target: 'http://192.168.88.238:9999',
// target: 'http://127.0.0.1:9999',
// 配置了这个可以从 http 代理到 https
// 依赖 origin 的功能可能需要这个,比如 cookie
changeOrigin: true,

View File

@ -4,18 +4,15 @@ import { history } from 'umi';
import RightContent from '@/components/RightContent';
import RoutePath from '@/routes/routePath';
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
export async function getInitialState() {
if (localStorage.getItem(CACHE_TOKEN)) {
const res = await getRoleList({});
// return {
// routeList: res,
// };
const res = await getAccounPermission({});
return {
routeList: [],
routeList: res,
};
}
}

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

@ -107,7 +107,7 @@ const WithdrawList = () => {
<div>
<Table
columns={columns}
rowKey="id"
rowKey="uuid"
actionRef={tableRef}
request={async (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 AddAccountModal from '../components/AddAccountModal';
import EditAccountModal from '../components/EditAccountModal';
import { getRoleList } from '@/services/system/role';
const AccountManageList = () => {
const [isModalVisible, setIsModalVisible] = useState(false);
@ -37,7 +38,15 @@ const AccountManageList = () => {
title: '角色',
dataIndex: 'role',
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: '操作',

View File

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

View File

@ -28,14 +28,14 @@ const EditAccountModal = ({
editModalData,
...rest
}: EditAccountModalPropsType) => {
const [roleListData, setRoleListData] = useState({});
// const [roleListData, setRoleListData] = useState({});
const getSelectData = async () => {
const list = await getRoleList({ page: 1, size: 10 });
setRoleListData(list);
};
// const getSelectData = async () => {
// const list =
// setRoleListData(list);
// };
const useAsyncDataSource = (
const UseAsyncDataSource = (
pattern: FormPathPattern,
service: (field: Field) => Promise<{ label: string; value: any }[]>,
) => {
@ -50,10 +50,8 @@ const EditAccountModal = ({
const form = createForm({
effects: () => {
// eslint-disable-next-line react-hooks/rules-of-hooks
useAsyncDataSource('role', async (field) => {
getSelectData();
const list = roleListData;
UseAsyncDataSource('role', async (field) => {
const list = await getRoleList({ page: 1, size: 10 });
const option = [];
for (let index = 0; index < list.items.length; index++) {
const element = list.items[index];
@ -76,7 +74,6 @@ const EditAccountModal = ({
form.submit(async () => {
onOk();
const formState = form.getFormState();
formState.values.role = parseInt(formState.values.role);
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 { fetchTableData } from '@/utils/table';
import DeleteButton from '@/components/Table/DeleteButton';
import { Switch } from 'antd';
import { Popover, Switch } from 'antd';
import AddNoticeModal from '../components/AddNoticeModal';
import EditNoticeModal from '../components/EditNoticeModal';
import { NoticeType } from '@/constants/enum/notice';
@ -80,6 +80,13 @@ const NoticeList = () => {
>
</a>,
<Popover
content={
<div>
<p>/</p>
</div>
}
>
<Switch
key="switch"
defaultChecked={row.status}
@ -88,7 +95,10 @@ const NoticeList = () => {
row.status = checked;
await updateNotice(row);
}}
/>,
/>
,
</Popover>,
<DeleteButton
key="delete"
onDelete={() => {
@ -102,7 +112,7 @@ const NoticeList = () => {
<div>
<Table
columns={columns}
rowKey="id"
rowKey="code"
search={false}
toolBarActions={[
{

View File

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

View File

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

View File

@ -1,17 +1,15 @@
// 创建弹窗
import React, { useRef, useState } from 'react';
import { Form, FormItem, Input } from '@formily/antd';
import React, { useEffect, useRef, useState } from 'react';
import { Button, Drawer, DrawerProps, message, Space } from 'antd';
import { ActionType, ProColumns } from '@ant-design/pro-table';
import Table from '@/components/Table';
import { TableRowSelection } from 'antd/lib/table/interface';
import routes from '@/routes';
import { getPermission } from '@/services/system/permission';
interface AuthPermissionsDrawerPropsType extends DrawerProps {
onCancel: () => void;
onOk: (val: any) => void;
rowData: any;
}
const columnsPermissions: ProColumns<any>[] = [
@ -22,9 +20,8 @@ const columnsPermissions: ProColumns<any>[] = [
];
const valueMap = {};
function loops(list, parent) {
const loops = (list, parent) => {
return (list || []).map(({ children, name }) => {
// console.log('children = ', children);
const node = (valueMap[name] = {
parent,
name,
@ -32,9 +29,9 @@ function loops(list, parent) {
node.children = loops(children, node);
return node;
});
}
};
function getPath(name) {
const getPath = (name) => {
const path = [];
let current = valueMap[name];
while (current) {
@ -42,39 +39,75 @@ function getPath(name) {
current = current.parent;
}
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 [selectedKeys, setSelectedKeys] = useState(['']);
const [postSelectedKeys, setPostSelectedKeys] = useState([]);
const [selectedKeys, setSelectedKeys] = useState(new Array());
const rowSelection: TableRowSelection<DataType> = {
onChange: (selectedRowKeys, selectedRows) => {
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 = () => {
let postSelectedKeys = new Array();
selectedKeys.forEach((element) => {
const path = getPath(element);
postSelectedKeys = mergeArray(postSelectedKeys, path);
});
if (postSelectedKeys.length == 0) {
message.warning('请选择权限。');
return;
}
onOk(postSelectedKeys);
onOk({ id: rowData.id, permission: postSelectedKeys });
};
const handleCancel = () => {
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 (
<Drawer

View File

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

View File

@ -73,3 +73,16 @@ export const deleteUser = (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();
if (!provider) {
console.log('请安装MetaMask');
message.warning('请安装MetaMask');
return false;
}