mirror of
https://github.com/woodchen-ink/clash-and-dashboard.git
synced 2025-07-18 22:11:56 +08:00
Chore: adjust style & logic
This commit is contained in:
parent
9b0bf2727c
commit
42a6dfea87
@ -46,7 +46,7 @@ $delete-height: 22px;
|
|||||||
.tags-expand {
|
.tags-expand {
|
||||||
height: 30px;
|
height: 30px;
|
||||||
line-height: 30px;
|
line-height: 30px;
|
||||||
padding: 0 10px;
|
padding: 0 20px;
|
||||||
user-select: none;
|
user-select: none;
|
||||||
cursor: pointer;
|
cursor: pointer;
|
||||||
}
|
}
|
||||||
|
@ -4,17 +4,17 @@ import { Header, Card, Row, Col } from '@components'
|
|||||||
import { I18nProps, BaseRouterProps } from '@models'
|
import { I18nProps, BaseRouterProps } from '@models'
|
||||||
import './style.scss'
|
import './style.scss'
|
||||||
import { storeKeys } from '@lib/createStore'
|
import { storeKeys } from '@lib/createStore'
|
||||||
import { inject } from 'mobx-react'
|
import { inject, observer } from 'mobx-react'
|
||||||
import { List, AutoSizer } from 'react-virtualized'
|
import { List, AutoSizer } from 'react-virtualized'
|
||||||
|
|
||||||
interface RulesProps extends BaseRouterProps, I18nProps {}
|
interface RulesProps extends BaseRouterProps, I18nProps {}
|
||||||
|
|
||||||
@inject(...storeKeys)
|
@inject(...storeKeys)
|
||||||
|
@observer
|
||||||
class Rules extends React.Component<RulesProps, {}> {
|
class Rules extends React.Component<RulesProps, {}> {
|
||||||
|
|
||||||
async componentDidMount () {
|
async componentWillMount () {
|
||||||
const { store } = this.props
|
await this.props.store.fetchData()
|
||||||
await store.fetchData()
|
|
||||||
}
|
}
|
||||||
|
|
||||||
renderRuleItem = ({ index, key, style }) => {
|
renderRuleItem = ({ index, key, style }) => {
|
||||||
|
@ -1,21 +1,22 @@
|
|||||||
import * as React from 'react'
|
import * as React from 'react'
|
||||||
import { translate } from 'react-i18next'
|
import { translate } from 'react-i18next'
|
||||||
import { changeLanguage } from 'i18next'
|
import { changeLanguage } from 'i18next'
|
||||||
|
import { inject, observer } from 'mobx-react'
|
||||||
import { Header, Card, Row, Col, Switch, ButtonSelect, ButtonSelectOptions, Input, Icon } from '@components'
|
import { Header, Card, Row, Col, Switch, ButtonSelect, ButtonSelectOptions, Input, Icon } from '@components'
|
||||||
import { ExternalControllerModal } from './components'
|
import { ExternalControllerModal } from './components'
|
||||||
import { I18nProps } from '@models'
|
import { I18nProps, BaseRouterProps } from '@models'
|
||||||
import { updateConfig } from '@lib/request'
|
import { updateConfig } from '@lib/request'
|
||||||
import { setLocalStorageItem, to } from '@lib/helper'
|
import { setLocalStorageItem, to } from '@lib/helper'
|
||||||
import { rootStores } from '@lib/createStore'
|
import { rootStores, storeKeys } from '@lib/createStore'
|
||||||
import './style.scss'
|
import './style.scss'
|
||||||
import { isClashX, jsBridge } from '@lib/jsBridge'
|
import { isClashX, jsBridge } from '@lib/jsBridge'
|
||||||
|
|
||||||
class Settings extends React.Component<I18nProps, {}> {
|
interface SettingProps extends BaseRouterProps, I18nProps {}
|
||||||
|
|
||||||
|
@inject(...storeKeys)
|
||||||
|
@observer
|
||||||
|
class Settings extends React.Component<SettingProps, {}> {
|
||||||
state = {
|
state = {
|
||||||
startAtLogin: false,
|
|
||||||
setAsSystemProxy: false,
|
|
||||||
allowConnectFromLan: false,
|
|
||||||
proxyMode: 'Rule',
|
|
||||||
socks5ProxyPort: 7891,
|
socks5ProxyPort: 7891,
|
||||||
httpProxyPort: 7890,
|
httpProxyPort: 7890,
|
||||||
externalControllerHost: '127.0.0.1',
|
externalControllerHost: '127.0.0.1',
|
||||||
@ -45,25 +46,31 @@ class Settings extends React.Component<I18nProps, {}> {
|
|||||||
|
|
||||||
handleProxyModeChange = async (mode: string) => {
|
handleProxyModeChange = async (mode: string) => {
|
||||||
const [, err] = await to(updateConfig({ mode }))
|
const [, err] = await to(updateConfig({ mode }))
|
||||||
if (err === null) {
|
if (!err) {
|
||||||
this.setState({ proxyMode: mode })
|
rootStores.store.fetchData()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
handleHttpPortSave = async () => {
|
handleHttpPortSave = async () => {
|
||||||
const [, err] = await to(updateConfig({ 'port': this.state.httpProxyPort }))
|
const [, err] = await to(updateConfig({ 'port': this.state.httpProxyPort }))
|
||||||
if (err === null) {}
|
if (!err) {
|
||||||
|
await this.props.store.fetchData()
|
||||||
|
this.setState({ httpProxyPort: this.props.store.data.general.port })
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
handleSocksPortSave = async () => {
|
handleSocksPortSave = async () => {
|
||||||
const [, err] = await to(updateConfig({ 'socks-port': this.state.socks5ProxyPort }))
|
const [, err] = await to(updateConfig({ 'socks-port': this.state.socks5ProxyPort }))
|
||||||
if (err === null) {}
|
if (!err) {
|
||||||
|
await this.props.store.fetchData()
|
||||||
|
this.setState({ socks5ProxyPort: this.props.store.data.general.socksPort })
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
handleAllowLanChange = async (state: boolean) => {
|
handleAllowLanChange = async (state: boolean) => {
|
||||||
const [, err] = await to(updateConfig({ 'allow-lan': state }))
|
const [, err] = await to(updateConfig({ 'allow-lan': state }))
|
||||||
if (err === null) {
|
if (!err) {
|
||||||
this.setState({ allowConnectFromLan: state })
|
await this.props.store.fetchData()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -77,47 +84,43 @@ class Settings extends React.Component<I18nProps, {}> {
|
|||||||
this.setState({ setAsSystemProxy: state })
|
this.setState({ setAsSystemProxy: state })
|
||||||
}
|
}
|
||||||
|
|
||||||
async componentDidMount () {
|
async componentWillMount () {
|
||||||
|
await rootStores.store.fetchData()
|
||||||
if (isClashX()) {
|
if (isClashX()) {
|
||||||
await rootStores.store.fetchAndParseConfig()
|
await rootStores.store.fetchClashXData()
|
||||||
const startAtLogin = await jsBridge.getStartAtLogin()
|
|
||||||
const setAsSystemProxy = await jsBridge.isSystemProxySet()
|
|
||||||
const apiInfo = await jsBridge.getAPIInfo()
|
const apiInfo = await jsBridge.getAPIInfo()
|
||||||
this.setState({
|
this.setState({
|
||||||
startAtLogin,
|
|
||||||
setAsSystemProxy,
|
|
||||||
isClashX: true,
|
isClashX: true,
|
||||||
externalControllerHost: apiInfo.host,
|
externalControllerHost: apiInfo.host,
|
||||||
externalControllerPort: apiInfo.port,
|
externalControllerPort: apiInfo.port,
|
||||||
externalControllerSecret: apiInfo.secret
|
externalControllerSecret: apiInfo.secret
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
await rootStores.store.fetchData()
|
|
||||||
|
|
||||||
const general = rootStores.store.data.general
|
const general = this.props.store.data.general
|
||||||
this.setState({
|
this.setState({
|
||||||
allowConnectFromLan: general.allowLan,
|
|
||||||
proxyMode: general.mode,
|
|
||||||
socks5ProxyPort: general.socksPort,
|
socks5ProxyPort: general.socksPort,
|
||||||
httpProxyPort: general.port
|
httpProxyPort: general.port
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
render () {
|
render () {
|
||||||
const { t, lng } = this.props
|
const { t, lng, store } = this.props
|
||||||
const {
|
const {
|
||||||
isClashX,
|
isClashX,
|
||||||
startAtLogin,
|
|
||||||
setAsSystemProxy,
|
|
||||||
allowConnectFromLan,
|
|
||||||
proxyMode,
|
|
||||||
socks5ProxyPort,
|
|
||||||
httpProxyPort,
|
|
||||||
externalControllerHost,
|
externalControllerHost,
|
||||||
externalControllerPort,
|
externalControllerPort,
|
||||||
externalControllerSecret,
|
externalControllerSecret,
|
||||||
showEditDrawer
|
showEditDrawer,
|
||||||
|
socks5ProxyPort,
|
||||||
|
httpProxyPort
|
||||||
} = this.state
|
} = this.state
|
||||||
|
|
||||||
|
const { allowLan, mode } = store.data.general
|
||||||
|
const {
|
||||||
|
startAtLogin,
|
||||||
|
systemProxy
|
||||||
|
} = store.clashxData
|
||||||
const proxyModeOptions: ButtonSelectOptions[] = [
|
const proxyModeOptions: ButtonSelectOptions[] = [
|
||||||
{ label: t('values.global'), value: 'Global' },
|
{ label: t('values.global'), value: 'Global' },
|
||||||
{ label: t('values.rules'), value: 'Rule' },
|
{ label: t('values.rules'), value: 'Rule' },
|
||||||
@ -149,7 +152,7 @@ class Settings extends React.Component<I18nProps, {}> {
|
|||||||
<Col span={4} className="value-column">
|
<Col span={4} className="value-column">
|
||||||
<Switch
|
<Switch
|
||||||
disabled={!isClashX}
|
disabled={!isClashX}
|
||||||
checked={setAsSystemProxy}
|
checked={systemProxy}
|
||||||
onChange={this.handleSetSystemProxy}
|
onChange={this.handleSetSystemProxy}
|
||||||
/>
|
/>
|
||||||
</Col>
|
</Col>
|
||||||
@ -158,7 +161,7 @@ class Settings extends React.Component<I18nProps, {}> {
|
|||||||
</Col>
|
</Col>
|
||||||
<Col span={4} className="value-column">
|
<Col span={4} className="value-column">
|
||||||
<Switch
|
<Switch
|
||||||
checked={allowConnectFromLan}
|
checked={allowLan}
|
||||||
onChange={this.handleAllowLanChange}
|
onChange={this.handleAllowLanChange}
|
||||||
/>
|
/>
|
||||||
</Col>
|
</Col>
|
||||||
@ -173,7 +176,7 @@ class Settings extends React.Component<I18nProps, {}> {
|
|||||||
<Col span={7} className="value-column">
|
<Col span={7} className="value-column">
|
||||||
<ButtonSelect
|
<ButtonSelect
|
||||||
options={proxyModeOptions}
|
options={proxyModeOptions}
|
||||||
value={proxyMode}
|
value={mode}
|
||||||
onSelect={this.handleProxyModeChange}
|
onSelect={this.handleProxyModeChange}
|
||||||
/>
|
/>
|
||||||
</Col>
|
</Col>
|
||||||
@ -194,6 +197,7 @@ class Settings extends React.Component<I18nProps, {}> {
|
|||||||
</Col>
|
</Col>
|
||||||
<Col span={3} offset={2}>
|
<Col span={3} offset={2}>
|
||||||
<Input
|
<Input
|
||||||
|
type="number"
|
||||||
value={httpProxyPort}
|
value={httpProxyPort}
|
||||||
onChange={httpProxyPort => this.setState({ httpProxyPort: parseInt(httpProxyPort, 10) })}
|
onChange={httpProxyPort => this.setState({ httpProxyPort: parseInt(httpProxyPort, 10) })}
|
||||||
onBlur={this.handleHttpPortSave}
|
onBlur={this.handleHttpPortSave}
|
||||||
|
@ -7,9 +7,5 @@
|
|||||||
</head>
|
</head>
|
||||||
<body>
|
<body>
|
||||||
<div id="root"></div>
|
<div id="root"></div>
|
||||||
|
|
||||||
<!-- Dependencies -->
|
|
||||||
<!-- <script src="https://cdnjs.cloudflare.com/ajax/libs/react/16.4.2/umd/react.production.min.js" integrity="sha256-2EQx5J1ux3sjgPLtDevlo449XNXfvEplcRYWIF6ui8w=" crossorigin="anonymous"></script> -->
|
|
||||||
<!-- <script src="https://cdnjs.cloudflare.com/ajax/libs/react-dom/16.4.2/umd/react-dom.production.min.js" integrity="sha256-3NNU/yoE0R7VxxapKiw/hkgQzcSMztyclb5RpeVlV7Y=" crossorigin="anonymous"></script> -->
|
|
||||||
</body>
|
</body>
|
||||||
</html>
|
</html>
|
||||||
|
@ -64,6 +64,11 @@ export interface Config {
|
|||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
export interface ClashXData {
|
||||||
|
startAtLogin: boolean
|
||||||
|
systemProxy: boolean
|
||||||
|
}
|
||||||
|
|
||||||
export interface Data {
|
export interface Data {
|
||||||
|
|
||||||
general?: {
|
general?: {
|
||||||
|
@ -22,6 +22,12 @@ export class ConfigStore {
|
|||||||
rules: []
|
rules: []
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@observable
|
||||||
|
clashxData: Models.ClashXData = {
|
||||||
|
startAtLogin: false,
|
||||||
|
systemProxy: false
|
||||||
|
}
|
||||||
|
|
||||||
@action
|
@action
|
||||||
async fetchData () {
|
async fetchData () {
|
||||||
const [{ data: general }, rawProxies, rules] = await Promise.all([API.getConfig(), API.getProxies(), API.getRules()])
|
const [{ data: general }, rawProxies, rules] = await Promise.all([API.getConfig(), API.getProxies(), API.getRules()])
|
||||||
@ -49,6 +55,19 @@ export class ConfigStore {
|
|||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@action
|
||||||
|
async fetchClashXData () {
|
||||||
|
const startAtLogin = await jsBridge.getStartAtLogin()
|
||||||
|
const systemProxy = await jsBridge.isSystemProxySet()
|
||||||
|
|
||||||
|
runInAction(() => {
|
||||||
|
this.clashxData = {
|
||||||
|
startAtLogin,
|
||||||
|
systemProxy
|
||||||
|
}
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
@action
|
@action
|
||||||
async fetchAndParseConfig () {
|
async fetchAndParseConfig () {
|
||||||
const rawConfig = await jsBridge.readConfigString()
|
const rawConfig = await jsBridge.readConfigString()
|
||||||
|
@ -33,6 +33,7 @@ body {
|
|||||||
.page-container {
|
.page-container {
|
||||||
width: 100%;
|
width: 100%;
|
||||||
height: 100vh;
|
height: 100vh;
|
||||||
|
overflow-y: scroll;
|
||||||
}
|
}
|
||||||
|
|
||||||
.page {
|
.page {
|
||||||
|
Loading…
x
Reference in New Issue
Block a user