方法一:使用openTabLayout方法(没实现点击第二次时刷新页面功能)
实现效果图
在根目录下index.html中写入代码:
<!doctype html>
<html>
<head>
<meta charset="utf-8">
<meta name="viewport" content="maximum-scale=1.0,minimum-scale=1.0,user-scalable=0,width=device-width,initial-scale=1.0"/>
<meta name="format-detection" content="telephone=no,email=no,date=no,address=no">
<title>demo</title>
<link rel="stylesheet" type="text/css" href="./css/api.css"/>
<link rel="stylesheet" type="text/css" href="./css/style.css"/>
<style>
html {
height: 100%;
background-color: #fff;
}
body {
background-color: #fff;
padding: 0;
margin: 0;
display: -webkit-box;
display: -webkit-flex;
display: flex;
height: 100%;
-webkit-box-orient: vertical;
-webkit-flex-flow: column;
flex-flow: column;
}
</style>
</head>
<body>
</body>
<script type="text/javascript" src="script/api.js"></script>
<script>
apiready = function () {
openNavTabWin();
}
function openNavTabWin(){
var param = {
name: 'nav-tab',
title:'nav-tab',
bgColor:'#fff',
slidBackEnabled: false,
hideNavigationBar: true, // 是否隐藏顶部导航,默认false
// navigationBar: { // 顶部navigationBar导航栏配置信息
// hideBackButton: true
// },
tabBar: {
animated: true,
scrollEnabled: false, // //(可选项)标签栏每项对应的页面间是否能够左右滚动切换,默认值true。布尔类型
list: [
{
text: "首页",
iconPath: "widget://image/footer/shouye2.png",
selectedIconPath: "widget://image/footer/shouye.png"
}, {
text: "菜谱",
iconPath: "widget://image/footer/caipu.png",
selectedIconPath: "widget://image/footer/caipu2.png"
}, {
text: "社区",
iconPath: "widget://image/footer/shequ.png",
selectedIconPath: "widget://image/footer/shequ2.png"
},
{
text: "购物车",
iconPath: "widget://image/footer/spcart.png",
selectedIconPath: "widget://image/footer/spcart2.png"
},
{
text: "我的",
iconPath: "widget://image/footer/wd.png",
selectedIconPath: "widget://image/footer/wd2.png"
}
],
frames: [
{
title: "首页",//tab切换时对应的标题
name: "index",
url: "widget://html/index.html",
//其他继承自openFrame的参数
}, {
title: "菜谱",
name: "tab_frm_2",
url: "widget://html/menu.html"
//其他继承自openFrame的参数
}, {
title: "社区",
name: "tab_frm_3",
url: "widget://html/community.html"
//其他继承自openFrame的参数
},
{
title: "购物车",
name: "tab_frm_3",
url: "widget://html/shopcart.html"
//其他继承自openFrame的参数
},
{
title: "我的",
name: "tab_frm_4",
url: "widget://html/my.html"
//其他继承自openFrame的参数
}
]
}
}
api.openTabLayout(param);
}
</script>
</html>
使用api: openTabLayout // 打开tabLayout布局
官方文档:https://docs.apicloud.com/Client-API/Func-Ext/api
相关论坛: https://community.apicloud.com/bbs/thread-123685-1-1.html
方法二:openFrameGroup + aui框架(该方法实现了点击某个页面可以刷新的功能)
根目录index.html
<!doctype html>
<html>
<head>
<meta charset="utf-8">
<meta name="viewport" content="maximum-scale=1.0,minimum-scale=1.0,user-scalable=0,width=device-width,initial-scale=1.0"/>
<meta name="format-detection" content="telephone=no,email=no,date=no,address=no">
<title>Hello APP</title>
<link rel="stylesheet" type="text/css" href="./css/api.css" />
<style type="text/css">
</style>
</head>
<body>
</body>
<script type="text/javascript" src="./script/api.js" ></script>
<script type="text/javascript" src="./script/aui-tab.js" ></script>
<script type="text/javascript" src="./script/mylib.js"></script>
<script type="text/javascript">
apiready = function(){
api.parseTapmode();
funIniGroup()
function funIniGroup(){
var frame_name=['index','menu','community','shopcart','my'],
frames = [];
for (var i = 0,len = frame_name.length; i < len; i++) {
frames.push( {
name: frame_name[i],
url: './html/'+frame_name[i]+'.html',
bgColor : '#fff',
scrollEnabled: true,
bounces:false,
})
}
api.openFrameGroup({
name: 'group',
index: 0,
frames: frames
}, function (ret, err) {
});
}
}
</script>
</html>
mylib.js
function select_footer(id){
// 设置 frame 组当前可见 frame
api.setFrameGroupIndex({
name: 'group',
index: id,
});
if(id == 3){
api.setFrameGroupIndex({
name: 'group',
index: 3,
reload:true
});
}
}
html/home.html
<!DOCTYPE html>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
<meta charset="utf-8" />
<meta name="viewport"
content="maximum-scale=1.0,minimum-scale=1.0,user-scalable=0,width=device-width,initial-scale=1.0" />
<meta name="format-detection" content="telephone=no,email=no,date=no,address=no" />
<meta name="apple-mobile-web-app-capable" content="yes" />
<meta name="apple-mobile-web-app-status-bar-style" content="black" />
<title>主页</title>
<link rel="stylesheet" type="text/css" href="../css/aui/aui.css" />
<link rel="stylesheet" type="text/css" href="../css/style.css" />
<link rel="stylesheet" type="text/css" href="../css/index.css" />
<link rel="stylesheet" type="text/css" href="../css/aui/aui-slide.css" />
<link rel="stylesheet" type="text/css" href="../font/iconfont.css">
<style type="text/css">
</style>
</head>
<body>
<footer class="aui-bar aui-bar-tab" id="footer" style="border-top: 1px solid #e1e1e1">
<div class="aui-bar-tab-item" tapmode >
<!-- <i class="aui-iconfont aui-icon-cart select"></i> -->
<img src="../image/footer/index2.png" alt="首页" />
<div class="aui-bar-tab-label aui-active">首页</div>
</div>
<div class="aui-bar-tab-item" tapmode onclick="select_footer(1);">
<!-- <i class="aui-iconfont aui-icon-cart"></i> -->
<img src="../image/footer/menu.png" alt="菜谱" />
<div class="aui-bar-tab-label">菜谱</div>
</div>
<div class="aui-bar-tab-item" tapmode onclick="select_footer(2);">
<!-- <i class="aui-iconfont aui-icon-cart"></i> -->
<img src="../image/footer/community.png" alt="社区" />
<div class="aui-bar-tab-label">社区</div>
</div>
<div class="aui-bar-tab-item" tapmode onclick="select_footer(3);">
<!-- <i class="aui-iconfont aui-icon-cart"></i> -->
<img src="../image/footer/shopcart.png" alt="购物车" />
<div class="aui-bar-tab-label">购物车</div>
</div>
<div class="aui-bar-tab-item" tapmode onclick="select_footer(4);">
<!-- <i class="aui-iconfont aui-icon-cart"></i> -->
<img src="../image/footer/my.png" alt="我的" />
<div class="aui-bar-tab-label">我的</div>
</div>
</footer>
</body>
<script type="text/javascript" src="../script/api.js"></script>
<script type="text/javascript" src="../script/mylib.js"></script>
<script type="text/javascript" src="../script/aui/aui-tab.js"></script>
<script>
apiready = function () {
}
</script>
</html>