FEAT => 本次更新项目为:
交互完成,开始封装
This commit is contained in:
@@ -48,13 +48,7 @@
|
||||
receivedMessages: [],
|
||||
messageId: 0,
|
||||
// URL 参数配置
|
||||
urlParams: {
|
||||
userId: '12345',
|
||||
token: 'abc123',
|
||||
theme: 'dark',
|
||||
language: 'zh-CN',
|
||||
timestamp: Date.now()
|
||||
}
|
||||
urlParams: {}
|
||||
}
|
||||
},
|
||||
onLoad() {
|
||||
@@ -84,10 +78,12 @@
|
||||
sendMessageToIframe() {
|
||||
this.messageId++;
|
||||
const message = {
|
||||
id: this.messageId,
|
||||
type: 'fromApp',
|
||||
content: `Hello,我是 App 发送的消息 ${this.messageId}`,
|
||||
timestamp: Date.now()
|
||||
type: 0, // 数据类型:0数据交互 1App功能调用
|
||||
data: {
|
||||
id: this.messageId,
|
||||
content: `Hello,我是 App 发送的消息 ${this.messageId}`,
|
||||
timestamp: Date.now()
|
||||
}
|
||||
};
|
||||
|
||||
// 将消息添加到URL参数中
|
||||
@@ -104,15 +100,18 @@
|
||||
|
||||
this.receivedMessages.push(`[${new Date().toLocaleTimeString()}] ${JSON.stringify(webData)}`);
|
||||
|
||||
if (webData.type === 'ready') {
|
||||
// console.log('web-view 已准备就绪');
|
||||
if (webData.type === 0) {
|
||||
// 数据交互
|
||||
console.log('收到数据交互消息:', webData.data);
|
||||
uni.showToast({
|
||||
title: 'web-view 连接成功',
|
||||
icon: 'success'
|
||||
title: `收到数据:${webData.data.content || '无内容'}`,
|
||||
icon: 'none'
|
||||
});
|
||||
} else if (webData.type === 'toApp') {
|
||||
} else if (webData.type === 1) {
|
||||
// App功能调用
|
||||
console.log('收到App功能调用:', webData.data);
|
||||
uni.showToast({
|
||||
title: `收到:${webData.content}`,
|
||||
title: `收到功能调用:${webData.data.action || '未知功能'}`,
|
||||
icon: 'none'
|
||||
});
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user