B2B网络软件

 找回密码
 立即注册 审核网站号:QQ:896757558
搜索
查看: 628|回复: 0
打印 上一主题 下一主题

原生webview的h5如何跟aiwork交互

[复制链接]

880

主题

885

帖子

6796

积分

abc

Rank: 9Rank: 9Rank: 9

积分
6796
跳转到指定楼层
楼主
发表于 2025-2-19 09:30:51 | 只看该作者 |只看大图 回帖奖励 |倒序浏览 |阅读模式
原生webview的h5如何跟aiwork交互
<!DOCTYPE html>
<html lang="en">

<head>
<meta charset="UTF-8">
<title>合并页面</title>
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<style>
body {
background-color: #fff; /* 改为白色 */
color: #333; /* 调整文字颜色以匹配白色背景 */
font-family: Arial, sans-serif;
padding: 20px;
}

.navbar {
background-color: #f0f0f0; /* 改为浅色以与白色背景区分 */
padding: 10px;
display: flex;
justify-content: space-around;
color: #000;
}

.navbar a {
text-decoration: none;
color: inherit;
font-weight: bold;
}

.section, .submenu {
background-color: #fff; /* 改为白色 */
color: #333; /* 调整文字颜色 */
padding: 20px;
margin-bottom: 20px;
border-radius: 10px;
box-shadow: 0 0 10px rgba(0, 0, 0, 0.1);
}

.section input[type="checkbox"],
.submenu input[type="checkbox"],
input[type="radio"],
input[type="text"],
select,
button {
color: #333; /* 调整文字颜色 */
background-color: #ddd; /* 改为浅色 */
border: none;
border-radius: 5px;
padding: 10px;
margin-right: 10px;
box-sizing: border-box;
}

button {
background-color: #4CAF50;
width: 60%;
font-size: 20px;
cursor: pointer;
margin-top: 20px;
color: #fff; /* 按钮文字颜色 */
}

h1 {
color: #e91e63;
}
</style>
</head>

<body>
<div class="navbar">
<a href="#">首页</a>
<a href="#">话术</a>
<a href="#">选择平台</a>
<a href="#">配置</a>
<a href="#">其他</a>
</div>

<h1>合并页面</h1>

<div class="section">
<h2>超级延迟</h2>
<input type="checkbox" id="charDelay" name="charDelay">
<label for="charDelay">按打字数量延迟</label>
<!-- 省略其他选项... -->
</div>

<div class="submenu">
<h2>招呼设置</h2>
<input type="checkbox" id="fixed-greeting" name="fixed-greeting">
<label for="fixed-greeting">钉定招呼语---勾选生效</label>
<input type="text" placeholder="请输入招呼1">
<input type="text" placeholder="请输入招呼2">
<input type="text" placeholder="请输入招呼3">
</div>

<!-- 省略其他部分... -->

<form>
<div class="section">
<h2>定时</h2>
<input type="checkbox" id="enableTiming" name="enableTiming">
<label for="enableTiming">开启定时</label><br>
<!-- 省略其他选项... -->
</div>

<button type="button" onClick="callHelloAI();">调用原生方法</button>
<button type="button" onClick="runJS();">执行脚本代码</button>
<button type="button" onClick="runJsFile();">执行脚本文件</button>
<button type="button" onClick="sendText();">传递控件值</button>
</form>

<script language="JavaScript">
function callHelloAI() {
window.at.callFun('main', 'hello');
}

function runJS() {
window.at.runJs(function () {
printl("你好");
auto.recents();
}.toString());
}

function runJsFile() {
window.at.runJsFile('主脚本.js');
}

function sendText() {
var inputValue = document.getElementById('input1').value;
window.at.runJsFile('测试传值.js');
}
</script>

</body>

</html>




原生webview的h5如何跟aiwork交互 B2B网络软件

原生webview的h5如何跟aiwork交互 B2B网络软件




原生activity和h5交互案例.zip



void runJs(function code)h5执行app JS脚本

window.at.runJs(function (){
     //这里写ATjs代码
     printl("你好");
     auto.home();
}.toString());

void runJsFile(String file) H5运行APP JS文件

window.at.runJsFile('主脚本.js');

void callFunction(String funname,String arg) H5执行脚本方法

window.at.callFun('main',"hello");

String getRootPath() 获取项目根目录

window.at.getRootPath();

String getResourcesPath() 获取项目资源目录

window.at.getResourcesPath();

void setConfig(String path,String arg,String value) 存储数据
path:存储路径,例如/sdcard/1.txt;
arg:参数
value:存储值

window.at.setConfig('/sdcard/1.txt','a','1');
//例如存储到资源目录
let res=window.at.getResourcesPath();
window.at.setConfig(res+'1.txt','a','1');

String getConfig(String path,String arg,String value) 读取数据
path:存储路径,例如/sdcard/1.txt;
arg:参数
value:默认值,没有数据的情况下默认返回

window.at.getConfig('/sdcard/1.txt','a','1');

//从资源目录取数据
let res=window.at.getResourcesPath();
window.at.getConfig(res+'1.txt','a','1');

publicSet(String key,String value) 公共变量传参

window.at.publicSet('a','1');

//对应aiwork取值就是
publicData.get('a')

publicGet(String key) 公共变量读参

window.at.publicGet('a');


//对应aiwork写值就是
publicData.set('a','1')

完整HTML案例

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>方式一</title>
    <script language="JavaScript">
        function test() {

           window.at.runJs(function (){
                //这里写js代码
                printl("你好");
           }.toString());

           /*
           window.at.close();
           window.at.runJsFile('主脚本.js');
          */
        }
    </script>
</head>
<body>
<input type="Button" width="300" value="启动脚本"  onClick="test()"  />
</body>
</html>

APP调用H5:

首先获取web控件,例如web控件的自定义ID是web

//初始化一个activity页面
var ac = new activity();
ac.loadXML(`
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    androidrientation="vertical"
 >

    <TextView
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:text="H5演示"
        android:textSize="18sp"
        android:textStyle="bold"
        android:gravity="center"
        android:paddingBottom="8dp" />

    <WebView
        android:id="@+id/web"
        android:layout_width="match_parent"
        android:layout_height="0dp"
        android:layout_weight="1" />

</LinearLayout>
`)

sleep.millisecond(毫秒 = 400);

var web1 = ac.findWebViewById('web');

加载网址loadUrl(url)

复制web1.url('/代码/h5.html');

执行h5的js方法,注意代码事字符串http://bbs.aiwork24.com/thread-124-1-1.html
String runWebJs(String jscode)
返回值:类似js中eval执行js代码的返回值,一般是返回最后一个变量的值http://www.postbbs.com/thread-2894-1-1.html

//让浏览器运行js代码
web1.runWebJs(`alert("123")`);

回复

使用道具 举报

本版积分规则

关闭

QQ|»营销软件综合讨论|»营销软件有问必答|»营销软件教程专区|»营销软件POST脚本分享|»营销软件普通脚本分享|»营销软件软件资讯|»营销软件精品软件|»营销软件更新公告|营销软件|B2B软件|B2B网络软件 ( 京ICP备09078825号 )本网站开发的营销软件是一款新的网络营销软件,这款营销可以去网站软件,博客软件,B2B软件,分类信息网发贴,可以抢沙发,可以到百度文库上传WORD文档,可以到一些是相册网站自动上传图片,这个自动发帖软件自带云蜘蛛,加快收录,有6种对接打码接口,方便,效率高,速度快,而且对拖动的验证码全网第一家独家支持,全部原创技术,独家研发,正版原创带版权软件。选择万能营销软件,就选择了一种赚钱的效率,从没有被超越过,一直在努力研发新技术。放飞梦想,解放双手,来点创意,成就你的梦想,就在万能营销软件开始

map2

GMT+8, 2025-6-20 19:28 , Processed in 1.201998 second(s), 36 queries .

快速回复 返回顶部 返回列表