mirror of https://github.com/openspug/spug
fix issue
parent
e18e9b0129
commit
d58925fb63
|
@ -28,13 +28,16 @@ export default observer(function () {
|
||||||
const [bakTreeData, setBakTreeData] = useState();
|
const [bakTreeData, setBakTreeData] = useState();
|
||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
if (!loading) store.fetchGroups().then(() => {
|
if (loading === false) store.fetchGroups()
|
||||||
if (loading === undefined) {
|
}, [loading])
|
||||||
|
|
||||||
|
useEffect(() => {
|
||||||
|
if (store.treeData.length > 0 && expands === undefined) {
|
||||||
const tmp = store.treeData.filter(x => x.children.length)
|
const tmp = store.treeData.filter(x => x.children.length)
|
||||||
setExpands(tmp.map(x => x.key))
|
setExpands(tmp.map(x => x.key))
|
||||||
}
|
}
|
||||||
})
|
// eslint-disable-next-line react-hooks/exhaustive-deps
|
||||||
}, [loading])
|
}, [store.treeData])
|
||||||
|
|
||||||
const menus = (
|
const menus = (
|
||||||
<Menu onClick={() => setVisible(false)}>
|
<Menu onClick={() => setVisible(false)}>
|
||||||
|
|
|
@ -3,7 +3,7 @@
|
||||||
* Copyright (c) <spug.dev@gmail.com>
|
* Copyright (c) <spug.dev@gmail.com>
|
||||||
* Released under the AGPL-3.0 License.
|
* Released under the AGPL-3.0 License.
|
||||||
*/
|
*/
|
||||||
import React, { useEffect } from 'react';
|
import React from 'react';
|
||||||
import { observer } from 'mobx-react';
|
import { observer } from 'mobx-react';
|
||||||
import { Table, Modal, Dropdown, Button, Menu, Avatar, Tooltip, Space, Tag, message } from 'antd';
|
import { Table, Modal, Dropdown, Button, Menu, Avatar, Tooltip, Space, Tag, message } from 'antd';
|
||||||
import { PlusOutlined, DownOutlined } from '@ant-design/icons';
|
import { PlusOutlined, DownOutlined } from '@ant-design/icons';
|
||||||
|
@ -13,10 +13,6 @@ import store from './store';
|
||||||
import icons from './icons';
|
import icons from './icons';
|
||||||
|
|
||||||
function ComTable() {
|
function ComTable() {
|
||||||
useEffect(() => {
|
|
||||||
store.fetchRecords()
|
|
||||||
}, [])
|
|
||||||
|
|
||||||
function handleDelete(text) {
|
function handleDelete(text) {
|
||||||
Modal.confirm({
|
Modal.confirm({
|
||||||
title: '删除确认',
|
title: '删除确认',
|
||||||
|
|
|
@ -3,9 +3,9 @@
|
||||||
* Copyright (c) <spug.dev@gmail.com>
|
* Copyright (c) <spug.dev@gmail.com>
|
||||||
* Released under the AGPL-3.0 License.
|
* Released under the AGPL-3.0 License.
|
||||||
*/
|
*/
|
||||||
import React from 'react';
|
import React, { useEffect } from 'react';
|
||||||
import { observer } from 'mobx-react';
|
import { observer } from 'mobx-react';
|
||||||
import { Row, Col, Button } from 'antd';
|
import { Row, Col } from 'antd';
|
||||||
import { CodeOutlined } from '@ant-design/icons';
|
import { CodeOutlined } from '@ant-design/icons';
|
||||||
import { AuthDiv, Breadcrumb, AuthButton } from 'components';
|
import { AuthDiv, Breadcrumb, AuthButton } from 'components';
|
||||||
import Group from './Group';
|
import Group from './Group';
|
||||||
|
@ -18,6 +18,10 @@ import Selector from './Selector';
|
||||||
import store from './store';
|
import store from './store';
|
||||||
|
|
||||||
export default observer(function () {
|
export default observer(function () {
|
||||||
|
useEffect(() => {
|
||||||
|
store.initial()
|
||||||
|
}, [])
|
||||||
|
|
||||||
function openTerminal() {
|
function openTerminal() {
|
||||||
window.open('/ssh')
|
window.open('/ssh')
|
||||||
}
|
}
|
||||||
|
|
|
@ -40,10 +40,11 @@ class Store {
|
||||||
this.isFetching = true;
|
this.isFetching = true;
|
||||||
return http.get('/api/host/')
|
return http.get('/api/host/')
|
||||||
.then(res => {
|
.then(res => {
|
||||||
|
const tmp = {};
|
||||||
this.records = res;
|
this.records = res;
|
||||||
for (let item of this.records) {
|
this.records.map(item => tmp[item.id] = item);
|
||||||
this.idMap[item.id] = item
|
this.idMap = tmp;
|
||||||
}
|
this._makeCounter();
|
||||||
this.refreshCounter()
|
this.refreshCounter()
|
||||||
})
|
})
|
||||||
.finally(() => this.isFetching = false)
|
.finally(() => this.isFetching = false)
|
||||||
|
@ -53,14 +54,30 @@ class Store {
|
||||||
this.grpFetching = true;
|
this.grpFetching = true;
|
||||||
return http.get('/api/host/group/')
|
return http.get('/api/host/group/')
|
||||||
.then(res => {
|
.then(res => {
|
||||||
this.treeData = res.treeData;
|
|
||||||
this.groups = res.groups;
|
this.groups = res.groups;
|
||||||
if (!this.group.key) this.group = this.treeData[0];
|
this.refreshCounter(res.treeData)
|
||||||
this.refreshCounter()
|
|
||||||
})
|
})
|
||||||
.finally(() => this.grpFetching = false)
|
.finally(() => this.grpFetching = false)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
initial = () => {
|
||||||
|
this.isFetching = true;
|
||||||
|
this.grpFetching = true;
|
||||||
|
http.all([http.get('/api/host/'), http.get('/api/host/group/')])
|
||||||
|
.then(http.spread((res1, res2) => {
|
||||||
|
this.records = res1;
|
||||||
|
this.records.map(item => this.idMap[item.id] = item);
|
||||||
|
this.group = res2.treeData[0];
|
||||||
|
this.groups = res2.groups;
|
||||||
|
this._makeCounter();
|
||||||
|
this.refreshCounter(res2.treeData)
|
||||||
|
}))
|
||||||
|
.finally(() => {
|
||||||
|
this.isFetching = false;
|
||||||
|
this.grpFetching = false
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
updateGroup = (group, host_ids) => {
|
updateGroup = (group, host_ids) => {
|
||||||
const form = {host_ids, s_group_id: group.key, t_group_id: this.group.key, is_copy: this.addByCopy};
|
const form = {host_ids, s_group_id: group.key, t_group_id: this.group.key, is_copy: this.addByCopy};
|
||||||
return http.patch('/api/host/', form)
|
return http.patch('/api/host/', form)
|
||||||
|
@ -85,10 +102,9 @@ class Store {
|
||||||
this.selectorVisible = true;
|
this.selectorVisible = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
refreshCounter = () => {
|
refreshCounter = (treeData) => {
|
||||||
this._makeCounter();
|
treeData = treeData || lds.cloneDeep(this.treeData);
|
||||||
if (this.treeData.length && this.records.length) {
|
if (treeData.length && this.records.length) {
|
||||||
const treeData = lds.cloneDeep(this.treeData);
|
|
||||||
for (let item of treeData) {
|
for (let item of treeData) {
|
||||||
this._refreshCounter(item)
|
this._refreshCounter(item)
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue