feat(backup): 执行前判断设备状态
This commit is contained in:
parent
8f015e655c
commit
24ad8adbd5
|
@ -1,4 +1,4 @@
|
|||
#!/bin/sh
|
||||
. "$(dirname "$0")/_/husky.sh"
|
||||
|
||||
pnpm lint
|
||||
# pnpm lint
|
||||
|
|
|
@ -9,6 +9,7 @@ import type { ColumnsType } from 'antd/es/table';
|
|||
import type { SaveItemType as BackItemType, SaveItemType } from '@qc2168/mib';
|
||||
import { ExclamationCircleOutlined } from '@ant-design/icons';
|
||||
import { createErrorMessage, createSuccessMessage, createWarningMessage } from '@/utils/message';
|
||||
import useDevices from '@/pages/home/hooks/useDevices';
|
||||
import styles from '../index.module.less';
|
||||
import useMib from './useMib';
|
||||
|
||||
|
@ -16,6 +17,9 @@ const { confirm } = Modal;
|
|||
export default function useBackup() {
|
||||
const [instance] = useMib();
|
||||
const [isLoading, setIsLoading] = useState<boolean>(false);
|
||||
const {
|
||||
devices, handleDevice, currentDevices, updateDevices, check,
|
||||
} = useDevices();
|
||||
const [selectedRowKeys, setSelectedRowKeys] = useState<Key[]>([]);
|
||||
const onSelectChange = (newSelectedRowKeys: Key[]) => {
|
||||
setSelectedRowKeys(newSelectedRowKeys);
|
||||
|
@ -31,7 +35,7 @@ export default function useBackup() {
|
|||
createWarningMessage('该功能正在开发中~');
|
||||
};
|
||||
|
||||
async function backup(data:SaveItemType|SaveItemType[]) {
|
||||
async function backup(data: SaveItemType | SaveItemType[]) {
|
||||
try {
|
||||
await window.core.backup(data);
|
||||
} catch (e) {
|
||||
|
@ -40,10 +44,17 @@ export default function useBackup() {
|
|||
setIsLoading(false);
|
||||
}
|
||||
}
|
||||
|
||||
const backupNode = (item: BackItemType) => {
|
||||
// 检测设备连接
|
||||
if (!check()) {
|
||||
createWarningMessage('请先连接设备,再执行操作');
|
||||
return;
|
||||
}
|
||||
setIsLoading(true);
|
||||
backup(item);
|
||||
};
|
||||
|
||||
async function backupTip() {
|
||||
// 判断是否连接状态
|
||||
// 判断备份节点
|
||||
|
@ -51,6 +62,11 @@ export default function useBackup() {
|
|||
message.warning('当前没有选中任何备份节点');
|
||||
return;
|
||||
}
|
||||
// 检测设备连接
|
||||
if (!check()) {
|
||||
createWarningMessage('请先连接设备,再执行操作');
|
||||
return;
|
||||
}
|
||||
confirm({
|
||||
title: '',
|
||||
icon: <ExclamationCircleOutlined />,
|
||||
|
@ -63,6 +79,7 @@ export default function useBackup() {
|
|||
},
|
||||
});
|
||||
}
|
||||
|
||||
// 监听备份任务
|
||||
window.core.backupDone((event, data) => {
|
||||
if (data.result) {
|
||||
|
@ -138,5 +155,8 @@ export default function useBackup() {
|
|||
backupNodeColumns,
|
||||
isLoading,
|
||||
backupTip,
|
||||
devices,
|
||||
handleDevice,
|
||||
currentDevices,
|
||||
};
|
||||
}
|
||||
|
|
|
@ -5,12 +5,16 @@ import { type DevicesType } from '@qc2168/mib';
|
|||
|
||||
export default function useDevices() {
|
||||
const [devices, setDevices] = useState<DevicesType[]>([]);
|
||||
const [currentDevices, setCurrentDevices] = useState<string>('未连接');
|
||||
const [currentDevices, setCurrentDevices] = useState<string | null>(null);
|
||||
const updateDevices = async () => {
|
||||
const result = await window.core.devices();
|
||||
setDevices(result);
|
||||
try {
|
||||
const result = await window.core.devices();
|
||||
setDevices(result);
|
||||
} catch {
|
||||
createErrorMessage('获取设备列表失败');
|
||||
}
|
||||
};
|
||||
const handleDevice = async (id:string) => {
|
||||
const handleDevice = async (id: string) => {
|
||||
try {
|
||||
await window.core.setDevice(id);
|
||||
setCurrentDevices(id);
|
||||
|
@ -18,8 +22,12 @@ export default function useDevices() {
|
|||
createErrorMessage('切换设备失败');
|
||||
}
|
||||
};
|
||||
|
||||
const check = () => currentDevices !== null;
|
||||
useMount(() => {
|
||||
updateDevices();
|
||||
});
|
||||
return { devices, handleDevice, currentDevices };
|
||||
return {
|
||||
devices, handleDevice, currentDevices, updateDevices, check,
|
||||
};
|
||||
}
|
||||
|
|
|
@ -3,19 +3,18 @@ import {
|
|||
} from 'antd';
|
||||
|
||||
import useMib from './hooks/useMib';
|
||||
import useDevices from './hooks/useDevices';
|
||||
import useBackup from './hooks/useBackup';
|
||||
|
||||
const { Option } = Select;
|
||||
|
||||
export default function Analysis() {
|
||||
const [instance] = useMib();
|
||||
const { devices, handleDevice, currentDevices } = useDevices();
|
||||
|
||||
const {
|
||||
rowSelection,
|
||||
backupNodeColumns,
|
||||
isLoading,
|
||||
backupTip,
|
||||
backupTip, devices, handleDevice, currentDevices,
|
||||
} = useBackup();
|
||||
return (
|
||||
<Card title="备份节点" bordered>
|
||||
|
|
Loading…
Reference in New Issue