apiCloud中实现头部与内容分离与操作规范,App头部header固定,头部与内容分离

简介:

官方案例

1.头部拆分成一个页面比如news-text

<!doctype html>
<html>
<head>
    <meta charset="utf-8">
    <meta name="viewport" content="initial-scale=1.0,maximum-scale=1.0,minimum-scale=1.0,user-scalable=0, width=device-width"/>
    <title>api</title>
    <link rel="stylesheet" type="text/css" href="../css/api.css" />
    <link rel="stylesheet" type="text/css" href="../css/common.css" />
    <link rel="stylesheet" type="text/css" href="../css/news-text.css" />
</head>
<body>
    <div id="wrap">
        <div id="header">
            <a class="back-icon" tapmode="" onclick="api.closeWin()"></a>
            <h1>热点新闻</h1>
        </div>
    </div>
</body>
<script type="text/javascript" src="../script/api.js"></script>
<script type="text/javascript" src="../script/news-text.js"></script>
</html>

 2.内容拆分成另一个页面比如news-textCon

<!doctype html>
<html>
<head>
    <meta charset="utf-8">
    <meta name="viewport" content="initial-scale=1.0,maximum-scale=1.0,minimum-scale=1.0,user-scalable=0, width=device-width"/>
    <title>api</title>
    <link rel="stylesheet" type="text/css" href="../css/api.css" />
    <link rel="stylesheet" type="text/css" href="../css/common.css" />
    <link rel="stylesheet" type="text/css" href="../css/news-text.css" />
</head>
<body>
    <div id="wrap">
        <div id="main">
        
            <script id="news-template" type="text/x-dot-template">
                <h1>{{=it.title}}</h1>
                <label>
                    {{? it.from }}
                        {{=it.from}}
                    {{?}}
                    <em>{{=it.date}}</em>
                </label>
                <div id="summary">
                    {{=it.summary}}
                </div>
                <div>
                    {{=it.content}}
                </div>
                
                <a id="fav" class="btn" tapmode="active" news-id="{{=it.id}}" >收藏</a>
                
            </script>
            
            <div id="content"></div>
            
        </div>
    </div>
</body>
<script type="text/javascript" src="../script/api.js"></script>
<script type="text/javascript" src="../script/common.js"></script>
<script type="text/javascript" src="../script/doT.min.js"></script>
<script type="text/javascript" src="../script/zepto.js"></script>
<script type="text/javascript" src="../script/news-textCon.js"></script>
</html>

以上就是一个非常规范的内容

1.css在头部

引入必要的css,api.css

引入通用的css,common.css

引入页面特有的css,news-text.css

2.js在尾部

引入必要的css,api.js

引入通用的css,common.js

引入页面特有的css,news-text.js

根据页面需要,引入doT模板和zepto(手机端的jQuery替代品)

来看看news-text.js中的内容


apiready = function(){
    var header = $api.byId('header'); // 获取头部
    $api.fixStatusBar(header); // 处理ios兼容
    
    var newsId = api.pageParam.newsId; // 获取参数
    var pos = $api.offset(header); // 获取位置数据
    api.openFrame({ // 打开Frame
        name: 'news-textCon',
        url: 'news-textCon.html',
        pageParam: {newsId: newsId}, // 传递参数
        rect:{
            x: 0,
            y: pos.h, // 头部留位置
            w: 'auto',
            h: 'auto'
        },
        bounces: true,
        vScrollBarEnabled: false
    });
};

打开frame,保证头部留有位置,同时可以传递参数

再看看news-textCon.js中的内容

apiready = function () {
    var newsId = api.pageParam.newsId; // 获取参数
    var getNewsByIdUrl = '/news/?filter=';
    var urlParam = {where: {id: newsId}};
    api.showProgress({
        title: '加载中...',
        modal: false
    });
    ajaxRequest(getNewsByIdUrl+JSON.stringify(urlParam),'get','',function(ret,err){
        if (ret) {
            api.toast({
                ...
            })
        } else {
            api.toast({
                ...
            })
        }
        api.hideProgress();
    });
};

获取传入的参数,

获取数据与相应的页面处理

我的案例

商品详情拆分

1.goods_detail.html
<!doctype html>
<html>
<head>
    <meta charset="utf-8">
    <meta name="viewport" content="initial-scale=1.0,maximum-scale=1.0,minimum-scale=1.0,user-scalable=0, width=device-width"/>
    <title>api</title>
    <link rel="stylesheet" type="text/css" href="../css/api.css" />
    <link rel="stylesheet" type="text/css" href="../css/aui.2.0.css" />
</head>
<body>
<div id="wrap">
    <div id="main">
        <header class="aui-bar aui-bar-nav fix-status-bar" id="aui-header">
            <a class="aui-btn aui-pull-left" tapmode onclick="api.closeWin();">
                <span class="aui-iconfont aui-icon-left"></span>
            </a>
            <div class="aui-title"><!-- 商品名称 --></div>
        </header>

    </div>
</div>
</body>
<script type="text/javascript" src="../script/api.js"></script>
<script type="text/javascript" src="../script/goods_detail.js"></script>

</html>
2.goods_detailCon.html

移除头部的

<header class="aui-bar aui-bar-nav fix-status-bar" id="aui-header">
            <a class="aui-btn aui-pull-left" tapmode onclick="api.closeWin();">
                <span class="aui-iconfont aui-icon-left"></span>
            </a>
            <div class="aui-title"><!-- 商品名称 --></div>
</header>
3.goods_detail.js
apiready = function(){
    var header = $api.byId('main'); // 获取头部
    $api.fixStatusBar(header); // 处理ios
    var pos = $api.offset(header); // 获取头部位置
    var title  = $api.dom(header,'.aui-title'); // 获取标题位置
    $api.html(title,api.pageParam.title); // 设置标题内容
    api.openFrame({ // 打开内容页,并传递参数
        name: 'goods_detailCon',
        url: 'goods_detailCon.html',
        rect:{
            x: 0,
            y: pos.h,
            w: 'auto',
            h: 'auto'
        },
        bounces: true,
        opaque: true,
        vScrollBarEnabled: false,
        pageParam:{
            goods_id:api.pageParam.goods_id
        }
    });
};
4.goods_detailCon.js
apiready = function(){
    fix_status_bar();// 修复头部
    var goods_id = api.pageParam.goods_id;
    // 获取商品相关信息
    api.ajax({
        url: 'http://zhudianbao.yunlutong.com/?g=Api&m=Goods&a=getGoodsInfo',
        method: 'get',
        data: {
            values: {
                goods_id: goods_id
            }
        }
    }, function(json, err) {
        if (json.status == '1') {
            var interText = doT.template($("#goodstmpl").text());
            $("#info_area").html(interText(json.info));
            var swiper = new Swiper('.swiper-container', {
                pagination: '.swiper-pagination',
                paginationClickable: true,
                spaceBetween: 30,
                centeredSlides: true,
                autoplay: 3500,
                autoplayDisableOnInteraction: false
            });
        } else {
            var toast = new auiToast();
            toast.fail({
                title:json.msg,
                duration:2000
            });
        }
    });
}

获取参数,根据参数获取数据,并使用doT进行页面布局。

看效果
422101-20161012150629203-388344045.png

422101-20161012150636578-324847631.png


本文转自TBHacker博客园博客,原文链接:http://www.cnblogs.com/jiqing9006/p/5952935.html,如需转载请自行联系原作者

相关文章
|
2天前
uni-app 4.4封装头部导航组件(二)
uni-app 4.4封装头部导航组件(二)
13 0
|
2天前
uni-app头部导航组件开发(4.1)
uni-app头部导航组件开发(4.1)
20 0
|
10月前
|
测试技术 iOS开发
|
6月前
|
开发工具 Android开发 iOS开发
2023年APP备案操作教程 阿里云APP备案试列 APP公钥sha1签名获取方法
核心要点:A,域名之前是哪里备案的,APP备案就到哪里去做,方便简单;B,APP备案核心预存信息为APP包名、MD5指纹(安卓)、sha1签名(IOS)、公钥;这3个信息请找APP开发人员获取;一门开发的可以自行到开发者后台【配置】-【证书与包名】获取对应安卓、苹果APP信息。
|
2天前
|
Java Android开发
常见APP的操作
常见APP的操作
15 0
|
2天前
|
测试技术 Android开发
快速上手App自动化测试利器,Toast原理解析及操作实例
`Toast`是Android中的轻量级通知,短暂显示在屏幕任意位置,1-2秒后自动消失,不获取焦点且不可点击。Appium通过uiautomator2在控件树中处理Toast。在测试中,可设置隐式等待,利用XPath或Accessibility ID定位Toast元素进行检测和验证。示例代码展示了如何初始化driver,点击触发Toast,以及如何定位并读取Toast文本。
28 3
|
2天前
uni-app 4.3封装头部导航组件(一)
uni-app 4.3封装头部导航组件(一)
17 0
|
2天前
|
测试技术 API 数据安全/隐私保护
『App自动化测试之Appium应用篇』| Appium常用API及操作
『App自动化测试之Appium应用篇』| Appium常用API及操作
86 1
|
2天前
|
算法 Java 数据安全/隐私保护
Android App开发之利用JNI实现加密和解密操作实战(附源码 简单易懂)
Android App开发之利用JNI实现加密和解密操作实战(附源码 简单易懂)
84 0
|
6月前
|
前端开发 Linux Android开发
请问阿里云rpa可以模拟手机app操作么?
请问阿里云rpa可以模拟手机app操作么?
107 1