Skip to content

Commit c03ec48

Browse files
committed
[feat]add whitelist
1 parent 78f456e commit c03ec48

File tree

5 files changed

+596
-0
lines changed

5 files changed

+596
-0
lines changed

src/modules/system/whitelist.ts

Lines changed: 63 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,63 @@
1+
import { createSlice, createAsyncThunk } from '@reduxjs/toolkit';
2+
import { RootState } from '../store';
3+
import { Page } from 'services/model/pageModel';
4+
import { Whitelist } from 'services/model/whitelistModel';
5+
import { createWhitelist, deleteWhitelist, findWhitelist, updateWhitelist } from 'services/whitelist';
6+
import { PAGE } from '../../constants';
7+
8+
const namespace = 'system/whitelist';
9+
10+
interface IInitialState {
11+
page: Page;
12+
list: Whitelist[];
13+
}
14+
15+
const initialState: IInitialState = {
16+
page: {
17+
num: PAGE.NUM,
18+
size: PAGE.SIZE,
19+
total: '0',
20+
disable: false,
21+
},
22+
list: [],
23+
};
24+
25+
export const find = createAsyncThunk(`${namespace}/find`, async (params: any) => {
26+
const res = await findWhitelist(params);
27+
return res;
28+
});
29+
30+
export const update = createAsyncThunk(`${namespace}/update`, async (data: any) => {
31+
const res = await updateWhitelist(data);
32+
return res;
33+
});
34+
35+
export const create = createAsyncThunk(`${namespace}/create`, async (params: { token: string; data: any }) => {
36+
const res = await createWhitelist(params.token, params.data);
37+
return res;
38+
});
39+
40+
export const deleteByIds = createAsyncThunk(`${namespace}/deleteByIds`, async (data: any) => {
41+
const res = await deleteWhitelist(data);
42+
return res;
43+
});
44+
45+
const systemWhitelistSlice = createSlice({
46+
name: namespace,
47+
initialState,
48+
reducers: {
49+
reset: () => initialState,
50+
},
51+
extraReducers: (builder) => {
52+
builder.addCase(find.fulfilled, (state, whitelist) => {
53+
state.page = whitelist.payload.page;
54+
state.list = whitelist.payload.list;
55+
});
56+
},
57+
});
58+
59+
export const { reset } = systemWhitelistSlice.actions;
60+
61+
export const selectSystemWhitelist = (state: RootState) => state.systemWhitelist;
62+
63+
export default systemWhitelistSlice.reducer;
Lines changed: 104 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,104 @@
1+
import React, { useRef, memo } from 'react';
2+
import { Select, Row, Col, Form, Input, Button } from 'tdesign-react';
3+
import { AddIcon, DeleteIcon } from 'tdesign-icons-react';
4+
import { FormInstanceFunctions, SubmitContext } from 'tdesign-react/es/form/type';
5+
import Permission from 'components/Permission';
6+
import { WHITELIST_OPTIONS } from '../../../../constants';
7+
8+
const { FormItem } = Form;
9+
10+
export type FormValueType = {
11+
name?: string;
12+
word?: string;
13+
};
14+
15+
export type SearchFormProps = {
16+
onSubmit?: (values: FormValueType) => void;
17+
onCancel?: () => void;
18+
onCreate?: () => void;
19+
onDelete?: () => void;
20+
deleteLoading?: boolean;
21+
};
22+
23+
const SearchForm: React.FC<SearchFormProps> = (props) => {
24+
const formRef = useRef<FormInstanceFunctions>();
25+
const onSubmit = (e: SubmitContext) => {
26+
if (e.validateResult === true) {
27+
const params = formRef?.current?.getFieldsValue?.(true);
28+
if (props.onSubmit) {
29+
props.onSubmit({ ...params });
30+
}
31+
}
32+
};
33+
34+
const onReset = () => {
35+
if (props.onCancel) {
36+
props.onCancel();
37+
}
38+
};
39+
40+
const onCreate = () => {
41+
if (props.onCreate) {
42+
props.onCreate();
43+
}
44+
};
45+
46+
const onDelete = () => {
47+
if (props.onDelete) {
48+
props.onDelete();
49+
}
50+
};
51+
52+
return (
53+
<div className='list-common-table-query'>
54+
<Form ref={formRef} onSubmit={onSubmit} onReset={onReset} labelWidth={80} colon>
55+
<Row>
56+
<Col flex='2'>
57+
<Row gutter={[16, 16]}>
58+
<Col span={6}>
59+
<FormItem label='分类' name='category'>
60+
<Select options={WHITELIST_OPTIONS} placeholder='请选择分类' />
61+
</FormItem>
62+
</Col>
63+
<Col span={6}>
64+
<FormItem label='授权资源' name='resource'>
65+
<Input placeholder='请输入资源' clearable />
66+
</FormItem>
67+
</Col>
68+
</Row>
69+
</Col>
70+
<Col>
71+
<Permission btn='system.whitelist.read'>
72+
<Button theme='primary' type='submit' style={{ marginLeft: '10px' }}>
73+
查询
74+
</Button>
75+
</Permission>
76+
<Permission btn='system.whitelist.read'>
77+
<Button type='reset' variant='base' theme='default' style={{ marginLeft: '8px' }}>
78+
重置
79+
</Button>
80+
</Permission>
81+
<Permission btn='system.whitelist.create'>
82+
<Button theme='primary' onClick={onCreate} icon={<AddIcon />} style={{ marginLeft: '8px' }}>
83+
新建
84+
</Button>
85+
</Permission>
86+
<Permission btn='system.whitelist.delete'>
87+
<Button
88+
theme='danger'
89+
loading={props.deleteLoading}
90+
onClick={onDelete}
91+
icon={<DeleteIcon />}
92+
style={{ marginLeft: '8px' }}
93+
>
94+
删除
95+
</Button>
96+
</Permission>
97+
</Col>
98+
</Row>
99+
</Form>
100+
</div>
101+
);
102+
};
103+
104+
export default memo(SearchForm);

0 commit comments

Comments
 (0)