这段时间再用apicloud的app开发,在这里做一下总结,主要是用apicloud构建app,vue绑定数据,zepto操作dom。
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>第一个应用</title>
<link rel="stylesheet" type="text/css" href="./css/api.css" />
<link rel="stylesheet" type="text/css" href="./css/common.css" />
</head>
<body ontouchstart="">
<div id="wrap">
<div id="main">
</div>
<div id="footer">
<ul id="footer_list">
<li class="list_li home active" onclick="changeIndexFrame(0);" tapmode="tap-active">
<span class="text">首页</span>
</li>
<li class="list_li loan" onclick="changeIndexFrame(1);" tapmode="tap-active">
<span class="text">home</span>
</li>
<li class="list_li profile" onclick="changeIndexFrame(2);" tapmode="tap-active">
<span class="text">我的</span>
</li>
<li class="list_bar">
<div class="list_bar_inner"></div>
</li>
</ul>
</div>
</div>
</body>
<script type="text/javascript" src="./script/api.js"></script>
<script type="text/javascript" src="./script/index.js"></script>
</html>
index.js
//chrome上调试接口请求和页面渲染
setTimeout(function() {
if (typeof api == 'undefined') {
api = {
pageParam: {}
}
apiready();
}
}, 500);
// 下方tabBar
var aFooterList = $api.domAll('#footer_list .list_li');
var listBar = $api.dom('#footer_list .list_bar');
// tabBar切换状态,同时切换header与frame
var frameJson = {
'0': 'index',
'1': 'home',
'2': 'profile'
};
// 切换frame
var changeIndexFrame = function(index) {
console.log(index);
for (var i = 0; i < 3; i++) {
if (i == index) {
$api.addCls(aFooterList[index], 'active');
} else {
$api.removeCls(aFooterList[i], 'active');
}
};
listBar.style.webkitTransform = 'translateX(' + index * 100 + '%)';
openIndexFrames(index);
};
apiready = function() {
// 阻止首页弹动
api.setWinAttr({
bounces: false
});
window.header = $api.byId('header');
$api.fixStatusBar(header);
var headerPos = $api.offset(header);
var main = $api.byId('main');
var mainPos = $api.offset(main);
var footer = $api.byId('footer');
var footerPos = $api.offset(footer);
// 打开app先设置funIndex为0;
window.openIndexFrames = function(index) {
console.log(frameJson[index]);
api.openFrame({
name: frameJson[index],
url: './html/main/' + frameJson[index] + '.html',
bounces: false,
opaque: false,
rect: {
x: 0,
// y: headerPos.h,
w: 'auto',
h: mainPos.h
}
});
};
//设置默认打开
changeIndexFrame(0);
};
common.css
html,
body {
height: 100%;
/*background-color: #EEEEF0;*/
}
#wrap {
height: 100%;
display: -webkit-box;
display: -webkit-flex;
display: flex;
-webkit-box-orient: vertical;
-webkit-flex-flow: column;
flex-flow: column;
}
#header {
text-align: center;
padding-top: 0.8em;
background-color: #7b7b7b;
color: #ddd;
font-size: 20px;
width: 100%;
height: 48px;
position: relative;
}
#header h1 {
font-size: 20px;
height: 44px;
line-height: 44px;
margin: 0em;
color: #ddd;
}
#header h5 {
font-size: 1em;
}
#main {
-webkit-box-flex: 1;
-webkit-flex: 1;
flex: 1;
}
#main .title {
font-size: 0.8em;
text-indent: 1em;
}
#main .brief {
font-size: 0.6em;
text-indent: 1.3em;
}
#footer {
height: 50px;
line-height: 50px;
background: url(../image/index_bg.png) left bottom repeat-x;
background-size: 11px 50px;
background-color: #81a9c3;
width: 100%;
text-align: center;
}
#footer h5 {
color: #ddd;
}
.con {
font-size: 28px;
text-align: center;
}
#header.profile {
height: 0;
}
/*主页footer自定义*/
#footer_list {
height: 50px;
width: 100%;
position: relative;
}
#footer_list .list_li {
float: left;
height: 50px;
width: 33%;
position: relative;
}
#footer_list .list_bar {
position: absolute;
bottom: 0;
left: 0%;
height: 2px;
width: 33%;
-webkit-transform: translateX(0%);
transform: translateX(0%);
-webkit-transition: all .25s ease;
transition: all .25s ease;
}
#footer_list .list_bar .list_bar_inner {
position: absolute;
width: 50%;
height: 100%;
top: 0;
left: 50%;
background-color: #C50000;
-webkit-transform: translateX(-50%);
transform: translateX(-50%);
}
#footer_list .home {
background: url(../image/icon_home.png) center 6px no-repeat;
background-size: 22px 21px;
}
#footer_list .home.active {
background: url(../image/icon_home_selected.png) center 6px no-repeat;
background-size: 22px 21px;
}
#footer_list .loan {
background: url(../image/icon_loan.png) center 6px no-repeat;
background-size: 22px 21px;
}
#footer_list .loan.active {
background: url(../image/icon_loan_selected.png) center 6px no-repeat;
background-size: 22px 21px;
}
#footer_list .profile {
background: url(../image/icon_profile.png) center 6px no-repeat;
background-size: 22px 21px;
}
#footer_list .profile.active {
background: url(../image/icon_profile_selected.png) center 6px no-repeat;
background-size: 22px 21px;
}
#footer_list .list_li .text {
position: absolute;
width: 100%;
height: 1em;
line-height: 1em;
left: 0;
bottom: 7px;
color: #848C98;
font-size: 11px;
}
#footer_list .list_li.active .text {
color: #444F59;
}
/* common响应 */
.container {}
.container:after {
clear: both;
content: '';
display: block;
}
.sp1_3,
.sp2_3,
.sp1_3_big,
.sp1_2,
.sp1 {
margin-left: 0.75em;
float: left;
}
.clearfix:after {
content: '';
display: block;
clear: both;
}
.pull-left {
float: left;
}
.pull-right {
float: right;
}
/*轮播图*/
.swipe {
overflow: hidden;
position: relative;
width: 100%;
margin-top: 1em;
}
.swipe-wrap {
overflow: hidden;
position: relative;
}
.swipe-wrap .swipe-box {
float: left;
width: 100%;
position: relative;
}
.swipe-wrap img {
width: 100%;
display: block;
}
#title-box {
height: 30px;
width: 100%;
position: absolute;
left: 0;
top: 85px;
/*background-color: rgba(0,0,0,0.3);*/
}
#title-box-text {
color: #FFF;
text-align: left;
text-indent: 1em;
line-height: 30px;
}
#title-box-ul {
position: absolute;
right: 0;
top: 0;
padding-right: 12px;
font-size: 1em;
}
#title-box-ul li.active {
background: url(../image/slider_dot_current.png) transparent center center no-repeat;
background-size: 8px 8px;
}
#title-box-ul li {
width: 11px;
height: 30px;
line-height: 30px;
float: left;
background: url(../image/slider_dot.png) transparent center center no-repeat;
background-size: 8px 8px;
}
.hidden {
display: none !important;
}
/* common响应 end */
/*textarea:focus,
input:focus {
-webkit-tap-highlight-color: rgba(255, 255, 255, 0) !important;
-webkit-focus-ring-color: rgba(255, 255, 255, 0) !important;
outline: none !important;
}*/
home.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>home</title>
</head>
<body>
<header>
<a class="back-history" onclick="api.closeFrame({name:'loan'})"><img src="../../image/back-icon.png" alt=""></a>
<span>home</span>
</header>
<section>
<div>
<div class="fl">
<div>
<span class="current">tab</span>
</div>
</div>
<div class="fl">
<div>
<span>tab2</span>
</div>
</div>
</div>
<div>
<div class="tab-content">
<div>
<div id="home-row" class="loan-product" v-cloak>
<div class="pro clearfix" v-for="item in items">
<div class="fl">
<img :src="item.icon" class="fl" />
<div class="fl">
<ul>
<li>
<span>{{item.organ_name}}</span>
<u>-</u>
<span>{{item.product_name}}</span>
</li>
<li>
<span>
额度
</span>
<u>:</u>
<span>{{item.minamount}}-{{item.maxamount}}</span>
</li>
<li>
<span>
费率
</span>
<u>:</u>
<span>{{item.minrate}}-{{item.maxrate}}%</span>
</li>
</ul>
</div>
</div>
<div class="fr">
<ul>
<li>
<span>期限</span>
<u>:</u>
<span>{{item.minunit}}-{{item.maxunit}}月</span>
</li>
<li>
<u>{{item.apply_count}}+</u>
<span>人申请</span>
</li>
</ul>
</div>
</div>
</div>
</div>
</div>
</div>
</section>
</body>
<script type="text/javascript" src="../../script/api.js"></script>
<script type="text/javascript" src="../../script/zepto.js"></script>
<script type="text/javascript" src="../../script/vue.min.js"></script>
<script type="text/javascript" src="../../script/js/home.js"></script>
</html>
home.js
ajax请求
apiready = function() {
getHome();
}
//获取列表
var getHome = function() {
var str = JSON.stringify({ params: { type: 1} });
// alert(str);
var vm = new Vue({
el: '#home-row',
data: {
items: []
},
created: function() {
var that = this;
api.ajax({
method: 'post',
dataType: 'json',
headers: {
'Content-type': 'application/json',
'Accept': 'application/json'
},
url: service_url,
data: {
body: desen
}
}, function(ret, err) {
alert(JSON.stringify(ret));
});
}
})
}