| | |
| | | <!-- |
| | | * @Author : yuan |
| | | * @Date : 2025-10-14 17:40:58 |
| | | * @LastEditors : yuan |
| | | * @LastEditTime : 2025-10-15 15:54:25 |
| | | * @FilePath : \src\pages\map\index.vue |
| | | * @Description : |
| | | * Copyright 2025 OBKoro1, All Rights Reserved. |
| | | * 2025-10-14 17:40:58 |
| | | --> |
| | | <template> |
| | | <view class="page-wrap"> |
| | | <web-view |
| | | ref="sWebViewRef" |
| | | :src="`${viewUrl}`" |
| | | @message="onPostMessage" |
| | | @onPostMessage="onPostMessage" |
| | | /> |
| | | <WebViewPlus :src="`${viewUrl}`" @webMessage="onPostMessage" /> |
| | | </view> |
| | | </template> |
| | | |
| | | <script setup> |
| | | import { useUserStore } from "@/store/index.js"; |
| | | import WebViewPlus from "@/components/WebViewPlus.vue"; |
| | | |
| | | const sWebViewRef = ref(null); |
| | | const userStore = useUserStore(); |
| | | const viewUrl = `http://192.168.1.194:5174/drone-app-web-view/#/webViewWrapper/defaultMap?params=${JSON.stringify( |
| | | userStore?.userInfo |
| | | )}`; |
| | | |
| | | const onPostMessage = (event) => { |
| | | // #ifdef APP-PLUS |
| | | if (event.detail.data[0].type === "scanCode") { |
| | | scanCode(); |
| | | } |
| | | // #endif |
| | | }; |
| | | const onPostMessage = (event) => {}; |
| | | |
| | | const scanCode = () => { |
| | | // 只允许通过相机扫码 |
| | | uni.scanCode({ |
| | | onlyFromCamera: true, |
| | | success: function (res) { |
| | | console.log("条码类型:" + res.scanType); |
| | | console.log("条码内容:" + res.result); |
| | | |
| | | // 获取扫码结果 |
| | | let url = res.result; |
| | | |
| | | // 跳转到B页面,并传递URL参数 |
| | | uni.navigateTo({ |
| | | url: "/subPackages/browser/index?url=" + encodeURIComponent(url), |
| | | }); |
| | | }, |
| | | fail: function (err) { |
| | | console.log("扫码失败:", err); |
| | | uni.showToast({ |
| | | title: "扫码失败", |
| | | icon: "none", |
| | | }); |
| | | }, |
| | | }); |
| | | }; |
| | | |
| | | onLoad(() => { |
| | | // #ifdef H5 |
| | | window.addEventListener("message", function (e) { |
| | | if (e.data.data.type === "scanCode") { |
| | | scanCode(); |
| | | } |
| | | }); |
| | | // #endif |
| | | }); |
| | | onLoad(() => {}); |
| | | </script> |
| | | |
| | | <style scoped lang="scss"> |