Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feat 1.x refresh local ip #33

Merged
merged 2 commits into from
Nov 25, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion app/web/layouts/header/header.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,7 @@ const HeaderComponent = (props: any) => {
<span className="local-ip ml-20">{`本机IP: ${localIp}`}</span>

{/* 主动更新本地IP */}
<SyncOutlined className='refresh-cion' onClick={changeLocalIp} />
<SyncOutlined className='refresh-cion' onClick={() => changeLocalIp(true)} />
</div>
</div>
</Header>
Expand Down
23 changes: 20 additions & 3 deletions app/web/pages/proxyServer/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ class ProxyServer extends React.PureComponent<any, any> {
expandedRowKeys: [],
//子表格
subTableData: [],
allIPChecked: true, // 查看全部IP的开关是否打开
subTableLoading: true,
commonTagList: [],
selectedTag: ''
Expand Down Expand Up @@ -109,8 +110,11 @@ class ProxyServer extends React.PureComponent<any, any> {
}
//获取子表格数据
loadSubTableData(row: any) {
const { localIp } = this.state;
const { id } = row;
const allIPChecked = localStorage.getItem(`${ localIp }-${ id }-all-ip-checked`) !== 'no'
this.setState({
allIPChecked,
subTableLoading: true
});
API.getProxyRuleList({
Expand Down Expand Up @@ -401,7 +405,7 @@ class ProxyServer extends React.PureComponent<any, any> {
localStorage.setItem('common-tags', JSON.stringify(newList));
};
tableExpandedRowRender = (mainTableRow: any) => {
const { subTableLoading, subTableData, localIp } = this.state;
const { subTableLoading, subTableData, localIp, allIPChecked } = this.state;
const columns: any = [{
title: '序号',
key: 'index',
Expand Down Expand Up @@ -462,13 +466,16 @@ class ProxyServer extends React.PureComponent<any, any> {
}]
return (
<div style={{ padding: '0 10px' }}>
<div className="text-right marginBottom12"><Button icon={<PlusOutlined />} size="small" type="primary" onClick={this.handleAddRule}>添加规则</Button></div>
<div className="text-right marginBottom12">
<Button icon={<PlusOutlined />} size="small" type="primary" onClick={this.handleAddRule}>添加规则</Button>
<Switch className='all-ip-switch' checkedChildren="全部" unCheckedChildren="我的" checked={allIPChecked} onChange={(checked) => { this.handleIPFilter(checked, mainTableRow) }} />
</div>
<Table
size="small"
rowKey={(row: any) => row.id}
loading={subTableLoading}
columns={columns}
dataSource={subTableData}
dataSource={allIPChecked ? subTableData : subTableData.filter(item => item.ip === localIp)}
pagination={false} />
</div>
);
Expand All @@ -488,6 +495,16 @@ class ProxyServer extends React.PureComponent<any, any> {
);
}

// 只看我的 IP (false)或者全部(true)
handleIPFilter = (allIPChecked, mainTableRow) => {
const { localIp } = this.state;
localStorage.setItem(`${ localIp }-${ mainTableRow.id }-all-ip-checked`, allIPChecked ? 'yes' : 'no')
Message.success(`${ allIPChecked ? '查看全部' : '只看我的IP' }`)
this.setState({
allIPChecked
})
}

// 获取已有目标服务列表
getTargetAddrs = (id: any, callback: any) => {
API.getTargetAddrs({ id }).then((response: any) => {
Expand Down
7 changes: 7 additions & 0 deletions app/web/pages/proxyServer/style.scss
Original file line number Diff line number Diff line change
@@ -1,4 +1,11 @@
.page-proxy-server {
.all-ip-switch {
margin-left: 15px;
background-color: #3fad09;
&.ant-switch-checked {
background-color: #3F87FF;
}
}
.title_wrap {
display: flex;
justify-content: space-between;
Expand Down
7 changes: 5 additions & 2 deletions app/web/store/actions.ts
Original file line number Diff line number Diff line change
@@ -1,15 +1,18 @@
import { message as Message } from 'antd';
import { message } from 'antd';
import { CHANGE_LOCAL_IP } from './constant';

export const changeLocalIp = () => (dispatch: any, getState: any, { API }: any) => {
export const changeLocalIp = (showMsg = false) => (dispatch: any, getState: any, { API }: any) => {
API.getLocalIp().then((response: any) => {
const { success, data } = response;
if (success) {
console.log(data);
showMsg && message.success('刷新成功!')
dispatch({
type: CHANGE_LOCAL_IP,
payload: data
})
}
}).catch(() => {
showMsg && message.warning('刷新失败!')
});
}