diff --git a/src/pages/Index/Index.js b/src/pages/Index/Index.js index 6f82d31..4a48292 100644 --- a/src/pages/Index/Index.js +++ b/src/pages/Index/Index.js @@ -11,9 +11,11 @@ import compass from "./compass.png"; import Shops from "../Shops/Shops"; import NavBottom from "../../components/NavBottom/NavBottom"; import Modal from "react-modal"; - +import { Html5Qrcode } from "html5-qrcode"; +// import vconsole from "vconsole"; +// const vConsole = new vconsole(); export const MallCode = React.createContext(null); -// const vConsole = new window.VConsole(); + let focusdDevice; const Index = () => { @@ -44,6 +46,8 @@ const Index = () => { const [end, _setEnd] = useState(null); const [doFocus, _setDoFocus] = useState(0); const [focusTextClicked, setFocusTextClicked] = useState(false); + const [showQrcodeModal, setShowQrcodeModal] = useState(false); + const [qrcodeModalOpened, setQrcodeModalOpened] = useState(false); useEffect(() => { if (!map) return; @@ -346,6 +350,7 @@ const Index = () => { }, [focusTextClicked]); const handleEndSet = (end) => { + if (!start) return setShowQrcodeModal(true); setEnd(end); map.startNavigate({ start, @@ -353,9 +358,102 @@ const Index = () => { }); }; + useEffect(() => { + if (qrcodeModalOpened) { + const html5QrCode = new Html5Qrcode("qrcode-scaner"); + html5QrCode + .start( + { facingMode: "environment" }, + { fps: 10, qrbox: { width: 320, height: 320 } }, + (code) => { + try { + code = decodeURIComponent(code); + const kvs = code + .split("?") + .pop() + .split("&") + .map((kv) => kv.split("=")); + const s = kvs.find(([k]) => k === "s") + ? kvs.find(([k]) => k === "s")[1] + : ""; + const startParamList = s.split("_"); + if (startParamList.length === 3) { + let [sfloororder, spoint, sname] = startParamList; + sfloororder = Number(sfloororder); + spoint = Number(spoint); + const nxt = { + isDevice: true, + name: sname, + navPoint: spoint, + yaxis: spoint, + floorOrder: sfloororder, + }; + setStart(nxt); + setEnd(shop); + map.startNavigate({ + start: nxt, + end: shop, + }); + try { + setQrcodeModalOpened(false); + setShowQrcodeModal(false); + html5QrCode.stop(); + } catch (error) {} + } + } catch (error) { + window.weui.toast("请扫大屏二维码", { + className: "toast", + }); + } + } + ) + .catch(() => { + window.weui.toast("启动二维码失败", { + className: "toast", + }); + setQrcodeModalOpened(false); + setShowQrcodeModal(false); + }); + return () => { + try { + html5QrCode.stop(); + } catch (error) {} + }; + } + }, [qrcodeModalOpened]); + return (
+ {showQrcodeModal && ( + setQrcodeModalOpened(true)} + isOpen + ariaHideApp={false} + className="ScanModal" + > +
+
+
+
+
+
{ + setQrcodeModalOpened(false); + setShowQrcodeModal(false); + }} + > + 取消 +
+
+
+ )} {!online && ( + + diff --git a/src/pages/Index/qrcodeTip.png b/src/pages/Index/qrcodeTip.png new file mode 100644 index 0000000..d44b986 Binary files /dev/null and b/src/pages/Index/qrcodeTip.png differ diff --git a/src/pages/Index/scaner.svg b/src/pages/Index/scaner.svg new file mode 100644 index 0000000..5747637 --- /dev/null +++ b/src/pages/Index/scaner.svg @@ -0,0 +1,10 @@ + + + + + + + + + +