FEAT => 本次更新项目为:
定版本app通信
This commit is contained in:
@@ -11,6 +11,11 @@
|
|||||||
:src="iframeUrl"
|
:src="iframeUrl"
|
||||||
@message="handleMessage"
|
@message="handleMessage"
|
||||||
:fullscreen="false"
|
:fullscreen="false"
|
||||||
|
:webview-styles="{
|
||||||
|
width:'100%',
|
||||||
|
height:'260px'
|
||||||
|
}"
|
||||||
|
|
||||||
></web-view>
|
></web-view>
|
||||||
</view>
|
</view>
|
||||||
|
|
||||||
@@ -18,6 +23,22 @@
|
|||||||
<view class="controls">
|
<view class="controls">
|
||||||
<button @click="sendMessageToIframe" class="btn">发送消息到iframe</button>
|
<button @click="sendMessageToIframe" class="btn">发送消息到iframe</button>
|
||||||
<button @click="toggleIframeSize" class="btn btn-secondary">切换iframe大小</button>
|
<button @click="toggleIframeSize" class="btn btn-secondary">切换iframe大小</button>
|
||||||
|
<button @click="refreshIframe" class="btn btn-refresh">刷新iframe</button>
|
||||||
|
</view>
|
||||||
|
|
||||||
|
<!-- URL 参数控制区域 -->
|
||||||
|
<view class="url-controls">
|
||||||
|
<text class="url-title">URL 参数控制:</text>
|
||||||
|
<view class="param-buttons">
|
||||||
|
<button @click="addUrlParam('testParam', 'testValue')" class="btn-param">添加测试参数</button>
|
||||||
|
<button @click="updateUrlParams({theme: 'light', userId: '67890'})" class="btn-param">更新主题和用户ID</button>
|
||||||
|
<button @click="removeUrlParam('token')" class="btn-param btn-danger">移除token</button>
|
||||||
|
<button @click="demoUrlParams()" class="btn-param btn-demo">演示参数传递</button>
|
||||||
|
</view>
|
||||||
|
<view class="current-url">
|
||||||
|
<text class="url-label">当前URL:</text>
|
||||||
|
<text class="url-text">{{iframeUrl}}</text>
|
||||||
|
</view>
|
||||||
</view>
|
</view>
|
||||||
|
|
||||||
<!-- 消息显示区域 -->
|
<!-- 消息显示区域 -->
|
||||||
@@ -38,17 +59,125 @@
|
|||||||
return {
|
return {
|
||||||
title: 'iframe 通信示例',
|
title: 'iframe 通信示例',
|
||||||
// iframeUrl: 'http://localhost:3000/iframe',
|
// iframeUrl: 'http://localhost:3000/iframe',
|
||||||
iframeUrl: 'https://kr-op.quwanzhi.com/iframe',
|
baseUrl: 'https://kr-op.quwanzhi.com/iframe',
|
||||||
|
iframeUrl: '', // 动态构建的 URL
|
||||||
receivedMessages: [],
|
receivedMessages: [],
|
||||||
messageId: 0,
|
messageId: 0,
|
||||||
iframeSize: 'medium' // 控制 iframe 大小:small, medium, large
|
iframeSize: 'medium', // 控制 iframe 大小:small, medium, large
|
||||||
|
// URL 参数配置
|
||||||
|
urlParams: {
|
||||||
|
userId: '12345',
|
||||||
|
token: 'abc123',
|
||||||
|
theme: 'dark',
|
||||||
|
language: 'zh-CN',
|
||||||
|
timestamp: Date.now()
|
||||||
|
}
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
onLoad() {
|
onLoad() {
|
||||||
// 页面加载时的初始化
|
// 页面加载时的初始化
|
||||||
console.log('页面加载完成');
|
console.log('页面加载完成');
|
||||||
|
this.buildIframeUrl();
|
||||||
},
|
},
|
||||||
methods: {
|
methods: {
|
||||||
|
// 构建 iframe URL,包含参数
|
||||||
|
buildIframeUrl() {
|
||||||
|
// 使用兼容的方式构建 URL 参数
|
||||||
|
const params = [];
|
||||||
|
|
||||||
|
// 添加所有参数
|
||||||
|
Object.keys(this.urlParams).forEach(key => {
|
||||||
|
const value = this.urlParams[key];
|
||||||
|
if (value !== null && value !== undefined) {
|
||||||
|
// 对参数进行 URL 编码
|
||||||
|
const encodedKey = encodeURIComponent(key);
|
||||||
|
const encodedValue = encodeURIComponent(String(value));
|
||||||
|
params.push(`${encodedKey}=${encodedValue}`);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
// 构建完整 URL
|
||||||
|
const queryString = params.join('&');
|
||||||
|
this.iframeUrl = queryString ? `${this.baseUrl}?${queryString}` : this.baseUrl;
|
||||||
|
console.log('构建的 iframe URL:', this.iframeUrl);
|
||||||
|
},
|
||||||
|
|
||||||
|
// 更新 URL 参数
|
||||||
|
updateUrlParams(newParams) {
|
||||||
|
this.urlParams = { ...this.urlParams, ...newParams };
|
||||||
|
this.buildIframeUrl();
|
||||||
|
console.log('URL 参数已更新:', this.urlParams);
|
||||||
|
},
|
||||||
|
|
||||||
|
// 添加新的 URL 参数
|
||||||
|
addUrlParam(key, value) {
|
||||||
|
this.urlParams[key] = value;
|
||||||
|
this.buildIframeUrl();
|
||||||
|
console.log(`添加参数: ${key} = ${value}`);
|
||||||
|
},
|
||||||
|
|
||||||
|
// 移除 URL 参数
|
||||||
|
removeUrlParam(key) {
|
||||||
|
if (this.urlParams.hasOwnProperty(key)) {
|
||||||
|
delete this.urlParams[key];
|
||||||
|
this.buildIframeUrl();
|
||||||
|
console.log(`移除参数: ${key}`);
|
||||||
|
}
|
||||||
|
},
|
||||||
|
|
||||||
|
// 刷新 iframe(重新加载页面)
|
||||||
|
refreshIframe() {
|
||||||
|
this.buildIframeUrl();
|
||||||
|
console.log('iframe 已刷新,新 URL:', this.iframeUrl);
|
||||||
|
},
|
||||||
|
|
||||||
|
// 演示 URL 参数传递
|
||||||
|
demoUrlParams() {
|
||||||
|
// 模拟不同的参数组合
|
||||||
|
const demos = [
|
||||||
|
{
|
||||||
|
name: '用户登录',
|
||||||
|
params: {
|
||||||
|
userId: 'user123',
|
||||||
|
token: 'auth_token_456',
|
||||||
|
theme: 'light',
|
||||||
|
language: 'zh-CN'
|
||||||
|
}
|
||||||
|
},
|
||||||
|
{
|
||||||
|
name: '管理员模式',
|
||||||
|
params: {
|
||||||
|
userId: 'admin001',
|
||||||
|
token: 'admin_token_789',
|
||||||
|
theme: 'dark',
|
||||||
|
language: 'en-US',
|
||||||
|
role: 'admin',
|
||||||
|
permissions: 'all'
|
||||||
|
}
|
||||||
|
},
|
||||||
|
{
|
||||||
|
name: '测试模式',
|
||||||
|
params: {
|
||||||
|
userId: 'test_user',
|
||||||
|
token: 'test_token',
|
||||||
|
theme: 'blue',
|
||||||
|
language: 'zh-CN',
|
||||||
|
debug: 'true',
|
||||||
|
version: '1.0.0'
|
||||||
|
}
|
||||||
|
}
|
||||||
|
];
|
||||||
|
|
||||||
|
// 随机选择一个演示
|
||||||
|
const demo = demos[Math.floor(Math.random() * demos.length)];
|
||||||
|
this.updateUrlParams(demo.params);
|
||||||
|
|
||||||
|
uni.showToast({
|
||||||
|
title: `已切换到${demo.name}`,
|
||||||
|
icon: 'success'
|
||||||
|
});
|
||||||
|
},
|
||||||
|
|
||||||
// 接收 web-view 发送的消息
|
// 接收 web-view 发送的消息
|
||||||
handleMessage(event) {
|
handleMessage(event) {
|
||||||
// 消息在 event.detail.data 中(是一个数组,取最后一条)
|
// 消息在 event.detail.data 中(是一个数组,取最后一条)
|
||||||
@@ -92,11 +221,36 @@
|
|||||||
// App 向 web-view 发送消息
|
// App 向 web-view 发送消息
|
||||||
sendMessageToWebView(message) {
|
sendMessageToWebView(message) {
|
||||||
// 通过 ref 获取 web-view 实例,调用 evalJS 执行 web-view 中的函数
|
// 通过 ref 获取 web-view 实例,调用 evalJS 执行 web-view 中的函数
|
||||||
// 注意:需将数据转为字符串(避免语法错误)
|
|
||||||
|
// 验证 message 参数
|
||||||
|
if (!message) {
|
||||||
|
console.error('message 参数为空');
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
// 安全地序列化消息
|
||||||
|
let safeMessage;
|
||||||
|
try {
|
||||||
|
safeMessage = JSON.parse(JSON.stringify(message));
|
||||||
|
} catch (e) {
|
||||||
|
console.error('消息序列化失败:', e);
|
||||||
|
// 如果序列化失败,创建一个简单的消息对象
|
||||||
|
safeMessage = {
|
||||||
|
id: message.id || 0,
|
||||||
|
type: message.type || 'fromApp',
|
||||||
|
content: String(message.content || ''),
|
||||||
|
timestamp: message.timestamp || Date.now()
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
console.log('webviewRef:', this.$refs.webviewRef);
|
||||||
|
|
||||||
if (this.$refs.webviewRef && this.$refs.webviewRef.evalJS) {
|
if (this.$refs.webviewRef && this.$refs.webviewRef.evalJS) {
|
||||||
try {
|
try {
|
||||||
this.$refs.webviewRef.evalJS(`receiveFromApp(${JSON.stringify(message)})`);
|
const jsCode = `receiveFromApp(${JSON.stringify(safeMessage)})`;
|
||||||
console.log('App 发送消息到 web-view:', message);
|
console.log('要执行的 JS 代码:', jsCode);
|
||||||
|
this.$refs.webviewRef.evalJS(jsCode);
|
||||||
|
console.log('App 发送消息到 web-view:', safeMessage);
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
console.error('evalJS 执行失败:', e);
|
console.error('evalJS 执行失败:', e);
|
||||||
}
|
}
|
||||||
@@ -214,6 +368,123 @@
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
.btn-secondary {
|
||||||
|
background: linear-gradient(135deg, #6c757d 0%, #5a6268 100%);
|
||||||
|
box-shadow: 0 4rpx 12rpx rgba(108, 117, 125, 0.3);
|
||||||
|
|
||||||
|
&:active {
|
||||||
|
transform: translateY(2rpx);
|
||||||
|
box-shadow: 0 2rpx 8rpx rgba(108, 117, 125, 0.4);
|
||||||
|
}
|
||||||
|
|
||||||
|
&:hover {
|
||||||
|
background: linear-gradient(135deg, #5a6268 0%, #495057 100%);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
.btn-refresh {
|
||||||
|
background: linear-gradient(135deg, #ff9800 0%, #f57c00 100%);
|
||||||
|
box-shadow: 0 4rpx 12rpx rgba(255, 152, 0, 0.3);
|
||||||
|
|
||||||
|
&:hover {
|
||||||
|
background: linear-gradient(135deg, #f57c00 0%, #ef6c00 100%);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// URL 参数控制区域
|
||||||
|
.url-controls {
|
||||||
|
padding: 20rpx;
|
||||||
|
background: #f0f0f0;
|
||||||
|
border-bottom: 2rpx solid #e0e0e0;
|
||||||
|
display: flex;
|
||||||
|
flex-direction: column;
|
||||||
|
gap: 16rpx;
|
||||||
|
}
|
||||||
|
|
||||||
|
.url-title {
|
||||||
|
font-size: 28rpx;
|
||||||
|
color: #333;
|
||||||
|
font-weight: 600;
|
||||||
|
margin-bottom: 16rpx;
|
||||||
|
padding-bottom: 16rpx;
|
||||||
|
border-bottom: 2rpx solid #d0d0d0;
|
||||||
|
}
|
||||||
|
|
||||||
|
.param-buttons {
|
||||||
|
display: flex;
|
||||||
|
gap: 16rpx;
|
||||||
|
flex-wrap: wrap;
|
||||||
|
}
|
||||||
|
|
||||||
|
.btn-param {
|
||||||
|
flex: 1;
|
||||||
|
background: linear-gradient(135deg, #4caf50 0%, #388e3c 100%);
|
||||||
|
color: white;
|
||||||
|
border: none;
|
||||||
|
border-radius: 20rpx;
|
||||||
|
padding: 20rpx 16rpx;
|
||||||
|
font-size: 26rpx;
|
||||||
|
font-weight: 600;
|
||||||
|
cursor: pointer;
|
||||||
|
transition: all 0.3s ease;
|
||||||
|
box-shadow: 0 4rpx 12rpx rgba(76, 175, 80, 0.3);
|
||||||
|
|
||||||
|
&:active {
|
||||||
|
transform: translateY(2rpx);
|
||||||
|
box-shadow: 0 2rpx 8rpx rgba(76, 175, 80, 0.4);
|
||||||
|
}
|
||||||
|
|
||||||
|
&:hover {
|
||||||
|
background: linear-gradient(135deg, #388e3c 0%, #2e7d32 100%);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
.btn-danger {
|
||||||
|
background: linear-gradient(135deg, #f44336 0%, #d32f2f 100%);
|
||||||
|
box-shadow: 0 4rpx 12rpx rgba(244, 67, 54, 0.3);
|
||||||
|
|
||||||
|
&:active {
|
||||||
|
transform: translateY(2rpx);
|
||||||
|
box-shadow: 0 2rpx 8rpx rgba(244, 67, 54, 0.4);
|
||||||
|
}
|
||||||
|
|
||||||
|
&:hover {
|
||||||
|
background: linear-gradient(135deg, #d32f2f 0%, #c62828 100%);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
.btn-demo {
|
||||||
|
background: linear-gradient(135deg, #007bff 0%, #0056b3 100%);
|
||||||
|
box-shadow: 0 4rpx 12rpx rgba(0, 123, 255, 0.3);
|
||||||
|
|
||||||
|
&:active {
|
||||||
|
transform: translateY(2rpx);
|
||||||
|
box-shadow: 0 2rpx 8rpx rgba(0, 123, 255, 0.4);
|
||||||
|
}
|
||||||
|
|
||||||
|
&:hover {
|
||||||
|
background: linear-gradient(135deg, #0056b3 0%, #004085 100%);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
.current-url {
|
||||||
|
display: flex;
|
||||||
|
align-items: center;
|
||||||
|
gap: 16rpx;
|
||||||
|
font-size: 24rpx;
|
||||||
|
color: #555;
|
||||||
|
}
|
||||||
|
|
||||||
|
.url-label {
|
||||||
|
font-weight: 600;
|
||||||
|
}
|
||||||
|
|
||||||
|
.url-text {
|
||||||
|
font-family: "Courier New", monospace;
|
||||||
|
word-break: break-all;
|
||||||
|
line-height: 1.5;
|
||||||
|
}
|
||||||
|
|
||||||
// 消息显示区域
|
// 消息显示区域
|
||||||
.message-area {
|
.message-area {
|
||||||
flex: 1;
|
flex: 1;
|
||||||
|
|||||||
@@ -276,3 +276,62 @@
|
|||||||
width: 100%;
|
width: 100%;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// URL 参数区域样式
|
||||||
|
.url-params-section {
|
||||||
|
margin-top: 20px;
|
||||||
|
padding-top: 20px;
|
||||||
|
border-top: 2px solid #e1e5e9;
|
||||||
|
|
||||||
|
h4 {
|
||||||
|
margin: 0 0 15px 0;
|
||||||
|
color: #333;
|
||||||
|
font-size: 1.1rem;
|
||||||
|
font-weight: 600;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
.no-params {
|
||||||
|
color: #666;
|
||||||
|
font-style: italic;
|
||||||
|
text-align: center;
|
||||||
|
padding: 20px;
|
||||||
|
background: #f8f9fa;
|
||||||
|
border-radius: 8px;
|
||||||
|
border: 2px dashed #dee2e6;
|
||||||
|
}
|
||||||
|
|
||||||
|
.params-list {
|
||||||
|
display: flex;
|
||||||
|
flex-direction: column;
|
||||||
|
gap: 8px;
|
||||||
|
}
|
||||||
|
|
||||||
|
.param-item {
|
||||||
|
display: flex;
|
||||||
|
align-items: center;
|
||||||
|
padding: 10px 15px;
|
||||||
|
background: #f8f9fa;
|
||||||
|
border-radius: 8px;
|
||||||
|
border-left: 4px solid var(--primary-color);
|
||||||
|
transition: all 0.3s ease;
|
||||||
|
|
||||||
|
&:hover {
|
||||||
|
background: #e9ecef;
|
||||||
|
transform: translateX(5px);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
.param-key {
|
||||||
|
font-weight: 600;
|
||||||
|
color: #333;
|
||||||
|
min-width: 80px;
|
||||||
|
margin-right: 10px;
|
||||||
|
}
|
||||||
|
|
||||||
|
.param-value {
|
||||||
|
color: #666;
|
||||||
|
font-family: "Courier New", monospace;
|
||||||
|
word-break: break-all;
|
||||||
|
flex: 1;
|
||||||
|
}
|
||||||
|
|||||||
@@ -19,18 +19,50 @@ const IframeDebugPage: React.FC = () => {
|
|||||||
const [receivedMessages, setReceivedMessages] = useState<string[]>([]);
|
const [receivedMessages, setReceivedMessages] = useState<string[]>([]);
|
||||||
const [messageId, setMessageId] = useState(0);
|
const [messageId, setMessageId] = useState(0);
|
||||||
const [inputMessage, setInputMessage] = useState("");
|
const [inputMessage, setInputMessage] = useState("");
|
||||||
|
const [urlParams, setUrlParams] = useState<Record<string, string>>({});
|
||||||
|
const [processedMessages] = useState(new Set<string>()); // 用于防止重复处理消息
|
||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
|
// 解析 URL 参数
|
||||||
|
const parseUrlParams = () => {
|
||||||
|
// 使用兼容的方式解析 URL 参数
|
||||||
|
const search = window.location.search.substring(1); // 移除开头的 '?'
|
||||||
|
const params: Record<string, string> = {};
|
||||||
|
|
||||||
|
if (search) {
|
||||||
|
const pairs = search.split("&");
|
||||||
|
pairs.forEach(pair => {
|
||||||
|
const [key, value] = pair.split("=");
|
||||||
|
if (key) {
|
||||||
|
params[decodeURIComponent(key)] = decodeURIComponent(value || "");
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
setUrlParams(params);
|
||||||
|
console.log("解析到的 URL 参数:", JSON.stringify(params));
|
||||||
|
|
||||||
|
// 将 URL 参数作为消息添加到列表
|
||||||
|
if (Object.keys(params).length > 0) {
|
||||||
|
const paramMessage = `[${new Date().toLocaleTimeString()}] URL参数: ${JSON.stringify(params)}`;
|
||||||
|
setReceivedMessages(prev => [paramMessage, ...prev]);
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
// 初始化 uni-app web-view SDK
|
// 初始化 uni-app web-view SDK
|
||||||
const initUniSDK = () => {
|
const initUniSDK = () => {
|
||||||
console.log("web-view SDK 初始化完成");
|
console.log("web-view SDK 初始化完成");
|
||||||
|
|
||||||
// 页面加载完成后发送准备就绪消息
|
// 页面加载完成后发送准备就绪消息,包含 URL 参数
|
||||||
setTimeout(() => {
|
setTimeout(() => {
|
||||||
sendMessageToParent({
|
sendMessageToParent({
|
||||||
id: 0,
|
id: 0,
|
||||||
type: "ready",
|
type: "ready",
|
||||||
data: { status: "loaded", url: window.location.href },
|
data: {
|
||||||
|
status: "loaded",
|
||||||
|
url: window.location.href,
|
||||||
|
urlParams: urlParams,
|
||||||
|
},
|
||||||
timestamp: Date.now(),
|
timestamp: Date.now(),
|
||||||
});
|
});
|
||||||
}, 500);
|
}, 500);
|
||||||
@@ -39,6 +71,9 @@ const IframeDebugPage: React.FC = () => {
|
|||||||
// 监听 SDK 初始化完成事件
|
// 监听 SDK 初始化完成事件
|
||||||
document.addEventListener("UniAppJSBridgeReady", initUniSDK);
|
document.addEventListener("UniAppJSBridgeReady", initUniSDK);
|
||||||
|
|
||||||
|
// 解析 URL 参数
|
||||||
|
parseUrlParams();
|
||||||
|
|
||||||
// 检查URL参数中的消息
|
// 检查URL参数中的消息
|
||||||
checkUrlMessage();
|
checkUrlMessage();
|
||||||
|
|
||||||
@@ -64,15 +99,28 @@ const IframeDebugPage: React.FC = () => {
|
|||||||
document.removeEventListener("UniAppJSBridgeReady", initUniSDK);
|
document.removeEventListener("UniAppJSBridgeReady", initUniSDK);
|
||||||
window.removeEventListener("message", handlePostMessage);
|
window.removeEventListener("message", handlePostMessage);
|
||||||
};
|
};
|
||||||
}, []);
|
}, []); // 移除 urlParams 依赖,避免无限循环
|
||||||
|
|
||||||
// 检查URL参数中的消息
|
// 检查URL参数中的消息
|
||||||
const checkUrlMessage = () => {
|
const checkUrlMessage = () => {
|
||||||
const urlParams = new URLSearchParams(window.location.search);
|
// 使用兼容的方式解析 URL 参数
|
||||||
const messageParam = urlParams.get("message");
|
const search = window.location.search.substring(1);
|
||||||
|
let messageParam = null;
|
||||||
|
|
||||||
|
if (search) {
|
||||||
|
const pairs = search.split("&");
|
||||||
|
for (const pair of pairs) {
|
||||||
|
const [key, value] = pair.split("=");
|
||||||
|
if (key === "message" && value) {
|
||||||
|
messageParam = decodeURIComponent(value);
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
if (messageParam) {
|
if (messageParam) {
|
||||||
try {
|
try {
|
||||||
const message = JSON.parse(decodeURIComponent(messageParam));
|
const message = JSON.parse(messageParam);
|
||||||
handleParentMessage(message);
|
handleParentMessage(message);
|
||||||
// 清除URL参数
|
// 清除URL参数
|
||||||
const newUrl = window.location.pathname;
|
const newUrl = window.location.pathname;
|
||||||
@@ -102,6 +150,18 @@ const IframeDebugPage: React.FC = () => {
|
|||||||
|
|
||||||
// 接收 App 发送的消息
|
// 接收 App 发送的消息
|
||||||
const handleParentMessage = (message: Message) => {
|
const handleParentMessage = (message: Message) => {
|
||||||
|
// 生成消息的唯一标识,用于防重复处理
|
||||||
|
const messageKey = `${message.id}-${message.timestamp}-${JSON.stringify(message.data)}`;
|
||||||
|
|
||||||
|
// 检查是否已经处理过这个消息
|
||||||
|
if (processedMessages.has(messageKey)) {
|
||||||
|
console.log("消息已处理过,跳过:", message);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
// 添加到已处理集合
|
||||||
|
processedMessages.add(messageKey);
|
||||||
|
|
||||||
console.log("web-view 收到 App 消息:", message);
|
console.log("web-view 收到 App 消息:", message);
|
||||||
const messageText = `[${new Date().toLocaleTimeString()}] 收到: ${JSON.stringify(message)}`;
|
const messageText = `[${new Date().toLocaleTimeString()}] 收到: ${JSON.stringify(message)}`;
|
||||||
setReceivedMessages(prev => [...prev, messageText]);
|
setReceivedMessages(prev => [...prev, messageText]);
|
||||||
@@ -256,6 +316,23 @@ const IframeDebugPage: React.FC = () => {
|
|||||||
<div className={style["info-item"]}>
|
<div className={style["info-item"]}>
|
||||||
<strong>消息ID:</strong> {messageId}
|
<strong>消息ID:</strong> {messageId}
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
|
{/* URL 参数显示区域 */}
|
||||||
|
<div className={style["url-params-section"]}>
|
||||||
|
<h4>URL 参数</h4>
|
||||||
|
{Object.keys(urlParams).length === 0 ? (
|
||||||
|
<div className={style["no-params"]}>暂无 URL 参数</div>
|
||||||
|
) : (
|
||||||
|
<div className={style["params-list"]}>
|
||||||
|
{Object.entries(urlParams).map(([key, value]) => (
|
||||||
|
<div key={key} className={style["param-item"]}>
|
||||||
|
<span className={style["param-key"]}>{key}:</span>
|
||||||
|
<span className={style["param-value"]}>{value}</span>
|
||||||
|
</div>
|
||||||
|
))}
|
||||||
|
</div>
|
||||||
|
)}
|
||||||
|
</div>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
);
|
);
|
||||||
|
|||||||
Reference in New Issue
Block a user