diff --git a/public/index.html b/public/index.html
index aa069f2..2cd49c2 100644
--- a/public/index.html
+++ b/public/index.html
@@ -3,7 +3,7 @@
-
+
+ } />
}>
- }>
+ }>
}>
}>
}>
diff --git a/src/pages/Measure.tsx b/src/pages/Measure.tsx
index cd3e034..e4b4158 100644
--- a/src/pages/Measure.tsx
+++ b/src/pages/Measure.tsx
@@ -11,6 +11,24 @@ import { rail6001, railTypes } from '../utils/constant';
import RailTypeBtn from '../components/RailTypeBtn';
import { Picker } from 'antd-mobile';
+declare global {
+ interface Window {
+ ReactNativeWebView: { postMessage: (arg: string) => void };
+ funcMap: Record;
+ bridgeCall: (func: string, args: any[]) => void;
+ }
+}
+window.funcMap = {
+ add: (a: number, b: number) => a + b,
+ sub: (a: number, b: number) => a - b,
+};
+
+window.bridgeCall = (func, ...args) => {
+ console.log(func, args);
+ const res = window.funcMap[func].apply(null, args);
+ console.log('res:', res);
+};
+
export default function Measure() {
const navigate = useNavigate();
@@ -19,6 +37,14 @@ export default function Measure() {
const [railPickerVisible, setRailPickerVisible] = useState(false);
const [railId, setRailId] = useState<(number | string | null)[]>([1]);
+ const onStartClick = () => {
+ if (typeof window.ReactNativeWebView !== 'undefined') {
+ // 发送消息给 React Native
+ window.ReactNativeWebView.postMessage(JSON.stringify(['add', 2, 3]));
+ } else {
+ console.log('当前环境不支持 React Native WebView');
+ }
+ };
const onSaveClick = () => {
navigate('/measure/save');
};
@@ -31,7 +57,7 @@ export default function Measure() {
}, []);
function railName() {
- return railTypes.find(r => r.id === railId[0])?.name || ''
+ return railTypes.find(r => r.id === railId[0])?.name || '';
}
return (
@@ -51,7 +77,7 @@ export default function Measure() {
gridStep={3}
origin={{ x: 0, y: 20 }}
pixelPerMm={window.innerWidth / 90}
- maxZoom={5}
+ maxZoom={8}
showGrid={true}
showBenchmark={true}
showAnalysis={false}
@@ -61,10 +87,7 @@ export default function Measure() {
ref={canvasRef}
/>
- setRailPickerVisible(true)}
- />
+ setRailPickerVisible(true)} />
@@ -77,7 +100,9 @@ export default function Measure() {