zhang
2025-05-20 1313906bb1eb983d3beece810035e7fc28d6a92f
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
import React, { useState, useRef, useEffect, useMemo } from "react";
import { useTranslate } from "react-admin";
import {
    Fab,
} from '@mui/material';
import LensBlurIcon from '@mui/icons-material/LensBlur';
import { getFakeSign, setFakeSign } from "../http";
import { VERIFY_PASSWORD } from '@/config/setting';
 
const FakeFab = (props) => {
    const translate = useTranslate();
    const [fakeRun, setFakeRun] = useState(false);
 
    useEffect(() => {
        getFakeSign(null, (res) => {
            setFakeRun(res);
        });
    }, [props]);
 
    const handleToggle = () => {
        getFakeSign(null, (res) => {
            let pass = true;
            if (!res) {
                const pwd = prompt("please enter password:");
                if (pwd === VERIFY_PASSWORD) {
                    pass = true;
                } else {
                    pass = false;
                    if (pwd) {
                        alert('Incorrect password');
                    }
                }
            }
            if (pass) {
                setFakeSign(!res, (updatedSign) => {
                    setFakeRun(updatedSign);
                });
            }
        });
    }
 
    return (
        <>
            <Fab
                variant="extended"
                color={fakeRun ? 'primary' : 'default'}
                size="small"
                onClick={handleToggle}
            >
                <LensBlurIcon />
                &nbsp;{translate('page.map.action.fake')}&nbsp;
            </Fab>
        </>
    )
}
 
export default FakeFab;